9 import java.lang.Throwable;
10 public class BuildIR {
12 private boolean isRunningRecursiveInnerClass;
13 private int m_taskexitnum;
15 public BuildIR(State state) {
17 this.m_taskexitnum = 0;
18 this.isRunningRecursiveInnerClass = false;
21 public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) {
22 parseFile(pn, toanalyze, sourcefile);
24 // numering the interfaces
26 Iterator it_classes = state.getClassSymbolTable().getValueSet().iterator();
27 while(it_classes.hasNext()) {
28 ClassDescriptor cd = (ClassDescriptor)it_classes.next();
29 if(cd.isInterface()) {
30 cd.setInterfaceId(if_num++);
35 //This is all single imports and a subset of the
36 //multi imports that have been resolved.
37 ChainHashMap mandatoryImports;
38 //maps class names in file to full name
39 //Note may map a name to an ERROR.
40 ChainHashMap multiimports;
43 String currsourcefile;
46 void pushChainMaps() {
47 mandatoryImports=mandatoryImports.makeChild();
48 multiimports=multiimports.makeChild();
52 mandatoryImports=mandatoryImports.getParent();
53 multiimports=multiimports.getParent();
56 /** Parse the classes in this file */
57 public void parseFile(ParseNode pn, Set toanalyze, String sourcefile) {
58 mandatoryImports = new ChainHashMap();
59 multiimports = new ChainHashMap();
60 currsourcefile=sourcefile;
64 //add java.lang as our default multi-import
65 this.addMultiImport(sourcefile, "java.lang", false);
68 ParseNode ipn = pn.getChild("imports").getChild("import_decls_list");
69 if ((ipn != null) && !state.MGC) {
70 ParseNodeVector pnv = ipn.getChildren();
71 for (int i = 0; i < pnv.size(); i++) {
72 ParseNode pnimport = pnv.elementAt(i);
73 NameDescriptor nd = parseName(pnimport.getChild("name"));
74 if (isNode(pnimport, "import_single")) {
75 if (!mandatoryImports.containsKey(nd.getIdentifier())) {
76 // map name to full name (includes package/directory
77 mandatoryImports.put(nd.getIdentifier(), nd.getPathFromRootToHere());
79 throw new Error("An ambiguous class "+ nd.getIdentifier() +" has been found. It is included for " +
80 ((String)mandatoryImports.get(nd.getIdentifier())) + " and " +
81 nd.getPathFromRootToHere());
84 addMultiImport(sourcefile, nd.getPathFromRootToHere(), false);
89 ParseNode ppn=pn.getChild("packages").getChild("package");
91 if ((ppn!=null) && !state.MGC){
92 NameDescriptor nd = parseClassName(ppn.getChild("name"));
93 packageName = nd.getPathFromRootToHere();
94 //Trick -> import the package directory as a multi-import and it'll
95 //automatically recognize files in the same directory.
96 addMultiImport(sourcefile, packageName, true);
99 ParseNode tpn=pn.getChild("type_declaration_list");
101 ParseNodeVector pnv = tpn.getChildren();
102 for (int i = 0; i < pnv.size(); i++) {
103 ParseNode type_pn = pnv.elementAt(i);
104 if (isEmpty(type_pn)) /* Skip the semicolon */
106 if (isNode(type_pn, "class_declaration")) {
107 ClassDescriptor cn = parseTypeDecl(type_pn);
108 parseInitializers(cn);
110 // for inner classes/enum
111 HashSet tovisit = new HashSet();
112 Iterator it_icds = cn.getInnerClasses();
113 while (it_icds.hasNext()) {
114 tovisit.add(it_icds.next());
117 while (!tovisit.isEmpty()) {
118 ClassDescriptor cd = (ClassDescriptor) tovisit.iterator().next();
120 parseInitializers(cd);
122 Iterator it_ics = cd.getInnerClasses();
123 while (it_ics.hasNext()) {
124 tovisit.add(it_ics.next());
127 } else if (isNode(type_pn, "task_declaration")) {
128 TaskDescriptor td = parseTaskDecl(type_pn);
129 if (toanalyze != null)
132 } else if (isNode(type_pn, "interface_declaration")) {
133 // TODO add version for normal Java later
134 ClassDescriptor cn = parseInterfaceDecl(type_pn, null);
135 } else if (isNode(type_pn, "enum_declaration")) {
136 // TODO add version for normal Java later
137 ClassDescriptor cn = parseEnumDecl(null, type_pn);
139 } else if(isNode(type_pn,"annotation_type_declaration")) {
140 ClassDescriptor cn=parseAnnotationTypeDecl(type_pn);
142 throw new Error(type_pn.getLabel());
149 //This kind of breaks away from tradition a little bit by doing the file checks here
150 // instead of in Semantic check, but doing it here is easier because we have a mapping early on
151 // if I wait until semantic check, I have to change ALL the type descriptors to match the new
152 // mapping and that's both ugly and tedious.
153 private void addMultiImport(String currentSource, String importPath, boolean isPackageDirectory) {
154 boolean found = false;
155 for (int j = 0; j < state.classpath.size(); j++) {
156 String path = (String) state.classpath.get(j);
157 File folder = new File(path, importPath.replace('.', '/'));
158 if (folder.exists()) {
160 for (String file : folder.list()) {
161 // if the file is of type *.java add to multiImport list.
162 if (file.lastIndexOf('.') != -1 && file.substring(file.lastIndexOf('.')).equalsIgnoreCase(".java")) {
163 String classname = file.substring(0, file.length() - 5);
164 // single imports have precedence over multi-imports
165 if (!mandatoryImports.containsKey(classname)) {
166 //package files have precedence over multi-imports.
167 if (multiimports.containsKey(classname) && !isPackageDirectory) {
168 // put error in for later, in case we try to import
169 multiimports.put(classname, new Error("Error: class " + classname + " is defined more than once in a multi-import in " + currentSource));
171 multiimports.put(classname, importPath + "." + classname);
180 throw new Error("Import package " + importPath + " in " + currentSource
181 + " cannot be resolved.");
185 public void parseInitializers(ClassDescriptor cn) {
186 Vector fv=cn.getFieldVec();
188 for(int i=0; i<fv.size(); i++) {
189 FieldDescriptor fd=(FieldDescriptor)fv.get(i);
190 if(fd.getExpressionNode()!=null) {
191 Iterator methodit = cn.getMethods();
192 while(methodit.hasNext()) {
193 MethodDescriptor currmd=(MethodDescriptor)methodit.next();
194 if(currmd.isConstructor()) {
195 BlockNode bn=state.getMethodBody(currmd);
196 NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
197 AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
198 bn.addBlockStatementAt(new BlockExpressionNode(an), pos);
206 private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
207 String basename=pn.getChild("name").getTerminal();
208 String classname=(cn!=null)?cn.getClassName()+"$"+basename:basename;
209 ClassDescriptor ecd=new ClassDescriptor(cn!=null?cn.getPackage():null, classname, false);
212 if (packageName==null)
213 cn.getSingleImportMappings().put(basename,classname);
215 cn.getSingleImportMappings().put(basename,packageName+"."+classname);
219 ecd.setImports(mandatoryImports, multiimports);
222 ecd.setSurroundingClass(cn.getSymbol());
223 ecd.setSurrounding(cn);
226 if (!(ecd.getSymbol().equals(TypeUtil.ObjectClass)||
227 ecd.getSymbol().equals(TypeUtil.TagClass))) {
228 ecd.setSuper(TypeUtil.ObjectClass);
230 ecd.setModifiers(parseModifiersList(pn.getChild("modifiers")));
231 parseEnumBody(ecd, pn.getChild("enumbody"));
233 if (analyzeset != null)
235 ecd.setSourceFileName(currsourcefile);
242 private void parseEnumBody(ClassDescriptor cn, ParseNode pn) {
243 ParseNode decls=pn.getChild("enum_constants_list");
245 ParseNodeVector pnv=decls.getChildren();
246 for(int i=0; i<pnv.size(); i++) {
247 ParseNode decl=pnv.elementAt(i);
248 if (isNode(decl,"enum_constant")) {
249 parseEnumConstant(cn,decl);
250 } else throw new Error();
255 private void parseEnumConstant(ClassDescriptor cn, ParseNode pn) {
256 cn.addEnumConstant(pn.getChild("name").getTerminal());
259 private ClassDescriptor parseAnnotationTypeDecl(ParseNode pn) {
260 ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
262 cn.setImports(mandatoryImports, multiimports);
263 ParseNode modifiers=pn.getChild("modifiers");
264 if(modifiers!=null) {
265 cn.setModifiers(parseModifiersList(modifiers));
267 parseAnnotationTypeBody(cn,pn.getChild("body"));
270 if (analyzeset != null)
272 cn.setSourceFileName(currsourcefile);
278 private void parseAnnotationTypeBody(ClassDescriptor cn, ParseNode pn) {
279 ParseNode list_node=pn.getChild("annotation_type_element_list");
280 if(list_node!=null) {
281 ParseNodeVector pnv = list_node.getChildren();
282 for (int i = 0; i < pnv.size(); i++) {
283 ParseNode element_node = pnv.elementAt(i);
284 if (isNode(element_node, "annotation_type_element_declaration")) {
285 ParseNodeVector elementProps = element_node.getChildren();
286 String identifier=null;
287 TypeDescriptor type=null;
288 Modifiers modifiers=new Modifiers();
289 for(int eidx=0; eidx<elementProps.size(); eidx++) {
290 ParseNode prop_node=elementProps.elementAt(eidx);
291 if(isNode(prop_node,"name")) {
292 identifier=prop_node.getTerminal();
293 } else if(isNode(prop_node,"type")) {
294 type=parseTypeDescriptor(prop_node);
295 } else if(isNode(prop_node,"modifier")) {
296 modifiers=parseModifiersList(prop_node);
299 cn.addField(new FieldDescriptor(modifiers, type, identifier, null, false));
305 public ClassDescriptor parseInterfaceDecl(ParseNode pn, ClassDescriptor outerclass) {
306 String basename=pn.getChild("name").getTerminal();
307 String classname=((outerclass==null)?"":(outerclass.getClassName()+"$"))+basename;
308 if (outerclass!=null) {
309 if (packageName==null)
310 outerclass.getSingleImportMappings().put(basename,classname);
312 outerclass.getSingleImportMappings().put(basename,packageName+"."+classname);
314 ClassDescriptor cn= new ClassDescriptor(packageName, classname, true);
317 cn.setImports(mandatoryImports, multiimports);
318 //cn.setAsInterface();
319 if (!isEmpty(pn.getChild("superIF").getTerminal())) {
320 /* parse inherited interface name */
321 ParseNode snlist=pn.getChild("superIF").getChild("extend_interface_list");
322 ParseNodeVector pnv=snlist.getChildren();
323 for(int i=0; i<pnv.size(); i++) {
324 ParseNode decl=pnv.elementAt(i);
325 if (isNode(decl,"type")) {
326 NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
327 cn.addSuperInterface(nd.toString());
328 } else if (isNode(decl, "interface_declaration")) {
329 ClassDescriptor innercn = parseInterfaceDecl(decl, cn);
330 } else throw new Error();
333 cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
334 parseInterfaceBody(cn, pn.getChild("interfacebody"));
335 if (analyzeset != null)
337 cn.setSourceFileName(currsourcefile);
343 private void parseInterfaceBody(ClassDescriptor cn, ParseNode pn) {
344 assert(cn.isInterface());
345 ParseNode decls=pn.getChild("interface_member_declaration_list");
347 ParseNodeVector pnv=decls.getChildren();
348 for(int i=0; i<pnv.size(); i++) {
349 ParseNode decl=pnv.elementAt(i);
350 if (isNode(decl,"constant")) {
351 parseInterfaceConstant(cn,decl);
352 } else if (isNode(decl,"method")) {
353 parseInterfaceMethod(cn,decl.getChild("method_declaration"));
354 } else if (isNode(decl, "interface_declaration")) {
355 parseInterfaceDecl(decl, cn);
356 } else throw new Error(decl.PPrint(2, true));
363 private void parseInterfaceConstant(ClassDescriptor cn, ParseNode pn) {
365 parseFieldDecl(cn,pn.getChild("field_declaration"));
371 private void parseInterfaceMethod(ClassDescriptor cn, ParseNode pn) {
372 ParseNode headern=pn.getChild("header");
373 ParseNode bodyn=pn.getChild("body");
374 MethodDescriptor md=parseMethodHeader(headern.getChild("method_header"));
375 md.getModifiers().addModifier(Modifiers.PUBLIC);
376 md.getModifiers().addModifier(Modifiers.ABSTRACT);
378 BlockNode bn=parseBlock(bodyn);
380 state.addTreeCode(md,bn);
381 } catch (Exception e) {
382 System.out.println("Error with method:"+md.getSymbol());
386 System.out.println("Error with method:"+md.getSymbol());
392 public TaskDescriptor parseTaskDecl(ParseNode pn) {
393 TaskDescriptor td=new TaskDescriptor(pn.getChild("name").getTerminal());
394 ParseNode bodyn=pn.getChild("body");
395 BlockNode bn=parseBlock(bodyn);
396 parseParameterList(td, pn);
397 state.addTreeCode(td,bn);
398 if (pn.getChild("flag_effects_list")!=null)
399 td.addFlagEffects(parseFlags(pn.getChild("flag_effects_list")));
403 public Vector parseFlags(ParseNode pn) {
404 Vector vfe=new Vector();
405 ParseNodeVector pnv=pn.getChildren();
406 for(int i=0; i<pnv.size(); i++) {
407 ParseNode fn=pnv.elementAt(i);
408 FlagEffects fe=parseFlagEffects(fn);
414 public FlagEffects parseFlagEffects(ParseNode pn) {
415 if (isNode(pn,"flag_effect")) {
416 String flagname=pn.getChild("name").getTerminal();
417 FlagEffects fe=new FlagEffects(flagname);
418 if (pn.getChild("flag_list")!=null)
419 parseFlagEffect(fe, pn.getChild("flag_list"));
420 if (pn.getChild("tag_list")!=null)
421 parseTagEffect(fe, pn.getChild("tag_list"));
423 } else throw new Error();
426 public void parseTagEffect(FlagEffects fes, ParseNode pn) {
427 ParseNodeVector pnv=pn.getChildren();
428 for(int i=0; i<pnv.size(); i++) {
429 ParseNode pn2=pnv.elementAt(i);
431 if (isNode(pn2,"not")) {
433 pn2=pn2.getChild("name");
435 String name=pn2.getTerminal();
436 fes.addTagEffect(new TagEffect(name,status));
440 public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
441 ParseNodeVector pnv=pn.getChildren();
442 for(int i=0; i<pnv.size(); i++) {
443 ParseNode pn2=pnv.elementAt(i);
445 if (isNode(pn2,"not")) {
447 pn2=pn2.getChild("name");
449 String name=pn2.getTerminal();
450 fes.addEffect(new FlagEffect(name,status));
454 public FlagExpressionNode parseFlagExpression(ParseNode pn) {
455 if (isNode(pn,"or")) {
456 ParseNodeVector pnv=pn.getChildren();
457 ParseNode left=pnv.elementAt(0);
458 ParseNode right=pnv.elementAt(1);
459 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_OR));
460 } else if (isNode(pn,"and")) {
461 ParseNodeVector pnv=pn.getChildren();
462 ParseNode left=pnv.elementAt(0);
463 ParseNode right=pnv.elementAt(1);
464 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_AND));
465 } else if (isNode(pn, "not")) {
466 ParseNodeVector pnv=pn.getChildren();
467 ParseNode left=pnv.elementAt(0);
468 return new FlagOpNode(parseFlagExpression(left), new Operation(Operation.LOGIC_NOT));
470 } else if (isNode(pn,"name")) {
471 return new FlagNode(pn.getTerminal());
477 public Vector parseChecks(ParseNode pn) {
478 Vector ccs=new Vector();
479 ParseNodeVector pnv=pn.getChildren();
480 for(int i=0; i<pnv.size(); i++) {
481 ParseNode fn=pnv.elementAt(i);
482 ConstraintCheck cc=parseConstraintCheck(fn);
488 public ConstraintCheck parseConstraintCheck(ParseNode pn) {
489 if (isNode(pn,"cons_check")) {
490 String specname=pn.getChild("name").getChild("identifier").getTerminal();
491 Vector[] args=parseConsArgumentList(pn);
492 ConstraintCheck cc=new ConstraintCheck(specname);
493 for(int i=0; i<args[0].size(); i++) {
494 cc.addVariable((String)args[0].get(i));
495 cc.addArgument((ExpressionNode)args[1].get(i));
498 } else throw new Error();
501 public void parseParameterList(TaskDescriptor td, ParseNode pn) {
504 ParseNode paramlist=pn.getChild("task_parameter_list");
507 ParseNodeVector pnv=paramlist.getChildren();
508 for(int i=0; i<pnv.size(); i++) {
509 ParseNode paramn=pnv.elementAt(i);
510 if(paramn.getChild("optional")!=null) {
512 paramn = paramn.getChild("optional").getFirstChild();
513 System.out.println("OPTIONAL FOUND!!!!!!!");
514 } else { optional = false;
515 System.out.println("NOT OPTIONAL"); }
517 TypeDescriptor type=parseTypeDescriptor(paramn);
519 String paramname=paramn.getChild("single").getTerminal();
520 FlagExpressionNode fen=null;
521 if (paramn.getChild("flag")!=null)
522 fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
524 ParseNode tagnode=paramn.getChild("tag");
526 TagExpressionList tel=null;
528 tel=parseTagExpressionList(tagnode);
531 td.addParameter(type,paramname,fen, tel, optional);
535 public TagExpressionList parseTagExpressionList(ParseNode pn) {
536 //BUG FIX: change pn.getChildren() to pn.getChild("tag_expression_list").getChildren()
537 //To test, feed in any input program that uses tags
538 ParseNodeVector pnv=pn.getChild("tag_expression_list").getChildren();
539 TagExpressionList tel=new TagExpressionList();
540 for(int i=0; i<pnv.size(); i++) {
541 ParseNode tn=pnv.elementAt(i);
542 String type=tn.getChild("type").getTerminal();
543 String name=tn.getChild("single").getTerminal();
544 tel.addTag(type, name);
549 public ClassDescriptor parseTypeDecl(ParseNode pn) {
550 ClassDescriptor cn=new ClassDescriptor(packageName, pn.getChild("name").getTerminal(), false);
552 cn.setImports(mandatoryImports, multiimports);
553 if (!isEmpty(pn.getChild("super").getTerminal())) {
554 /* parse superclass name */
555 ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
556 NameDescriptor nd=parseClassName(snn);
557 cn.setSuper(nd.toString());
559 if (!(cn.getSymbol().equals(TypeUtil.ObjectClass)||
560 cn.getSymbol().equals(TypeUtil.TagClass)))
561 cn.setSuper(TypeUtil.ObjectClass);
563 // check inherited interfaces
564 if (!isEmpty(pn.getChild("superIF").getTerminal())) {
565 /* parse inherited interface name */
566 ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
567 ParseNodeVector pnv=snlist.getChildren();
568 for(int i=0; i<pnv.size(); i++) {
569 ParseNode decl=pnv.elementAt(i);
570 if (isNode(decl,"type")) {
571 NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
572 cn.addSuperInterface(nd.toString());
576 cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
577 parseClassBody(cn, pn.getChild("classbody"));
579 boolean hasConstructor = false;
580 for(Iterator method_it=cn.getMethods(); method_it.hasNext(); ) {
581 MethodDescriptor md=(MethodDescriptor)method_it.next();
582 hasConstructor |= md.isConstructor();
584 if((!hasConstructor) && (!cn.isEnum())) {
585 // add a default constructor for this class
586 MethodDescriptor md = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC),
587 cn.getSymbol(), false);
588 BlockNode bn=new BlockNode();
589 state.addTreeCode(md,bn);
590 md.setDefaultConstructor();
597 cn.setSourceFileName(currsourcefile);
601 if (analyzeset != null)
604 //create this$n representing a final reference to the next surrounding class. each inner class should have whatever inner class
605 //pointers the surrounding class has + a pointer to the surrounding class.
608 this.isRunningRecursiveInnerClass = true; //fOR dEBUGGING PURPOSES IN ORDER TO DUMP STRINGS WHILE IN THIS CODE PATH
609 addOuterClassReferences( cn, 0 );
610 addOuterClassParam( cn, 0 );
611 this.isRunningRecursiveInnerClass = false;
616 private void initializeOuterMember( MethodDescriptor md, String fieldName, String formalParameter ) {
617 BlockNode obn = state.getMethodBody(md);
618 NameNode nn=new NameNode( new NameDescriptor( fieldName ) );
619 NameNode fn = new NameNode ( new NameDescriptor( formalParameter ) );
620 //nn.setNumLine(en.getNumLine())
621 AssignmentNode an=new AssignmentNode(nn,fn,new AssignOperation(1));
622 //an.setNumLine(pn.getLine());
623 obn.addFirstBlockStatement(new BlockExpressionNode(an));
624 // System.out.print( "The code inserted is : " + obn.printNode( 0 ) + "\n" );
625 state.addTreeCode(md, obn);
628 private void addOuterClassParam( ClassDescriptor cn, int depth )
630 Iterator nullCheckItr = cn.getInnerClasses();
631 if( false == nullCheckItr.hasNext() )
634 //create a typedescriptor of type cn
635 TypeDescriptor theTypeDesc = new TypeDescriptor( cn );
637 for(Iterator it=cn.getInnerClasses(); it.hasNext(); ) {
638 ClassDescriptor icd=(ClassDescriptor)it.next();
640 //iterate over all ctors of I.Cs and add a new param
641 for(Iterator method_it=icd.getMethods(); method_it.hasNext(); ) {
642 MethodDescriptor md=(MethodDescriptor)method_it.next();
643 if( md.isConstructor() ){
644 md.addParameter( theTypeDesc, "surrounding$" + String.valueOf(depth) );
645 initializeOuterMember( md, "this$" + String.valueOf( depth ), "surrounding$" + String.valueOf(depth) );
646 //System.out.println( "The added param is " + md.toString() + "\n" );
649 addOuterClassParam( icd, depth + 1 );
654 private void addOuterClassReferences( ClassDescriptor cn, int depth )
656 //SYMBOLTABLE does not have a length or empty method, hence could not define a hasInnerClasses method in classDescriptor
657 Iterator nullCheckItr = cn.getInnerClasses();
658 if( false == nullCheckItr.hasNext() )
661 String tempCopy = cn.getClassName();
665 ParseNode theNode = new ParseNode( "field_declaration" );
666 theNode.addChild("modifier").addChild( new ParseNode( "modifier_list" ) ).addChild("final");
667 ParseNode theTypeNode = new ParseNode("type");
668 ParseNode tempChildNode = theTypeNode.addChild("class").addChild( "name" );
669 //tempChildNode.addChild("base").addChild( new ParseNode("empty") );
670 tempChildNode.addChild("identifier").addChild ( tempCopy );
671 theNode.addChild("type").addChild( theTypeNode );
672 ParseNode variableDeclaratorID = new ParseNode("single");
673 String theStr = "this$" + String.valueOf( depth );
674 variableDeclaratorID.addChild( theStr );
675 ParseNode variableDeclarator = new ParseNode( "variable_declarator" );
676 variableDeclarator.addChild( variableDeclaratorID );
677 ParseNode variableDeclaratorList = new ParseNode("variable_declarators_list");
678 variableDeclaratorList.addChild( variableDeclarator );
679 theNode.addChild("variables").addChild( variableDeclaratorList );
681 for(Iterator it=cn.getInnerClasses(); it.hasNext(); ) {
682 ClassDescriptor icd=(ClassDescriptor)it.next();
683 parseFieldDecl( icd, theNode );
685 SymbolTable fieldTable = icd.getFieldTable();
686 //System.out.println( fieldTable.toString() );
688 icd.setInnerDepth( depth + 1 );
689 addOuterClassReferences( icd, depth + 1 );
693 private void parseClassBody(ClassDescriptor cn, ParseNode pn) {
694 ParseNode decls=pn.getChild("class_body_declaration_list");
696 ParseNodeVector pnv=decls.getChildren();
697 for(int i=0; i<pnv.size(); i++) {
698 ParseNode decl=pnv.elementAt(i);
699 if (isNode(decl,"member")) {
700 parseClassMember(cn,decl);
701 } else if (isNode(decl,"constructor")) {
702 parseConstructorDecl(cn,decl.getChild("constructor_declaration"));
703 } else if (isNode(decl, "static_block")) {
704 parseStaticBlockDecl(cn, decl.getChild("static_block_declaration"));
705 } else if (isNode(decl,"block")) {
706 } else throw new Error();
711 private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
712 ParseNode fieldnode=pn.getChild("field");
713 if (fieldnode!=null) {
714 //System.out.println( pn.PPrint( 0, true ) );
715 parseFieldDecl(cn,fieldnode.getChild("field_declaration"));
718 ParseNode methodnode=pn.getChild("method");
719 if (methodnode!=null) {
720 parseMethodDecl(cn,methodnode.getChild("method_declaration"));
723 ParseNode innerclassnode=pn.getChild("inner_class_declaration");
724 if (innerclassnode!=null) {
725 parseInnerClassDecl(cn,innerclassnode);
728 ParseNode innerinterfacenode=pn.getChild("interface_declaration");
729 if (innerinterfacenode!=null) {
730 parseInterfaceDecl(innerinterfacenode, cn);
734 ParseNode enumnode=pn.getChild("enum_declaration");
735 if (enumnode!=null) {
736 ClassDescriptor ecn=parseEnumDecl(cn,enumnode);
739 ParseNode flagnode=pn.getChild("flag");
740 if (flagnode!=null) {
741 parseFlagDecl(cn, flagnode.getChild("flag_declaration"));
744 // in case there are empty node
745 ParseNode emptynode=pn.getChild("empty");
746 if(emptynode != null) {
749 System.out.println("Unrecognized node:"+pn.PPrint(2,true));
753 //10/9/2011 changed this function to enable creation of default constructor for inner classes.
754 //the change was refactoring this function with the corresponding version for normal classes. sganapat
755 private ClassDescriptor parseInnerClassDecl(ClassDescriptor cn, ParseNode pn) {
756 String basename=pn.getChild("name").getTerminal();
757 String classname=cn.getClassName()+"$"+basename;
759 if (cn.getPackage()==null)
760 cn.getSingleImportMappings().put(basename,classname);
762 cn.getSingleImportMappings().put(basename,cn.getPackage()+"."+classname);
764 ClassDescriptor icn=new ClassDescriptor(cn.getPackage(), classname, false);
766 icn.setImports(mandatoryImports, multiimports);
767 icn.setSurroundingClass(cn.getSymbol());
768 icn.setSurrounding(cn);
769 cn.addInnerClass(icn);
771 if (!isEmpty(pn.getChild("super").getTerminal())) {
772 /* parse superclass name */
773 ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
774 NameDescriptor nd=parseClassName(snn);
775 icn.setSuper(nd.toString());
777 if (!(icn.getSymbol().equals(TypeUtil.ObjectClass)||
778 icn.getSymbol().equals(TypeUtil.TagClass)))
779 icn.setSuper(TypeUtil.ObjectClass);
781 // check inherited interfaces
782 if (!isEmpty(pn.getChild("superIF").getTerminal())) {
783 /* parse inherited interface name */
784 ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
785 ParseNodeVector pnv=snlist.getChildren();
786 for(int i=0; i<pnv.size(); i++) {
787 ParseNode decl=pnv.elementAt(i);
788 if (isNode(decl,"type")) {
789 NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
790 icn.addSuperInterface(nd.toString());
794 icn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
797 icn.setAsInnerClass();
799 parseClassBody(icn, pn.getChild("classbody"));
801 boolean hasConstructor = false;
802 for(Iterator method_it=icn.getMethods(); method_it.hasNext(); ) {
803 MethodDescriptor md=(MethodDescriptor)method_it.next();
804 hasConstructor |= md.isConstructor();
806 //sganapat adding change to allow proper construction of inner class objects
807 if((!hasConstructor) && (!icn.isEnum())) {
808 // add a default constructor for this class
809 MethodDescriptor md = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC),
810 icn.getSymbol(), false);
811 BlockNode bn=new BlockNode();
812 state.addTreeCode(md,bn);
813 md.setDefaultConstructor();
818 if (analyzeset != null)
820 icn.setSourceFileName(currsourcefile);
826 private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
827 ParseNode tn=pn.getChild("type");
828 String type_st=tn.getTerminal();
829 if(type_st.equals("byte")) {
830 return state.getTypeDescriptor(TypeDescriptor.BYTE);
831 } else if(type_st.equals("short")) {
832 return state.getTypeDescriptor(TypeDescriptor.SHORT);
833 } else if(type_st.equals("boolean")) {
834 return state.getTypeDescriptor(TypeDescriptor.BOOLEAN);
835 } else if(type_st.equals("int")) {
836 return state.getTypeDescriptor(TypeDescriptor.INT);
837 } else if(type_st.equals("long")) {
838 return state.getTypeDescriptor(TypeDescriptor.LONG);
839 } else if(type_st.equals("char")) {
840 return state.getTypeDescriptor(TypeDescriptor.CHAR);
841 } else if(type_st.equals("float")) {
842 return state.getTypeDescriptor(TypeDescriptor.FLOAT);
843 } else if(type_st.equals("double")) {
844 return state.getTypeDescriptor(TypeDescriptor.DOUBLE);
845 } else if(type_st.equals("class")) {
846 ParseNode nn=tn.getChild("class");
847 return state.getTypeDescriptor(parseClassName(nn.getChild("name")));
848 } else if(type_st.equals("array")) {
849 ParseNode nn=tn.getChild("array");
850 TypeDescriptor td=parseTypeDescriptor(nn.getChild("basetype"));
851 Integer numdims=(Integer)nn.getChild("dims").getLiteral();
852 for(int i=0; i<numdims.intValue(); i++)
853 td=td.makeArray(state);
856 System.out.println(pn.PPrint(2, true));
861 //Needed to separate out top level call since if a base exists,
862 //we do not want to apply our resolveName function (i.e. deal with imports)
863 //otherwise, if base == null, we do just want to resolve name.
864 private NameDescriptor parseClassName(ParseNode nn) {
867 ParseNode base=nn.getChild("base");
868 ParseNode id=nn.getChild("identifier");
869 String classname = id.getTerminal();
871 return new NameDescriptor(resolveName(classname));
873 return new NameDescriptor(parseClassNameRecursive(base.getChild("name")),classname);
876 private NameDescriptor parseClassNameRecursive(ParseNode nn) {
877 ParseNode base=nn.getChild("base");
878 ParseNode id=nn.getChild("identifier");
879 String classname = id.getTerminal();
881 return new NameDescriptor(classname);
883 return new NameDescriptor(parseClassNameRecursive(base.getChild("name")),classname);
886 //This will get the mapping of a terminal class name
887 //to a canonical classname (with imports/package locations in them)
888 private String resolveName(String terminal) {
890 if(mandatoryImports.containsKey(terminal)) {
891 return (String) mandatoryImports.get(terminal);
893 if(multiimports.containsKey(terminal)) {
895 Object o = multiimports.get(terminal);
896 if(o instanceof Error) {
897 throw new Error("Class " + terminal + " is ambiguous. Cause: more than 1 package import contain the same class.");
899 //At this point, if we found a unique class
900 //we can treat it as a single, mandatory import.
901 mandatoryImports.put(terminal, o);
910 //only function difference between this and parseName() is that this
911 //does not look for a import mapping.
912 private NameDescriptor parseName(ParseNode nn) {
913 ParseNode base=nn.getChild("base");
914 ParseNode id=nn.getChild("identifier");
916 return new NameDescriptor(id.getTerminal());
918 return new NameDescriptor(parseName(base.getChild("name")),id.getTerminal());
921 private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
922 String name=pn.getChild("name").getTerminal();
923 FlagDescriptor flag=new FlagDescriptor(name);
924 if (pn.getChild("external")!=null)
929 private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
930 ParseNode mn=pn.getChild("modifier");
931 Modifiers m=parseModifiersList(mn);
932 if(cn.isInterface()) {
933 // TODO add version for normal Java later
934 // Can only be PUBLIC or STATIC or FINAL
935 if((m.isAbstract()) || (m.isAtomic()) || (m.isNative())
936 || (m.isSynchronized())) {
937 throw new Error("Error: field in Interface " + cn.getSymbol() + "can only be PUBLIC or STATIC or FINAL");
939 m.addModifier(Modifiers.PUBLIC);
940 m.addModifier(Modifiers.STATIC);
941 m.addModifier(Modifiers.FINAL);
944 ParseNode tn=pn.getChild("type");
945 TypeDescriptor t=parseTypeDescriptor(tn);
946 ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
947 ParseNodeVector pnv=vn.getChildren();
948 boolean isglobal=pn.getChild("global")!=null;
950 for(int i=0; i<pnv.size(); i++) {
951 ParseNode vardecl=pnv.elementAt(i);
952 ParseNode tmp=vardecl;
953 TypeDescriptor arrayt=t;
954 if( this.isRunningRecursiveInnerClass && false )
956 System.out.println( "the length of the list is " + String.valueOf( pnv.size() ) );
957 System.out.println( "\n the parse node is \n" + tmp.PPrint( 0, true ) );
959 while (tmp.getChild("single")==null) {
960 arrayt=arrayt.makeArray(state);
961 tmp=tmp.getChild("array");
963 String identifier=tmp.getChild("single").getTerminal();
964 ParseNode epn=vardecl.getChild("initializer");
966 ExpressionNode en=null;
969 en=parseExpression(epn.getFirstChild());
970 en.setNumLine(epn.getFirstChild().getLine());
972 // for static field, the initializer should be considered as a
974 boolean isfirst = false;
975 MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks");
977 // the first static block for this class
978 Modifiers m_i=new Modifiers();
979 m_i.addModifier(Modifiers.STATIC);
980 md = new MethodDescriptor(m_i, "staticblocks", false);
981 md.setAsStaticBlock();
987 cn.incStaticBlocks();
988 BlockNode bn=new BlockNode();
989 NameNode nn=new NameNode(new NameDescriptor(identifier));
990 nn.setNumLine(en.getNumLine());
991 AssignmentNode an=new AssignmentNode(nn,en,new AssignOperation(1));
992 an.setNumLine(pn.getLine());
993 bn.addBlockStatement(new BlockExpressionNode(an));
995 state.addTreeCode(md,bn);
997 BlockNode obn = state.getMethodBody(md);
998 for(int ii = 0; ii < bn.size(); ii++) {
999 BlockStatementNode bsn = bn.get(ii);
1000 obn.addBlockStatement(bsn);
1002 state.addTreeCode(md, obn);
1009 cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal));
1010 assignAnnotationsToType(m,arrayt);
1014 private void assignAnnotationsToType(Modifiers modifiers, TypeDescriptor type) {
1015 Vector<AnnotationDescriptor> annotations=modifiers.getAnnotations();
1016 for(int i=0; i<annotations.size(); i++) {
1017 // it only supports a marker annotation
1018 AnnotationDescriptor an=annotations.elementAt(i);
1019 type.addAnnotationMarker(an);
1025 private ExpressionNode parseExpression(ParseNode pn) {
1026 if (isNode(pn,"assignment"))
1028 //System.out.println( "parsing a field decl in my class that has assignment in initialization " + pn.PPrint( 0, true ) + "\n");
1029 return parseAssignmentExpression(pn);
1031 else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
1032 isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
1033 isNode(pn,"bitwise_and")||isNode(pn,"equal")||
1034 isNode(pn,"not_equal")||isNode(pn,"comp_lt")||
1035 isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
1036 isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
1037 isNode(pn,"rightshift")||isNode(pn,"sub")||
1038 isNode(pn,"urightshift")||isNode(pn,"sub")||
1039 isNode(pn,"add")||isNode(pn,"mult")||
1040 isNode(pn,"div")||isNode(pn,"mod")) {
1041 ParseNodeVector pnv=pn.getChildren();
1042 ParseNode left=pnv.elementAt(0);
1043 ParseNode right=pnv.elementAt(1);
1044 Operation op=new Operation(pn.getLabel());
1045 OpNode on=new OpNode(parseExpression(left),parseExpression(right),op);
1046 on.setNumLine(pn.getLine());
1048 } else if (isNode(pn,"unaryplus")||
1049 isNode(pn,"unaryminus")||
1051 isNode(pn,"comp")) {
1052 ParseNode left=pn.getFirstChild();
1053 Operation op=new Operation(pn.getLabel());
1054 OpNode on=new OpNode(parseExpression(left),op);
1055 on.setNumLine(pn.getLine());
1057 } else if (isNode(pn,"postinc")||
1058 isNode(pn,"postdec")) {
1059 ParseNode left=pn.getFirstChild();
1060 AssignOperation op=new AssignOperation(pn.getLabel());
1061 AssignmentNode an=new AssignmentNode(parseExpression(left),null,op);
1062 an.setNumLine(pn.getLine());
1065 } else if (isNode(pn,"preinc")||
1066 isNode(pn,"predec")) {
1067 ParseNode left=pn.getFirstChild();
1068 AssignOperation op=isNode(pn,"preinc")?new AssignOperation(AssignOperation.PLUSEQ):new AssignOperation(AssignOperation.MINUSEQ);
1069 AssignmentNode an=new AssignmentNode(parseExpression(left),
1070 new LiteralNode("integer",new Integer(1)),op);
1071 an.setNumLine(pn.getLine());
1073 } else if (isNode(pn,"literal")) {
1074 String literaltype=pn.getTerminal();
1075 ParseNode literalnode=pn.getChild(literaltype);
1076 Object literal_obj=literalnode.getLiteral();
1077 LiteralNode ln=new LiteralNode(literaltype, literal_obj);
1078 ln.setNumLine(pn.getLine());
1080 } else if (isNode(pn, "createobject")) {
1081 TypeDescriptor td = parseTypeDescriptor(pn);
1083 Vector args = parseArgumentList(pn);
1084 boolean isglobal = pn.getChild("global") != null || pn.getChild("scratch") != null;
1085 String disjointId = null;
1086 if (pn.getChild("disjoint") != null) {
1087 disjointId = pn.getChild("disjoint").getTerminal();
1089 ParseNode idChild = (pn.getChild( "id" ));
1090 ParseNode baseChild = (pn.getChild( "base" ));
1092 CreateObjectNode con = new CreateObjectNode(td, isglobal, disjointId);
1093 if( null != idChild && null != idChild.getFirstChild() ) {
1094 idChild = idChild.getFirstChild();
1095 //System.out.println( "\nThe object passed has this expression " + idChild.PPrint( 0, true ) );
1096 ExpressionNode en = parseExpression( idChild );
1097 //System.out.println( "\nThe object passed has this expression " + en.printNode( 0 ) );
1098 con.setSurroundingExpression( en );
1100 else if( null != baseChild && null != baseChild.getFirstChild() ) {
1101 baseChild = baseChild.getFirstChild();
1102 //System.out.println( "\nThe object passed has this expression " + baseChild.PPrint( 0, true ) );
1103 ExpressionNode en = parseExpression( baseChild );
1104 //System.out.println( "\nThe object passed has this expression " + en.printNode( 0 ) );
1105 con.setSurroundingExpression( en );
1107 con.setNumLine(pn.getLine());
1108 for (int i = 0; i < args.size(); i++) {
1109 con.addArgument((ExpressionNode) args.get(i));
1111 /* Could have flag set or tag added here */
1112 if (pn.getChild("flag_list") != null || pn.getChild("tag_list") != null) {
1113 FlagEffects fe = new FlagEffects(null);
1114 if (pn.getChild("flag_list") != null)
1115 parseFlagEffect(fe, pn.getChild("flag_list"));
1117 if (pn.getChild("tag_list") != null)
1118 parseTagEffect(fe, pn.getChild("tag_list"));
1119 con.addFlagEffects(fe);
1123 } else if (isNode(pn,"createobjectcls")) {
1124 //TODO::: FIX BUG!!! static fields in caller context need to become parameters
1125 //TODO::: caller context need to be passed in here
1126 TypeDescriptor td=parseTypeDescriptor(pn);
1128 ClassDescriptor cnnew=new ClassDescriptor(packageName,td.getSymbol()+"$"+innerCount, false);
1130 cnnew.setImports(mandatoryImports, multiimports);
1131 cnnew.setSuper(td.getSymbol());
1133 parseClassBody(cnnew, pn.getChild("decl").getChild("classbody"));
1134 TypeDescriptor tdnew=state.getTypeDescriptor(cnnew.getSymbol());
1136 Vector args=parseArgumentList(pn);
1137 ParseNode idChild = pn.getChild( "id" );
1138 ParseNode baseChild = pn.getChild( "base" );
1139 //System.out.println("\n to print idchild and basechild for ");
1140 /*if( null != idChild )
1141 System.out.println( "\n trying to create an inner class and the id child passed is " + idChild.PPrint( 0, true ) );
1142 if( null != baseChild )
1143 System.out.println( "\n trying to create an inner class and the base child passed is " + baseChild.PPrint( 0, true ) );*/
1144 CreateObjectNode con=new CreateObjectNode(tdnew, false, null);
1145 con.setNumLine(pn.getLine());
1146 for(int i=0; i<args.size(); i++) {
1147 con.addArgument((ExpressionNode)args.get(i));
1151 if (analyzeset != null)
1152 analyzeset.add(cnnew);
1153 cnnew.setSourceFileName(currsourcefile);
1154 state.addClass(cnnew);
1157 } else if (isNode(pn,"createarray")) {
1158 //System.out.println(pn.PPrint(3,true));
1159 boolean isglobal=pn.getChild("global")!=null||
1160 pn.getChild("scratch")!=null;
1161 String disjointId=null;
1162 if( pn.getChild("disjoint") != null) {
1163 disjointId = pn.getChild("disjoint").getTerminal();
1165 TypeDescriptor td=parseTypeDescriptor(pn);
1166 Vector args=parseDimExprs(pn);
1168 if (pn.getChild("dims_opt").getLiteral()!=null)
1169 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
1170 for(int i=0; i<(args.size()+num); i++)
1171 td=td.makeArray(state);
1172 CreateObjectNode con=new CreateObjectNode(td, isglobal, disjointId);
1173 con.setNumLine(pn.getLine());
1174 for(int i=0; i<args.size(); i++) {
1175 con.addArgument((ExpressionNode)args.get(i));
1179 if (isNode(pn,"createarray2")) {
1180 TypeDescriptor td=parseTypeDescriptor(pn);
1182 if (pn.getChild("dims_opt").getLiteral()!=null)
1183 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
1184 for(int i=0; i<num; i++)
1185 td=td.makeArray(state);
1186 CreateObjectNode con=new CreateObjectNode(td, false, null);
1187 con.setNumLine(pn.getLine());
1188 ParseNode ipn = pn.getChild("initializer");
1189 Vector initializers=parseVariableInitializerList(ipn);
1190 ArrayInitializerNode ain = new ArrayInitializerNode(initializers);
1191 ain.setNumLine(pn.getLine());
1192 con.addArrayInitializer(ain);
1194 } else if (isNode(pn,"name")) {
1195 NameDescriptor nd=parseName(pn);
1196 NameNode nn=new NameNode(nd);
1197 nn.setNumLine(pn.getLine());
1199 } else if (isNode(pn,"this")) {
1200 NameDescriptor nd=new NameDescriptor("this");
1201 NameNode nn=new NameNode(nd);
1202 nn.setNumLine(pn.getLine());
1204 } else if (isNode(pn,"parentclass")) {
1205 NameDescriptor nd=new NameDescriptor("this");
1206 NameNode nn=new NameNode(nd);
1207 nn.setNumLine(pn.getLine());
1208 //because inner classes pass right thru......
1209 /* FieldAccessNode fan=new FieldAccessNode(nn,"this$0");
1210 fan.setNumLine(pn.getLine());*/
1212 } else if (isNode(pn,"isavailable")) {
1213 NameDescriptor nd=new NameDescriptor(pn.getTerminal());
1214 NameNode nn=new NameNode(nd);
1215 nn.setNumLine(pn.getLine());
1216 return new OpNode(nn,null,new Operation(Operation.ISAVAILABLE));
1217 } else if (isNode(pn,"methodinvoke1")) {
1218 NameDescriptor nd=parseName(pn.getChild("name"));
1219 Vector args=parseArgumentList(pn);
1220 MethodInvokeNode min=new MethodInvokeNode(nd);
1221 min.setNumLine(pn.getLine());
1222 for(int i=0; i<args.size(); i++) {
1223 min.addArgument((ExpressionNode)args.get(i));
1226 } else if (isNode(pn,"methodinvoke2")) {
1227 String methodid=pn.getChild("id").getTerminal();
1228 ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
1229 Vector args=parseArgumentList(pn);
1230 MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
1231 min.setNumLine(pn.getLine());
1232 for(int i=0; i<args.size(); i++) {
1233 min.addArgument((ExpressionNode)args.get(i));
1236 } else if (isNode(pn,"fieldaccess")) {
1237 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
1238 String fieldname=pn.getChild("field").getTerminal();
1240 FieldAccessNode fan=new FieldAccessNode(en,fieldname);
1241 fan.setNumLine(pn.getLine());
1243 } else if (isNode(pn,"arrayaccess")) {
1244 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
1245 ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
1246 ArrayAccessNode aan=new ArrayAccessNode(en,index);
1247 aan.setNumLine(pn.getLine());
1249 } else if (isNode(pn,"cast1")) {
1251 CastNode cn=new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
1252 cn.setNumLine(pn.getLine());
1254 } catch (Exception e) {
1255 System.out.println(pn.PPrint(1,true));
1256 e.printStackTrace();
1259 } else if (isNode(pn,"cast2")) {
1260 CastNode cn=new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
1261 cn.setNumLine(pn.getLine());
1263 } else if (isNode(pn, "getoffset")) {
1264 TypeDescriptor td=parseTypeDescriptor(pn);
1265 String fieldname = pn.getChild("field").getTerminal();
1266 //System.out.println("Checking the values of: "+ " td.toString()= " + td.toString()+ " fieldname= " + fieldname);
1267 return new OffsetNode(td, fieldname);
1268 } else if (isNode(pn, "tert")) {
1270 TertiaryNode tn=new TertiaryNode(parseExpression(pn.getChild("cond").getFirstChild()),
1271 parseExpression(pn.getChild("trueexpr").getFirstChild()),
1272 parseExpression(pn.getChild("falseexpr").getFirstChild()) );
1273 tn.setNumLine(pn.getLine());
1276 } else if (isNode(pn, "instanceof")) {
1277 ExpressionNode exp=parseExpression(pn.getChild("exp").getFirstChild());
1278 TypeDescriptor t=parseTypeDescriptor(pn);
1279 InstanceOfNode ion=new InstanceOfNode(exp,t);
1280 ion.setNumLine(pn.getLine());
1282 } else if (isNode(pn, "array_initializer")) {
1283 Vector initializers=parseVariableInitializerList(pn);
1284 return new ArrayInitializerNode(initializers);
1285 } else if (isNode(pn, "class_type")) {
1286 TypeDescriptor td=parseTypeDescriptor(pn);
1287 ClassTypeNode ctn=new ClassTypeNode(td);
1288 ctn.setNumLine(pn.getLine());
1290 } else if (isNode(pn, "empty")) {
1293 System.out.println("---------------------");
1294 System.out.println(pn.PPrint(3,true));
1299 private Vector parseDimExprs(ParseNode pn) {
1300 Vector arglist=new Vector();
1301 ParseNode an=pn.getChild("dim_exprs");
1302 if (an==null) /* No argument list */
1304 ParseNodeVector anv=an.getChildren();
1305 for(int i=0; i<anv.size(); i++) {
1306 arglist.add(parseExpression(anv.elementAt(i)));
1311 private Vector parseArgumentList(ParseNode pn) {
1312 Vector arglist=new Vector();
1313 ParseNode an=pn.getChild("argument_list");
1314 if (an==null) /* No argument list */
1316 ParseNodeVector anv=an.getChildren();
1317 for(int i=0; i<anv.size(); i++) {
1318 arglist.add(parseExpression(anv.elementAt(i)));
1323 private Vector[] parseConsArgumentList(ParseNode pn) {
1324 Vector arglist=new Vector();
1325 Vector varlist=new Vector();
1326 ParseNode an=pn.getChild("cons_argument_list");
1327 if (an==null) /* No argument list */
1328 return new Vector[] {varlist, arglist};
1329 ParseNodeVector anv=an.getChildren();
1330 for(int i=0; i<anv.size(); i++) {
1331 ParseNode cpn=anv.elementAt(i);
1332 ParseNode var=cpn.getChild("var");
1333 ParseNode exp=cpn.getChild("exp").getFirstChild();
1334 varlist.add(var.getTerminal());
1335 arglist.add(parseExpression(exp));
1337 return new Vector[] {varlist, arglist};
1340 private Vector parseVariableInitializerList(ParseNode pn) {
1341 Vector varInitList=new Vector();
1342 ParseNode vin=pn.getChild("var_init_list");
1343 if (vin==null) /* No argument list */
1345 ParseNodeVector vinv=vin.getChildren();
1346 for(int i=0; i<vinv.size(); i++) {
1347 varInitList.add(parseExpression(vinv.elementAt(i)));
1352 private ExpressionNode parseAssignmentExpression(ParseNode pn) {
1353 AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
1354 ParseNodeVector pnv=pn.getChild("args").getChildren();
1356 AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
1357 an.setNumLine(pn.getLine());
1362 private void parseMethodDecl(ClassDescriptor cn, ParseNode pn) {
1363 ParseNode headern=pn.getChild("method_header");
1364 ParseNode bodyn=pn.getChild("body");
1365 MethodDescriptor md=parseMethodHeader(headern);
1367 BlockNode bn=parseBlock(bodyn);
1368 bn.setNumLine(pn.getLine()); // assume that method header is located at the beginning of method body
1370 state.addTreeCode(md,bn);
1372 // this is a hack for investigating new language features
1373 // at the AST level, someday should evolve into a nice compiler
1375 //if( cn.getSymbol().equals( ***put a class in here like: "Test" ) &&
1376 // md.getSymbol().equals( ***put your method in here like: "main" )
1378 // bn.setStyle( BlockNode.NORMAL );
1379 // System.out.println( bn.printNode( 0 ) );
1382 } catch (Exception e) {
1383 System.out.println("Error with method:"+md.getSymbol());
1384 e.printStackTrace();
1387 System.out.println("Error with method:"+md.getSymbol());
1388 e.printStackTrace();
1393 private void parseConstructorDecl(ClassDescriptor cn, ParseNode pn) {
1394 ParseNode mn=pn.getChild("modifiers");
1395 Modifiers m=parseModifiersList(mn);
1396 ParseNode cdecl=pn.getChild("constructor_declarator");
1397 boolean isglobal=cdecl.getChild("global")!=null;
1398 String name=resolveName(cn.getSymbol());
1399 MethodDescriptor md=new MethodDescriptor(m, name, isglobal);
1400 ParseNode paramnode=cdecl.getChild("parameters");
1401 parseParameterList(md,paramnode);
1402 ParseNode bodyn0=pn.getChild("body");
1403 ParseNode bodyn=bodyn0.getChild("constructor_body");
1406 if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
1407 bn=parseBlock(bodyn);
1410 if (bodyn!=null&&bodyn.getChild("superinvoke")!=null) {
1411 ParseNode sin=bodyn.getChild("superinvoke");
1412 NameDescriptor nd=new NameDescriptor("super");
1413 Vector args=parseArgumentList(sin);
1414 MethodInvokeNode min=new MethodInvokeNode(nd);
1415 min.setNumLine(sin.getLine());
1416 for(int i=0; i<args.size(); i++) {
1417 min.addArgument((ExpressionNode)args.get(i));
1419 BlockExpressionNode ben=new BlockExpressionNode(min);
1420 bn.addFirstBlockStatement(ben);
1422 } else if (bodyn!=null&&bodyn.getChild("explconstrinv")!=null) {
1423 ParseNode eci=bodyn.getChild("explconstrinv");
1424 NameDescriptor nd=new NameDescriptor(cn.getSymbol());
1425 Vector args=parseArgumentList(eci);
1426 MethodInvokeNode min=new MethodInvokeNode(nd);
1427 min.setNumLine(eci.getLine());
1428 for(int i=0; i<args.size(); i++) {
1429 min.addArgument((ExpressionNode)args.get(i));
1431 BlockExpressionNode ben=new BlockExpressionNode(min);
1432 ben.setNumLine(eci.getLine());
1433 bn.addFirstBlockStatement(ben);
1435 state.addTreeCode(md,bn);
1438 private void parseStaticBlockDecl(ClassDescriptor cn, ParseNode pn) {
1439 // Each class maintains one MethodDecscriptor which combines all its
1440 // static blocks in their declaration order
1441 boolean isfirst = false;
1442 MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks");
1444 // the first static block for this class
1445 Modifiers m_i=new Modifiers();
1446 m_i.addModifier(Modifiers.STATIC);
1447 md = new MethodDescriptor(m_i, "staticblocks", false);
1448 md.setAsStaticBlock();
1451 ParseNode bodyn=pn.getChild("body");
1455 cn.incStaticBlocks();
1457 if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
1458 bn=parseBlock(bodyn);
1462 state.addTreeCode(md,bn);
1464 BlockNode obn = state.getMethodBody(md);
1465 for(int i = 0; i < bn.size(); i++) {
1466 BlockStatementNode bsn = bn.get(i);
1467 obn.addBlockStatement(bsn);
1469 state.addTreeCode(md, obn);
1474 public BlockNode parseBlock(ParseNode pn) {
1475 this.m_taskexitnum = 0;
1476 if (pn==null||isEmpty(pn.getTerminal()))
1477 return new BlockNode();
1478 ParseNode bsn=pn.getChild("block_statement_list");
1479 return parseBlockHelper(bsn);
1482 private BlockNode parseBlockHelper(ParseNode pn) {
1483 ParseNodeVector pnv=pn.getChildren();
1484 BlockNode bn=new BlockNode();
1485 for(int i=0; i<pnv.size(); i++) {
1486 Vector bsv=parseBlockStatement(pnv.elementAt(i));
1487 for(int j=0; j<bsv.size(); j++) {
1488 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
1494 public BlockNode parseSingleBlock(ParseNode pn, String label){
1495 BlockNode bn=new BlockNode();
1496 Vector bsv=parseBlockStatement(pn,label);
1497 for(int j=0; j<bsv.size(); j++) {
1498 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
1500 bn.setStyle(BlockNode.NOBRACES);
1504 public BlockNode parseSingleBlock(ParseNode pn) {
1505 return parseSingleBlock(pn,null);
1508 public Vector parseSESEBlock(Vector parentbs, ParseNode pn) {
1509 ParseNodeVector pnv=pn.getChildren();
1510 Vector bv=new Vector();
1511 for(int i=0; i<pnv.size(); i++) {
1512 bv.addAll(parseBlockStatement(pnv.elementAt(i)));
1517 public Vector parseBlockStatement(ParseNode pn){
1518 return parseBlockStatement(pn,null);
1521 public Vector parseBlockStatement(ParseNode pn, String label) {
1522 Vector blockstatements=new Vector();
1523 if (isNode(pn,"tag_declaration")) {
1524 String name=pn.getChild("single").getTerminal();
1525 String type=pn.getChild("type").getTerminal();
1527 TagDeclarationNode tdn=new TagDeclarationNode(name, type);
1528 tdn.setNumLine(pn.getLine());
1530 blockstatements.add(tdn);
1531 } else if (isNode(pn,"local_variable_declaration")) {
1533 TypeDescriptor t=parseTypeDescriptor(pn);
1534 ParseNode vn=pn.getChild("variable_declarators_list");
1535 ParseNodeVector pnv=vn.getChildren();
1536 for(int i=0; i<pnv.size(); i++) {
1537 ParseNode vardecl=pnv.elementAt(i);
1540 ParseNode tmp=vardecl;
1541 TypeDescriptor arrayt=t;
1543 while (tmp.getChild("single")==null) {
1544 arrayt=arrayt.makeArray(state);
1545 tmp=tmp.getChild("array");
1547 String identifier=tmp.getChild("single").getTerminal();
1549 ParseNode epn=vardecl.getChild("initializer");
1552 ExpressionNode en=null;
1554 en=parseExpression(epn.getFirstChild());
1556 DeclarationNode dn=new DeclarationNode(new VarDescriptor(arrayt, identifier),en);
1557 dn.setNumLine(tmp.getLine());
1559 ParseNode mn=pn.getChild("modifiers");
1561 // here, modifers parse node has the list of annotations
1562 Modifiers m=parseModifiersList(mn);
1563 assignAnnotationsToType(m, arrayt);
1566 blockstatements.add(dn);
1568 } else if (isNode(pn,"nop")) {
1570 } else if (isNode(pn,"expression")) {
1571 BlockExpressionNode ben=new BlockExpressionNode(parseExpression(pn.getFirstChild()));
1572 ben.setNumLine(pn.getLine());
1573 blockstatements.add(ben);
1574 } else if (isNode(pn,"ifstatement")) {
1575 IfStatementNode isn=new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
1576 parseSingleBlock(pn.getChild("statement").getFirstChild()),
1577 pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null);
1578 isn.setNumLine(pn.getLine());
1580 blockstatements.add(isn);
1581 } else if (isNode(pn,"switch_statement")) {
1582 // TODO add version for normal Java later
1583 SwitchStatementNode ssn=new SwitchStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
1584 parseSingleBlock(pn.getChild("statement").getFirstChild()));
1585 ssn.setNumLine(pn.getLine());
1586 blockstatements.add(ssn);
1587 } else if (isNode(pn,"switch_block_list")) {
1588 // TODO add version for normal Java later
1589 ParseNodeVector pnv=pn.getChildren();
1590 for(int i=0; i<pnv.size(); i++) {
1591 ParseNode sblockdecl=pnv.elementAt(i);
1593 if(isNode(sblockdecl, "switch_block")) {
1594 ParseNode lpn=sblockdecl.getChild("switch_labels").getChild("switch_label_list");
1595 ParseNodeVector labelv=lpn.getChildren();
1596 Vector<SwitchLabelNode> slv = new Vector<SwitchLabelNode>();
1597 for(int j=0; j<labelv.size(); j++) {
1598 ParseNode labeldecl=labelv.elementAt(j);
1599 if(isNode(labeldecl, "switch_label")) {
1600 SwitchLabelNode sln=new SwitchLabelNode(parseExpression(labeldecl.getChild("constant_expression").getFirstChild()), false);
1601 sln.setNumLine(labeldecl.getLine());
1602 slv.addElement(sln);
1603 } else if(isNode(labeldecl, "default_switch_label")) {
1604 SwitchLabelNode sln=new SwitchLabelNode(null, true);
1605 sln.setNumLine(labeldecl.getLine());
1606 slv.addElement(sln);
1610 SwitchBlockNode sbn=new SwitchBlockNode(slv,
1611 parseSingleBlock(sblockdecl.getChild("switch_statements").getFirstChild()));
1612 sbn.setNumLine(sblockdecl.getLine());
1614 blockstatements.add(sbn);
1618 } else if (isNode(pn, "trycatchstatement")) {
1619 // TODO add version for normal Java later
1620 // Do not fully support exceptions now. Only make sure that if there are no
1621 // exceptions thrown, the execution is right
1622 ParseNode tpn = pn.getChild("tryblock").getFirstChild();
1623 BlockNode bn=parseBlockHelper(tpn);
1624 blockstatements.add(new SubBlockNode(bn));
1626 ParseNode fbk = pn.getChild("finallyblock");
1628 ParseNode fpn = fbk.getFirstChild();
1629 BlockNode fbn=parseBlockHelper(fpn);
1630 blockstatements.add(new SubBlockNode(fbn));
1632 } else if (isNode(pn, "throwstatement")) {
1633 // TODO Simply return here
1634 //blockstatements.add(new ReturnNode());
1635 } else if (isNode(pn,"taskexit")) {
1637 if (pn.getChild("flag_effects_list")!=null)
1638 vfe=parseFlags(pn.getChild("flag_effects_list"));
1640 if (pn.getChild("cons_checks")!=null)
1641 ccs=parseChecks(pn.getChild("cons_checks"));
1642 TaskExitNode ten=new TaskExitNode(vfe, ccs, this.m_taskexitnum++);
1643 ten.setNumLine(pn.getLine());
1644 blockstatements.add(ten);
1645 } else if (isNode(pn,"atomic")) {
1646 BlockNode bn=parseBlockHelper(pn);
1647 AtomicNode an=new AtomicNode(bn);
1648 an.setNumLine(pn.getLine());
1649 blockstatements.add(an);
1650 } else if (isNode(pn,"synchronized")) {
1651 BlockNode bn=parseBlockHelper(pn.getChild("block"));
1652 ExpressionNode en=parseExpression(pn.getChild("expr").getFirstChild());
1653 SynchronizedNode sn=new SynchronizedNode(en, bn);
1654 sn.setNumLine(pn.getLine());
1655 blockstatements.add(sn);
1656 } else if (isNode(pn,"return")) {
1657 if (isEmpty(pn.getTerminal()))
1658 blockstatements.add(new ReturnNode());
1660 ExpressionNode en=parseExpression(pn.getFirstChild());
1661 ReturnNode rn=new ReturnNode(en);
1662 rn.setNumLine(pn.getLine());
1663 blockstatements.add(rn);
1665 } else if (isNode(pn,"block_statement_list")) {
1666 BlockNode bn=parseBlockHelper(pn);
1667 blockstatements.add(new SubBlockNode(bn));
1668 } else if (isNode(pn,"empty")) {
1670 } else if (isNode(pn,"statement_expression_list")) {
1671 ParseNodeVector pnv=pn.getChildren();
1672 BlockNode bn=new BlockNode();
1673 for(int i=0; i<pnv.size(); i++) {
1674 ExpressionNode en=parseExpression(pnv.elementAt(i));
1675 blockstatements.add(new BlockExpressionNode(en));
1677 bn.setStyle(BlockNode.EXPRLIST);
1678 } else if (isNode(pn,"forstatement")) {
1679 BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
1680 BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
1681 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1682 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1683 if(condition == null) {
1684 // no condition clause, make a 'true' expression as the condition
1685 condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
1687 LoopNode ln=new LoopNode(init,condition,update,body,label);
1688 ln.setNumLine(pn.getLine());
1689 blockstatements.add(ln);
1690 } else if (isNode(pn,"whilestatement")) {
1691 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1692 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1693 if(condition == null) {
1694 // no condition clause, make a 'true' expression as the condition
1695 condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
1697 blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP,label));
1698 } else if (isNode(pn,"dowhilestatement")) {
1699 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1700 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1701 if(condition == null) {
1702 // no condition clause, make a 'true' expression as the condition
1703 condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
1705 blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP,label));
1706 } else if (isNode(pn,"sese")) {
1707 ParseNode pnID=pn.getChild("identifier");
1709 if( pnID != null ) {
1710 stID=pnID.getFirstChild().getTerminal();
1712 SESENode start=new SESENode(stID);
1713 start.setNumLine(pn.getLine());
1714 SESENode end =new SESENode(stID);
1716 end.setStart(start);
1717 blockstatements.add(start);
1718 blockstatements.addAll(parseSESEBlock(blockstatements,pn.getChild("body").getFirstChild()));
1719 blockstatements.add(end);
1720 } else if (isNode(pn,"continue")) {
1721 ContinueBreakNode cbn=new ContinueBreakNode(false);
1722 cbn.setNumLine(pn.getLine());
1723 blockstatements.add(cbn);
1724 } else if (isNode(pn,"break")) {
1725 ContinueBreakNode cbn=new ContinueBreakNode(true);
1726 cbn.setNumLine(pn.getLine());
1727 blockstatements.add(cbn);
1728 ParseNode idopt_pn=pn.getChild("identifier_opt");
1729 ParseNode name_pn=idopt_pn.getChild("name");
1730 // name_pn.getTerminal() gives you the label
1732 } else if (isNode(pn,"genreach")) {
1733 String graphName = pn.getChild("graphName").getTerminal();
1734 blockstatements.add(new GenReachNode(graphName) );
1736 } else if (isNode(pn,"gen_def_reach")) {
1737 String outputName = pn.getChild("outputName").getTerminal();
1738 blockstatements.add(new GenDefReachNode(outputName) );
1740 } else if(isNode(pn,"labeledstatement")) {
1741 String labeledstatement = pn.getChild("name").getTerminal();
1742 BlockNode bn=parseSingleBlock(pn.getChild("statement").getFirstChild(),labeledstatement);
1743 blockstatements.add(new SubBlockNode(bn));
1745 System.out.println("---------------");
1746 System.out.println(pn.PPrint(3,true));
1749 return blockstatements;
1752 public MethodDescriptor parseMethodHeader(ParseNode pn) {
1753 ParseNode mn=pn.getChild("modifiers");
1754 Modifiers m=parseModifiersList(mn);
1756 ParseNode tn=pn.getChild("returntype");
1757 TypeDescriptor returntype;
1759 returntype=parseTypeDescriptor(tn);
1761 returntype=new TypeDescriptor(TypeDescriptor.VOID);
1763 ParseNode pmd=pn.getChild("method_declarator");
1764 String name=pmd.getChild("name").getTerminal();
1765 MethodDescriptor md=new MethodDescriptor(m, returntype, name);
1767 ParseNode paramnode=pmd.getChild("parameters");
1768 parseParameterList(md,paramnode);
1772 public void parseParameterList(MethodDescriptor md, ParseNode pn) {
1773 ParseNode paramlist=pn.getChild("formal_parameter_list");
1774 if (paramlist==null)
1776 ParseNodeVector pnv=paramlist.getChildren();
1777 for(int i=0; i<pnv.size(); i++) {
1778 ParseNode paramn=pnv.elementAt(i);
1780 if (isNode(paramn, "tag_parameter")) {
1781 String paramname=paramn.getChild("single").getTerminal();
1782 TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG);
1783 md.addTagParameter(type, paramname);
1786 TypeDescriptor type=parseTypeDescriptor(paramn);
1788 ParseNode tmp=paramn;
1789 while (tmp.getChild("single")==null) {
1790 type=type.makeArray(state);
1791 tmp=tmp.getChild("array");
1793 String paramname=tmp.getChild("single").getTerminal();
1795 md.addParameter(type, paramname);
1796 if(isNode(paramn, "annotation_parameter")) {
1797 ParseNode listnode=paramn.getChild("annotation_list");
1798 parseParameterAnnotation(listnode,type);
1805 public Modifiers parseModifiersList(ParseNode pn) {
1806 Modifiers m=new Modifiers();
1807 ParseNode modlist=pn.getChild("modifier_list");
1808 if (modlist!=null) {
1809 ParseNodeVector pnv=modlist.getChildren();
1810 for(int i=0; i<pnv.size(); i++) {
1811 ParseNode modn=pnv.elementAt(i);
1812 if (isNode(modn,"public"))
1813 m.addModifier(Modifiers.PUBLIC);
1814 else if (isNode(modn,"protected"))
1815 m.addModifier(Modifiers.PROTECTED);
1816 else if (isNode(modn,"private"))
1817 m.addModifier(Modifiers.PRIVATE);
1818 else if (isNode(modn,"static"))
1819 m.addModifier(Modifiers.STATIC);
1820 else if (isNode(modn,"final"))
1821 m.addModifier(Modifiers.FINAL);
1822 else if (isNode(modn,"native"))
1823 m.addModifier(Modifiers.NATIVE);
1824 else if (isNode(modn,"synchronized"))
1825 m.addModifier(Modifiers.SYNCHRONIZED);
1826 else if (isNode(modn,"atomic"))
1827 m.addModifier(Modifiers.ATOMIC);
1828 else if (isNode(modn,"abstract"))
1829 m.addModifier(Modifiers.ABSTRACT);
1830 else if (isNode(modn,"volatile"))
1831 m.addModifier(Modifiers.VOLATILE);
1832 else if (isNode(modn,"transient"))
1833 m.addModifier(Modifiers.TRANSIENT);
1834 else if(isNode(modn,"annotation_list"))
1835 parseAnnotationList(modn,m);
1837 throw new Error("Unrecognized Modifier:"+modn.getLabel());
1844 private void parseAnnotationList(ParseNode pn, Modifiers m) {
1845 ParseNodeVector pnv = pn.getChildren();
1846 for (int i = 0; i < pnv.size(); i++) {
1847 ParseNode body_list = pnv.elementAt(i);
1848 if (isNode(body_list, "annotation_body")) {
1849 ParseNode body_node = body_list.getFirstChild();
1850 if (isNode(body_node, "marker_annotation")) {
1851 m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
1852 } else if (isNode(body_node, "single_annotation")) {
1853 m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
1854 body_node.getChild("element_value").getTerminal()));
1855 } else if (isNode(body_node, "normal_annotation")) {
1856 throw new Error("Annotation with multiple data members is not supported yet.");
1862 private void parseParameterAnnotation(ParseNode pn,TypeDescriptor type) {
1863 ParseNodeVector pnv = pn.getChildren();
1864 for (int i = 0; i < pnv.size(); i++) {
1865 ParseNode body_list = pnv.elementAt(i);
1866 if (isNode(body_list, "annotation_body")) {
1867 ParseNode body_node = body_list.getFirstChild();
1868 if (isNode(body_node, "marker_annotation")) {
1869 type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
1870 } else if (isNode(body_node, "single_annotation")) {
1871 type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
1872 body_node.getChild("element_value").getTerminal()));
1873 } else if (isNode(body_node, "normal_annotation")) {
1874 throw new Error("Annotation with multiple data members is not supported yet.");
1880 private boolean isNode(ParseNode pn, String label) {
1881 if (pn.getLabel().equals(label))
1886 private static boolean isEmpty(ParseNode pn) {
1887 if (pn.getLabel().equals("empty"))
1893 private static boolean isEmpty(String s) {
1894 if (s.equals("empty"))
1900 /** Throw an exception if something is unexpected */
1901 private void check(ParseNode pn, String label) {
1903 throw new Error(pn+ "IE: Expected '" + label + "', got null");
1905 if (!pn.getLabel().equals(label)) {
1906 throw new Error(pn+ "IE: Expected '" + label + "', got '"+pn.getLabel()+"'");