30440944e12ba848cfe29967e08b5b00dd2cc796
[IRC.git] / Robust / src / IR / Tree / BuildIR.java
1 package IR.Tree;
2 import IR.*;
3 import Util.Lattice;
4 import Util.Pair;
5
6 import java.io.File;
7 import java.util.*;
8
9 public class BuildIR {
10   State state;
11
12   private int m_taskexitnum;
13
14   public BuildIR(State state) {
15     this.state=state;
16     this.m_taskexitnum = 0;
17   }
18
19   public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) {
20     parseFile(pn, toanalyze, sourcefile);
21
22     // numering the interfaces
23     int if_num = 0;
24     Iterator it_classes = state.getClassSymbolTable().getValueSet().iterator();
25     while(it_classes.hasNext()) {
26       ClassDescriptor cd = (ClassDescriptor)it_classes.next();
27       if(cd.isInterface()) {
28         cd.setInterfaceId(if_num++);
29       }
30     }
31   }
32
33   //This is all single imports and a subset of the
34   //multi imports that have been resolved.
35   ChainHashMap mandatoryImports;
36   //maps class names in file to full name
37   //Note may map a name to an ERROR.
38   ChainHashMap multiimports;
39   String packageName;
40
41   String currsourcefile;
42   Set analyzeset;
43
44   void pushChainMaps() {
45     mandatoryImports=mandatoryImports.makeChild();
46     multiimports=multiimports.makeChild();
47   }
48   
49   void popChainMaps() {
50     mandatoryImports=mandatoryImports.getParent();
51     multiimports=multiimports.getParent();
52   }
53
54   /** Parse the classes in this file */
55   public void parseFile(ParseNode pn, Set toanalyze, String sourcefile) {
56     mandatoryImports = new ChainHashMap();
57     multiimports = new ChainHashMap();
58     currsourcefile=sourcefile;
59     analyzeset=toanalyze;
60
61     if(state.JNI) {
62       //add java.lang as our default multi-import
63       this.addMultiImport(sourcefile, "java.lang", false);
64     }
65
66     ParseNode ipn = pn.getChild("imports").getChild("import_decls_list");
67     if ((ipn != null) && !state.MGC) {
68       ParseNodeVector pnv = ipn.getChildren();
69       for (int i = 0; i < pnv.size(); i++) {
70         ParseNode pnimport = pnv.elementAt(i);
71         NameDescriptor nd = parseName(pnimport.getChild("name"));
72         if (isNode(pnimport, "import_single")) {
73           if (!mandatoryImports.containsKey(nd.getIdentifier())) {
74             // map name to full name (includes package/directory
75             mandatoryImports.put(nd.getIdentifier(), nd.getPathFromRootToHere());
76           } else {
77             throw new Error("An ambiguous class "+ nd.getIdentifier() +" has been found. It is included for " +
78                             ((String)mandatoryImports.get(nd.getIdentifier())) + " and " +
79                             nd.getPathFromRootToHere());
80           }
81         } else {
82           addMultiImport(sourcefile, nd.getPathFromRootToHere(), false);
83         }
84       }
85     }
86
87     ParseNode ppn=pn.getChild("packages").getChild("package");
88     packageName = null;
89     if ((ppn!=null) && !state.MGC){
90       NameDescriptor nd = parseClassName(ppn.getChild("name"));
91       packageName = nd.getPathFromRootToHere();
92       //Trick -> import the package directory as a multi-import and it'll
93       //automatically recognize files in the same directory.
94       addMultiImport(sourcefile, packageName, true);
95     }
96
97     ParseNode tpn=pn.getChild("type_declaration_list");
98     if (tpn != null) {
99       ParseNodeVector pnv = tpn.getChildren();
100       for (int i = 0; i < pnv.size(); i++) {
101         ParseNode type_pn = pnv.elementAt(i);
102         if (isEmpty(type_pn)) /* Skip the semicolon */
103           continue;
104         if (isNode(type_pn, "class_declaration")) {
105           ClassDescriptor cn = parseTypeDecl(type_pn);
106           parseInitializers(cn);
107
108           // for inner classes/enum
109           HashSet tovisit = new HashSet();
110           Iterator it_icds = cn.getInnerClasses();
111           while (it_icds.hasNext()) {
112             tovisit.add(it_icds.next());
113           }
114
115           while (!tovisit.isEmpty()) {
116             ClassDescriptor cd = (ClassDescriptor) tovisit.iterator().next();
117             tovisit.remove(cd);
118             parseInitializers(cd);
119
120             Iterator it_ics = cd.getInnerClasses();
121             while (it_ics.hasNext()) {
122               tovisit.add(it_ics.next());
123             }
124           }
125         } else if (isNode(type_pn, "task_declaration")) {
126           TaskDescriptor td = parseTaskDecl(type_pn);
127           if (toanalyze != null)
128             toanalyze.add(td);
129           state.addTask(td);
130         } else if (isNode(type_pn, "interface_declaration")) {
131           // TODO add version for normal Java later
132           ClassDescriptor cn = parseInterfaceDecl(type_pn, null);
133         } else if (isNode(type_pn, "enum_declaration")) {
134           // TODO add version for normal Java later
135           ClassDescriptor cn = parseEnumDecl(null, type_pn);
136
137         } else if(isNode(type_pn,"annotation_type_declaration")) {
138           ClassDescriptor cn=parseAnnotationTypeDecl(type_pn);
139         } else {
140           throw new Error(type_pn.getLabel());
141         }
142       }
143     }
144   }
145
146
147   //This kind of breaks away from tradition a little bit by doing the file checks here
148   // instead of in Semantic check, but doing it here is easier because we have a mapping early on
149   // if I wait until semantic check, I have to change ALL the type descriptors to match the new
150   // mapping and that's both ugly and tedious.
151   private void addMultiImport(String currentSource, String importPath, boolean isPackageDirectory) {
152     boolean found = false;
153     for (int j = 0; j < state.classpath.size(); j++) {
154       String path = (String) state.classpath.get(j);
155       File folder = new File(path, importPath.replace('.', '/'));
156       if (folder.exists()) {
157         found = true;
158         for (String file : folder.list()) {
159           // if the file is of type *.java add to multiImport list.
160           if (file.lastIndexOf('.') != -1 && file.substring(file.lastIndexOf('.')).equalsIgnoreCase(".java")) {
161             String classname = file.substring(0, file.length() - 5);
162             // single imports have precedence over multi-imports
163             if (!mandatoryImports.containsKey(classname)) {
164               //package files have precedence over multi-imports.
165               if (multiimports.containsKey(classname)  && !isPackageDirectory) {
166                 // put error in for later, in case we try to import
167                 multiimports.put(classname, new Error("Error: class " + classname + " is defined more than once in a multi-import in " + currentSource));
168               } else {
169                 multiimports.put(classname, importPath + "." + classname);
170               }
171             }
172           }
173         }
174       }
175     }
176
177     if(!found) {
178       throw new Error("Import package " + importPath + " in  " + currentSource
179                       + " cannot be resolved.");
180     }
181   }
182
183   public void parseInitializers(ClassDescriptor cn) {
184     Vector fv=cn.getFieldVec();
185     int pos = 0;
186     for(int i=0; i<fv.size(); i++) {
187       FieldDescriptor fd=(FieldDescriptor)fv.get(i);
188       if(fd.getExpressionNode()!=null) {
189         Iterator methodit = cn.getMethods();
190         while(methodit.hasNext()) {
191           MethodDescriptor currmd=(MethodDescriptor)methodit.next();
192           if(currmd.isConstructor()) {
193             BlockNode bn=state.getMethodBody(currmd);
194             NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
195             AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
196             bn.addBlockStatementAt(new BlockExpressionNode(an), pos);
197           }
198         }
199         pos++;
200       }
201     }
202   }
203   
204   private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {    
205     String basename=pn.getChild("name").getTerminal();
206     String classname=(cn!=null)?cn.getClassName()+"$"+basename:basename;
207     ClassDescriptor ecd=new ClassDescriptor(cn!=null?cn.getPackage():null, classname, false);
208     
209     if (cn!=null) {
210       if (packageName==null)
211         cn.getSingleImportMappings().put(basename,classname);
212       else
213         cn.getSingleImportMappings().put(basename,packageName+"."+classname);
214     }
215
216     pushChainMaps();
217     ecd.setImports(mandatoryImports, multiimports);
218     ecd.setAsEnum();
219     if(cn != null) {
220       ecd.setSurroundingClass(cn.getSymbol());
221       ecd.setSurrounding(cn);
222       cn.addEnum(ecd);
223     }
224     if (!(ecd.getSymbol().equals(TypeUtil.ObjectClass)||
225           ecd.getSymbol().equals(TypeUtil.TagClass))) {
226       ecd.setSuper(TypeUtil.ObjectClass);
227     }
228     ecd.setModifiers(parseModifiersList(pn.getChild("modifiers")));
229     parseEnumBody(ecd, pn.getChild("enumbody"));
230
231     if (analyzeset != null)
232       analyzeset.add(ecd);
233     ecd.setSourceFileName(currsourcefile);
234     state.addClass(ecd);
235
236     popChainMaps();
237     return ecd;
238   }
239
240   private void parseEnumBody(ClassDescriptor cn, ParseNode pn) {
241     ParseNode decls=pn.getChild("enum_constants_list");
242     if (decls!=null) {
243       ParseNodeVector pnv=decls.getChildren();
244       for(int i=0; i<pnv.size(); i++) {
245         ParseNode decl=pnv.elementAt(i);
246         if (isNode(decl,"enum_constant")) {
247           parseEnumConstant(cn,decl);
248         } else throw new Error();
249       }
250     }
251   }
252
253   private void parseEnumConstant(ClassDescriptor cn, ParseNode pn) {
254     cn.addEnumConstant(pn.getChild("name").getTerminal());
255   }
256
257   private ClassDescriptor parseAnnotationTypeDecl(ParseNode pn) {
258     ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
259     pushChainMaps();
260     cn.setImports(mandatoryImports, multiimports);
261     ParseNode modifiers=pn.getChild("modifiers");
262     if(modifiers!=null) {
263       cn.setModifiers(parseModifiersList(modifiers));
264     }
265     parseAnnotationTypeBody(cn,pn.getChild("body"));
266     popChainMaps();
267
268     if (analyzeset != null)
269       analyzeset.add(cn);
270     cn.setSourceFileName(currsourcefile);
271     state.addClass(cn);
272
273     return cn;
274   }
275
276   private void parseAnnotationTypeBody(ClassDescriptor cn, ParseNode pn) {
277     ParseNode list_node=pn.getChild("annotation_type_element_list");
278     if(list_node!=null) {
279       ParseNodeVector pnv = list_node.getChildren();
280       for (int i = 0; i < pnv.size(); i++) {
281         ParseNode element_node = pnv.elementAt(i);
282         if (isNode(element_node, "annotation_type_element_declaration")) {
283           ParseNodeVector elementProps = element_node.getChildren();
284           String identifier=null;
285           TypeDescriptor type=null;
286           Modifiers modifiers=new Modifiers();
287           for(int eidx=0; eidx<elementProps.size(); eidx++) {
288             ParseNode prop_node=elementProps.elementAt(eidx);
289             if(isNode(prop_node,"name")) {
290               identifier=prop_node.getTerminal();
291             } else if(isNode(prop_node,"type")) {
292               type=parseTypeDescriptor(prop_node);
293             } else if(isNode(prop_node,"modifier")) {
294               modifiers=parseModifiersList(prop_node);
295             }
296           }
297           cn.addField(new FieldDescriptor(modifiers, type, identifier, null, false));
298         }
299       }
300     }
301   }
302
303   public ClassDescriptor parseInterfaceDecl(ParseNode pn, ClassDescriptor outerclass) {
304     String basename=pn.getChild("name").getTerminal();
305     String classname=((outerclass==null)?"":(outerclass.getClassName()+"$"))+basename;
306     if (outerclass!=null) {
307       if (packageName==null)
308         outerclass.getSingleImportMappings().put(basename,classname);
309       else
310         outerclass.getSingleImportMappings().put(basename,packageName+"."+classname);
311     }
312     ClassDescriptor cn= new ClassDescriptor(packageName, classname, true);
313
314     pushChainMaps();
315     cn.setImports(mandatoryImports, multiimports);
316     //cn.setAsInterface();
317     if (!isEmpty(pn.getChild("superIF").getTerminal())) {
318       /* parse inherited interface name */
319       ParseNode snlist=pn.getChild("superIF").getChild("extend_interface_list");
320       ParseNodeVector pnv=snlist.getChildren();
321       for(int i=0; i<pnv.size(); i++) {
322         ParseNode decl=pnv.elementAt(i);
323         if (isNode(decl,"type")) {
324           NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
325           cn.addSuperInterface(nd.toString());
326         } else if (isNode(decl, "interface_declaration")) {
327           ClassDescriptor innercn = parseInterfaceDecl(decl, cn);
328         } else throw new Error();
329       }
330     }
331     cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
332     parseInterfaceBody(cn, pn.getChild("interfacebody"));
333     if (analyzeset != null)
334       analyzeset.add(cn);
335     cn.setSourceFileName(currsourcefile);
336     state.addClass(cn);
337     popChainMaps();
338     return cn;
339   }
340
341   private void parseInterfaceBody(ClassDescriptor cn, ParseNode pn) {
342     assert(cn.isInterface());
343     ParseNode decls=pn.getChild("interface_member_declaration_list");
344     if (decls!=null) {
345       ParseNodeVector pnv=decls.getChildren();
346       for(int i=0; i<pnv.size(); i++) {
347         ParseNode decl=pnv.elementAt(i);
348         if (isNode(decl,"constant")) {
349           parseInterfaceConstant(cn,decl);
350         } else if (isNode(decl,"method")) {
351           parseInterfaceMethod(cn,decl.getChild("method_declaration"));
352         } else if (isNode(decl, "interface_declaration")) {
353           parseInterfaceDecl(decl, cn);
354         } else throw new Error(decl.PPrint(2, true));
355       }
356     }
357   }
358
359
360
361   private void parseInterfaceConstant(ClassDescriptor cn, ParseNode pn) {
362     if (pn!=null) {
363       parseFieldDecl(cn,pn.getChild("field_declaration"));
364       return;
365     }
366     throw new Error();
367   }
368
369   private void parseInterfaceMethod(ClassDescriptor cn, ParseNode pn) {
370     ParseNode headern=pn.getChild("header");
371     ParseNode bodyn=pn.getChild("body");
372     MethodDescriptor md=parseMethodHeader(headern.getChild("method_header"));
373     md.getModifiers().addModifier(Modifiers.PUBLIC);
374     md.getModifiers().addModifier(Modifiers.ABSTRACT);
375     try {
376       BlockNode bn=parseBlock(bodyn);
377       cn.addMethod(md);
378       state.addTreeCode(md,bn);
379     } catch (Exception e) {
380       System.out.println("Error with method:"+md.getSymbol());
381       e.printStackTrace();
382       throw new Error();
383     } catch (Error e) {
384       System.out.println("Error with method:"+md.getSymbol());
385       e.printStackTrace();
386       throw new Error();
387     }
388   }
389
390   public TaskDescriptor parseTaskDecl(ParseNode pn) {
391     TaskDescriptor td=new TaskDescriptor(pn.getChild("name").getTerminal());
392     ParseNode bodyn=pn.getChild("body");
393     BlockNode bn=parseBlock(bodyn);
394     parseParameterList(td, pn);
395     state.addTreeCode(td,bn);
396     if (pn.getChild("flag_effects_list")!=null)
397       td.addFlagEffects(parseFlags(pn.getChild("flag_effects_list")));
398     return td;
399   }
400
401   public Vector parseFlags(ParseNode pn) {
402     Vector vfe=new Vector();
403     ParseNodeVector pnv=pn.getChildren();
404     for(int i=0; i<pnv.size(); i++) {
405       ParseNode fn=pnv.elementAt(i);
406       FlagEffects fe=parseFlagEffects(fn);
407       vfe.add(fe);
408     }
409     return vfe;
410   }
411
412   public FlagEffects parseFlagEffects(ParseNode pn) {
413     if (isNode(pn,"flag_effect")) {
414       String flagname=pn.getChild("name").getTerminal();
415       FlagEffects fe=new FlagEffects(flagname);
416       if (pn.getChild("flag_list")!=null)
417         parseFlagEffect(fe, pn.getChild("flag_list"));
418       if (pn.getChild("tag_list")!=null)
419         parseTagEffect(fe, pn.getChild("tag_list"));
420       return fe;
421     } else throw new Error();
422   }
423
424   public void parseTagEffect(FlagEffects fes, ParseNode pn) {
425     ParseNodeVector pnv=pn.getChildren();
426     for(int i=0; i<pnv.size(); i++) {
427       ParseNode pn2=pnv.elementAt(i);
428       boolean status=true;
429       if (isNode(pn2,"not")) {
430         status=false;
431         pn2=pn2.getChild("name");
432       }
433       String name=pn2.getTerminal();
434       fes.addTagEffect(new TagEffect(name,status));
435     }
436   }
437
438   public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
439     ParseNodeVector pnv=pn.getChildren();
440     for(int i=0; i<pnv.size(); i++) {
441       ParseNode pn2=pnv.elementAt(i);
442       boolean status=true;
443       if (isNode(pn2,"not")) {
444         status=false;
445         pn2=pn2.getChild("name");
446       }
447       String name=pn2.getTerminal();
448       fes.addEffect(new FlagEffect(name,status));
449     }
450   }
451
452   public FlagExpressionNode parseFlagExpression(ParseNode pn) {
453     if (isNode(pn,"or")) {
454       ParseNodeVector pnv=pn.getChildren();
455       ParseNode left=pnv.elementAt(0);
456       ParseNode right=pnv.elementAt(1);
457       return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_OR));
458     } else if (isNode(pn,"and")) {
459       ParseNodeVector pnv=pn.getChildren();
460       ParseNode left=pnv.elementAt(0);
461       ParseNode right=pnv.elementAt(1);
462       return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_AND));
463     } else if (isNode(pn, "not")) {
464       ParseNodeVector pnv=pn.getChildren();
465       ParseNode left=pnv.elementAt(0);
466       return new FlagOpNode(parseFlagExpression(left), new Operation(Operation.LOGIC_NOT));
467
468     } else if (isNode(pn,"name")) {
469       return new FlagNode(pn.getTerminal());
470     } else {
471       throw new Error();
472     }
473   }
474
475   public Vector parseChecks(ParseNode pn) {
476     Vector ccs=new Vector();
477     ParseNodeVector pnv=pn.getChildren();
478     for(int i=0; i<pnv.size(); i++) {
479       ParseNode fn=pnv.elementAt(i);
480       ConstraintCheck cc=parseConstraintCheck(fn);
481       ccs.add(cc);
482     }
483     return ccs;
484   }
485
486   public ConstraintCheck parseConstraintCheck(ParseNode pn) {
487     if (isNode(pn,"cons_check")) {
488       String specname=pn.getChild("name").getChild("identifier").getTerminal();
489       Vector[] args=parseConsArgumentList(pn);
490       ConstraintCheck cc=new ConstraintCheck(specname);
491       for(int i=0; i<args[0].size(); i++) {
492         cc.addVariable((String)args[0].get(i));
493         cc.addArgument((ExpressionNode)args[1].get(i));
494       }
495       return cc;
496     } else throw new Error();
497   }
498
499   public void parseParameterList(TaskDescriptor td, ParseNode pn) {
500
501     boolean optional;
502     ParseNode paramlist=pn.getChild("task_parameter_list");
503     if (paramlist==null)
504       return;
505     ParseNodeVector pnv=paramlist.getChildren();
506     for(int i=0; i<pnv.size(); i++) {
507       ParseNode paramn=pnv.elementAt(i);
508       if(paramn.getChild("optional")!=null) {
509         optional = true;
510         paramn = paramn.getChild("optional").getFirstChild();
511         System.out.println("OPTIONAL FOUND!!!!!!!");
512       } else { optional = false;
513                System.out.println("NOT OPTIONAL"); }
514
515       TypeDescriptor type=parseTypeDescriptor(paramn);
516
517       String paramname=paramn.getChild("single").getTerminal();
518       FlagExpressionNode fen=null;
519       if (paramn.getChild("flag")!=null)
520         fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
521
522       ParseNode tagnode=paramn.getChild("tag");
523
524       TagExpressionList tel=null;
525       if (tagnode!=null) {
526         tel=parseTagExpressionList(tagnode);
527       }
528
529       td.addParameter(type,paramname,fen, tel, optional);
530     }
531   }
532
533   public TagExpressionList parseTagExpressionList(ParseNode pn) {
534     //BUG FIX: change pn.getChildren() to pn.getChild("tag_expression_list").getChildren()
535     //To test, feed in any input program that uses tags
536     ParseNodeVector pnv=pn.getChild("tag_expression_list").getChildren();
537     TagExpressionList tel=new TagExpressionList();
538     for(int i=0; i<pnv.size(); i++) {
539       ParseNode tn=pnv.elementAt(i);
540       String type=tn.getChild("type").getTerminal();
541       String name=tn.getChild("single").getTerminal();
542       tel.addTag(type, name);
543     }
544     return tel;
545   }
546
547   public ClassDescriptor parseTypeDecl(ParseNode pn) {
548     ClassDescriptor cn=new ClassDescriptor(packageName, pn.getChild("name").getTerminal(), false);
549     pushChainMaps();
550     cn.setImports(mandatoryImports, multiimports);
551     if (!isEmpty(pn.getChild("super").getTerminal())) {
552       /* parse superclass name */
553       ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
554       NameDescriptor nd=parseClassName(snn);
555       cn.setSuper(nd.toString());
556     } else {
557       if (!(cn.getSymbol().equals(TypeUtil.ObjectClass)||
558             cn.getSymbol().equals(TypeUtil.TagClass)))
559         cn.setSuper(TypeUtil.ObjectClass);
560     }
561     // check inherited interfaces
562     if (!isEmpty(pn.getChild("superIF").getTerminal())) {
563       /* parse inherited interface name */
564       ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
565       ParseNodeVector pnv=snlist.getChildren();
566       for(int i=0; i<pnv.size(); i++) {
567         ParseNode decl=pnv.elementAt(i);
568         if (isNode(decl,"type")) {
569           NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
570           cn.addSuperInterface(nd.toString());
571         }
572       }
573     }
574     cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
575     parseClassBody(cn, pn.getChild("classbody"));
576
577     boolean hasConstructor = false;
578     for(Iterator method_it=cn.getMethods(); method_it.hasNext(); ) {
579       MethodDescriptor md=(MethodDescriptor)method_it.next();
580       hasConstructor |= md.isConstructor();
581     }
582     if((!hasConstructor) && (!cn.isEnum())) {
583       // add a default constructor for this class
584       MethodDescriptor md = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC),
585                                                  cn.getSymbol(), false);
586       BlockNode bn=new BlockNode();
587       state.addTreeCode(md,bn);
588       md.setDefaultConstructor();
589       cn.addMethod(md);
590     }
591     popChainMaps();
592
593     cn.setSourceFileName(currsourcefile);
594     if (analyzeset != null)
595       analyzeset.add(cn);
596     state.addClass(cn);
597
598     return cn;
599   }
600
601   private void parseClassBody(ClassDescriptor cn, ParseNode pn) {
602     ParseNode decls=pn.getChild("class_body_declaration_list");
603     if (decls!=null) {
604       ParseNodeVector pnv=decls.getChildren();
605       for(int i=0; i<pnv.size(); i++) {
606         ParseNode decl=pnv.elementAt(i);
607         if (isNode(decl,"member")) {
608           parseClassMember(cn,decl);
609         } else if (isNode(decl,"constructor")) {
610           parseConstructorDecl(cn,decl.getChild("constructor_declaration"));
611         } else if (isNode(decl, "static_block")) {
612           parseStaticBlockDecl(cn, decl.getChild("static_block_declaration"));
613         } else if (isNode(decl,"block")) {
614         } else throw new Error();
615       }
616     }
617   }
618
619   private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
620     ParseNode fieldnode=pn.getChild("field");
621     if (fieldnode!=null) {
622       parseFieldDecl(cn,fieldnode.getChild("field_declaration"));
623       return;
624     }
625     ParseNode methodnode=pn.getChild("method");
626     if (methodnode!=null) {
627       parseMethodDecl(cn,methodnode.getChild("method_declaration"));
628       return;
629     }
630     ParseNode innerclassnode=pn.getChild("inner_class_declaration");
631     if (innerclassnode!=null) {
632       parseInnerClassDecl(cn,innerclassnode);
633       return;
634     }
635      ParseNode innerinterfacenode=pn.getChild("interface_declaration");
636     if (innerinterfacenode!=null) {
637       parseInterfaceDecl(innerinterfacenode, cn);
638       return;
639     }
640
641     ParseNode enumnode=pn.getChild("enum_declaration");
642     if (enumnode!=null) {
643       ClassDescriptor ecn=parseEnumDecl(cn,enumnode);
644       return;
645     }
646     ParseNode flagnode=pn.getChild("flag");
647     if (flagnode!=null) {
648       parseFlagDecl(cn, flagnode.getChild("flag_declaration"));
649       return;
650     }
651     // in case there are empty node
652     ParseNode emptynode=pn.getChild("empty");
653     if(emptynode != null) {
654       return;
655     }
656     System.out.println("Unrecognized node:"+pn.PPrint(2,true));
657     throw new Error();
658   }
659
660   private ClassDescriptor parseInnerClassDecl(ClassDescriptor cn, ParseNode pn) {
661     String basename=pn.getChild("name").getTerminal();
662     String classname=cn.getClassName()+"$"+basename;
663
664     if (cn.getPackage()==null)
665       cn.getSingleImportMappings().put(basename,classname);
666     else
667       cn.getSingleImportMappings().put(basename,cn.getPackage()+"."+classname);
668     
669     ClassDescriptor icn=new ClassDescriptor(cn.getPackage(), classname, false);
670     pushChainMaps();
671     icn.setImports(mandatoryImports, multiimports);
672     icn.setAsInnerClass();
673     icn.setSurroundingClass(cn.getSymbol());
674     icn.setSurrounding(cn);
675     cn.addInnerClass(icn);
676     if (!isEmpty(pn.getChild("super").getTerminal())) {
677       /* parse superclass name */
678       ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
679       NameDescriptor nd=parseClassName(snn);
680       icn.setSuper(nd.toString());
681     } else {
682       if (!(icn.getSymbol().equals(TypeUtil.ObjectClass)||
683             icn.getSymbol().equals(TypeUtil.TagClass)))
684         icn.setSuper(TypeUtil.ObjectClass);
685     }
686     // check inherited interfaces
687     if (!isEmpty(pn.getChild("superIF").getTerminal())) {
688       /* parse inherited interface name */
689       ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
690       ParseNodeVector pnv=snlist.getChildren();
691       for(int i=0; i<pnv.size(); i++) {
692         ParseNode decl=pnv.elementAt(i);
693         if (isNode(decl,"type")) {
694           NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
695           icn.addSuperInterface(nd.toString());
696         }
697       }
698     }
699     icn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
700
701     parseClassBody(icn, pn.getChild("classbody"));
702     popChainMaps();
703     if (analyzeset != null)
704       analyzeset.add(icn);
705     icn.setSourceFileName(currsourcefile);
706     state.addClass(icn);
707
708     return icn;
709   }
710
711   private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
712     ParseNode tn=pn.getChild("type");
713     String type_st=tn.getTerminal();
714     if(type_st.equals("byte")) {
715       return state.getTypeDescriptor(TypeDescriptor.BYTE);
716     } else if(type_st.equals("short")) {
717       return state.getTypeDescriptor(TypeDescriptor.SHORT);
718     } else if(type_st.equals("boolean")) {
719       return state.getTypeDescriptor(TypeDescriptor.BOOLEAN);
720     } else if(type_st.equals("int")) {
721       return state.getTypeDescriptor(TypeDescriptor.INT);
722     } else if(type_st.equals("long")) {
723       return state.getTypeDescriptor(TypeDescriptor.LONG);
724     } else if(type_st.equals("char")) {
725       return state.getTypeDescriptor(TypeDescriptor.CHAR);
726     } else if(type_st.equals("float")) {
727       return state.getTypeDescriptor(TypeDescriptor.FLOAT);
728     } else if(type_st.equals("double")) {
729       return state.getTypeDescriptor(TypeDescriptor.DOUBLE);
730     } else if(type_st.equals("class")) {
731       ParseNode nn=tn.getChild("class");
732       return state.getTypeDescriptor(parseClassName(nn.getChild("name")));
733     } else if(type_st.equals("array")) {
734       ParseNode nn=tn.getChild("array");
735       TypeDescriptor td=parseTypeDescriptor(nn.getChild("basetype"));
736       Integer numdims=(Integer)nn.getChild("dims").getLiteral();
737       for(int i=0; i<numdims.intValue(); i++)
738         td=td.makeArray(state);
739       return td;
740     } else {
741       System.out.println(pn.PPrint(2, true));
742       throw new Error();
743     }
744   }
745
746   //Needed to separate out top level call since if a base exists,
747   //we do not want to apply our resolveName function (i.e. deal with imports)
748   //otherwise, if base == null, we do just want to resolve name.
749   private NameDescriptor parseClassName(ParseNode nn) {
750     ParseNode base=nn.getChild("base");
751     ParseNode id=nn.getChild("identifier");
752     String classname = id.getTerminal();
753     if (base==null) {
754       return new NameDescriptor(resolveName(classname));
755     }
756     return new NameDescriptor(parseClassNameRecursive(base.getChild("name")),classname);
757   }
758
759   private NameDescriptor parseClassNameRecursive(ParseNode nn) {
760     ParseNode base=nn.getChild("base");
761     ParseNode id=nn.getChild("identifier");
762     String classname = id.getTerminal();
763     if (base==null) {
764       return new NameDescriptor(classname);
765     }
766     return new NameDescriptor(parseClassNameRecursive(base.getChild("name")),classname);
767   }
768
769   //This will get the mapping of a terminal class name
770   //to a canonical classname (with imports/package locations in them)
771   private String resolveName(String terminal) {
772     
773     if(mandatoryImports.containsKey(terminal)) {
774       return (String) mandatoryImports.get(terminal);
775     } else {
776       if(multiimports.containsKey(terminal)) {
777         //Test for error
778         Object o = multiimports.get(terminal);
779         if(o instanceof Error) {
780           throw new Error("Class " + terminal + " is ambiguous. Cause: more than 1 package import contain the same class.");
781         } else {
782           //At this point, if we found a unique class
783           //we can treat it as a single, mandatory import.
784           mandatoryImports.put(terminal, o);
785           return (String) o;
786         }
787       }
788     }
789
790     return terminal;
791   }
792
793   //only function difference between this and parseName() is that this
794   //does not look for a import mapping.
795   private NameDescriptor parseName(ParseNode nn) {
796     ParseNode base=nn.getChild("base");
797     ParseNode id=nn.getChild("identifier");
798     if (base==null) {
799       return new NameDescriptor(id.getTerminal());
800     }
801     return new NameDescriptor(parseName(base.getChild("name")),id.getTerminal());
802   }
803
804   private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
805     String name=pn.getChild("name").getTerminal();
806     FlagDescriptor flag=new FlagDescriptor(name);
807     if (pn.getChild("external")!=null)
808       flag.makeExternal();
809     cn.addFlag(flag);
810   }
811
812   private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
813     ParseNode mn=pn.getChild("modifier");
814     Modifiers m=parseModifiersList(mn);
815     if(cn.isInterface()) {
816       // TODO add version for normal Java later
817       // Can only be PUBLIC or STATIC or FINAL
818       if((m.isAbstract()) || (m.isAtomic()) || (m.isNative())
819          || (m.isSynchronized())) {
820         throw new Error("Error: field in Interface " + cn.getSymbol() + "can only be PUBLIC or STATIC or FINAL");
821       }
822       m.addModifier(Modifiers.PUBLIC);
823       m.addModifier(Modifiers.STATIC);
824       m.addModifier(Modifiers.FINAL);
825     }
826
827     ParseNode tn=pn.getChild("type");
828     TypeDescriptor t=parseTypeDescriptor(tn);
829     ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
830     ParseNodeVector pnv=vn.getChildren();
831     boolean isglobal=pn.getChild("global")!=null;
832
833     for(int i=0; i<pnv.size(); i++) {
834       ParseNode vardecl=pnv.elementAt(i);
835       ParseNode tmp=vardecl;
836       TypeDescriptor arrayt=t;
837       while (tmp.getChild("single")==null) {
838         arrayt=arrayt.makeArray(state);
839         tmp=tmp.getChild("array");
840       }
841       String identifier=tmp.getChild("single").getTerminal();
842       ParseNode epn=vardecl.getChild("initializer");
843
844       ExpressionNode en=null;
845       if (epn!=null) {
846         en=parseExpression(epn.getFirstChild());
847         en.setNumLine(epn.getFirstChild().getLine());
848         if(m.isStatic()) {
849           // for static field, the initializer should be considered as a
850           // static block
851           boolean isfirst = false;
852           MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks");
853           if(md == null) {
854             // the first static block for this class
855             Modifiers m_i=new Modifiers();
856             m_i.addModifier(Modifiers.STATIC);
857             md = new MethodDescriptor(m_i, "staticblocks", false);
858             md.setAsStaticBlock();
859             isfirst = true;
860           }
861           if(isfirst) {
862             cn.addMethod(md);
863           }
864           cn.incStaticBlocks();
865           BlockNode bn=new BlockNode();
866           NameNode nn=new NameNode(new NameDescriptor(identifier));
867           nn.setNumLine(en.getNumLine());
868           AssignmentNode an=new AssignmentNode(nn,en,new AssignOperation(1));
869           an.setNumLine(pn.getLine());
870           bn.addBlockStatement(new BlockExpressionNode(an));
871           if(isfirst) {
872             state.addTreeCode(md,bn);
873           } else {
874             BlockNode obn = state.getMethodBody(md);
875             for(int ii = 0; ii < bn.size(); ii++) {
876               BlockStatementNode bsn = bn.get(ii);
877               obn.addBlockStatement(bsn);
878             }
879             state.addTreeCode(md, obn);
880             bn = null;
881           }
882           en = null;
883         }
884       }
885
886       cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal));
887       assignAnnotationsToType(m,arrayt);
888     }
889   }
890
891   private void assignAnnotationsToType(Modifiers modifiers, TypeDescriptor type) {
892     Vector<AnnotationDescriptor> annotations=modifiers.getAnnotations();
893     for(int i=0; i<annotations.size(); i++) {
894       // it only supports a marker annotation
895       AnnotationDescriptor an=annotations.elementAt(i);
896       type.addAnnotationMarker(an);
897     }
898   }
899
900   int innerCount=0;
901
902   private ExpressionNode parseExpression(ParseNode pn) {
903     if (isNode(pn,"assignment"))
904       return parseAssignmentExpression(pn);
905     else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
906              isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
907              isNode(pn,"bitwise_and")||isNode(pn,"equal")||
908              isNode(pn,"not_equal")||isNode(pn,"comp_lt")||
909              isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
910              isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
911              isNode(pn,"rightshift")||isNode(pn,"sub")||
912              isNode(pn,"urightshift")||isNode(pn,"sub")||
913              isNode(pn,"add")||isNode(pn,"mult")||
914              isNode(pn,"div")||isNode(pn,"mod")) {
915       ParseNodeVector pnv=pn.getChildren();
916       ParseNode left=pnv.elementAt(0);
917       ParseNode right=pnv.elementAt(1);
918       Operation op=new Operation(pn.getLabel());
919       OpNode on=new OpNode(parseExpression(left),parseExpression(right),op);
920       on.setNumLine(pn.getLine());
921       return on;
922     } else if (isNode(pn,"unaryplus")||
923                isNode(pn,"unaryminus")||
924                isNode(pn,"not")||
925                isNode(pn,"comp")) {
926       ParseNode left=pn.getFirstChild();
927       Operation op=new Operation(pn.getLabel());
928       OpNode on=new OpNode(parseExpression(left),op);
929       on.setNumLine(pn.getLine());
930       return on;
931     } else if (isNode(pn,"postinc")||
932                isNode(pn,"postdec")) {
933       ParseNode left=pn.getFirstChild();
934       AssignOperation op=new AssignOperation(pn.getLabel());
935       AssignmentNode an=new AssignmentNode(parseExpression(left),null,op);
936       an.setNumLine(pn.getLine());
937       return an;
938
939     } else if (isNode(pn,"preinc")||
940                isNode(pn,"predec")) {
941       ParseNode left=pn.getFirstChild();
942       AssignOperation op=isNode(pn,"preinc")?new AssignOperation(AssignOperation.PLUSEQ):new AssignOperation(AssignOperation.MINUSEQ);
943       AssignmentNode an=new AssignmentNode(parseExpression(left),
944                                            new LiteralNode("integer",new Integer(1)),op);
945       an.setNumLine(pn.getLine());
946       return an;
947     } else if (isNode(pn,"literal")) {
948       String literaltype=pn.getTerminal();
949       ParseNode literalnode=pn.getChild(literaltype);
950       Object literal_obj=literalnode.getLiteral();
951       LiteralNode ln=new LiteralNode(literaltype, literal_obj);
952       ln.setNumLine(pn.getLine());
953       return ln;
954     } else if (isNode(pn, "createobject")) {
955       TypeDescriptor td = parseTypeDescriptor(pn);
956
957       Vector args = parseArgumentList(pn);
958       boolean isglobal = pn.getChild("global") != null || pn.getChild("scratch") != null;
959       String disjointId = null;
960       if (pn.getChild("disjoint") != null) {
961         disjointId = pn.getChild("disjoint").getTerminal();
962       }
963       CreateObjectNode con = new CreateObjectNode(td, isglobal, disjointId);
964       con.setNumLine(pn.getLine());
965       for (int i = 0; i < args.size(); i++) {
966         con.addArgument((ExpressionNode) args.get(i));
967       }
968       /* Could have flag set or tag added here */
969       if (pn.getChild("flag_list") != null || pn.getChild("tag_list") != null) {
970         FlagEffects fe = new FlagEffects(null);
971         if (pn.getChild("flag_list") != null)
972           parseFlagEffect(fe, pn.getChild("flag_list"));
973
974         if (pn.getChild("tag_list") != null)
975           parseTagEffect(fe, pn.getChild("tag_list"));
976         con.addFlagEffects(fe);
977       }
978
979       return con;
980     } else if (isNode(pn,"createobjectcls")) {
981       //TODO:::  FIX BUG!!!  static fields in caller context need to become parameters
982       TypeDescriptor td=parseTypeDescriptor(pn);
983       innerCount++;
984       ClassDescriptor cnnew=new ClassDescriptor(packageName,td.getSymbol()+"$"+innerCount, false);
985       pushChainMaps();
986       cnnew.setImports(mandatoryImports, multiimports);
987       cnnew.setSuper(td.getSymbol());
988       cnnew.setInline();
989       parseClassBody(cnnew, pn.getChild("decl").getChild("classbody"));
990       TypeDescriptor tdnew=state.getTypeDescriptor(cnnew.getSymbol());
991
992       Vector args=parseArgumentList(pn);
993
994       CreateObjectNode con=new CreateObjectNode(tdnew, false, null);
995       con.setNumLine(pn.getLine());
996       for(int i=0; i<args.size(); i++) {
997         con.addArgument((ExpressionNode)args.get(i));
998       }
999       popChainMaps();
1000
1001       if (analyzeset != null)
1002         analyzeset.add(cnnew);
1003       cnnew.setSourceFileName(currsourcefile);
1004       state.addClass(cnnew);
1005
1006       return con;
1007     } else if (isNode(pn,"createarray")) {
1008       //System.out.println(pn.PPrint(3,true));
1009       boolean isglobal=pn.getChild("global")!=null||
1010                         pn.getChild("scratch")!=null;
1011       String disjointId=null;
1012       if( pn.getChild("disjoint") != null) {
1013         disjointId = pn.getChild("disjoint").getTerminal();
1014       }
1015       TypeDescriptor td=parseTypeDescriptor(pn);
1016       Vector args=parseDimExprs(pn);
1017       int num=0;
1018       if (pn.getChild("dims_opt").getLiteral()!=null)
1019         num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
1020       for(int i=0; i<(args.size()+num); i++)
1021         td=td.makeArray(state);
1022       CreateObjectNode con=new CreateObjectNode(td, isglobal, disjointId);
1023       con.setNumLine(pn.getLine());
1024       for(int i=0; i<args.size(); i++) {
1025         con.addArgument((ExpressionNode)args.get(i));
1026       }
1027       return con;
1028     }
1029     if (isNode(pn,"createarray2")) {
1030       TypeDescriptor td=parseTypeDescriptor(pn);
1031       int num=0;
1032       if (pn.getChild("dims_opt").getLiteral()!=null)
1033         num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
1034       for(int i=0; i<num; i++)
1035         td=td.makeArray(state);
1036       CreateObjectNode con=new CreateObjectNode(td, false, null);
1037       con.setNumLine(pn.getLine());
1038       ParseNode ipn = pn.getChild("initializer");
1039       Vector initializers=parseVariableInitializerList(ipn);
1040       ArrayInitializerNode ain = new ArrayInitializerNode(initializers);
1041       ain.setNumLine(pn.getLine());
1042       con.addArrayInitializer(ain);
1043       return con;
1044     } else if (isNode(pn,"name")) {
1045       NameDescriptor nd=parseName(pn);
1046       NameNode nn=new NameNode(nd);
1047       nn.setNumLine(pn.getLine());
1048       return nn;
1049     } else if (isNode(pn,"this")) {
1050       NameDescriptor nd=new NameDescriptor("this");
1051       NameNode nn=new NameNode(nd);
1052       nn.setNumLine(pn.getLine());
1053       return nn;
1054     } else if (isNode(pn,"parentclass")) {
1055       NameDescriptor nd=new NameDescriptor("this");
1056       NameNode nn=new NameNode(nd);
1057       nn.setNumLine(pn.getLine());
1058
1059       FieldAccessNode fan=new FieldAccessNode(nn,"this$parent");
1060       fan.setNumLine(pn.getLine());
1061       return fan;
1062     } else if (isNode(pn,"isavailable")) {
1063       NameDescriptor nd=new NameDescriptor(pn.getTerminal());
1064       NameNode nn=new NameNode(nd);
1065       nn.setNumLine(pn.getLine());
1066       return new OpNode(nn,null,new Operation(Operation.ISAVAILABLE));
1067     } else if (isNode(pn,"methodinvoke1")) {
1068       NameDescriptor nd=parseName(pn.getChild("name"));
1069       Vector args=parseArgumentList(pn);
1070       MethodInvokeNode min=new MethodInvokeNode(nd);
1071       min.setNumLine(pn.getLine());
1072       for(int i=0; i<args.size(); i++) {
1073         min.addArgument((ExpressionNode)args.get(i));
1074       }
1075       return min;
1076     } else if (isNode(pn,"methodinvoke2")) {
1077       String methodid=pn.getChild("id").getTerminal();
1078       ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
1079       Vector args=parseArgumentList(pn);
1080       MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
1081       min.setNumLine(pn.getLine());
1082       for(int i=0; i<args.size(); i++) {
1083         min.addArgument((ExpressionNode)args.get(i));
1084       }
1085       return min;
1086     } else if (isNode(pn,"fieldaccess")) {
1087       ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
1088       String fieldname=pn.getChild("field").getTerminal();
1089
1090       FieldAccessNode fan=new FieldAccessNode(en,fieldname);
1091       fan.setNumLine(pn.getLine());
1092       return fan;
1093     } else if (isNode(pn,"arrayaccess")) {
1094       ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
1095       ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
1096       ArrayAccessNode aan=new ArrayAccessNode(en,index);
1097       aan.setNumLine(pn.getLine());
1098       return aan;
1099     } else if (isNode(pn,"cast1")) {
1100       try {
1101         CastNode cn=new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
1102         cn.setNumLine(pn.getLine());
1103         return cn;
1104       } catch (Exception e) {
1105         System.out.println(pn.PPrint(1,true));
1106         e.printStackTrace();
1107         throw new Error();
1108       }
1109     } else if (isNode(pn,"cast2")) {
1110       CastNode cn=new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
1111       cn.setNumLine(pn.getLine());
1112       return cn;
1113     } else if (isNode(pn, "getoffset")) {
1114       TypeDescriptor td=parseTypeDescriptor(pn);
1115       String fieldname = pn.getChild("field").getTerminal();
1116       //System.out.println("Checking the values of: "+ " td.toString()= " + td.toString()+ "  fieldname= " + fieldname);
1117       return new OffsetNode(td, fieldname);
1118     } else if (isNode(pn, "tert")) {
1119
1120       TertiaryNode tn=new TertiaryNode(parseExpression(pn.getChild("cond").getFirstChild()),
1121                                        parseExpression(pn.getChild("trueexpr").getFirstChild()),
1122                                        parseExpression(pn.getChild("falseexpr").getFirstChild()) );
1123       tn.setNumLine(pn.getLine());
1124
1125       return tn;
1126     } else if (isNode(pn, "instanceof")) {
1127       ExpressionNode exp=parseExpression(pn.getChild("exp").getFirstChild());
1128       TypeDescriptor t=parseTypeDescriptor(pn);
1129       InstanceOfNode ion=new InstanceOfNode(exp,t);
1130       ion.setNumLine(pn.getLine());
1131       return ion;
1132     } else if (isNode(pn, "array_initializer")) {
1133       Vector initializers=parseVariableInitializerList(pn);
1134       return new ArrayInitializerNode(initializers);
1135     } else if (isNode(pn, "class_type")) {
1136       TypeDescriptor td=parseTypeDescriptor(pn);
1137       ClassTypeNode ctn=new ClassTypeNode(td);
1138       ctn.setNumLine(pn.getLine());
1139       return ctn;
1140     } else if (isNode(pn, "empty")) {
1141       return null;
1142     } else {
1143       System.out.println("---------------------");
1144       System.out.println(pn.PPrint(3,true));
1145       throw new Error();
1146     }
1147   }
1148
1149   private Vector parseDimExprs(ParseNode pn) {
1150     Vector arglist=new Vector();
1151     ParseNode an=pn.getChild("dim_exprs");
1152     if (an==null)       /* No argument list */
1153       return arglist;
1154     ParseNodeVector anv=an.getChildren();
1155     for(int i=0; i<anv.size(); i++) {
1156       arglist.add(parseExpression(anv.elementAt(i)));
1157     }
1158     return arglist;
1159   }
1160
1161   private Vector parseArgumentList(ParseNode pn) {
1162     Vector arglist=new Vector();
1163     ParseNode an=pn.getChild("argument_list");
1164     if (an==null)       /* No argument list */
1165       return arglist;
1166     ParseNodeVector anv=an.getChildren();
1167     for(int i=0; i<anv.size(); i++) {
1168       arglist.add(parseExpression(anv.elementAt(i)));
1169     }
1170     return arglist;
1171   }
1172
1173   private Vector[] parseConsArgumentList(ParseNode pn) {
1174     Vector arglist=new Vector();
1175     Vector varlist=new Vector();
1176     ParseNode an=pn.getChild("cons_argument_list");
1177     if (an==null)       /* No argument list */
1178       return new Vector[] {varlist, arglist};
1179     ParseNodeVector anv=an.getChildren();
1180     for(int i=0; i<anv.size(); i++) {
1181       ParseNode cpn=anv.elementAt(i);
1182       ParseNode var=cpn.getChild("var");
1183       ParseNode exp=cpn.getChild("exp").getFirstChild();
1184       varlist.add(var.getTerminal());
1185       arglist.add(parseExpression(exp));
1186     }
1187     return new Vector[] {varlist, arglist};
1188   }
1189
1190   private Vector parseVariableInitializerList(ParseNode pn) {
1191     Vector varInitList=new Vector();
1192     ParseNode vin=pn.getChild("var_init_list");
1193     if (vin==null)       /* No argument list */
1194       return varInitList;
1195     ParseNodeVector vinv=vin.getChildren();
1196     for(int i=0; i<vinv.size(); i++) {
1197       varInitList.add(parseExpression(vinv.elementAt(i)));
1198     }
1199     return varInitList;
1200   }
1201
1202   private ExpressionNode parseAssignmentExpression(ParseNode pn) {
1203     AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
1204     ParseNodeVector pnv=pn.getChild("args").getChildren();
1205
1206     AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
1207     an.setNumLine(pn.getLine());
1208     return an;
1209   }
1210
1211
1212   private void parseMethodDecl(ClassDescriptor cn, ParseNode pn) {
1213     ParseNode headern=pn.getChild("method_header");
1214     ParseNode bodyn=pn.getChild("body");
1215     MethodDescriptor md=parseMethodHeader(headern);
1216     try {
1217       BlockNode bn=parseBlock(bodyn);
1218       bn.setNumLine(pn.getLine()); // assume that method header is located at the beginning of method body
1219       cn.addMethod(md);
1220       state.addTreeCode(md,bn);
1221
1222       // this is a hack for investigating new language features
1223       // at the AST level, someday should evolve into a nice compiler
1224       // option *wink*
1225       //if( cn.getSymbol().equals( ***put a class in here like:     "Test" ) &&
1226       //    md.getSymbol().equals( ***put your method in here like: "main" )
1227       //) {
1228       //  bn.setStyle( BlockNode.NORMAL );
1229       //  System.out.println( bn.printNode( 0 ) );
1230       //}
1231
1232     } catch (Exception e) {
1233       System.out.println("Error with method:"+md.getSymbol());
1234       e.printStackTrace();
1235       throw new Error();
1236     } catch (Error e) {
1237       System.out.println("Error with method:"+md.getSymbol());
1238       e.printStackTrace();
1239       throw new Error();
1240     }
1241   }
1242
1243   private void parseConstructorDecl(ClassDescriptor cn, ParseNode pn) {
1244     ParseNode mn=pn.getChild("modifiers");
1245     Modifiers m=parseModifiersList(mn);
1246     ParseNode cdecl=pn.getChild("constructor_declarator");
1247     boolean isglobal=cdecl.getChild("global")!=null;
1248     String name=resolveName(cn.getSymbol());
1249     MethodDescriptor md=new MethodDescriptor(m, name, isglobal);
1250     ParseNode paramnode=cdecl.getChild("parameters");
1251     parseParameterList(md,paramnode);
1252     ParseNode bodyn0=pn.getChild("body");
1253     ParseNode bodyn=bodyn0.getChild("constructor_body");
1254     cn.addMethod(md);
1255     BlockNode bn=null;
1256     if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
1257       bn=parseBlock(bodyn);
1258     else
1259       bn=new BlockNode();
1260     if (bodyn!=null&&bodyn.getChild("superinvoke")!=null) {
1261       ParseNode sin=bodyn.getChild("superinvoke");
1262       NameDescriptor nd=new NameDescriptor("super");
1263       Vector args=parseArgumentList(sin);
1264       MethodInvokeNode min=new MethodInvokeNode(nd);
1265       min.setNumLine(sin.getLine());
1266       for(int i=0; i<args.size(); i++) {
1267         min.addArgument((ExpressionNode)args.get(i));
1268       }
1269       BlockExpressionNode ben=new BlockExpressionNode(min);
1270       bn.addFirstBlockStatement(ben);
1271
1272     } else if (bodyn!=null&&bodyn.getChild("explconstrinv")!=null) {
1273       ParseNode eci=bodyn.getChild("explconstrinv");
1274       NameDescriptor nd=new NameDescriptor(cn.getSymbol());
1275       Vector args=parseArgumentList(eci);
1276       MethodInvokeNode min=new MethodInvokeNode(nd);
1277       min.setNumLine(eci.getLine());
1278       for(int i=0; i<args.size(); i++) {
1279         min.addArgument((ExpressionNode)args.get(i));
1280       }
1281       BlockExpressionNode ben=new BlockExpressionNode(min);
1282       ben.setNumLine(eci.getLine());
1283       bn.addFirstBlockStatement(ben);
1284     }
1285     state.addTreeCode(md,bn);
1286   }
1287
1288   private void parseStaticBlockDecl(ClassDescriptor cn, ParseNode pn) {
1289     // Each class maintains one MethodDecscriptor which combines all its
1290     // static blocks in their declaration order
1291     boolean isfirst = false;
1292     MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks");
1293     if(md == null) {
1294       // the first static block for this class
1295       Modifiers m_i=new Modifiers();
1296       m_i.addModifier(Modifiers.STATIC);
1297       md = new MethodDescriptor(m_i, "staticblocks", false);
1298       md.setAsStaticBlock();
1299       isfirst = true;
1300     }
1301     ParseNode bodyn=pn.getChild("body");
1302     if(isfirst) {
1303       cn.addMethod(md);
1304     }
1305     cn.incStaticBlocks();
1306     BlockNode bn=null;
1307     if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
1308       bn=parseBlock(bodyn);
1309     else
1310       bn=new BlockNode();
1311     if(isfirst) {
1312       state.addTreeCode(md,bn);
1313     } else {
1314       BlockNode obn = state.getMethodBody(md);
1315       for(int i = 0; i < bn.size(); i++) {
1316         BlockStatementNode bsn = bn.get(i);
1317         obn.addBlockStatement(bsn);
1318       }
1319       state.addTreeCode(md, obn);
1320       bn = null;
1321     }
1322   }
1323
1324   public BlockNode parseBlock(ParseNode pn) {
1325     this.m_taskexitnum = 0;
1326     if (pn==null||isEmpty(pn.getTerminal()))
1327       return new BlockNode();
1328     ParseNode bsn=pn.getChild("block_statement_list");
1329     return parseBlockHelper(bsn);
1330   }
1331
1332   private BlockNode parseBlockHelper(ParseNode pn) {
1333     ParseNodeVector pnv=pn.getChildren();
1334     BlockNode bn=new BlockNode();
1335     for(int i=0; i<pnv.size(); i++) {
1336       Vector bsv=parseBlockStatement(pnv.elementAt(i));
1337       for(int j=0; j<bsv.size(); j++) {
1338         bn.addBlockStatement((BlockStatementNode)bsv.get(j));
1339       }
1340     }
1341     return bn;
1342   }
1343
1344   public BlockNode parseSingleBlock(ParseNode pn) {
1345     BlockNode bn=new BlockNode();
1346     Vector bsv=parseBlockStatement(pn);
1347     for(int j=0; j<bsv.size(); j++) {
1348       bn.addBlockStatement((BlockStatementNode)bsv.get(j));
1349     }
1350     bn.setStyle(BlockNode.NOBRACES);
1351     return bn;
1352   }
1353
1354   public Vector parseSESEBlock(Vector parentbs, ParseNode pn) {
1355     ParseNodeVector pnv=pn.getChildren();
1356     Vector bv=new Vector();
1357     for(int i=0; i<pnv.size(); i++) {
1358       bv.addAll(parseBlockStatement(pnv.elementAt(i)));
1359     }
1360     return bv;
1361   }
1362
1363   public Vector parseBlockStatement(ParseNode pn) {
1364     Vector blockstatements=new Vector();
1365     if (isNode(pn,"tag_declaration")) {
1366       String name=pn.getChild("single").getTerminal();
1367       String type=pn.getChild("type").getTerminal();
1368
1369       TagDeclarationNode tdn=new TagDeclarationNode(name, type);
1370       tdn.setNumLine(pn.getLine());
1371
1372       blockstatements.add(tdn);
1373     } else if (isNode(pn,"local_variable_declaration")) {
1374
1375       TypeDescriptor t=parseTypeDescriptor(pn);
1376       ParseNode vn=pn.getChild("variable_declarators_list");
1377       ParseNodeVector pnv=vn.getChildren();
1378       for(int i=0; i<pnv.size(); i++) {
1379         ParseNode vardecl=pnv.elementAt(i);
1380
1381
1382         ParseNode tmp=vardecl;
1383         TypeDescriptor arrayt=t;
1384
1385         while (tmp.getChild("single")==null) {
1386           arrayt=arrayt.makeArray(state);
1387           tmp=tmp.getChild("array");
1388         }
1389         String identifier=tmp.getChild("single").getTerminal();
1390
1391         ParseNode epn=vardecl.getChild("initializer");
1392
1393
1394         ExpressionNode en=null;
1395         if (epn!=null)
1396           en=parseExpression(epn.getFirstChild());
1397
1398         DeclarationNode dn=new DeclarationNode(new VarDescriptor(arrayt, identifier),en);
1399         dn.setNumLine(tmp.getLine());
1400         
1401         ParseNode mn=pn.getChild("modifiers");
1402         if(mn!=null) {
1403           // here, modifers parse node has the list of annotations
1404           Modifiers m=parseModifiersList(mn);
1405           assignAnnotationsToType(m, arrayt);
1406         }
1407
1408         blockstatements.add(dn);
1409       }
1410     } else if (isNode(pn,"nop")) {
1411       /* Do Nothing */
1412     } else if (isNode(pn,"expression")) {
1413       BlockExpressionNode ben=new BlockExpressionNode(parseExpression(pn.getFirstChild()));
1414       ben.setNumLine(pn.getLine());
1415       blockstatements.add(ben);
1416     } else if (isNode(pn,"ifstatement")) {
1417       IfStatementNode isn=new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
1418                                               parseSingleBlock(pn.getChild("statement").getFirstChild()),
1419                                               pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null);
1420       isn.setNumLine(pn.getLine());
1421
1422       blockstatements.add(isn);
1423     } else if (isNode(pn,"switch_statement")) {
1424       // TODO add version for normal Java later
1425       SwitchStatementNode ssn=new SwitchStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
1426                                                       parseSingleBlock(pn.getChild("statement").getFirstChild()));
1427       ssn.setNumLine(pn.getLine());
1428       blockstatements.add(ssn);
1429     } else if (isNode(pn,"switch_block_list")) {
1430       // TODO add version for normal Java later
1431       ParseNodeVector pnv=pn.getChildren();
1432       for(int i=0; i<pnv.size(); i++) {
1433         ParseNode sblockdecl=pnv.elementAt(i);
1434
1435         if(isNode(sblockdecl, "switch_block")) {
1436           ParseNode lpn=sblockdecl.getChild("switch_labels").getChild("switch_label_list");
1437           ParseNodeVector labelv=lpn.getChildren();
1438           Vector<SwitchLabelNode> slv = new Vector<SwitchLabelNode>();
1439           for(int j=0; j<labelv.size(); j++) {
1440             ParseNode labeldecl=labelv.elementAt(j);
1441             if(isNode(labeldecl, "switch_label")) {
1442               SwitchLabelNode sln=new SwitchLabelNode(parseExpression(labeldecl.getChild("constant_expression").getFirstChild()), false);
1443               sln.setNumLine(labeldecl.getLine());
1444               slv.addElement(sln);
1445             } else if(isNode(labeldecl, "default_switch_label")) {
1446               SwitchLabelNode sln=new SwitchLabelNode(null, true);
1447               sln.setNumLine(labeldecl.getLine());
1448               slv.addElement(sln);
1449             }
1450           }
1451
1452           SwitchBlockNode sbn=new SwitchBlockNode(slv,
1453                                                   parseSingleBlock(sblockdecl.getChild("switch_statements").getFirstChild()));
1454           sbn.setNumLine(sblockdecl.getLine());
1455
1456           blockstatements.add(sbn);
1457
1458         }
1459       }
1460     } else if (isNode(pn, "trycatchstatement")) {
1461       // TODO add version for normal Java later
1462       // Do not fully support exceptions now. Only make sure that if there are no
1463       // exceptions thrown, the execution is right
1464       ParseNode tpn = pn.getChild("tryblock").getFirstChild();
1465       BlockNode bn=parseBlockHelper(tpn);
1466       blockstatements.add(new SubBlockNode(bn));
1467
1468       ParseNode fbk = pn.getChild("finallyblock");
1469       if(fbk != null) {
1470         ParseNode fpn = fbk.getFirstChild();
1471         BlockNode fbn=parseBlockHelper(fpn);
1472         blockstatements.add(new SubBlockNode(fbn));
1473       }
1474     } else if (isNode(pn, "throwstatement")) {
1475       // TODO Simply return here
1476       //blockstatements.add(new ReturnNode());
1477     } else if (isNode(pn,"taskexit")) {
1478       Vector vfe=null;
1479       if (pn.getChild("flag_effects_list")!=null)
1480         vfe=parseFlags(pn.getChild("flag_effects_list"));
1481       Vector ccs=null;
1482       if (pn.getChild("cons_checks")!=null)
1483         ccs=parseChecks(pn.getChild("cons_checks"));
1484       TaskExitNode ten=new TaskExitNode(vfe, ccs, this.m_taskexitnum++);
1485       ten.setNumLine(pn.getLine());
1486       blockstatements.add(ten);
1487     } else if (isNode(pn,"atomic")) {
1488       BlockNode bn=parseBlockHelper(pn);
1489       AtomicNode an=new AtomicNode(bn);
1490       an.setNumLine(pn.getLine());
1491       blockstatements.add(an);
1492     } else if (isNode(pn,"synchronized")) {
1493       BlockNode bn=parseBlockHelper(pn.getChild("block"));
1494       ExpressionNode en=parseExpression(pn.getChild("expr").getFirstChild());
1495       SynchronizedNode sn=new SynchronizedNode(en, bn);
1496       sn.setNumLine(pn.getLine());
1497       blockstatements.add(sn);
1498     } else if (isNode(pn,"return")) {
1499       if (isEmpty(pn.getTerminal()))
1500         blockstatements.add(new ReturnNode());
1501       else {
1502         ExpressionNode en=parseExpression(pn.getFirstChild());
1503         ReturnNode rn=new ReturnNode(en);
1504         rn.setNumLine(pn.getLine());
1505         blockstatements.add(rn);
1506       }
1507     } else if (isNode(pn,"block_statement_list")) {
1508       BlockNode bn=parseBlockHelper(pn);
1509       blockstatements.add(new SubBlockNode(bn));
1510     } else if (isNode(pn,"empty")) {
1511       /* nop */
1512     } else if (isNode(pn,"statement_expression_list")) {
1513       ParseNodeVector pnv=pn.getChildren();
1514       BlockNode bn=new BlockNode();
1515       for(int i=0; i<pnv.size(); i++) {
1516         ExpressionNode en=parseExpression(pnv.elementAt(i));
1517         blockstatements.add(new BlockExpressionNode(en));
1518       }
1519       bn.setStyle(BlockNode.EXPRLIST);
1520     } else if (isNode(pn,"forstatement")) {
1521       BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
1522       BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
1523       ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1524       BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1525       if(condition == null) {
1526         // no condition clause, make a 'true' expression as the condition
1527         condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
1528       }
1529       LoopNode ln=new LoopNode(init,condition,update,body);
1530       ln.setNumLine(pn.getLine());
1531       blockstatements.add(ln);
1532     } else if (isNode(pn,"whilestatement")) {
1533       ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1534       BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1535       if(condition == null) {
1536         // no condition clause, make a 'true' expression as the condition
1537         condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
1538       }
1539       blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
1540     } else if (isNode(pn,"dowhilestatement")) {
1541       ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1542       BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1543       if(condition == null) {
1544         // no condition clause, make a 'true' expression as the condition
1545         condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
1546       }
1547       blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
1548     } else if (isNode(pn,"sese")) {
1549       ParseNode pnID=pn.getChild("identifier");
1550       String stID=null;
1551       if( pnID != null ) {
1552         stID=pnID.getFirstChild().getTerminal();
1553       }
1554       SESENode start=new SESENode(stID);
1555       start.setNumLine(pn.getLine());
1556       SESENode end  =new SESENode(stID);
1557       start.setEnd(end);
1558       end.setStart(start);
1559       blockstatements.add(start);
1560       blockstatements.addAll(parseSESEBlock(blockstatements,pn.getChild("body").getFirstChild()));
1561       blockstatements.add(end);
1562     } else if (isNode(pn,"continue")) {
1563       ContinueBreakNode cbn=new ContinueBreakNode(false);
1564       cbn.setNumLine(pn.getLine());
1565       blockstatements.add(cbn);
1566     } else if (isNode(pn,"break")) {
1567       ContinueBreakNode cbn=new ContinueBreakNode(true);
1568       cbn.setNumLine(pn.getLine());
1569       blockstatements.add(cbn);
1570       ParseNode idopt_pn=pn.getChild("identifier_opt");
1571       ParseNode name_pn=idopt_pn.getChild("name");
1572       // name_pn.getTerminal() gives you the label
1573     } else if (isNode(pn,"genreach")) {
1574       String graphName = pn.getChild("graphName").getTerminal();
1575       blockstatements.add(new GenReachNode(graphName) );
1576
1577     } else if(isNode(pn,"labeledstatement")) {
1578       String label = pn.getChild("name").getTerminal();
1579       BlockNode bn=parseSingleBlock(pn.getChild("statement").getFirstChild());
1580       bn.setLabel(label);
1581       blockstatements.add(new SubBlockNode(bn));
1582     } else {
1583       System.out.println("---------------");
1584       System.out.println(pn.PPrint(3,true));
1585       throw new Error();
1586     }
1587     return blockstatements;
1588   }
1589
1590   public MethodDescriptor parseMethodHeader(ParseNode pn) {
1591     ParseNode mn=pn.getChild("modifiers");
1592     Modifiers m=parseModifiersList(mn);
1593
1594     ParseNode tn=pn.getChild("returntype");
1595     TypeDescriptor returntype;
1596     if (tn!=null)
1597       returntype=parseTypeDescriptor(tn);
1598     else
1599       returntype=new TypeDescriptor(TypeDescriptor.VOID);
1600
1601     ParseNode pmd=pn.getChild("method_declarator");
1602     String name=pmd.getChild("name").getTerminal();
1603     MethodDescriptor md=new MethodDescriptor(m, returntype, name);
1604
1605     ParseNode paramnode=pmd.getChild("parameters");
1606     parseParameterList(md,paramnode);
1607     return md;
1608   }
1609
1610   public void parseParameterList(MethodDescriptor md, ParseNode pn) {
1611     ParseNode paramlist=pn.getChild("formal_parameter_list");
1612     if (paramlist==null)
1613       return;
1614     ParseNodeVector pnv=paramlist.getChildren();
1615     for(int i=0; i<pnv.size(); i++) {
1616       ParseNode paramn=pnv.elementAt(i);
1617
1618       if (isNode(paramn, "tag_parameter")) {
1619         String paramname=paramn.getChild("single").getTerminal();
1620         TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG);
1621         md.addTagParameter(type, paramname);
1622       } else  {
1623
1624         TypeDescriptor type=parseTypeDescriptor(paramn);
1625
1626         ParseNode tmp=paramn;
1627         while (tmp.getChild("single")==null) {
1628           type=type.makeArray(state);
1629           tmp=tmp.getChild("array");
1630         }
1631         String paramname=tmp.getChild("single").getTerminal();
1632
1633         md.addParameter(type, paramname);
1634         if(isNode(paramn, "annotation_parameter")) {
1635           ParseNode bodynode=paramn.getChild("annotation_body");
1636           parseParameterAnnotation(bodynode,type);
1637         }
1638
1639       }
1640     }
1641   }
1642
1643   public Modifiers parseModifiersList(ParseNode pn) {
1644     Modifiers m=new Modifiers();
1645     ParseNode modlist=pn.getChild("modifier_list");
1646     if (modlist!=null) {
1647       ParseNodeVector pnv=modlist.getChildren();
1648       for(int i=0; i<pnv.size(); i++) {
1649         ParseNode modn=pnv.elementAt(i);
1650         if (isNode(modn,"public"))
1651           m.addModifier(Modifiers.PUBLIC);
1652         else if (isNode(modn,"protected"))
1653           m.addModifier(Modifiers.PROTECTED);
1654         else if (isNode(modn,"private"))
1655           m.addModifier(Modifiers.PRIVATE);
1656         else if (isNode(modn,"static"))
1657           m.addModifier(Modifiers.STATIC);
1658         else if (isNode(modn,"final"))
1659           m.addModifier(Modifiers.FINAL);
1660         else if (isNode(modn,"native"))
1661           m.addModifier(Modifiers.NATIVE);
1662         else if (isNode(modn,"synchronized"))
1663           m.addModifier(Modifiers.SYNCHRONIZED);
1664         else if (isNode(modn,"atomic"))
1665           m.addModifier(Modifiers.ATOMIC);
1666         else if (isNode(modn,"abstract"))
1667           m.addModifier(Modifiers.ABSTRACT);
1668         else if (isNode(modn,"volatile"))
1669           m.addModifier(Modifiers.VOLATILE);
1670         else if (isNode(modn,"transient"))
1671           m.addModifier(Modifiers.TRANSIENT);
1672         else if(isNode(modn,"annotation_list"))
1673           parseAnnotationList(modn,m);
1674         else {
1675           throw new Error("Unrecognized Modifier:"+modn.getLabel());
1676         }
1677       }
1678     }
1679     return m;
1680   }
1681
1682   private void parseAnnotationList(ParseNode pn, Modifiers m) {
1683     ParseNodeVector pnv = pn.getChildren();
1684     for (int i = 0; i < pnv.size(); i++) {
1685       ParseNode body_list = pnv.elementAt(i);
1686       if (isNode(body_list, "annotation_body")) {
1687         ParseNode body_node = body_list.getFirstChild();
1688         if (isNode(body_node, "marker_annotation")) {
1689           m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
1690         } else if (isNode(body_node, "single_annotation")) {
1691           m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
1692                                                    body_node.getChild("element_value").getTerminal()));
1693         } else if (isNode(body_node, "normal_annotation")) {
1694           throw new Error("Annotation with multiple data members is not supported yet.");
1695         }
1696       }
1697     }
1698   }
1699
1700   private void parseParameterAnnotation(ParseNode body_list,TypeDescriptor type) {
1701     ParseNode body_node = body_list.getFirstChild();
1702     if (isNode(body_node, "marker_annotation")) {
1703       type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
1704     } else if (isNode(body_node, "single_annotation")) {
1705       type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
1706                                                         body_node.getChild("element_value").getTerminal()));
1707     } else if (isNode(body_node, "normal_annotation")) {
1708       throw new Error("Annotation with multiple data members is not supported yet.");
1709     }
1710   }
1711
1712   private boolean isNode(ParseNode pn, String label) {
1713     if (pn.getLabel().equals(label))
1714       return true;
1715     else return false;
1716   }
1717
1718   private static boolean isEmpty(ParseNode pn) {
1719     if (pn.getLabel().equals("empty"))
1720       return true;
1721     else
1722       return false;
1723   }
1724
1725   private static boolean isEmpty(String s) {
1726     if (s.equals("empty"))
1727       return true;
1728     else
1729       return false;
1730   }
1731
1732   /** Throw an exception if something is unexpected */
1733   private void check(ParseNode pn, String label) {
1734     if (pn == null) {
1735       throw new Error(pn+ "IE: Expected '" + label + "', got null");
1736     }
1737     if (!pn.getLabel().equals(label)) {
1738       throw new Error(pn+ "IE: Expected '" + label + "', got '"+pn.getLabel()+"'");
1739     }
1740   }
1741 }