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