General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Tutorial for Name Analysis Using ScopeGraphsPredefined Identifiers
Most programming languages use pre-defined identifiers to represent a few
basic entities.
For example, it would be useful for NameLan to have a pre-defined class
class Object { int hashCode() { } }
object.nl[145]== class C { int h() { hashCode(); } } class D { } { C c; c.hashCode(); D d; d.hashCode(); Object o; o.hashCode(); } This macro is attached to a non-product file.
This chapter explains how to extend NameLan with a pre-defined
Pre-defined identifiers have no actual defining occurrences in the program
text, so their bindings must be created by the generated processor.
Eli provides a module (
The developer needs to instantiate Specification files[146]== $/Name/SGPreDefId.gnrc +referto=(Predef.d) :inst $/Tech/MakeName.gnrc +instance=Ident :inst This macro is defined in definitions 12, 16, 23, 27, 74, 78, 81, 91, 117, 121, 139, 142, 146, and 152. This macro is invoked in definition 13.
We use the operations provided by
The three macro calls appear in the file whose name was given
by the Predef.d[147]== PreDefKeyNdx ("Object", ObjectKey, classGraph) PreDefNode(ObjectKey, ObjectEnv) PreDefKeyEnvNdx("hashCode", hashCodeKey, ObjectEnv, methodGraph) This macro is attached to a non-product file.
The developer must define Properties and property computations[148]== "ScopeGraphs.h" ObjectKey -> GraphIndex={classGraph}, IsType={1}; hashCodeKey -> GraphIndex={methodGraph}; This macro is defined in definitions 79, 94, 126, 132, 143, and 148. This macro is invoked in definition 80.
See Multiple Scope Graphs, for the
Predef.c[149]== #include "Predef.h" NodeTuplePtr ObjectEnv; /* Establish the variable ObjectEnv */ This macro is attached to a product file. Predef.h[150]== #ifndef PREDEF_H /* Prevent multiple inclusions */ #define PREDEF_H #include "Model.h" /* Define the NodeTuplePtr type */ extern NodeTuplePtr ObjectEnv; #endif This macro is attached to a product file.
Predef.head[151]== #include "Predef.h" This macro is attached to a product file. These three files are all additional specifications: Specification files[152]== Predef.head Predef.h Predef.c This macro is defined in definitions 12, 16, 23, 27, 74, 78, 81, 91, 117, 121, 139, 142, 146, and 152. This macro is invoked in definition 13.
This completes the pre-definition of
RULE: Inheritance ::= Default END; RULE: Default ::= END;The computation is close to that for specific super classes (see Inheritance). It uses the BoundEdge role instead of the WLCreateEdge role
because the edge tip is known
(see Path edge creation roles of Name Analysis Reference Manual).
Abstract syntax tree[153]== SYMBOL Default INHERITS BoundEdge COMPUTE SYNT.tailEnv = INCLUDING Inheritance.SubClassEnv; SYNT.tipEnv = ObjectEnv; END; This macro is defined in definitions 10, 18, 22, 38, 47, 52, 53, 65, 69, 71, 88, 89, 92, 93, 95, 96, 101, 105, 108, 110, 111, 112, 113, 122, 133, 134, 135, 136, 137, 144, and 153. This macro is invoked in definition 11.
ExercisesThese exercises are based on files defined in the Tutorial. To obtain copies of those files in your current directory, enter Eli and give the following command:
-> $elipkg/Name/LearnSG%Predef > . None of these files will have write permission in your current directory.
|