Figure 2.8. Concrete Syntax for Constant Declaration
|
Figure 2.8, “Concrete Syntax for Constant Declaration” presents the concrete syntax for BIR constant declaration. Constants are useful to parameterize BIR models. A constant declaration consists of declarations of its identifier <const-id>, its elements, and the literals assigned to the elements. The type of constant elements depend on the type of the literals assigned to them. Constant elements are not variables, instead, they are simply value bindings of the literals to the constant element identifiers. The bindings cannot be changed at run-time. The fully qualified name of a constant element is <const-id> "." <const-elem-id>. A constant element can only be referred using its fully qualified name.
Namespace. The namespace for constants is the global namespace that is shared with enumerations, records, extensions, type-aliases, global variables, threads and functions, virtual tables, and functional expressions. Each constant has its own namespace for its elements.
Examples.
const C { N = 5; // int constant M = (int wrap (0, 255)) 5; // int wrap (0, 255) constant L1 = 5L; // long constant L2 = 5l; // long constant L3 = -5L; // long constant L4 = -5l; // long constant F1 = 1.0F; // float constant F2 = 1.0f; // float constant F3 = -1.0F; // float constant F4 = -1.0f; // float constant F5 = 1F; // float constant F6 = 1f; // float constant F7 = -1F; // float constant F8 = -1f; // float constant D1 = 1.0; // double constant D2 = 1.0D; // double constant D3 = 1.0d; // double constant D4 = -1.0; // double constant D5 = -1.0D; // double constant D6 = -1.0d; // double constant D7 = 1D; // double constant D8 = 1d; // double constant D9 = -1D; // double constant D10 = -1d; // double constant C = 'c'; // char constant B1 = true; // boolean constant B2 = false; // boolean constant S1 = null; // string constant S2 = "s"; // string constant }
Abstract Syntax Tree.
The Java AST class for BIR constant is the ConstantDefinition . The top level Java AST class for BIR constant elements is Constant class. The Java AST class for boolean constant element, char constant element, int constant element, long constant element, float constant element, double constant element, and string constant element are the BooleanConstant class, the IntConstant class, the IntConstant class, the LongConstant class, the FloatConstant class, the DoubleConstant class, and the StringConstant class, respectively.