Guide to the HP Structure Definition Language


Previous Contents Index

3.2.3.9 Integer Data Types

The keywords BYTE, WORD, LONGWORD, QUADWORD, and OCTAWORD declare storage units of 8, 16, 32, 64, and 128 bits, respectively, to represent signed integer data.

You may also specify the keyword UNSIGNED with any of these data types to indicate unsigned integer data.

It is also possible to specify the keyword SIGNED.

The keywords INTEGER_BYTE, INTEGER_WORD, INTEGER_LONG and INTEGER_QUAD are synonyms for BYTE, WORD, LONGWORD, QUADWORD, respectively, although some back ends treat INTEGER_QUAD and QUADWORD different (C, FORTRAN and PL/I). The keyword INTEGER is also synonym for LONGWORD and INTEGER_LONG.

The keywords INTEGER_HW and HARDWARE_INTEGER describe integer data types whose size depends on the underlying hardware. If the qualifier /VAX is specified, they are 4 bytes wide, and if /ALPHA is specified, they are 8 bytes wide.

The integer data types have the following syntax:

BYTE             [ UNSIGNED | SIGNED ] 
INTEGER_BYTE     [ UNSIGNED | SIGNED ] 
WORD             [ UNSIGNED | SIGNED ] 
INTEGER_WORD     [ UNSIGNED | SIGNED ] 
LONGWORD         [ UNSIGNED | SIGNED ] 
INTEGER_LONG     [ UNSIGNED | SIGNED ] 
INTEGER          [ UNSIGNED | SIGNED ] 
QUADWORD         [ UNSIGNED | SIGNED ] 
INTEGER_QUAD     [ UNSIGNED | SIGNED ] 
OCTAWORD         [ UNSIGNED | SIGNED ] 
INTEGER_HW       [ UNSIGNED | SIGNED ] 
HARDWARE_INTEGER [ UNSIGNED | SIGNED ] 

The following are examples of the LONGWORD and BYTE data types used in an ITEM declaration:


ITEM foo LONGWORD UNSIGNED; 
ITEM bar BYTE; 

3.3 Expressions

A HP SDL expression evaluates to an arithmetic value and can consist of any of the following syntax elements:

The following is an example of an expression used in a CONSTANT declaration, which appears in the context of an AGGREGATE declaration:


