Module
Module interface and body declaration and definition.
Module Name
module_name: path
where the path reflects the hierarchy of namespaces until the module itself
Use Directive
use_directive: use path (as ID)?
where
- path is an absolute path from the top level namespace to the name of the module to be used.
- In the module where the use directive is added, an element of this
used module is referenced by :
<used_module_name>::<element_name>. - used_module_name is either the local
IDprovided through the optional (as ID) aliasing, or the module name at the end of the path. It means that, the complete path only appears in the use directive.
Module Interface Syntax
module_interface_file: use_directive* (type_and_global_declaration or operator_interface_declaration ;)*The module interface declarations are gathered in a file called module_name.swani,
where the :: in the module_name are replaced by
- in the file name.
Module Body Syntax
module_body_file: use_directive* (type_and_global_declaration or operator_declaration )*
The module body declarations are gathered in a file called
module_name.swan, where the :: in the
module_name are replaced by - in the file name.
Note: In module interface and body declarations, the path cannot refer to the
module itself (for example, a type T defined and used in the
module M is referenced by T and not by
M::T in M)
Consistency constraints
- A module element can be declared only once, either in the interface or in the body
- A module element can be defined only once, either in the interface or in the body
- A module element declared in the interface, can be defined in the body
- A module element that is declared, and not defined is called imported (it means that its definition is given in C language)
A definition (in the body) must be consistent with the declaration (in the
interface):
- A constant must have the same type
- An operator must have the same formal parameter names with same types, and same inlining information