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