CONSTANT foo EQUALS %Ag + 72 / (#abc * boo + .); 

3.4 Local Comments

A comment that is local to the HP SDL source file is not written to the output file. Local comments begin with the left brace ({) and extend to the end of the line. They can appear anywhere within the source file (not necessarily within a module) where white space (a space, tab, or carriage return) is allowed. The following is an example of a local comment:


{Assigning the value 255 to #max_args. 

3.5 Output Comments

Comments appearing on lines by themselves are typically written to the output file as separate comment lines. Comments appearing at the end of a line are output at the end of the corresponding target source line, if possible.

Output comments begin with a slash and an asterisk (/*) and terminate at the end of the current line. They can appear in the following contexts:

The following is an example of an output comment:


/* Get Job/Process Information System Service. 

3.6 INCLUDE Statement

The INCLUDE statement specifies that the contents of an external file are to be incorporated in the HP SDL input file directly following the INCLUDE statement. The INCLUDE statement has the following syntax:

 INCLUDE "file-spec"; 

"file-spec"

Is any valid VMS file specification enclosed in quotation marks (" "). An INCLUDE statement cannot appear embedded within an AGGREGATE declaration, but can appear anywhere else within the module. If a directory is not included in the file specification, the current default directory is used.

When HP SDL encounters an INCLUDE statement, it stops reading from the current file and reads the statements in the included file. When it reaches the end of the included file, HP SDL resumes translation with the source statement immediately following the INCLUDE statement.

3.7 READ Statement

The READ statement allows a .SDI intermediate file to be included in an SDL source, without causing it to be emitted to the output stream. Apart from these two differences, its operation is similar to INCLUDE.

The READ statement allows previously-compiled definitions, such as constants and user-defined types, to be used by the current compilation, without affecting the language output. The READ statement has the following syntax:


    READ "file-spec" ; 

3.8 Conditional SDL Compilation

3.8.1 Conditional SDL Compilation using the IFLANGUAGE statement

This feature allows a section of SDL source code to be conditionally compiled, depending on whether output is being generated for a particular language or not.

The syntax for conditional compilation has the format:


    IFLANGUAGE language-name [ language-name ... ] 
                   . 
                   . 
                   . 
    [ELSE ; 
                   . 
                   . 
                   . 
    ] 
    END_IFLANGUAGE [ language-name [ language-name ... ] ] ; 

Note the following:

In the following example, SDL generates a translation of the ITEM statement if output is being generated for Pascal, Ada, or FORTRAN. For other languages, SDL does not generate a translation of the ITEM statement.


         IFLANGUAGE PASCAL ADA FORTRAN ; 
            ITEM foo LONGWORD; 
         END_IFLANGUAGE PASCAL ADA FORTRAN; 

3.8.2 Conditional SDL Compilation using the IFSYMBOL statement

This feature allows a section of SDL source code to be conditionally compiled, depending on symbols specified with the command line qualifier /SYMBOLS.

The syntax for conditional compilation has the format:


    IFSYMBOL symbol-name ; 
           . 
           . 
           . 
    { ELSE_IFSYMBOL symbol-name ; 
           . 
           . 
           . 
    } 
    [ELSE ; 
           . 
           . 
           . 
    ] 
    END_IFSYMBOL ; 

Note the following:

With the following example:


         IFSYMBOL s1; 
             <sdl code 1> 
         END_IFSYMBOL; 
 
         IFSYMBOL s2; 
             <sdl code 2> 
         ELSE_IFSYMBOL s3; 
             <sdl code 3> 
         ELSE; 
             <sdl code 4> 
         END_IFSYMBOL; 


    $ SDL/LANG=<LANGUAGE>/SYMBOLS=(S1=0,S2=0,S3=0) <FILE-SPEC>

produces


    <sdl code 4> 


    $ SDL/LANG=<LANGUAGE>/SYMBOLS=(S1=1,S2=0,S3=0) <FILE-SPEC>

produces


    <sdl code 1> 
    <sdl code 4> 


    $ SDL/LANG=<LANGUAGE>/SYMBOLS=(S1=1,S2=1,S3=x) <FILE-SPEC>

produces


    <sdl code 1> 
    <sdl code 2> 


    $ SDL/LANG=<LANGUAGE>/SYMBOLS=(S1=1,S2=0,S3=1) <FILE-SPEC>

produces


    <sdl code 1> 
    <sdl code 3> 

3.9 Text Pass-through

Text pass-through allows literal text to be passed through to the output language file without translation. It is normally used in conjunction with conditional compilation for a specific target language. The purpose is to allow language-specific constructs, which cannot be represented in SDL, to be emitted.

The syntax for text pass-through is:


    LITERAL; 
    Any number of lines to be passed directly to 
    the output stream without translation 
    END_LITERAL; 

Note the following:

Literal text is processed identically in all back ends. The literal text is merely written directly to the output file.

The following is an example of text pass-through for the C language.


    IFLANGUAGE CC 
    LITERAL 
    #define ctext "This appears in C language output only" 
    END_LITERAL 
    END_IFLANGUAGE CC 

3.10 DECLARE Statement

The DECLARE statement allows you to declare a data item of a type that you define, which may be unknown in the current SDL compilation. When you use DECLARE, the type is made known when the target language source is compiled.

The DECLARE statement uses the SIZEOF clause to allow you to specify the size of the user-defined data type being declared. The parameter you specify in the SIZEOF clause may be a built-in SDL data type, a user-defined type defined in the current SDL compilation, or an expression.

The DECLARE statement has the following syntax:

        DECLARE user-type SIZEOF { data-type  }     [ PREFIX prefix-string ] 
{ user-type  }     [ TAG tag-string       ] 
{ ( expression ) } 

user-type

Represents the unknown data type name you wish to declare.

SIZEOF

A clause that must be appended to user-type. The SIZEOF clause may be specified in several ways, as shown, to indicate the size of the user-defined type being declared.

data-type

Represents either a built-in SDL data type, a user-defined type that is known at SDL compile time, or a data type that has been sized by a previous SIZEOF clause.

user-type

Represents a user-defined data type.

( expression )

Represents an expression. If specified, the expression must specify the number of bytes to be reserved for this data type. If the data type is dimensioned, the SIZEOF clause must specify the size of a single element. When you specify an expression, always enclose it in parentheses, as shown in this syntax.

Notes:

  1. DECLARE identifies the size of the data type when included in an AGGREGATE declaration. (SDL needs to know its equivalent predefined type so that the correct default tag letter, if required, can be output.)
  2. You may declare a user-defined data type more than once (either explicitly or implicitly), but any subsequent declaration must match the first.
  3. The default tag letter for the unknown variable being sized is derived from the type specified in the SIZEOF clause. If you use an expression in place of a data type to reserve a fixed number of bytes, the default tag letter is T. You may override the default tag by using an explicit TAG option.
  4. SIZEOF clauses cannot be nested.
  5. You cannot qualify a reference to the name of a previously-declared aggregate using the SIZEOF clause.
  6. Although DECLARE statements and implicit SIZEOF declarations appear in the output tree for use by the back ends, these do not result in specific generated code.
  7. Do not use the SIZEOF clause for data types that are aggregate names. Also, do not nest SIZEOF clauses where the syntax would otherwise allow aggregate names. For example, the following statements are valid:


    DECLARE type SIZEOF ADDRESS (CHARACTER); 
     
    ITEM type ADDRESS (bar SIZEOF LONGWORD); 
    

    However, the following statement generates an error message:


    DECLARE type SIZEOF ADDRESS (bar SIZEOF LONGWORD); 
    

Examples

A database contains information on a number of forests in a region, each of which contains a number of different types of trees. The definition of the tree structure is held in a different SDL file from the other definitions. When the second SDL file is compiled, the composition of the tree structure is unknown --- the definitions will only come together when the output files are included in a compilation in the target language.

The following shows the two SDL files and the corresponding output in C.

TREE1.SDL:


AGGREGATE tree STRUCTURE TYPEDEF; 
    flink ADDRESS (tree); 
    blink ADDRESS (tree); 
    height LONGWORD; 
    age LONGWORD; 
END; 

TREE2.SDL:


DECLARE tree SIZEOF (16); 
 
AGGREGATE forest STRUCTURE TYPEDEF; 
    oak tree; 
    ash tree; 
    elm tree; 
    confirs tree DIMENSION 6; 
END; 
 
ITEM tree_pointer ADDRESS (tree); 
 
ITEM tree_storage tree DIMENSION 1000; 
 
ITEM region forest DIMENSION 4; { No SIZEOF, since 'forest' defined here} 

TREE1.H:


typedef struct _tree { 
    _tree    *flink; 
    _tree    *blink; 
    long int height; 
    long int age; 
    } tree; 

TREE2.H:


typedef struct _forest { 
    tree    oak; 
    tree    ash; 
    tree    elm; 
    tree    conifers[6]; 
    } forest; 
 
tree    *tree_pointer; 
tree    tree_storage[1000]; 
forest  region[4]; 

Note that the SIZEOF information is discarded by C, but is used by other languages, such as HP MACRO.


Previous Next Contents Index