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