[Home] [Prev] [Next] [Index]
13.4 Record Representation Clauses
13.4 Record Representation Clauses
- 1
- A record representation clause specifies the storage representation of records, that is, the order, position, and size of record components (including discriminants, if any).
- 2
- record_representation_clause ::=
for
type_simple_name use
record
[alignment_clause]
{component clause}
end record
;
alignment_clause ::= at mod
static_simple_expression;
component_clause ::=
component_name at
static_simple_expression range
static_range;
- 3
- The simple expression given after the reserved words
at mod
in an alignment clause, or after the reserved word at
in a component clause, must be a static expression of some integer type. If the bounds of the range of a component clause are defined by simple expressions, then each bound of the range must be defined by a static expression of some integer type, but the two bounds need not have the same integer type.
- 4
- An alignment clause forces each record of the given type to be allocated at a starting address that is a multiple of the value of the given expression (that is, the address modulo the expression must be zero). An implementation may place restrictions on the allowable alignments.
- 5
- A component clause specifies the storage place of a component, relative to the start of the record. The integer defined by the static expression of a component clause is a relative address expressed in storage units. The range defines the bit positions of the storage place, relative to the storage unit. The first storage unit of a record is numbered zero.The first bit of a storage unit is numbered zero. The ordering of bits in a storage unit is machine_dependent and may extend to adjacent storage units (For a specific machine, the size in bits of a storage unit is given by the configuration-dependent named number SYSTEM.STORAGE_UNIT.) Whether a component is allowed to overlap a storage boundary, and if so, how, is implementation-defined.
- 6
- At most one component clause is allowed for each component of the record type, including for each discriminant (component clauses may be given for some, all, or none of the components). If no component clause is given for a component, then the choice of the storage place for the component is left to the compiler. If component clauses are given for all components, the record representation clause completely specifies the representation of the record type and must be obeyed exactly by the compiler.
- 7
- Storage places within a record variant must not overlap, but overlap of the storage for distinct variants is allowed. Each component clause must allow for enough storage space to accommodate every allowable value of the component. A component clause is only allowed for a component if any constraint on this component or on any of its subcomponents is static.
- 8
- An implementation may generate names that denote implementation-dependent components (for example, one containing the offset of another component). Such implementation-dependent names can be used in record representation clauses (these names need not be simple names; for example, they could be implementation-dependent attributes).
- 9
- Example:
WORD : constant
:= 4; -- storage unit is byte, 4 bytes per word
type
STATE is
(A,M,W,P);
type
MODE is
(FIX, DEC, EXP, SIGNIF);
type
BYTE_MASK is array
(0.. 7) of
BOOLEAN;
type
STATE_MASK is array
(STATE) of
BOOLEAN;
type
MODE_MASK is array
(MODE) of
BOOLEAN;
type
PROGRAM_STATUS_WORD is
record
SYSTEM_MASK : BYTE_MASK;
PROTECTION_KEY : INTEGER range
0 .. 3;
MACHINE_STATE : STATE_MASK;
INTERRUPT_CAUSE : INTERRUPTION_CODE;
ILC : INTEGER range
0 .. 3;
CC : INTEGER range
0 .. 3;
PROGRAM_MASK : MODE_MASK;
INST_ADDRESS : ADDRESS;
end record
;
for
PROGRAM_STATUS_WORD use
record at mod
8;
SYSTEM_MASK at
0*WORD range
0 .. 7;
PROTECTION_KEY at
0*WORD range
10 .. 11; -- bits 8,9
-- unused
MACHINE_STATE at
0*WORD range
12 .. 15;
INTERRUPT_CAUSE at
0*WORD range
16 .. 31;
ILC at
1*WORD range
0 .. 1; -- second word
CC at
1*WORD range
2 .. 3;
PROGRAM_MASK at
1*WORD range
4 .. 7;
INST_ADDRESS at
1*WORD range
8 .. 31;
end record
;
for
PROGRAM_STATUS_WORD'SIZE use
8*SYSTEM.STORAGE_UNIT;
- Note on the example:
- 10
- The record representation clause defines the record layout. The length clause guarantees that exactly eight storage units are used.
- 11
- References:

- allow 1.6

- attribute 4.1.4

- constant 3.2.1

- constraint 3.3

- discriminant 3.7.1

- integer type 3.5.4

- must 1.6

- named number 3.2

- range 3.5

- record component 3.7

- record type 3.7

- simple expression 4.4

- simple name 4.1

- static constraint 4.9

- static expression 4.9

- storage unit 13.7

- subcomponent 3.3

- system package 13.7

- variant 3.7.3
[Home] [Prev] [Next] [Index]
documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights
reserved.