13.1 Operational and Representation Items
Representation and operational items can be used
to specify aspects of entities. Two kinds of aspects of entities can
be specified: aspects of representation and operational aspects. Representation
items specify how the types and other entities of the language are to
be mapped onto the underlying machine. Operational items specify other
properties of entities.
An operational item or a representation item applies
to an entity identified by a
local_name,
which denotes an entity declared local to the current declarative region,
or a library unit declared immediately preceding a representation pragma
in a
compilation.
Syntax
Name Resolution Rules
In an operational item or representation item, if
the
local_name
is a
direct_name,
then it shall resolve to denote a declaration (or, in the case of a
pragma,
one or more declarations) that occurs immediately within the same declarative
region as the item. If the
local_name
has an
attribute_designator,
then it shall resolve to denote an implementation-defined component (see
13.5.1) or a class-wide type implicitly
declared immediately within the same declarative region as the item.
A
local_name
that is a
library_unit_name
(only permitted in a representation pragma) shall resolve to denote the
library_item
that immediately precedes (except for other pragmas) the representation
pragma.
Legality Rules
The
representation
of an object consists of a certain number of bits (the
size of
the object). For an object of an elementary type, these are the bits
that are normally read or updated by the machine code when loading, storing,
or operating-on the value of the object. For an object of a composite
type, these are the bits reserved for this object, and include bits occupied
by subcomponents of the object. If the size of an object is greater than
that of its subtype, the additional bits are padding bits.
For
an elementary object, these padding bits are normally read and updated
along with the others. For a composite object, padding bits might not
be read or updated in any given composite operation, depending on the
implementation.
A
representation item
directly specifies an
aspect of representation
of the entity denoted by the
local_name,
except in the case of a type-related representation item, whose
local_name
shall denote a first subtype, and which directly specifies an aspect
of the subtype's type.
A
representation item that names a subtype is either
subtype-specific
(Size and Alignment clauses) or
type-related (all others). Subtype-specific
aspects may differ for different subtypes of the same type.
An operational item
directly specifies an
operational aspect of the type of the subtype denoted by the
local_name.
The
local_name
of an operational item shall denote a first subtype. An operational item
that names a subtype is type-related.
A representation item that directly specifies an
aspect of a subtype or type shall appear after the type is completely
defined (see
3.11.1), and before the subtype
or type is frozen (see
13.14). If a representation
item is given that directly specifies an aspect of an entity, then it
is illegal to give another representation item that directly specifies
the same aspect of the entity.
An operational item that directly specifies an aspect
of a type shall appear before the type is frozen (see
13.14).
If an operational item is given that directly specifies an aspect of
a type, then it is illegal to give another operational item that directly
specifies the same aspect of the type.
For an untagged derived type, no type-related representation
items are allowed if the parent type is a by-reference type, or has any
user-defined primitive subprograms.
Operational and representation aspects of a generic
formal parameter are the same as those of the actual. Operational and
representation aspects are the same for all views of a type. A type-related
representation item is not allowed for a descendant of a generic formal
untagged type.
A representation item that specifies the Size for
a given subtype, or the size or storage place for an object (including
a component) of a given subtype, shall allow for enough storage space
to accommodate any value of the subtype.
A representation or operational item that is not
supported by the implementation is illegal, or raises an exception at
run time.
A
type_declaration
is illegal if it has one or more progenitors, and a representation item
applies to an ancestor, and this representation item conflicts with the
representation of some other ancestor. The cases that cause conflicts
are implementation defined.
Static Semantics
If two subtypes statically match, then their subtype-specific
aspects (Size and Alignment) are the same.
A derived type inherits each type-related aspect
of representation of its parent type that was directly specified before
the declaration of the derived type, or (in the case where the parent
is derived) that was inherited by the parent type from the grandparent
type. A derived subtype inherits each subtype-specific aspect of representation
of its parent subtype that was directly specified before the declaration
of the derived type, or (in the case where the parent is derived) that
was inherited by the parent subtype from the grandparent subtype, but
only if the parent subtype statically matches the first subtype of the
parent type. An inherited aspect of representation is overridden by a
subsequent representation item that specifies the same aspect of the
type or subtype.
In contrast, whether operational aspects are inherited
by an untagged derived type depends on each specific aspect. Operational
aspects are never inherited for a tagged type. When operational aspects
are inherited by an untagged derived type, aspects that were directly
specified by operational items that are visible at the point of the derived
type declaration, or (in the case where the parent is derived) that were
inherited by the parent type from the grandparent type are inherited.
An inherited operational aspect is overridden by a subsequent operational
item that specifies the same aspect of the type.
When an aspect that is a subprogram is inherited,
the derived type inherits the aspect in the same way that a derived type
inherits a user-defined primitive subprogram from its parent (see
3.4).
Each aspect of representation
of an entity is as follows:
If the aspect is
specified
for the entity, meaning that it is either directly specified or inherited,
then that aspect of the entity is as specified, except in the case of
Storage_Size, which specifies a minimum.
If an aspect of representation
of an entity is not specified, it is chosen by default in an unspecified
manner.
If an operational aspect is
specified for an entity (meaning that it is either directly specified
or inherited), then that aspect of the entity is as specified. Otherwise,
the aspect of the entity has the default value for that aspect.
A representation item that specifies an aspect
of representation that would have been chosen in the absence of the representation
item is said to be
confirming.
Dynamic Semantics
For the elaboration of an
aspect_clause,
any evaluable constructs within it are evaluated.
Implementation Permissions
An implementation may interpret aspects of representation
in an implementation-defined manner. An implementation may place implementation-defined
restrictions on representation items.
A
recommended
level of support is specified for representation items and related
features in each subclause. These recommendations are changed to requirements
for implementations that support the Systems Programming Annex (see
C.2,
“
Required Representation Support”).
Implementation Advice
The
recommended level of support for all representation items is qualified
as follows:
A confirming representation item should be supported.
An implementation need not support representation
items containing nonstatic expressions, except that an implementation
should support a representation item for a given entity if each nonstatic
expression in the representation item is a name that statically denotes
a constant declared before the entity.
An implementation need not support a specification
for the Size for a given composite subtype, nor the size or storage place
for an object (including a component) of a given composite subtype, unless
the constraints on the subtype and its composite subcomponents (if any)
are all static constraints.
An implementation need not support a nonconfirming
representation item if it could cause an aliased object or an object
of a by-reference type to be allocated at a nonaddressable location or,
when the alignment attribute of the subtype of such an object is nonzero,
at an address that is not an integral multiple of that alignment.
An implementation need not support a nonconfirming
representation item if it could cause an aliased object of an elementary
type to have a size other than that which would have been chosen by default.
An implementation need not support a nonconfirming
representation item if it could cause an aliased object of a composite
type, or an object whose type is by-reference, to have a size smaller
than that which would have been chosen by default.
An implementation need not support a nonconfirming
subtype-specific representation item specifying an aspect of representation
of an indefinite or abstract subtype.
For purposes of these rules, the determination of
whether a representation item applied to a type could cause an
object to have some property is based solely on the properties of the
type itself, not on any available information about how the type is used.
In particular, it presumes that minimally aligned objects of this type
might be declared at some point.