next up previous contents
Next: Processing Local Declarations Up: Feature and Local Declarations Previous: Scope Rules

Attributes

 
  attribute ::= [ 'shared' ] [ 'readonly' ] attribute_declaration .
  attribute_declaration::= attribute_specification |
                           initialized_attribute_specification .
  attribute_specification::= identifiers ':' type_specifier .
  initialized_attribute_specification ::=
                [ 'constant' ] ( attribute_specification ':=' general_expression |
                              identifiers ':' type_constructor ) .
For general expressions see 7.

An attribute is defined by an attribute declaration. It introduces the identifier, the type and the initial value of the attribute. Several attribute declarations may be combined into one in which case all attributes have the same type and the same initial value. The initial value is only computed once. If no initial value is specified then attributes of a reference type are automatically initialized by the value void. For value attributes the initialization is implementation dependent.

Shared attributes, declared with the keyword shared, simultaneously belong to all objects of the class.

For accessing an attribute the scope rules of section 5.1 apply. In particular any qualified access name.a will result in a procedure call tex2html_wrap_inline2315 or name.a depending on whether there was a write or read access.

Access to shared attributes follows the same rules. Additionally a shared attribute a, declared in class C may be accessed by C::a without mentioning any object. This is particularly useful before any object of class C is created. It also allows access to shared attributes of abstract or external classes.

The declarations of shared attributes of a class are processed in textual order prior to calling the procedure main in the main class. The initializing expressions for shared attributes can only contain constant values or other shared attributes as operands; they may only call procedures which do not refer to non-shared attributes in their body.

If the initialization of a shared attribute a in class C refers to another shared attribute b or to a procedure r of class C' then the declaration of b must either textually precede the given declaration in the same class or the declarations of the shared features of the class C' must already be processed before class C is processed. The implied order must have a common acyclic refinement and the classes are considered in the order of such a refinement.

All non-shared attribute declarations in a class C are processed in textual order whenever an object o of class C is created.

An attribute declaration comprising a type constructor (cf. 7.1) is an abbreviation for a declaration of an attribute of the type constructor initialized with the value resulting from the type constructor. In case of value types the declarations tex2html_wrap_inline2349 and tex2html_wrap_inline2351 are equivalent.

Note: In case of constant attributes only the quantity is constant. Thus if its value designates a reference or value object then nevertheless assignments to non-constant attributes of such an object are allowed. tex2html_wrap_inline1707


next up previous contents
Next: Processing Local Declarations Up: Feature and Local Declarations Previous: Scope Rules

Martin Trapp
Mon Feb 17 16:49:16 MET 1997