Java Reference
In-Depth Information
4.4.5 JFieldDeclaration.preAnalyze()
Pre-analysis for a JFieldDeclaration is similar to that for a JMethodDeclaration . In a
JFieldDeclaration , preAnalyze() does the following:
1. It enforces the rule that fields may not be declared abstract .
2. It resolves the eld's declared type.
3. It generates the JVM code for the field declaration, via the CLEmitter created for the
enclosing class declaration.
The code itself is rather simple:
publicvoidpreAnalyze(Contextcontext,CLEmitterpartial){
//Fieldsmaynotbedeclaredabstract.
if(mods.contains("abstract")){
JAST.compilationUnit.reportSemanticError(line(),
"Fieldcannotbedeclaredabstract");
}
for(JVariableDeclaratordecl:decls){
//Addfieldto(partial)class
decl.setType(decl.type().resolve(context));
partial.addField(mods,decl.name(),
decl.type().toDescriptor(),false);
}
}
4.4.6 Symbol Table Built by preAnalyze()
So, pre-analysis recursively descends only so far as the class members declared in a program
and constructs only a CompilationUnitContext (in which all types are declared) and a
ClassContext . No local variables are declared in pre-analysis. Figure 4.4 illustrates how
much of the symbol table is constructed for our Factorial program once pre-analysis is
complete.
 
Search WWH ::




Custom Search