next up previous contents
Next: Linking Up: Shore Data Language Reference Previous: Objects and Values

 

Modules

 
    specification : module*
    module : 'module' ID '{' mod_export* mod_import* 
            module_member* '}' [';']
    mod_export : 'export' ( ID | 'all' ) ';'
    mod_import : 'use' module_name [ 'as' ID ] ';'
        | 'import' module_name ';'
    module_name : STRING_LITERAL
    module_member : const_dcl ';'
        | type_dcl ';'
        | interface_dcl ';'
    scoped_name : ID ( '::' ID )*

An SDL definition is a sequence of module definitions. Multiple module declarations can be combined in one source file, but they are separately processed as if they were in separate source files. In other words, there is no special scope associated with a file. The result of compiling a module definition is a module object in the database. A module defines a name scope (see the following section) in which names are bound to constants, types, and interfaces. These names are exported if they appear in the export declaration at the start of the module; otherwise, they are local and can only be used in the module in which they are defined. gif

The declaration export all exports all ``top level'' names defined in the module. The declaration use module_name as ID; makes all exported names defined in the named module (as well as the types, constants, etc. that they designate) available in the current module. The module_name is a file name of a module object stored in the database, expressed as a string literal. It is interpreted relative to a path given as a command-line argument to the SDL compiler (see the manual page sdl(sdl)).

Each exported name in that module can be used in the current module as ID::name, where ID is the identifier specified in the use declaration. If no ID is specified, the name of the module (as indicated in the module header) is used.

The import declaration imports all names exported by the indicated module as if they were defined in the current module. That is, they can be used without any ID:: prefix if there is no ambiguity. (Importing a module M does not import the modules imported by M; it imports only the names exported by M, except if M exports ``all''.)

The module name given on an import declaration can be an identifier or a quoted path name. An identifier mod is treated the same as "mod", and the module is expected to be found in the list of directories determined by command-line arguments to the compiler.  

Examples

    module constants { 
        // installed as "constants" in the 
        // directory determined by the first -d flag if present,
        // /types otherwise.
        export TitleSize; 
        const long CharacterWidth = 1; 
        const long TitleSize = 40*CharacterWidth;
    } 

    module mod1 {
        export all; 
        use "constants" as C;
        typedef char Title[C::TitleSize]; 
    } 

    module mod2 {
        export all; 
        import "constants"; 
        typedef char header[TitleSize]; // NB: TitleSize is 40!
    }

The import declarations must follow the export declarations.



next up previous contents
Next: Linking Up: Shore Data Language Reference Previous: Objects and Values



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