This is an old revision of the document!
Table of Contents
Declaration
Modules are declared similarly as classes. Their declaration include:
- A name
- An optional list of attributes
- An optional list of class/interfaces that are extended/ implemented
Modules are declared in XL with the keyword module (different from the java keyword module).
module A(int attr1, Object attr2) extends N { /* body */ } ==> ;
Syntax
Only the Name is non optional in the declaration. Thus, the smallest module declaration is:
module A;
This declaration is equivalent to:
class A extends N { public static class Pattern extends UserDefinedPattern { private static void signature(@In @Out X node) {} ... // suitable implementation of abstract methods } }
The declaration uses an implicit superclass N which is determined by the annotation @DefaultModuleSuperclass of the innermost enclosing declaration which has such an annotation. RGG files have default annotations, one of these is the @DefaultModuleSuperclass. Its value is Node. Thus, by default all module extends Node.
The parametrized pattern is created implicitly and takes the module attributes declared after the name as additional arguments.
Attributes declaration
Attributes can be declared in :
- The list of typed arguments that follow the name
- As fields directly in the module body
Attributes declared in the the list of typed arguments are used implicitly for both: the constructor, and the pattern.
All attributes implicitly declare their accessors.
Attribute accessors are the methods to get and set the attribute value. The accessors of a Node are automatically resolved by the compiler with the syntax:
Sphere s; // has an attribute diameter s[diameter] = 5; // automatically resolve the setter float d = s[diameter]; // automatically resolve the getter
module A (float len); // is equiavent to: class A extends Node { float len; public A(float l) { len = l; } public static class Pattern extends UserDefinedPattern { private static void signature(@In @Out X node, float len ) {} ... // suitable implementation of abstract methods } }
