next up previous contents
Next: Attributes Up: Shore Data Language Reference Previous: Constants

 

Types

    type_dcl : 'typedef' type_spec declarators
        | struct_type | union_type | enum_type | external_type
    type_spec : simple_type | constructed_type
    simple_type : atomic_type
        | string_type
        | enum_type
        | ref_type
        | type_name
    constructed_type : struct_type
        | union_type
        | sequence_type
    atomic_type : floating_pt_type
        | integer_type
        | char_type
        | boolean_type
        | octet_type
        | any_type
    type_name : scoped_name
    declarators : declarator ( ',' declarator )*
    declarator : ID [ array_size ]
    array_size : '[' positive_int_const ']'
    positive_int_const : const_exp 
            // must evaluate to a positive integer

    octet_type : 'octet'
    char_type : 'char'
    any_type : 'any'

    struct_type : 'struct' ID [ struct_body ]
    struct_body : '{' struct_member* '}'
    struct_member : type_spec declarators ';'

    union_type : 'union' ID [ union_body ]
    union_body : 'switch' '(' discriminator ')' '{' case* '}'
    discriminator : scalar_type ID
    scalar_type : integer_type
        | char_type
        | boolean_type
        | enum_type
        | type_name // denoting a scalar type
    case : case_label+ ( type_spec declarators ';' )+
    case_label : 'case' const_exp ':' | 'default' ':'

    enum_type : 'enum' ID '{' ID ( ',' ID )* '}'
    sequence_type :
        'sequence' '<' type_name [ ',' positive_int_const ] '>'
    string_type :
        'string' [ '<' positive_int_const '>' ]

    external_type : 'external' external_qualifier ID 
    external_qualifier : 'typedef' | 'class' | 'enum' | 'union' | 'struct'

Types are either simple or constructed. Simple types include the atomic types (integer, floating-point, etc.), character strings, and enumerations. The positive_int_const in a string type bounds the maximum length of the string. If the constant is omitted, the length of the string is unbounded.

Constructed types are built from base types, which may themselves be simple or constructed. A struct is a fixed heterogeneous sequence of values, selected by field names. It corresponds to a Pascal record or a C struct. A union consists of a discriminator value of a scalar type and a heterogeneous sequence of values (as in a struct) whose types are determined by the value of the discriminator.   A sequence is a homogeneous sequence of values of a base type. As with strings, a bound on the length is optional.

Beware the construction sequence<ref<T>>, as the two adjacent ``>>'' characters are parsed as a right-shift operator. In order to avoid this problem, you must put a space between the two brackets: ``> >''.

Arrays are as in C: one-dimensional, fixed-length sequences of values of the base type, whose elements are indexed by non-negative integers. As in C (and C++), the fact that a name denotes an array type is indicated in its definition by following it with a size in brackets. References are either local or remote. Local references are similar to pointers in other languages, but are constrained to point to values in the object containing the reference. A remote reference is a ``pointer'' to zero, one, or several objects. A reference that appears at the ``top level'' of an object, called a relationship, may be paired with an inverse.

Each type_decl defines one or more names and binds them to types (or, in the case of enum, values). As in C++, the exact semantics is rather convoluted because the typedef syntax is optional for struct, union, and enum types. gif The names defined by a type_dcl include the identifiers in its declarators, as well as the first ID in each struct or union, and all the IDs in each enum.

A type_dcl of the form

typedefS D;
where the S is a struct_type, union_type, or enum_type and D is a list of declarators, is equivalent to the pair of type_dcls
S;

typedefN D;

where N is the first ID in S. A type_dcl beginning with the keyword typedef binds each ID appearing in the declarators to a type: An ID without an array_size is bound to the type T denoted by the type_spec. An ID followed by an array_size that evaluates to a value N (which must be a positive integer) is bound to the type array [0..N-1] of T.

A type_dcl that is a struct_type, union_type, or enum_type binds the first ID to the type denoted by the type_spec. An enum_type also defines each ID inside the braces and binds it to a (distinct) constant. Note that an enum_type is not a name scope; the constant names are defined in the enclosing scope. In particular, the same name may not appear in two enum declarations in the same scope.

 

Examples

    typedef long vector[100];
    const long MaxName = 40;
    struct FullName {
        string<MaxName> given_name, family_name;
        char initial;
    };
    typedef struct FullName2 {
        string<MaxName> given_name, family_name;
        char initial;
    } FullName3;
    struct PersonalInfo {
        FullName name;
            struct Addr {
            string number, name;
            string city;
            char state[2];
            long zip;
        } address;
    };
    enum WidgetType { Simple, Complex };
    struct simple_case {
        float cost;
        string description;
    };
    struct complex_case {
        short part_count;
        sequence<Widget> components;
    };
    union Widget switch (WidgetType part_type) {
        case Simple:
            simple_case si;
        case Complex:
            complex_case cx;
    };

These declarations define the types vector, FullName, FullName2, FullName3, PersonalInfo, WidgetType, and Widget, and the constants MaxName (with type long and value 40), Simple, and Complex (enumeration values of type WidgetType). The names FullName2 and FullName3 are aliases for a type that is equivalent to (but distinct from) the type bound to FullName.

 

External Types

All data types that represent persistent data must be defined in the SDL sources, but data types for arguments to operations may be defined externally. The names of these data types must be declared in the SDL sources with the appropriate declaration, as in the example below:

 

Examples

    module exeg {
        external class a;
        external enum b;
        external typedef c;
        external union d;
        external struct e;

        interface eg {
            // ...
        public:
            e op(in a _a, in b _b, out c _c, out d _d);
        };
    }

These declarations appear in the same places that any other type declarations may appear, but externally defined types can be used only in operations declarations. gif See Section 14 for more information about operations.

Depending on the language for which a binding is generated, types declared to be external in the SDL source might have to be defined before the language binding header file is included in the application program source.



next up previous contents
Next: Attributes Up: Shore Data Language Reference Previous: Constants



Marvin Solomon
Fri Aug 2 13:39:38 CDT 1996