test
[IRC.git] / Robust / src / IR / Tree / BuildIR.java
1 package IR.Tree;
2 import IR.*;
3 import java.util.*;
4
5
6 public class BuildIR {
7     State state;
8     public BuildIR(State state) {
9         this.state=state;
10     }
11     public void buildtree() {
12         for(Iterator it=state.parsetrees.iterator();it.hasNext();) {
13             ParseNode pn=(ParseNode)it.next();
14             parseFile(pn);
15         }
16     }
17
18     /** Parse the classes in this file */
19     public void parseFile(ParseNode pn) {
20         ParseNode tpn=pn.getChild("type_declaration_list");
21         if (tpn!=null) {
22             ParseNodeVector pnv=tpn.getChildren();
23             for(int i=0;i<pnv.size();i++) {
24                 ParseNode type_pn=pnv.elementAt(i);
25                 if (isEmpty(type_pn)) /* Skip the semicolon */
26                     continue;
27                 if (isNode(type_pn,"class_declaration")) {
28                     ClassDescriptor cn=parseTypeDecl(type_pn);
29                     state.addClass(cn);
30                 } else if (isNode(type_pn,"task_declaration")) {
31                     TaskDescriptor td=parseTaskDecl(type_pn);
32                     state.addTask(td);
33                 } throw new Error();
34             }
35         }
36     }
37
38     public TaskDescriptor parseTaskDecl(ParseNode pn) {
39         TaskDescriptor td=new TaskDescriptor(pn.getChild("name").getTerminal());
40         ParseNode bodyn=pn.getChild("body");
41         BlockNode bn=parseBlock(bodyn);
42         parseParameterList(td, pn);
43         state.addTreeCode(td,bn);
44         if (pn.getChild("flag_effects_list")!=null)
45             td.addFlagEffects(parseFlagEffects(pn.getChild("flag_effects_list")));
46         return td;
47     }
48
49     public FlagEffects parseFlagEffects(ParseNode pn) {
50          ParseNodeVector pnv=pn.getChildren();
51          FlagEffects fes=new FlagEffects();
52          for(int i=0;i<pnv.size();i++) {
53              ParseNode fn=pnv.elementAt(i);
54              Vector vfe=parseFlagEffect(fn);
55              for (int j=0;j<vfe.size();j++) {
56                  FlagEffect fe=(FlagEffect)vfe.get(j);
57                  fes.addEffect(fe);
58              }
59          }
60          return fes;
61     }
62
63     public Vector parseFlagEffect(ParseNode pn) {
64         
65         if (pn.isNode("flag_effect")) {
66             Vector v=new Vector();
67             String flagname=pn.getChild("name").getTerminal();
68             
69             
70             return v;
71         } else throw new Error();
72     }
73
74     public FlagExpressionNode parseFlagExpression(ParseNode pn) {
75         if (pn.getChild("or")!=null) {
76             ParseNodeVector pnv=pn.getChild("or").getChildren();
77             ParseNode left=pnv.elementAt(0);
78             ParseNode right=pnv.elementAt(1);
79             return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_OR));
80         } else if (pn.getChild("and")!=null) {
81             ParseNodeVector pnv=pn.getChild("and").getChildren();
82             ParseNode left=pnv.elementAt(0);
83             ParseNode right=pnv.elementAt(1);
84             return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_AND));
85         } else if (pn.getChild("not")!=null) {
86             ParseNodeVector pnv=pn.getChild("not").getChildren();
87             ParseNode left=pnv.elementAt(0);
88             return new FlagOpNode(parseFlagExpression(left), new Operation(Operation.LOGIC_NOT));           
89
90         } else if (pn.getChild("name")!=null) {
91             return new FlagNode(pn.getChild("name").getTerminal());
92         } else throw new Error();
93     }
94
95     public void parseParameterList(TaskDescriptor td, ParseNode pn) {
96         ParseNode paramlist=pn.getChild("task_parameter_list");
97         if (paramlist==null)
98             return;
99          ParseNodeVector pnv=paramlist.getChildren();
100          for(int i=0;i<pnv.size();i++) {
101              ParseNode paramn=pnv.elementAt(i);
102              TypeDescriptor type=parseTypeDescriptor(paramn);
103
104              ParseNode tmp=paramn;
105              while (tmp.getChild("single")==null) {
106                  type=type.makeArray(state);
107                  tmp=tmp.getChild("array");
108              }
109              String paramname=tmp.getChild("single").getTerminal();
110              FlagExpressionNode fen=parseFlagExpression(paramn.getChild("flag"));
111              
112              td.addParameter(type,paramname,fen);
113          }
114     }
115
116     public ClassDescriptor parseTypeDecl(ParseNode pn) {
117         ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal());
118         if (!isEmpty(pn.getChild("super").getTerminal())) {
119             /* parse superclass name */
120             ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
121             NameDescriptor nd=parseName(snn);
122             cn.setSuper(nd.toString());
123         } else {
124             if (!cn.getSymbol().equals(TypeUtil.ObjectClass))
125                 cn.setSuper(TypeUtil.ObjectClass);
126         }
127         cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
128         parseClassBody(cn, pn.getChild("classbody"));
129         return cn;
130     }
131
132     private void parseClassBody(ClassDescriptor cn, ParseNode pn) {
133         ParseNode decls=pn.getChild("class_body_declaration_list");
134         if (decls!=null) {
135             ParseNodeVector pnv=decls.getChildren();
136             for(int i=0;i<pnv.size();i++) {
137                 ParseNode decl=pnv.elementAt(i);
138                 if (isNode(decl,"member")) {
139                     parseClassMember(cn,decl);
140                 } else if (isNode(decl,"constructor")) {
141                     parseConstructorDecl(cn,decl.getChild("constructor_declaration"));
142                 } else if (isNode(decl,"block")) {
143                 } else throw new Error();
144             }
145         }
146     }
147
148     private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
149         ParseNode fieldnode=pn.getChild("field");
150
151         if (fieldnode!=null) {
152             parseFieldDecl(cn,fieldnode.getChild("field_declaration"));
153             return;
154         }
155         ParseNode methodnode=pn.getChild("method");
156         if (methodnode!=null) {
157             parseMethodDecl(cn,methodnode.getChild("method_declaration"));
158             return;
159         }
160         throw new Error();
161     }
162
163     private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
164         ParseNode tn=pn.getChild("type");
165         String type_st=tn.getTerminal();
166         if(type_st.equals("byte")) {
167             return state.getTypeDescriptor(TypeDescriptor.BYTE);
168         } else if(type_st.equals("short")) {
169             return state.getTypeDescriptor(TypeDescriptor.SHORT);
170         } else if(type_st.equals("boolean")) {
171             return state.getTypeDescriptor(TypeDescriptor.BOOLEAN);
172         } else if(type_st.equals("int")) {
173             return state.getTypeDescriptor(TypeDescriptor.INT);
174         } else if(type_st.equals("long")) {
175             return state.getTypeDescriptor(TypeDescriptor.LONG);
176         } else if(type_st.equals("char")) {
177             return state.getTypeDescriptor(TypeDescriptor.CHAR);
178         } else if(type_st.equals("float")) {
179             return state.getTypeDescriptor(TypeDescriptor.FLOAT);
180         } else if(type_st.equals("double")) {
181             return state.getTypeDescriptor(TypeDescriptor.DOUBLE);
182         } else if(type_st.equals("class")) {
183             ParseNode nn=tn.getChild("class");
184             return state.getTypeDescriptor(parseName(nn.getChild("name")));
185         } else if(type_st.equals("array")) {
186             ParseNode nn=tn.getChild("array");
187             TypeDescriptor td=parseTypeDescriptor(nn.getChild("basetype"));
188             Integer numdims=(Integer)nn.getChild("dims").getLiteral();
189             for(int i=0;i<numdims.intValue();i++)
190                 td=td.makeArray(state);
191             return td;
192         } else {
193             throw new Error();
194         }
195     }
196
197     private NameDescriptor parseName(ParseNode nn) {
198         ParseNode base=nn.getChild("base");
199         ParseNode id=nn.getChild("identifier");
200         if (base==null)
201             return new NameDescriptor(id.getTerminal());
202         return new NameDescriptor(parseName(base.getChild("name")),id.getTerminal());
203         
204     }
205
206     private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
207         ParseNode mn=pn.getChild("modifier");
208         Modifiers m=parseModifiersList(mn);
209
210         ParseNode tn=pn.getChild("type");
211         TypeDescriptor t=parseTypeDescriptor(tn);
212         ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
213         ParseNodeVector pnv=vn.getChildren();
214         for(int i=0;i<pnv.size();i++) {
215             ParseNode vardecl=pnv.elementAt(i);
216
217             
218             ParseNode tmp=vardecl;
219             TypeDescriptor arrayt=t;
220             while (tmp.getChild("single")==null) {
221                 arrayt=arrayt.makeArray(state);
222                 tmp=tmp.getChild("array");
223             }
224             String identifier=tmp.getChild("single").getTerminal();
225
226             ParseNode epn=vardecl.getChild("initializer");
227             
228             ExpressionNode en=null;
229             if (epn!=null)
230                 en=parseExpression(epn.getFirstChild());
231   
232             cn.addField(new FieldDescriptor(m,arrayt,identifier, en));
233         }
234         
235     }
236
237     private ExpressionNode parseExpression(ParseNode pn) {
238         if (isNode(pn,"assignment"))
239             return parseAssignmentExpression(pn);
240         else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
241                  isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
242                  isNode(pn,"bitwise_and")||isNode(pn,"equal")||
243                  isNode(pn,"not_equal")||isNode(pn,"comp_lt")||
244                  isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
245                  isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
246                  isNode(pn,"rightshift")||isNode(pn,"sub")||
247                  isNode(pn,"add")||isNode(pn,"mult")||
248                  isNode(pn,"div")||isNode(pn,"mod")) {
249             ParseNodeVector pnv=pn.getChildren();
250             ParseNode left=pnv.elementAt(0);
251             ParseNode right=pnv.elementAt(1);
252             Operation op=new Operation(pn.getLabel());
253             return new OpNode(parseExpression(left),parseExpression(right),op);
254         } else if (isNode(pn,"unaryplus")||
255                    isNode(pn,"unaryminus")||
256                    isNode(pn,"postinc")||
257                    isNode(pn,"postdec")||
258                    isNode(pn,"preinc")||
259                    isNode(pn,"not")||
260                    isNode(pn,"predec")) {
261             ParseNode left=pn.getFirstChild();
262             Operation op=new Operation(pn.getLabel());
263             return new OpNode(parseExpression(left),op);
264         } else if (isNode(pn,"literal")) {
265             String literaltype=pn.getTerminal();
266             ParseNode literalnode=pn.getChild(literaltype);
267             Object literal_obj=literalnode.getLiteral();
268             return new LiteralNode(literaltype, literal_obj);
269         } else if (isNode(pn,"createobject")) {
270             TypeDescriptor td=parseTypeDescriptor(pn);
271             Vector args=parseArgumentList(pn);
272             CreateObjectNode con=new CreateObjectNode(td);
273             for(int i=0;i<args.size();i++) {
274                 con.addArgument((ExpressionNode)args.get(i));
275             }
276             return con;
277         } else if (isNode(pn,"createarray")) {
278             System.out.println(pn.PPrint(3,true));
279             TypeDescriptor td=parseTypeDescriptor(pn);
280             Vector args=parseDimExprs(pn);
281             int num=0;
282             if (pn.getChild("dims_opt").getLiteral()!=null)
283                 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
284             for(int i=0;i<(args.size()+num);i++)
285                 td=td.makeArray(state);
286             CreateObjectNode con=new CreateObjectNode(td);
287             for(int i=0;i<args.size();i++) {
288                 con.addArgument((ExpressionNode)args.get(i));
289             }
290             return con;
291         } else if (isNode(pn,"name")) {
292             NameDescriptor nd=parseName(pn);
293             return new NameNode(nd);
294         } else if (isNode(pn,"this")) {
295             NameDescriptor nd=new NameDescriptor("this");
296             return new NameNode(nd);
297         } else if (isNode(pn,"methodinvoke1")) {
298             NameDescriptor nd=parseName(pn.getChild("name"));
299             Vector args=parseArgumentList(pn);
300             MethodInvokeNode min=new MethodInvokeNode(nd);
301             for(int i=0;i<args.size();i++) {
302                 min.addArgument((ExpressionNode)args.get(i));
303             }
304             return min;
305         } else if (isNode(pn,"methodinvoke2")) {
306             String methodid=pn.getChild("id").getTerminal();
307             ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
308             Vector args=parseArgumentList(pn);
309             MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
310             for(int i=0;i<args.size();i++) {
311                 min.addArgument((ExpressionNode)args.get(i));
312             }
313             return min;
314         } else if (isNode(pn,"fieldaccess")) { 
315             ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());         String fieldname=pn.getChild("field").getTerminal();
316             return new FieldAccessNode(en,fieldname);
317         } else if (isNode(pn,"arrayaccess")) { 
318             ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
319             ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
320             return new ArrayAccessNode(en,index);
321         } else if (isNode(pn,"cast1")) { 
322             return new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
323         } else if (isNode(pn,"cast2")) { 
324             return new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
325         } else {
326             System.out.println("---------------------");
327             System.out.println(pn.PPrint(3,true));
328             throw new Error();
329         }
330     }
331
332     private Vector parseDimExprs(ParseNode pn) {
333         Vector arglist=new Vector();
334         ParseNode an=pn.getChild("dim_exprs");
335         if (an==null)   /* No argument list */
336             return arglist;
337         ParseNodeVector anv=an.getChildren();
338         for(int i=0;i<anv.size();i++) {
339             arglist.add(parseExpression(anv.elementAt(i)));
340         }
341         return arglist;
342     }
343
344     private Vector parseArgumentList(ParseNode pn) {
345         Vector arglist=new Vector();
346         ParseNode an=pn.getChild("argument_list");
347         if (an==null)   /* No argument list */
348             return arglist;
349         ParseNodeVector anv=an.getChildren();
350         for(int i=0;i<anv.size();i++) {
351             arglist.add(parseExpression(anv.elementAt(i)));
352         }
353         return arglist;
354     }
355
356     private ExpressionNode parseAssignmentExpression(ParseNode pn) {
357         AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
358         ParseNodeVector pnv=pn.getChild("args").getChildren();
359         
360         AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
361         return an;
362     }
363
364
365     private void parseMethodDecl(ClassDescriptor cn, ParseNode pn) {
366         ParseNode headern=pn.getChild("method_header");
367         ParseNode bodyn=pn.getChild("body");
368         MethodDescriptor md=parseMethodHeader(headern);
369         BlockNode bn=parseBlock(bodyn);
370         cn.addMethod(md);
371         state.addTreeCode(md,bn);
372     }
373
374     private void parseConstructorDecl(ClassDescriptor cn, ParseNode pn) {
375         ParseNode mn=pn.getChild("modifiers");
376         Modifiers m=parseModifiersList(mn);
377         ParseNode cdecl=pn.getChild("constructor_declarator");
378         String name=cdecl.getChild("name").getChild("identifier").getTerminal();
379         MethodDescriptor md=new MethodDescriptor(m, name);
380         ParseNode paramnode=cdecl.getChild("parameters");
381         parseParameterList(md,paramnode);
382         ParseNode bodyn0=pn.getChild("body");
383         ParseNode bodyn=bodyn0.getChild("constructor_body");
384         cn.addMethod(md);
385         if (bodyn!=null) {
386             BlockNode bn=parseBlock(bodyn);
387             state.addTreeCode(md,bn);
388         }
389     }
390
391     public BlockNode parseBlock(ParseNode pn) {
392         if (isEmpty(pn.getTerminal()))
393             return new BlockNode();
394         ParseNode bsn=pn.getChild("block_statement_list");
395         return parseBlockHelper(bsn);
396     }
397     
398     private BlockNode parseBlockHelper(ParseNode pn) {
399         ParseNodeVector pnv=pn.getChildren();
400         BlockNode bn=new BlockNode();
401         for(int i=0;i<pnv.size();i++) {
402             Vector bsv=parseBlockStatement(pnv.elementAt(i));
403             for(int j=0;j<bsv.size();j++) {
404                 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
405             }
406         }
407         return bn;
408     }
409
410     public BlockNode parseSingleBlock(ParseNode pn) {
411         BlockNode bn=new BlockNode();
412         Vector bsv=parseBlockStatement(pn);
413         for(int j=0;j<bsv.size();j++) {
414             bn.addBlockStatement((BlockStatementNode)bsv.get(j));
415         }
416         bn.setStyle(BlockNode.NOBRACES);
417         return bn;
418     }
419
420     public Vector parseBlockStatement(ParseNode pn) {
421         Vector blockstatements=new Vector();
422         if (isNode(pn,"local_variable_declaration")) {
423             TypeDescriptor t=parseTypeDescriptor(pn);
424             ParseNode vn=pn.getChild("variable_declarators_list");
425             ParseNodeVector pnv=vn.getChildren();
426             for(int i=0;i<pnv.size();i++) {
427                 ParseNode vardecl=pnv.elementAt(i);
428
429             
430                 ParseNode tmp=vardecl;
431                 TypeDescriptor arrayt=t;
432                 while (tmp.getChild("single")==null) {
433                     arrayt=arrayt.makeArray(state);
434                     tmp=tmp.getChild("array");
435                 }
436                 String identifier=tmp.getChild("single").getTerminal();
437                 
438                 ParseNode epn=vardecl.getChild("initializer");
439             
440
441                 ExpressionNode en=null;
442                 if (epn!=null)
443                     en=parseExpression(epn.getFirstChild());
444                 
445                 blockstatements.add(new DeclarationNode(new VarDescriptor(arrayt, identifier),en));
446             }
447         } else if (isNode(pn,"nop")) {
448             /* Do Nothing */
449         } else if (isNode(pn,"expression")) {
450             blockstatements.add(new BlockExpressionNode(parseExpression(pn.getFirstChild())));
451         } else if (isNode(pn,"ifstatement")) {
452             blockstatements.add(new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
453                                        parseSingleBlock(pn.getChild("statement").getFirstChild()),
454                                        pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null));
455         } else if (isNode(pn,"taskexit")) {
456             FlagEffects fe=null;
457             if (pn.getChild("flag_effects_list")!=null)
458                 fe=parseFlagEffects(pn.getChild("flag_effects_list"));
459             blockstatements.add(new TaskExitNode(fe));
460         } else if (isNode(pn,"return")) {
461             if (isEmpty(pn.getTerminal()))
462                 blockstatements.add(new ReturnNode());
463             else {
464                 ExpressionNode en=parseExpression(pn.getFirstChild());
465                 blockstatements.add(new ReturnNode(en));
466             }
467         } else if (isNode(pn,"block_statement_list")) {
468             BlockNode bn=parseBlockHelper(pn);
469             blockstatements.add(new SubBlockNode(bn));
470         } else if (isNode(pn,"empty")) {
471             /* nop */
472         } else if (isNode(pn,"statement_expression_list")) {
473             ParseNodeVector pnv=pn.getChildren();
474             BlockNode bn=new BlockNode();
475             for(int i=0;i<pnv.size();i++) {
476                 ExpressionNode en=parseExpression(pnv.elementAt(i));
477                 blockstatements.add(new BlockExpressionNode(en));
478             }
479             bn.setStyle(BlockNode.EXPRLIST);
480         } else if (isNode(pn,"forstatement")) {
481             BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
482             BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
483             ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
484             BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
485             blockstatements.add(new LoopNode(init,condition,update,body));
486         } else if (isNode(pn,"whilestatement")) {
487             ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
488             BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
489             blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
490         } else if (isNode(pn,"dowhilestatement")) {
491             ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
492             BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
493             blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
494         } else {
495             System.out.println("---------------");
496             System.out.println(pn.PPrint(3,true));
497             throw new Error();
498         }
499         return blockstatements;
500     }
501
502     public MethodDescriptor parseMethodHeader(ParseNode pn) {
503         ParseNode mn=pn.getChild("modifiers");
504         Modifiers m=parseModifiersList(mn);
505         
506         ParseNode tn=pn.getChild("returntype");
507         TypeDescriptor returntype;
508         if (tn!=null) 
509             returntype=parseTypeDescriptor(tn);
510         else
511             returntype=new TypeDescriptor(TypeDescriptor.VOID);
512
513         ParseNode pmd=pn.getChild("method_declarator");
514         String name=pmd.getChild("name").getTerminal();
515         MethodDescriptor md=new MethodDescriptor(m, returntype, name);
516        
517         ParseNode paramnode=pmd.getChild("parameters");
518         parseParameterList(md,paramnode);
519         return md;
520     }
521
522     public void parseParameterList(MethodDescriptor md, ParseNode pn) {
523         ParseNode paramlist=pn.getChild("formal_parameter_list");
524         if (paramlist==null)
525             return;
526          ParseNodeVector pnv=paramlist.getChildren();
527          for(int i=0;i<pnv.size();i++) {
528              ParseNode paramn=pnv.elementAt(i);
529              TypeDescriptor type=parseTypeDescriptor(paramn);
530
531              ParseNode tmp=paramn;
532              while (tmp.getChild("single")==null) {
533                  type=type.makeArray(state);
534                  tmp=tmp.getChild("array");
535              }
536              String paramname=tmp.getChild("single").getTerminal();
537             
538              md.addParameter(type,paramname);
539          }
540     }
541
542     public Modifiers parseModifiersList(ParseNode pn) {
543         Modifiers m=new Modifiers();
544         ParseNode modlist=pn.getChild("modifier_list");
545         if (modlist!=null) {
546             ParseNodeVector pnv=modlist.getChildren();
547             for(int i=0;i<pnv.size();i++) {
548                 ParseNode modn=pnv.elementAt(i);
549                 if (isNode(modn,"public"))
550                     m.addModifier(Modifiers.PUBLIC);
551                 if (isNode(modn,"protected"))
552                     m.addModifier(Modifiers.PROTECTED);
553                 if (isNode(modn,"private"))
554                     m.addModifier(Modifiers.PRIVATE);
555                 if (isNode(modn,"static"))
556                     m.addModifier(Modifiers.STATIC);
557                 if (isNode(modn,"final"))
558                     m.addModifier(Modifiers.FINAL);
559                 if (isNode(modn,"native"))
560                     m.addModifier(Modifiers.NATIVE);
561             }
562         }
563         return m;
564     }
565
566     private boolean isNode(ParseNode pn, String label) {
567         if (pn.getLabel().equals(label))
568             return true;
569         else return false;
570     }
571
572     private static boolean isEmpty(ParseNode pn) {
573         if (pn.getLabel().equals("empty"))
574             return true;
575         else
576             return false;
577     }
578
579     private static boolean isEmpty(String s) {
580         if (s.equals("empty"))
581             return true;
582         else
583             return false;
584     }
585
586     /** Throw an exception if something is unexpected */
587     private void check(ParseNode pn, String label) {
588         if (pn == null) {
589             throw new Error(pn+ "IE: Expected '" + label + "', got null");
590         }
591         if (! pn.getLabel().equals(label)) {
592             throw new Error(pn+ "IE: Expected '" + label + "', got '"+pn.getLabel()+"'");
593         }
594     }
595 }