Chapter 2. Implementation-Defined Attributes

The Ada 95 Reference Manual defines a set of attributes that provide useful additional functionality in all areas of the language. These language defined attributes are implemented in XGC Ada and work as described in the Manual.

In addition, Ada 95 allows implementations to define additional attributes whose meaning is defined by the implementation. XGC Ada provides a number of these implementation-dependent attributes which can be used to extend and enhance the functionality of the compiler. This section of the reference manual describes these additional attributes.

Address_Size

Standard'Address_Size (Standard is the only allowed prefix) is a static constant giving the number of bits in an Address. It is used primarily for constructing the definition of Memory_Size in package Standard, but may be freely used in user programs.

Bit

obj'Bit, where obj is any object, yields the bit offset within the storage unit (byte) that contains the first bit of storage allocated for the object. The value of this attribute is of the type Universal_Integer, and is always a non-negative number not exceeding the value of System.Storage_Unit.

For an object that is a variable or a constant allocated in a register, the value is zero. (The use of this attribute does not force the allocation of a variable to memory).

For an object that is a formal parameter, this attribute applies to either the matching actual parameter or to a copy of the matching actual parameter.

For an access object the value is zero. Note that obj.all'Bit is subject to an Access_Check for the designated object. Similarly for a record component X.C'Bit is subject to a discriminant check and X(I).Bit and X(I1..I2)'Bit are subject to index checks.

Bit_Position

R.C'Bit, where R is a record object and C is one of the fields of the record type, yields the bit offset within the record contains the first bit of storage allocated for the object. The value of this attribute is of the type Universal_Integer. The value depends only on the field C and is independent of the alignment of the containing record R.

Code_Address

The 'Address attribute may be applied to subprograms in Ada 95, but the intended effect from the Ada 95 Reference Manual seems to be to provide an address value which can be used to call the subprogram by means of an address clause as in the following example:

procedure K is ...
procedure L;
for L'Address use K'Address;
pragma Import (Ada, L);

A call to L is then expected to result in a call to K. In Ada 83, where there were no access-to-subprogram values, this was a common work around for getting the effect of an indirect call. XGC Ada implements the above use of Address and the technique illustrated by the example code works correctly.

However, for some purposes, it is useful to have the address of the start of the generated code for the subprogram. On some architectures, this is not necessarily the same as the Address value described above. For example, the Address value may reference a subprogram descriptor rather than the subprogram itself.

The 'Code_Address attribute, which can only be applied to subprogram entities, always returns the address of the start of the generated code of the specified subprogram, which may or may not be the same value as is returned by the corresponding 'Address attribute.

Default_Bit_Order

Standard'Default_Bit_Order (Standard is the only permissible prefix), provides the value System.Default_Bit_Order as a Pos value (0 for High_Order_First, 1 for Low_Order_First). This is used to construct the definition of Default_Bit_Order in package System.

Elaborated

The prefix of the 'Elaborated attribute must be a unit name. The value is a Boolean which indicates whether or not the given unit has been elaborated. This attribute is primarily intended for internal use by the generated code for dynamic elaboration checking, but it can also be used in user programs. The value will always be True once elaboration of all units has been completed.

Elab_Body

This attribute can only be applied to a program unit name. It returns the entity for the corresponding elaboration procedure for elaborating the body of the referenced unit. This is used in the main generated elaboration procedure by the binder and is not normally used in any other context. However, there may be specialized situations in which it is useful to be able to call this elaboration procedure from Ada code, for example if it is necessary to do selective re-elaboration to fix some error.

Elab_Spec

This attribute can only be applied to a program unit name. It returns the entity for the corresponding elaboration procedure for elaborating the specification of the referenced unit. This is used in the main generated elaboration procedure by the binder and is not normally used in any other context. However, there may be specialized situations in which it is useful to be able to call this elaboration procedure from Ada code, for example if it is necessary to do selective re-elaboration to fix some error.

Enum_Rep

For every enumeration subtype S, S'Enum_Rep denotes a function with the following specification:

function S'Enum_Rep (Arg : S'Base) return Universal_Integer;

The function returns the representation value for the given enumeration value. This will be equal to value of the Pos attribute in the absence of an enumeration representation clause. This is a static attribute (that is the result is static if the argument is static).

Fixed_Value

For every fixed-point type S, S'Fixed_Value denotes a function with the following specification:

function S'Fixed_Value (Arg : Universal_Integer) return S;

The value returned is the fixed-point value V such that

V = Arg * S'Small

The effect is thus equivalent to first converting the argument to the integer type used to represent S, and then doing an unchecked conversion to the fixed-point type. This attribute is primarily intended for use in implementation of the input-output functions for fixed-point values.

Has_Discriminants

The prefix of the Has_Disctriminants attribute is a type. The result is a Boolean value which is True if the type has discriminants, and False otherwise. The intended use of this attribute is in conjunction with generic definitions. If the attribute is applied to a generic private type, it indicates whether or not the corresponding actual type has discriminants.

Integer_Value

For every integer type S, S'Integer_Value denotes a function with the following specification:

function S'Integer_Value (Arg : Universal_Fixed) return S;

The value returned is the integer value V, such that

Arg = V * type'Small

