Previous | Contents | Index |
AGGREGATE operator STRUCTURE PREFIX opr$; id WORD; "typename" CHARACTER; CONSTANT (fixed_bin_,float_) EQUALS 0 INCREMENT 1; bits STRUCTURE; variable_size BITFIELD; size_units BITFIELD LENGTH 3; END bits; END operator; |
In the previous example, the member name "typename" is enclosed in quotation marks because it is a HP SDL keyword.
The previous declaration produces the following names, with the prefix opr$ and default tags, in the Kednos PL/I output file:
%replace opr$k_fixed_bin_ by 0; %replace opr$k_float_ by 1; %replace opr$s_operator by 4; dcl 1 operator based, 2 opr$w_id fixed binary(15), 2 opr$t_typename character(1), 2 opr$r_bits , 3 opr$v_variable_size bit(1), 3 opr$v_size_units bit(3), 3 opr$v_fill_0 bit(4); |
The name opr$v_fill_0 in the previous list is the result of a BITFIELD declaration that HP SDL supplied because the subaggregate did not end on a byte boundary. The name (opr$v_fill_0) ensures that the next aggregate begins on a byte boundary. Section 4.5.7 describes data alignment in detail. HP SDL uses default codes followed by an underscore (_) for the tag portion of a prefix when the TAG option is not specified. You can override the default OpenVMS codes by specifying a tag, which may be null (" "). For example:
CONSTANT (abc,def,ghi) EQUALS 0 INCREMENT 1 PREFIX new TAG ""; |
This declaration results in the names new_abc,
new_def, and new_ghi.
Both the ALIGN and BASEALIGN keywords can ensure that items are
properly aligned. The BASEALIGN keyword takes an argument, which
specifies the alignment, whereas the ALIGN keyword uses the natural
alignment of the item.
The size of the aggregate will be a multiple of 4 ( 22 ), in
this case 12, and neither i1 nor i2 will be aligned.
3.2.2.3 Alignment Keywords
AGGREGATE MyStruct STRUCTURE ALIGN;
c1 CHARACTER;
i1 LONGWORD;
c2 CHARACTER;
i2 LONGWORD;
END;
AGGREGATE MyStruct STRUCTURE NOALIGN;
c CHARACTER;
i1 LONGWORD;
i2 LONGWORD ALIGN;
END;
AGGREGATE MyStruct STRUCTURE ALIGN;
c CHARACTER;
i1 LONGWORD NOALIGN;
i2 LONGWORD;
END;
AGGREGATE MyStruct STRUCTURE NOALIGN;
c CHARACTER;
i1 LONGWORD;
i2 LONGWORD;
END;
AGGREGATE MyStruct STRUCTURE NOALIGN;
c CHARACTER;
i1 LONGWORD;
i2 LONGWORD BASEALIGN(8);
END;
AGGREGATE MyStruct STRUCTURE BASEALIGN (2);
c CHARACTER;
i1 LONGWORD;
i2 LONGWORD;
END;
In the
following example, the item will have a size of 8 ( 23 ).
ITEM MyItem LONGWORD UNSIGNED BASEALIGN (3);
3.2.2.4 Storage Class Keywords
Storage class refers to the way in which the target language compiler
allocates storage for scalar items and aggregates. In general,
declarations produce a template describing data for which the compiler
allocates storage dynamically at run time, rather than at compile time.
This type of storage is the default and is specified using the BASED
option in some languages, although the default storage class option is
language-dependent. The Kednos PL/I back end generates the BASED
storage class option, which has the following syntax:
BASED (pointer-name) |
In languages that support the construct, you can use the BASED pointer-name option on an AGGREGATE declaration to bind a named pointer to that aggregate. In all target languages, the aggregate resulting from such a declaration has the default storage class (BASED).
A subaggregate always acquires the storage class of the aggregate to which it belongs.
The default storage class associated with any declaration is language-dependent. You can override the default storage class by specifying either of the following storage classes:
typedef struct {int jg$l_i1; int jg$l_i2;} MyStruct ; static MyStruct foo ; |
static struct {int jg$l_i1; int jg$l_i2;} foo ; |
static struct MyStruct {int jg$l_i1; int jg$l_i2;} foo ; |
struct MyStruct {int jg$l_i1; int jg$l_i2;} ; static struct MyStruct foo ; |
If COMMON and GLOBAL appear together in a declaration, a DUPCONATT
(duplicate or conflicting attributes) error is given. The COMMON,
GLOBAL and TYPEDEF storage classes are mutually exclusive.
3.2.2.5 SDL Storage Classes and Typedef Syntax
Explicit SDL Storage classes are COMMON and GLOBAL. To maintain orthogonal syntax, TYPEDEF is permitted wherever COMMON and GLOBAL are permitted.
The Storage class definition in SDL is included as an option on an ITEM or AGGREGATE declaration. This means that an AGGREGATE TYPEDEF for the preceding example would be:
AGGREGATE MyStruct STRUCTURE TYPEDEF PREFIX jg$ ; i1 LONGWORD ; i2 LONGWORD ; END ; |
In most cases it is possible to refer to a user-defined Data Type where a standard built-in SDL Data Type (BYTE, LONGWORD etc.) can be referenced.
Reference to the type MyStruct defined in the preceding example is made as follows:
ITEM foo MyStruct ; |
You can apply a dimension to AGGREGATE (as well as members of aggregates and subaggregates) and ITEM declarations, which means that you can define an array of structures, a structure that contains one or more arrays, or an array of structures each of which contains one or more arrays. The DIMENSION option is valid when specified with any of the data types described in Section 3.2.3 and has the following syntax:
DIMENSION [lbound:]hbound |
lbound
Is any valid HP SDL expression giving the value of the lowest-numbered element of the array. If lbound is not specified, HP SDL supplies a default lbound of 1.hbound
Is any valid HP SDL expression giving the number of elements in the array, or, if lbound is specified, the highest-numbered element.
The following is an example of the DIMENSION option specified on an AGGREGATE declaration:
AGGREGATE array_info STRUCTURE; bound STRUCTURE DIMENSION 8; lower LONGWORD; upper LONGWORD; multiplier LONGWORD; constant_lower BITFIELD LENGTH 1; constant_upper BITFIELD LENGTH 1; constant_multiplier BITFIELD LENGTH 1; reserved BITFIELD LENGTH 13; END bound; END array_info; |
The subaggregate bound has eight elements. Each element consists of the members upper, lower, multiplier, and so on. Because bound is an array, each of its members (upper, lower, multiplier, and so on) can also be considered an array of eight elements.
When you specify a single value after the DIMENSION keyword, as in the previous example, the specified back end assumes that the value represents the high bound value and supplies a default low bound value of one. You can override this default by specifying both a low bound and a high bound value as follows:
ITEM node_pointers DIMENSION 0:255 ADDRESS; |
This declaration results in a declaration of the array node_pointers, whose low bound is 0 and whose high bound is 255. Only one dimension can be specified for an AGGREGATE or ITEM declaration. This restriction ensures that there is no interlanguage conflict in an array declaration.
You can see how HP SDL translates the DIMENSION option for each output
language by processing the HP SDL source file EXAMPLE.SDL in
SDL$EXAMPLES.
3.2.3 Data Type Keywords
Data type keywords specify the data types of scalar objects, which can be declared as members of aggregates or as individual items. Data type keywords are also used to describe the data types of parameters, as well as the return value of an ENTRY. They can also be used in an AGGREGATE declaration to generate an implicit union. The data type declaration also specifies, either implicitly or explicitly, the size of a member.
The following sections describe the data types and the keywords you use
to specify them.
ADDRESS, POINTER, POINTER_LONG are 4-byte-addresses.
The following is an example of an aggregate with a member of pointer
type:
3.2.3.1 Pointer Data Types
The keywords ADDRESS, POINTER, POINTER_LONG, POINTER_QUAD, POINTER_HW,
and HARDWARE_ADDRESS specify a data type that is an address, or
pointer. The ADDRESS data type has the following syntax:
pointer-type [ (object-type [ basealign-attribute ] ) ]
pointer-type
is one of the keywords ADDRESS, POINTER, POINTER_LONG, POINTER_QUAD,
POINTER_HW, and HARDWARE_ADDRESS.
POINTER_HW and HARDWARE_ADDRESS are 4-byte-addresses if /VAX us
specified and 8-byte-addresses if /ALPHA is specified.
POINTER_QUAD is an 8-byte-address.
object-type
is the optional data type of the object to which the address refers.
This construct is ignored for languages in which pointers are distinct
data types. Object-type is either a builtin object type, like LONGWORD
or ANY, or a user-defined object type, optionally followed by a
DIMENSION specification, or an ENTRY declaration.
basealign-attribute
Here, a BASEALIGN attribute can be specified, as desribed in
Section 3.2.2.3.
AGGREGATE any_node STRUCTURE;
flink ADDRESS (any_node);
blink ADDRESS (any_node);
END;
3.2.3.2 ANY Data Type
The ANY keyword specifies that the parameter being described in an
ENTRY declaration can be of any data type. The ANY data type can be
used only within the context of a parameter description and has the
following syntax:
ANY |
ANY
Specifies that the parameter can be of any data type.
The following is an example of the use of the ANY data type:
ENTRY sys$abc PARAMETER (ANY); |
The BITFIELD keyword specifies a bit field variable that must be a member of an AGGREGATE declaration. The BITFIELD data type has the following syntax:
BITFIELD [LENGTH n] [MASK] [SIGNED] |
[LENGTH n]
Is any valid HP SDL expression giving the number of bits in the bitfield. If no length is specified, HP SDL uses a default length of 1 bit.
[MASK]
Is a keyword specifying that HP SDL generate both a bitfield variable and a constant bit mask representing the bits defined in this field.[SIGNED]
Is a keyword specifying that HP SDL treat the output as a signed field.
Bitfields must be AGGREGATE declaration members. They cannot be scalar items, objects of ADDRESS declarations, parameters, or return data types of entries.
The following is an example of the BITFIELD keyword used in an AGGREGATE declaration that specifies a structure with two bitfield members:
AGGREGATE flags STRUCTURE PREFIX tst$; resolved BITFIELD MASK SIGNED; spare_bits BITFIELD LENGTH 5; END; |
The declaration of resolved in the previous example
results in two declarations in the output file: a declaration for the
bitfield itself and a declaration of a constant mask whose value is 1.
Because the PREFIX option is specified for this aggregate, the source
output file identifiers produced for this declaration are
tst$v_resolved and tst$m_resolved,
where the tag v_ indicates the bitfield variable and
the tag m_ indicates the mask. Prefixes and tags are
described in more detail in Section 3.2.2.2.
3.2.3.4 BOOLEAN Data Type
The BOOLEAN keyword specifies a Boolean data type that is a one-byte field that can have one of two values, 0 or 1. The BOOLEAN data type has the following syntax:
BOOLEAN |
BOOLEAN
Produces a Boolean variable in the output file.
The following is an example of the BOOLEAN keyword used in an ITEM declaration:
ITEM true BOOLEAN; |
The CHARACTER keyword declares a character string of a given length. The CHARACTER data type has the following syntax:
CHARACTER [LENGTH {n}] [VARYING] [ {*}] |
[LENGTH n]
Is the length of the character string. The length can be specified using any valid HP SDL expression. If no length is specified, HP SDL uses a default length of 1 character. You can specify a character string of unknown length using LENGTH *. An unknown length character string can be specified only for parameter types. For example:
ENTRY LIB$ROUTINE PARAMETER(CHARACTER LENGTH * NAMED foo);[VARYING]
Is a keyword indicating that the identifier represents a varying-length character string (for languages that support this data type). In a varying-length character string, the first word of the string contains its current length; its declared length is the maximum length that it can have.
The following is an example of the CHARACTER data type used in an AGGREGATE declaration. The aggregate msg_buffer contains a character-string member named message_text with a length of 256 characters.
AGGREGATE msg_buffer STRUCTURE; message_text CHARACTER LENGTH 256 VARYING; severity WORD; END; |
The COMPLEX keyword immediately follows any of the four floating-point data type keywords to specify any of the four COMPLEX data types. The COMPLEX data types have the following syntax:
F_FLOATING COMPLEX D_FLOATING COMPLEX G_FLOATING COMPLEX H_FLOATING COMPLEX |
The following is an example of the F_FLOATING COMPLEX data type used in an ITEM declaration:
ITEM foo F_FLOATING COMPLEX; |
Section 3.2.3.8 describes floating-point data types.
3.2.3.7 DECIMAL Data Type
The DECIMAL keyword specifies a packed decimal data type and the size of the data type. The DECIMAL data type has the following syntax:
DECIMAL PRECISION (precision,scale) |
PRECISION (precision,scale)
Is the fixed-point decimal member's precision and scale, respectively. Precision is the total number of decimal digits, and scale is the number of fractional digits.Both precision and scale must be specified using valid HP SDL expressions.
The following is an example of the DECIMAL keyword used in an ITEM declaration that indicates a packed decimal data type consisting of three decimal digits, two of which are fractional:
ITEM percentage DECIMAL PRECISION (3,2); |
The floating-point keywords, F_FLOATING, D_FLOATING, G_FLOATING, and H_FLOATING, declare storage units for single-, double-, G-, and H-floating-point data, respectively. The floating-point data types have the following syntax:
F_FLOATING D_FLOATING G_FLOATING H_FLOATING |
The following is an example of the D_FLOATING data type used in an ITEM declaration:
ITEM foo D_FLOATING; |
Section 3.2.3.6 describes COMPLEX data types.
Previous | Next | Contents | Index |