Next: Scope of a simple
Up: Name Analysis
Previous: Name Analysis
A package consists of a number of compilation units.
A compilation unit automatically has access to all types declared in its
package.
To model this behavior, we associate a definition table key with each
package, and make that key available in each compilation unit via the
compilation unit's PackageDeclarationOpt child:
TREE SYMBOL PackageDeclarationOpt: PkgKey: DefTableKey;
TREE SYMBOL PackageName INHERITS PkgIdDefScope END;
RULE: PackageDeclarationOpt ::= 'package' PackageName ';' COMPUTE
PackageDeclarationOpt.PkgKey=PackageName.PkgKey;
END;
This macro is defined in definitions 4, 5, 8, and 9.
This macro is invoked in definition 2.
A compilation unit that has no package declaration is part of an unnamed
package.
We have chosen to support an arbitrary number of unnamed packages, each
containing a single compilation unit:
RULE: PackageDeclarationOpt ::= COMPUTE
PackageDeclarationOpt.PkgKey=NewKey();
END;
This macro is defined in definitions 4, 5, 8, and 9.
This macro is invoked in definition 2.
Instantiate required modules[6]
:
$/Name/AlgScope.gnrc +instance=Pkg +referto=Pkg :inst
This macro is defined in definitions 3, 6, 7, 27, 30, and 36.
This macro is invoked in definition 1.
The members of a package are class and interface types, which are declared
in compilation units of the package.
We model this behavior by the Pty name space.
Instantiate required modules[7]
:
$/Name/AlgScope.gnrc +instance=Pty +referto=Pty :inst
This macro is defined in definitions 3, 6, 7, 27, 30, and 36.
This macro is invoked in definition 1.
All of the declarations of package members are children of the
TypeDeclarationsOpt child of a compilation unit.
The Pty name space must, however, define the full set of type scopes to
hide lower-level definitions:
TREE SYMBOL TypeDeclarationsOpt INHERITS PtyRangeScope END;
TREE SYMBOL ClassBody INHERITS PtyRangeScope END;
TREE SYMBOL InterfaceBody INHERITS PtyRangeScope END;
TREE SYMBOL MethodDeclaration INHERITS PtyRangeScope END;
TREE SYMBOL Block INHERITS PtyRangeScope END;
TREE SYMBOL SwitchBlockStatement INHERITS PtyRangeScope END;
TREE SYMBOL TypeIdDef INHERITS PtyIdDefScope END;
This macro is defined in definitions 4, 5, 8, and 9.
This macro is invoked in definition 2.
A single environment is used for all compilation units in a single package.
The package key is used to retrieve that environment:
RULE: CompilationUnit ::=
PackageDeclarationOpt
ImportJavaLang ImportDeclarationsOpt TypeDeclarationsOpt
COMPUTE
TypeDeclarationsOpt.PtyEnv=
PackagePtyScope(PackageDeclarationOpt.PkgKey,INCLUDING Goal.PtyEnv);
END;
This macro is defined in definitions 4, 5, 8, and 9.
This macro is invoked in definition 2.
PackagePtyScope obtains the package's environment from the definition
table, if it exists.
Otherwise, it returns a new environment and stores that environment as the
package's environment:
PtyScope: Environment [Package]; "envmod.h"
Environment Package(DefTableKey key, Environment env)
{ if (key == NoKey) return NoEnv;
if (!ACCESS) VALUE = NewScope(env);
return VALUE;
}
This macro is attached to a product file.
Next: Scope of a simple
Up: Name Analysis
Previous: Name Analysis
2008-09-11