The effect is thus equivalent to first doing an unchecked convert from the fixed-point type to its corresponding implementation type, and then converting the result to the target integer type. This attribute is primarily intended for use in implementation of the standard input-output functions for fixed-point values.

Machine_Size

This attribute is identical to the Object_Size attribute. It is provided for compatibility with other Ada compilers.

Max_Interrupt_Priority

Standard'Max_Interrupt_Priority (Standard is the only permissible prefix), provides the value System.Max_Interrupt_Priority and is intended primarily for constructing this definition in package System.

Max_Priority

Standard'Max_Priority (Standard is the only permissible prefix) provides the value System.Max_Priority and is intended primarily for constructing this definition in package System.

Maximum_Alignment

Standard'Maximum_Alignment (Standard is the only permissible prefix) provides the maximum useful alignment value for the target. This is a static value that can be used to specify the alignment for an object, guaranteeing that it is properly aligned in all cases. This is useful when an external object is imported and its alignment requirements are unknown.

Mechanism_Code

function'Mechanism_Code yields an integer code for the mechanism used for the result of function, and subprogram'Mechanism_Code(n) yields the mechanism used for formal parameter number n (a static integer value with 1 meaning the first parameter) of subprogram. The code returned is 1 for by copy and 2 for by reference.

Null_Parameter

A reference T'Null_Parameter denotes an imaginary object of type or subtype T allocated at machine address zero. The attribute is allowed only as the default expression of a formal parameter, or as an actual expression of a subporgram call. In either case, the subprogram must be imported.

The identity of the object is represented by the address zero in the argument list, independent of the passing mechanism (explicit or default).

This capability is needed to specify that a zero address should be passed for a record or other composite object passed by reference. There is no way of indicating this without the Null_Parameter attribute.

Object_Size

The size of an object is not necessarily the same as the size of the type of an object. This is because by default object sizes are increased to be a multiple of the alignment of the object. For example, Natural'Size is 31, but by default objects of type Natural will have a size of 32 bits. Similarly, a record containing an integer and a character:

type Rec is record
   I : Integer;
   C : Character;
end record;

will have a size of 40 (that is Rec'Size will be 40. The alignment will be 4, because of the integer field, and so the default size of record objects for this type will be 64 (8 bytes).

The type'Object_Size attribute has been added to XGC Ada to allow the default object size of a type to be easily determined. For example, Natural'Object_Size is 32, and Rec'Object_Size (for the record type in the above example) will be 64. Note also that, unlike the situation with the Size attribute as defined in the Ada 95 Reference Manual, the Object_Size attribute can be specified individually for different subtypes. For example:

type R is new Integer;
subtype R1 is R range 1 .. 10;
subtype R2 is R range 1 .. 10;
for R2'Object_Size use 8;

In this example, R'Object_Size and R1'Object_Size are both 32 since the default object size for a subtype is the same as the object size for the the parent subtype. This means that objects of type R or R1 will by default be 32 bits (four bytes). But objects of type R2 will be only 8 bits (one byte), since R2'Object_Size has been set to 8.

Passed_By_Reference

type'Passed_By_Reference for any subtype type returns a value of type Boolean value that is True if the type is normally passed by reference and False if the type is normally passed by copy in calls. For scalar types, the result is always False and is static. For non-scalar types, the result is non-static.

Range_Length

type'Range_Length for any discrete type type yields the number of values represented by the subtype (zero for a null range). The result is static for static subtypes. Range_Length applied to the index subtype of a one dimensional array always gives the same result as Range applied to the array itself.

Storage_Unit

Standard'Storage_Unit (Standard is the only permissible prefix) provides the value System.Storage_Unit and is intended primarily for constructing this definition in package System.

Tick

Standard'Tick (Standard is the only permissible prefix) provides the value of System.Tick and is intended primarily for constructing this definition in package System.

Type_Class

type'Type_Class for any type or subtype type yields the value of the type class for the full type of type. If type is a generic formal type, the value is the value for the corresponding actual subtype. The value of this attribute is of a type that has the following definition:

type Type_Class is
  (Type_Class_Enumeration,
   Type_Class_Integer,
   Type_Class_Fixed_Point,
   Type_Class_Floating_Point,
   Type_Class_Array,
   Type_Class_Record,
   Type_Class_Access,
   Type_Class_Task,
   Type_Class_Address); 

Protected types yield the value Type_Class_Task, which thus applies to all concurrent types.

Unrestricted_Access

The Unrestricted_Access attribute is similar to Access except that all accessibility and aliased view checks are omitted. This is very much a user-beware attribute. It is very similar to Address, for which it is a desirable replacement where the value desired is an access type. In other words, its effect is identical to first applying the Address attribute and then doing an unchecked conversion to a desired access type. In XGC Ada, but not necessarily in other implementations, the use of static chains for inner level subprograms means that Unrestricted_Access applied to a subprogram yields a value that can be called as long as the subprogram is in scope (normal Ada 95 accessibility rules restrict this usage).

Value_Size

type'Value_Size is the number of bits required to represent a value of the given subtype. It is the same as type'Size, but, unlike Size, may be set for non-first subtypes.

Word_Size

Standard'Word_Size (Standard is the only permissible prefix) provides the value System.Word_Size and is intended primarily for constructing this definition in package System.