8 public BuildIR(State state) {
11 public void buildtree() {
12 for(Iterator it=state.parsetrees.iterator();it.hasNext();) {
13 ParseNode pn=(ParseNode)it.next();
18 /** Parse the classes in this file */
19 public void parseFile(ParseNode pn) {
20 NameDescriptor packages;
21 Vector singleimports=new Vector();
22 Vector multiimports=new Vector();
24 ParseNode ipn=pn.getChild("imports").getChild("import_decls_list");
26 ParseNodeVector pnv=ipn.getChildren();
27 for(int i=0;i<pnv.size();i++) {
28 ParseNode pnimport=pnv.elementAt(i);
29 NameDescriptor nd=parseName(pnimport.getChild("name"));
30 if (isNode(pnimport,"import_single"))
31 singleimports.add(nd);
36 ParseNode ppn=pn.getChild("packages").getChild("package");
38 packages=parseName(pn.getChild("name"));
40 ParseNode tpn=pn.getChild("type_declaration_list");
42 ParseNodeVector pnv=tpn.getChildren();
43 for(int i=0;i<pnv.size();i++) {
44 ParseNode type_pn=pnv.elementAt(i);
45 if (isEmpty(type_pn)) /* Skip the semicolon */
47 if (isNode(type_pn,"class_declaration")) {
48 ClassDescriptor cn=parseTypeDecl(type_pn);
50 } else if (isNode(type_pn,"task_declaration")) {
51 TaskDescriptor td=parseTaskDecl(type_pn);
54 throw new Error(type_pn.getLabel());
60 public TaskDescriptor parseTaskDecl(ParseNode pn) {
61 TaskDescriptor td=new TaskDescriptor(pn.getChild("name").getTerminal());
62 ParseNode bodyn=pn.getChild("body");
63 BlockNode bn=parseBlock(bodyn);
64 parseParameterList(td, pn);
65 state.addTreeCode(td,bn);
66 if (pn.getChild("flag_effects_list")!=null)
67 td.addFlagEffects(parseFlags(pn.getChild("flag_effects_list")));
71 public Vector parseFlags(ParseNode pn) {
72 Vector vfe=new Vector();
73 ParseNodeVector pnv=pn.getChildren();
74 for(int i=0;i<pnv.size();i++) {
75 ParseNode fn=pnv.elementAt(i);
76 FlagEffects fe=parseFlagEffects(fn);
82 public FlagEffects parseFlagEffects(ParseNode pn) {
83 if (isNode(pn,"flag_effect")) {
84 String flagname=pn.getChild("name").getTerminal();
85 FlagEffects fe=new FlagEffects(flagname);
86 parseFlagEffect(fe, pn.getChild("flag_list"));
88 } else throw new Error();
91 public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
92 ParseNodeVector pnv=pn.getChildren();
93 for(int i=0;i<pnv.size();i++) {
94 ParseNode pn2=pnv.elementAt(i);
96 if (isNode(pn2,"not")) {
98 pn2=pn2.getChild("name");
100 String name=pn2.getTerminal();
101 fes.addEffect(new FlagEffect(name,status));
105 public FlagExpressionNode parseFlagExpression(ParseNode pn) {
106 if (isNode(pn,"or")) {
107 ParseNodeVector pnv=pn.getChildren();
108 ParseNode left=pnv.elementAt(0);
109 ParseNode right=pnv.elementAt(1);
110 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_OR));
111 } else if (isNode(pn,"and")) {
112 ParseNodeVector pnv=pn.getChildren();
113 ParseNode left=pnv.elementAt(0);
114 ParseNode right=pnv.elementAt(1);
115 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_AND));
116 } else if (isNode(pn, "not")) {
117 ParseNodeVector pnv=pn.getChildren();
118 ParseNode left=pnv.elementAt(0);
119 return new FlagOpNode(parseFlagExpression(left), new Operation(Operation.LOGIC_NOT));
121 } else if (isNode(pn,"name")) {
122 return new FlagNode(pn.getTerminal());
128 public Vector parseChecks(ParseNode pn) {
129 Vector ccs=new Vector();
130 ParseNodeVector pnv=pn.getChildren();
131 for(int i=0;i<pnv.size();i++) {
132 ParseNode fn=pnv.elementAt(i);
133 ConstraintCheck cc=parseConstraintCheck(fn);
139 public ConstraintCheck parseConstraintCheck(ParseNode pn) {
140 if (isNode(pn,"cons_check")) {
141 String specname=pn.getChild("name").getChild("identifier").getTerminal();
142 Vector[] args=parseConsArgumentList(pn);
143 ConstraintCheck cc=new ConstraintCheck(specname);
144 for(int i=0;i<args[0].size();i++) {
145 cc.addVariable((String)args[0].get(i));
146 cc.addArgument((ExpressionNode)args[1].get(i));
149 } else throw new Error();
152 public void parseParameterList(TaskDescriptor td, ParseNode pn) {
153 ParseNode paramlist=pn.getChild("task_parameter_list");
156 ParseNodeVector pnv=paramlist.getChildren();
157 for(int i=0;i<pnv.size();i++) {
158 ParseNode paramn=pnv.elementAt(i);
159 TypeDescriptor type=parseTypeDescriptor(paramn);
161 ParseNode tmp=paramn;
162 while (tmp.getChild("single")==null) {
163 type=type.makeArray(state);
164 tmp=tmp.getChild("array");
166 String paramname=tmp.getChild("single").getTerminal();
167 FlagExpressionNode fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
169 td.addParameter(type,paramname,fen);
173 public ClassDescriptor parseTypeDecl(ParseNode pn) {
174 ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal());
175 if (!isEmpty(pn.getChild("super").getTerminal())) {
176 /* parse superclass name */
177 ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
178 NameDescriptor nd=parseName(snn);
179 cn.setSuper(nd.toString());
181 if (!cn.getSymbol().equals(TypeUtil.ObjectClass))
182 cn.setSuper(TypeUtil.ObjectClass);
184 cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
185 parseClassBody(cn, pn.getChild("classbody"));
189 private void parseClassBody(ClassDescriptor cn, ParseNode pn) {
190 ParseNode decls=pn.getChild("class_body_declaration_list");
192 ParseNodeVector pnv=decls.getChildren();
193 for(int i=0;i<pnv.size();i++) {
194 ParseNode decl=pnv.elementAt(i);
195 if (isNode(decl,"member")) {
196 parseClassMember(cn,decl);
197 } else if (isNode(decl,"constructor")) {
198 parseConstructorDecl(cn,decl.getChild("constructor_declaration"));
199 } else if (isNode(decl,"block")) {
200 } else throw new Error();
205 private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
206 ParseNode fieldnode=pn.getChild("field");
208 if (fieldnode!=null) {
209 parseFieldDecl(cn,fieldnode.getChild("field_declaration"));
212 ParseNode methodnode=pn.getChild("method");
213 if (methodnode!=null) {
214 parseMethodDecl(cn,methodnode.getChild("method_declaration"));
217 ParseNode flagnode=pn.getChild("flag");
218 if (flagnode!=null) {
219 parseFlagDecl(cn, flagnode.getChild("flag_declaration"));
225 private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
226 ParseNode tn=pn.getChild("type");
228 String type_st=tn.getTerminal();
229 if(type_st.equals("byte")) {
230 return state.getTypeDescriptor(TypeDescriptor.BYTE);
231 } else if(type_st.equals("short")) {
232 return state.getTypeDescriptor(TypeDescriptor.SHORT);
233 } else if(type_st.equals("boolean")) {
234 return state.getTypeDescriptor(TypeDescriptor.BOOLEAN);
235 } else if(type_st.equals("int")) {
236 return state.getTypeDescriptor(TypeDescriptor.INT);
237 } else if(type_st.equals("long")) {
238 return state.getTypeDescriptor(TypeDescriptor.LONG);
239 } else if(type_st.equals("char")) {
240 return state.getTypeDescriptor(TypeDescriptor.CHAR);
241 } else if(type_st.equals("float")) {
242 return state.getTypeDescriptor(TypeDescriptor.FLOAT);
243 } else if(type_st.equals("double")) {
244 return state.getTypeDescriptor(TypeDescriptor.DOUBLE);
245 } else if(type_st.equals("class")) {
246 ParseNode nn=tn.getChild("class");
247 return state.getTypeDescriptor(parseName(nn.getChild("name")));
248 } else if(type_st.equals("array")) {
249 ParseNode nn=tn.getChild("array");
250 TypeDescriptor td=parseTypeDescriptor(nn.getChild("basetype"));
251 Integer numdims=(Integer)nn.getChild("dims").getLiteral();
252 for(int i=0;i<numdims.intValue();i++)
253 td=td.makeArray(state);
260 private NameDescriptor parseName(ParseNode nn) {
261 ParseNode base=nn.getChild("base");
262 ParseNode id=nn.getChild("identifier");
264 return new NameDescriptor(id.getTerminal());
265 return new NameDescriptor(parseName(base.getChild("name")),id.getTerminal());
269 private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
270 String name=pn.getChild("name").getTerminal();
271 FlagDescriptor flag=new FlagDescriptor(name);
272 if (pn.getChild("external")!=null)
277 private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
278 ParseNode mn=pn.getChild("modifier");
279 Modifiers m=parseModifiersList(mn);
281 ParseNode tn=pn.getChild("type");
282 TypeDescriptor t=parseTypeDescriptor(tn);
283 ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
284 ParseNodeVector pnv=vn.getChildren();
285 for(int i=0;i<pnv.size();i++) {
286 ParseNode vardecl=pnv.elementAt(i);
289 ParseNode tmp=vardecl;
290 TypeDescriptor arrayt=t;
291 while (tmp.getChild("single")==null) {
292 arrayt=arrayt.makeArray(state);
293 tmp=tmp.getChild("array");
295 String identifier=tmp.getChild("single").getTerminal();
297 ParseNode epn=vardecl.getChild("initializer");
299 ExpressionNode en=null;
301 en=parseExpression(epn.getFirstChild());
303 cn.addField(new FieldDescriptor(m,arrayt,identifier, en));
308 private ExpressionNode parseExpression(ParseNode pn) {
309 if (isNode(pn,"assignment"))
310 return parseAssignmentExpression(pn);
311 else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
312 isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
313 isNode(pn,"bitwise_and")||isNode(pn,"equal")||
314 isNode(pn,"not_equal")||isNode(pn,"comp_lt")||
315 isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
316 isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
317 isNode(pn,"rightshift")||isNode(pn,"sub")||
318 isNode(pn,"add")||isNode(pn,"mult")||
319 isNode(pn,"div")||isNode(pn,"mod")) {
320 ParseNodeVector pnv=pn.getChildren();
321 ParseNode left=pnv.elementAt(0);
322 ParseNode right=pnv.elementAt(1);
323 Operation op=new Operation(pn.getLabel());
324 return new OpNode(parseExpression(left),parseExpression(right),op);
325 } else if (isNode(pn,"unaryplus")||
326 isNode(pn,"unaryminus")||
328 ParseNode left=pn.getFirstChild();
329 Operation op=new Operation(pn.getLabel());
330 return new OpNode(parseExpression(left),op);
331 } else if (isNode(pn,"postinc")||
332 isNode(pn,"postdec")) {
333 ParseNode left=pn.getFirstChild();
334 AssignOperation op=new AssignOperation(pn.getLabel());
335 return new AssignmentNode(parseExpression(left),null,op);
337 } else if (isNode(pn,"preinc")||
338 isNode(pn,"predec")) {
339 ParseNode left=pn.getFirstChild();
340 AssignOperation op=isNode(pn,"preinc")?new AssignOperation(AssignOperation.PLUSEQ):new AssignOperation(AssignOperation.MINUSEQ);
341 return new AssignmentNode(parseExpression(left),
342 new LiteralNode("integer",new Integer(1)),op);
343 } else if (isNode(pn,"literal")) {
344 String literaltype=pn.getTerminal();
345 ParseNode literalnode=pn.getChild(literaltype);
346 Object literal_obj=literalnode.getLiteral();
347 return new LiteralNode(literaltype, literal_obj);
348 } else if (isNode(pn,"createobject")) {
349 TypeDescriptor td=parseTypeDescriptor(pn);
350 Vector args=parseArgumentList(pn);
351 CreateObjectNode con=new CreateObjectNode(td);
352 for(int i=0;i<args.size();i++) {
353 con.addArgument((ExpressionNode)args.get(i));
355 /* Could have flag set here */
356 if (pn.getChild("flag_list")!=null) {
357 FlagEffects fe=new FlagEffects(null);
358 parseFlagEffect(fe, pn.getChild("flag_list"));
359 con.addFlagEffects(fe);
362 } else if (isNode(pn,"createarray")) {
363 //System.out.println(pn.PPrint(3,true));
364 TypeDescriptor td=parseTypeDescriptor(pn);
365 Vector args=parseDimExprs(pn);
367 if (pn.getChild("dims_opt").getLiteral()!=null)
368 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
369 for(int i=0;i<(args.size()+num);i++)
370 td=td.makeArray(state);
371 CreateObjectNode con=new CreateObjectNode(td);
372 for(int i=0;i<args.size();i++) {
373 con.addArgument((ExpressionNode)args.get(i));
376 } else if (isNode(pn,"name")) {
377 NameDescriptor nd=parseName(pn);
378 return new NameNode(nd);
379 } else if (isNode(pn,"this")) {
380 NameDescriptor nd=new NameDescriptor("this");
381 return new NameNode(nd);
382 } else if (isNode(pn,"methodinvoke1")) {
383 NameDescriptor nd=parseName(pn.getChild("name"));
384 Vector args=parseArgumentList(pn);
385 MethodInvokeNode min=new MethodInvokeNode(nd);
386 for(int i=0;i<args.size();i++) {
387 min.addArgument((ExpressionNode)args.get(i));
390 } else if (isNode(pn,"methodinvoke2")) {
391 String methodid=pn.getChild("id").getTerminal();
392 ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
393 Vector args=parseArgumentList(pn);
394 MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
395 for(int i=0;i<args.size();i++) {
396 min.addArgument((ExpressionNode)args.get(i));
399 } else if (isNode(pn,"fieldaccess")) {
400 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild()); String fieldname=pn.getChild("field").getTerminal();
401 return new FieldAccessNode(en,fieldname);
402 } else if (isNode(pn,"arrayaccess")) {
403 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
404 ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
405 return new ArrayAccessNode(en,index);
406 } else if (isNode(pn,"cast1")) {
407 return new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
408 } else if (isNode(pn,"cast2")) {
409 return new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
411 System.out.println("---------------------");
412 System.out.println(pn.PPrint(3,true));
417 private Vector parseDimExprs(ParseNode pn) {
418 Vector arglist=new Vector();
419 ParseNode an=pn.getChild("dim_exprs");
420 if (an==null) /* No argument list */
422 ParseNodeVector anv=an.getChildren();
423 for(int i=0;i<anv.size();i++) {
424 arglist.add(parseExpression(anv.elementAt(i)));
429 private Vector parseArgumentList(ParseNode pn) {
430 Vector arglist=new Vector();
431 ParseNode an=pn.getChild("argument_list");
432 if (an==null) /* No argument list */
434 ParseNodeVector anv=an.getChildren();
435 for(int i=0;i<anv.size();i++) {
436 arglist.add(parseExpression(anv.elementAt(i)));
441 private Vector[] parseConsArgumentList(ParseNode pn) {
442 Vector arglist=new Vector();
443 Vector varlist=new Vector();
444 ParseNode an=pn.getChild("cons_argument_list");
445 if (an==null) /* No argument list */
446 return new Vector[] {varlist, arglist};
447 ParseNodeVector anv=an.getChildren();
448 for(int i=0;i<anv.size();i++) {
449 ParseNode cpn=anv.elementAt(i);
450 ParseNode var=cpn.getChild("var");
451 ParseNode exp=cpn.getChild("exp").getFirstChild();
452 varlist.add(var.getTerminal());
453 arglist.add(parseExpression(exp));
455 return new Vector[] {varlist, arglist};
458 private ExpressionNode parseAssignmentExpression(ParseNode pn) {
459 AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
460 ParseNodeVector pnv=pn.getChild("args").getChildren();
462 AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
467 private void parseMethodDecl(ClassDescriptor cn, ParseNode pn) {
468 ParseNode headern=pn.getChild("method_header");
469 ParseNode bodyn=pn.getChild("body");
470 MethodDescriptor md=parseMethodHeader(headern);
471 BlockNode bn=parseBlock(bodyn);
473 state.addTreeCode(md,bn);
476 private void parseConstructorDecl(ClassDescriptor cn, ParseNode pn) {
477 ParseNode mn=pn.getChild("modifiers");
478 Modifiers m=parseModifiersList(mn);
479 ParseNode cdecl=pn.getChild("constructor_declarator");
480 String name=cdecl.getChild("name").getChild("identifier").getTerminal();
481 MethodDescriptor md=new MethodDescriptor(m, name);
482 ParseNode paramnode=cdecl.getChild("parameters");
483 parseParameterList(md,paramnode);
484 ParseNode bodyn0=pn.getChild("body");
485 ParseNode bodyn=bodyn0.getChild("constructor_body");
487 BlockNode bn=parseBlock(bodyn);
488 state.addTreeCode(md,bn);
491 public BlockNode parseBlock(ParseNode pn) {
492 if (pn==null||isEmpty(pn.getTerminal()))
493 return new BlockNode();
494 ParseNode bsn=pn.getChild("block_statement_list");
495 return parseBlockHelper(bsn);
498 private BlockNode parseBlockHelper(ParseNode pn) {
499 ParseNodeVector pnv=pn.getChildren();
500 BlockNode bn=new BlockNode();
501 for(int i=0;i<pnv.size();i++) {
502 Vector bsv=parseBlockStatement(pnv.elementAt(i));
503 for(int j=0;j<bsv.size();j++) {
504 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
510 public BlockNode parseSingleBlock(ParseNode pn) {
511 BlockNode bn=new BlockNode();
512 Vector bsv=parseBlockStatement(pn);
513 for(int j=0;j<bsv.size();j++) {
514 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
516 bn.setStyle(BlockNode.NOBRACES);
520 public Vector parseBlockStatement(ParseNode pn) {
521 Vector blockstatements=new Vector();
522 if (isNode(pn,"local_variable_declaration")) {
523 TypeDescriptor t=parseTypeDescriptor(pn);
524 ParseNode vn=pn.getChild("variable_declarators_list");
525 ParseNodeVector pnv=vn.getChildren();
526 for(int i=0;i<pnv.size();i++) {
527 ParseNode vardecl=pnv.elementAt(i);
530 ParseNode tmp=vardecl;
531 TypeDescriptor arrayt=t;
532 while (tmp.getChild("single")==null) {
533 arrayt=arrayt.makeArray(state);
534 tmp=tmp.getChild("array");
536 String identifier=tmp.getChild("single").getTerminal();
538 ParseNode epn=vardecl.getChild("initializer");
541 ExpressionNode en=null;
543 en=parseExpression(epn.getFirstChild());
545 blockstatements.add(new DeclarationNode(new VarDescriptor(arrayt, identifier),en));
547 } else if (isNode(pn,"nop")) {
549 } else if (isNode(pn,"expression")) {
550 blockstatements.add(new BlockExpressionNode(parseExpression(pn.getFirstChild())));
551 } else if (isNode(pn,"ifstatement")) {
552 blockstatements.add(new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
553 parseSingleBlock(pn.getChild("statement").getFirstChild()),
554 pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null));
555 } else if (isNode(pn,"taskexit")) {
557 if (pn.getChild("flag_effects_list")!=null)
558 vfe=parseFlags(pn.getChild("flag_effects_list"));
560 if (pn.getChild("cons_checks")!=null)
561 ccs=parseChecks(pn.getChild("cons_checks"));
563 blockstatements.add(new TaskExitNode(vfe, ccs));
564 } else if (isNode(pn,"return")) {
565 if (isEmpty(pn.getTerminal()))
566 blockstatements.add(new ReturnNode());
568 ExpressionNode en=parseExpression(pn.getFirstChild());
569 blockstatements.add(new ReturnNode(en));
571 } else if (isNode(pn,"block_statement_list")) {
572 BlockNode bn=parseBlockHelper(pn);
573 blockstatements.add(new SubBlockNode(bn));
574 } else if (isNode(pn,"empty")) {
576 } else if (isNode(pn,"statement_expression_list")) {
577 ParseNodeVector pnv=pn.getChildren();
578 BlockNode bn=new BlockNode();
579 for(int i=0;i<pnv.size();i++) {
580 ExpressionNode en=parseExpression(pnv.elementAt(i));
581 blockstatements.add(new BlockExpressionNode(en));
583 bn.setStyle(BlockNode.EXPRLIST);
584 } else if (isNode(pn,"forstatement")) {
585 BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
586 BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
587 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
588 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
589 blockstatements.add(new LoopNode(init,condition,update,body));
590 } else if (isNode(pn,"whilestatement")) {
591 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
592 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
593 blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
594 } else if (isNode(pn,"dowhilestatement")) {
595 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
596 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
597 blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
599 System.out.println("---------------");
600 System.out.println(pn.PPrint(3,true));
603 return blockstatements;
606 public MethodDescriptor parseMethodHeader(ParseNode pn) {
607 ParseNode mn=pn.getChild("modifiers");
608 Modifiers m=parseModifiersList(mn);
610 ParseNode tn=pn.getChild("returntype");
611 TypeDescriptor returntype;
613 returntype=parseTypeDescriptor(tn);
615 returntype=new TypeDescriptor(TypeDescriptor.VOID);
617 ParseNode pmd=pn.getChild("method_declarator");
618 String name=pmd.getChild("name").getTerminal();
619 MethodDescriptor md=new MethodDescriptor(m, returntype, name);
621 ParseNode paramnode=pmd.getChild("parameters");
622 parseParameterList(md,paramnode);
626 public void parseParameterList(MethodDescriptor md, ParseNode pn) {
627 ParseNode paramlist=pn.getChild("formal_parameter_list");
630 ParseNodeVector pnv=paramlist.getChildren();
631 for(int i=0;i<pnv.size();i++) {
632 ParseNode paramn=pnv.elementAt(i);
633 TypeDescriptor type=parseTypeDescriptor(paramn);
635 ParseNode tmp=paramn;
636 while (tmp.getChild("single")==null) {
637 type=type.makeArray(state);
638 tmp=tmp.getChild("array");
640 String paramname=tmp.getChild("single").getTerminal();
642 md.addParameter(type,paramname);
646 public Modifiers parseModifiersList(ParseNode pn) {
647 Modifiers m=new Modifiers();
648 ParseNode modlist=pn.getChild("modifier_list");
650 ParseNodeVector pnv=modlist.getChildren();
651 for(int i=0;i<pnv.size();i++) {
652 ParseNode modn=pnv.elementAt(i);
653 if (isNode(modn,"public"))
654 m.addModifier(Modifiers.PUBLIC);
655 else if (isNode(modn,"protected"))
656 m.addModifier(Modifiers.PROTECTED);
657 else if (isNode(modn,"private"))
658 m.addModifier(Modifiers.PRIVATE);
659 else if (isNode(modn,"static"))
660 m.addModifier(Modifiers.STATIC);
661 else if (isNode(modn,"final"))
662 m.addModifier(Modifiers.FINAL);
663 else if (isNode(modn,"native"))
664 m.addModifier(Modifiers.NATIVE);
665 else if (isNode(modn,"synchronized"))
666 m.addModifier(Modifiers.SYNCHRONIZED);
667 else throw new Error("Unrecognized Modifier");
673 private boolean isNode(ParseNode pn, String label) {
674 if (pn.getLabel().equals(label))
679 private static boolean isEmpty(ParseNode pn) {
680 if (pn.getLabel().equals("empty"))
686 private static boolean isEmpty(String s) {
687 if (s.equals("empty"))
693 /** Throw an exception if something is unexpected */
694 private void check(ParseNode pn, String label) {
696 throw new Error(pn+ "IE: Expected '" + label + "', got null");
698 if (! pn.getLabel().equals(label)) {
699 throw new Error(pn+ "IE: Expected '" + label + "', got '"+pn.getLabel()+"'");