13
CS269: HW/SW Engineering of Embedded Systems, Winter02
Abstract syntax trees
•Example: annotate the AST of a file with the number of classes   declared in that file.
// Identifier of our property
public static final int NUMDECL_KEY = RESERVED_PROPERTIES + 1;
// Method to perform the annotation
void annoteNumDecls(CompileUnitNode ast) {
   int numDecls = ast.getDefTypes().size();
   ast.setProperty(NUMDECL_KEY,new Integer(numDecls));
}
// Method to read the annotation
int getNumDecls(CompileUnitNode ast) {
   Integer num = (Integer) getProperty(NUMDECL_KEY,val);
   return num.intValue();
}