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

Subsections
 

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.  

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. [*] 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 Manual Previous: Constants
This page was generated from LaTeX sources
10/27/1997