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 ParseNode tpn=pn.getChild("type_declaration_list");
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 */
27 if (isNode(type_pn,"class_declaration")) {
28 ClassDescriptor cn=parseTypeDecl(type_pn);
30 } else if (isNode(type_pn,"task_declaration")) {
31 TaskDescriptor td=parseTaskDecl(type_pn);
34 throw new Error(type_pn.getLabel());
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")));
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);
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"));
68 } else throw new Error();
71 public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
72 ParseNodeVector pnv=pn.getChildren();
73 for(int i=0;i<pnv.size();i++) {
74 ParseNode pn2=pnv.elementAt(i);
76 if (isNode(pn2,"not")) {
78 pn2=pn2.getChild("name");
80 String name=pn2.getTerminal();
81 fes.addEffect(new FlagEffect(name,status));
85 public FlagExpressionNode parseFlagExpression(ParseNode pn) {
86 if (pn.getChild("or")!=null) {
87 ParseNodeVector pnv=pn.getChild("or").getChildren();
88 ParseNode left=pnv.elementAt(0);
89 ParseNode right=pnv.elementAt(1);
90 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_OR));
91 } else if (pn.getChild("and")!=null) {
92 ParseNodeVector pnv=pn.getChild("and").getChildren();
93 ParseNode left=pnv.elementAt(0);
94 ParseNode right=pnv.elementAt(1);
95 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_AND));
96 } else if (pn.getChild("not")!=null) {
97 ParseNodeVector pnv=pn.getChild("not").getChildren();
98 ParseNode left=pnv.elementAt(0);
99 return new FlagOpNode(parseFlagExpression(left), new Operation(Operation.LOGIC_NOT));
101 } else if (pn.getChild("name")!=null) {
102 return new FlagNode(pn.getChild("name").getTerminal());
103 } else throw new Error();
106 public Vector parseChecks(ParseNode pn) {
107 Vector ccs=new Vector();
108 ParseNodeVector pnv=pn.getChildren();
109 for(int i=0;i<pnv.size();i++) {
110 ParseNode fn=pnv.elementAt(i);
111 ConstraintCheck cc=parseConstraintCheck(fn);
117 public ConstraintCheck parseConstraintCheck(ParseNode pn) {
118 if (isNode(pn,"cons_check")) {
119 String specname=pn.getChild("name").getChild("identifier").getTerminal();
120 Vector[] args=parseConsArgumentList(pn);
121 ConstraintCheck cc=new ConstraintCheck(specname);
122 for(int i=0;i<args[0].size();i++) {
123 cc.addVariable((String)args[0].get(i));
124 cc.addArgument((ExpressionNode)args[1].get(i));
127 } else throw new Error();
130 public void parseParameterList(TaskDescriptor td, ParseNode pn) {
131 ParseNode paramlist=pn.getChild("task_parameter_list");
134 ParseNodeVector pnv=paramlist.getChildren();
135 for(int i=0;i<pnv.size();i++) {
136 ParseNode paramn=pnv.elementAt(i);
137 TypeDescriptor type=parseTypeDescriptor(paramn);
139 ParseNode tmp=paramn;
140 while (tmp.getChild("single")==null) {
141 type=type.makeArray(state);
142 tmp=tmp.getChild("array");
144 String paramname=tmp.getChild("single").getTerminal();
145 FlagExpressionNode fen=parseFlagExpression(paramn.getChild("flag"));
147 td.addParameter(type,paramname,fen);
151 public ClassDescriptor parseTypeDecl(ParseNode pn) {
152 ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal());
153 if (!isEmpty(pn.getChild("super").getTerminal())) {
154 /* parse superclass name */
155 ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
156 NameDescriptor nd=parseName(snn);
157 cn.setSuper(nd.toString());
159 if (!cn.getSymbol().equals(TypeUtil.ObjectClass))
160 cn.setSuper(TypeUtil.ObjectClass);
162 cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
163 parseClassBody(cn, pn.getChild("classbody"));
167 private void parseClassBody(ClassDescriptor cn, ParseNode pn) {
168 ParseNode decls=pn.getChild("class_body_declaration_list");
170 ParseNodeVector pnv=decls.getChildren();
171 for(int i=0;i<pnv.size();i++) {
172 ParseNode decl=pnv.elementAt(i);
173 if (isNode(decl,"member")) {
174 parseClassMember(cn,decl);
175 } else if (isNode(decl,"constructor")) {
176 parseConstructorDecl(cn,decl.getChild("constructor_declaration"));
177 } else if (isNode(decl,"block")) {
178 } else throw new Error();
183 private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
184 ParseNode fieldnode=pn.getChild("field");
186 if (fieldnode!=null) {
187 parseFieldDecl(cn,fieldnode.getChild("field_declaration"));
190 ParseNode methodnode=pn.getChild("method");
191 if (methodnode!=null) {
192 parseMethodDecl(cn,methodnode.getChild("method_declaration"));
195 ParseNode flagnode=pn.getChild("flag");
196 if (flagnode!=null) {
197 parseFlagDecl(cn, flagnode.getChild("flag_declaration"));
203 private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
204 ParseNode tn=pn.getChild("type");
206 String type_st=tn.getTerminal();
207 if(type_st.equals("byte")) {
208 return state.getTypeDescriptor(TypeDescriptor.BYTE);
209 } else if(type_st.equals("short")) {
210 return state.getTypeDescriptor(TypeDescriptor.SHORT);
211 } else if(type_st.equals("boolean")) {
212 return state.getTypeDescriptor(TypeDescriptor.BOOLEAN);
213 } else if(type_st.equals("int")) {
214 return state.getTypeDescriptor(TypeDescriptor.INT);
215 } else if(type_st.equals("long")) {
216 return state.getTypeDescriptor(TypeDescriptor.LONG);
217 } else if(type_st.equals("char")) {
218 return state.getTypeDescriptor(TypeDescriptor.CHAR);
219 } else if(type_st.equals("float")) {
220 return state.getTypeDescriptor(TypeDescriptor.FLOAT);
221 } else if(type_st.equals("double")) {
222 return state.getTypeDescriptor(TypeDescriptor.DOUBLE);
223 } else if(type_st.equals("class")) {
224 ParseNode nn=tn.getChild("class");
225 return state.getTypeDescriptor(parseName(nn.getChild("name")));
226 } else if(type_st.equals("array")) {
227 ParseNode nn=tn.getChild("array");
228 TypeDescriptor td=parseTypeDescriptor(nn.getChild("basetype"));
229 Integer numdims=(Integer)nn.getChild("dims").getLiteral();
230 for(int i=0;i<numdims.intValue();i++)
231 td=td.makeArray(state);
238 private NameDescriptor parseName(ParseNode nn) {
239 ParseNode base=nn.getChild("base");
240 ParseNode id=nn.getChild("identifier");
242 return new NameDescriptor(id.getTerminal());
243 return new NameDescriptor(parseName(base.getChild("name")),id.getTerminal());
247 private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
248 String name=pn.getChild("name").getTerminal();
249 FlagDescriptor flag=new FlagDescriptor(name);
250 if (pn.getChild("external")!=null)
255 private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
256 ParseNode mn=pn.getChild("modifier");
257 Modifiers m=parseModifiersList(mn);
259 ParseNode tn=pn.getChild("type");
260 TypeDescriptor t=parseTypeDescriptor(tn);
261 ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
262 ParseNodeVector pnv=vn.getChildren();
263 for(int i=0;i<pnv.size();i++) {
264 ParseNode vardecl=pnv.elementAt(i);
267 ParseNode tmp=vardecl;
268 TypeDescriptor arrayt=t;
269 while (tmp.getChild("single")==null) {
270 arrayt=arrayt.makeArray(state);
271 tmp=tmp.getChild("array");
273 String identifier=tmp.getChild("single").getTerminal();
275 ParseNode epn=vardecl.getChild("initializer");
277 ExpressionNode en=null;
279 en=parseExpression(epn.getFirstChild());
281 cn.addField(new FieldDescriptor(m,arrayt,identifier, en));
286 private ExpressionNode parseExpression(ParseNode pn) {
287 if (isNode(pn,"assignment"))
288 return parseAssignmentExpression(pn);
289 else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
290 isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
291 isNode(pn,"bitwise_and")||isNode(pn,"equal")||
292 isNode(pn,"not_equal")||isNode(pn,"comp_lt")||
293 isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
294 isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
295 isNode(pn,"rightshift")||isNode(pn,"sub")||
296 isNode(pn,"add")||isNode(pn,"mult")||
297 isNode(pn,"div")||isNode(pn,"mod")) {
298 ParseNodeVector pnv=pn.getChildren();
299 ParseNode left=pnv.elementAt(0);
300 ParseNode right=pnv.elementAt(1);
301 Operation op=new Operation(pn.getLabel());
302 return new OpNode(parseExpression(left),parseExpression(right),op);
303 } else if (isNode(pn,"unaryplus")||
304 isNode(pn,"unaryminus")||
306 ParseNode left=pn.getFirstChild();
307 Operation op=new Operation(pn.getLabel());
308 return new OpNode(parseExpression(left),op);
309 } else if (isNode(pn,"postinc")||
310 isNode(pn,"postdec")) {
311 ParseNode left=pn.getFirstChild();
312 AssignOperation op=new AssignOperation(pn.getLabel());
313 return new AssignmentNode(parseExpression(left),null,op);
315 } else if (isNode(pn,"preinc")||
316 isNode(pn,"predec")) {
317 ParseNode left=pn.getFirstChild();
318 AssignOperation op=isNode(pn,"preinc")?new AssignOperation(AssignOperation.PLUSEQ):new AssignOperation(AssignOperation.MINUSEQ);
319 return new AssignmentNode(parseExpression(left),
320 new LiteralNode("integer",new Integer(1)),op);
321 } else if (isNode(pn,"literal")) {
322 String literaltype=pn.getTerminal();
323 ParseNode literalnode=pn.getChild(literaltype);
324 Object literal_obj=literalnode.getLiteral();
325 return new LiteralNode(literaltype, literal_obj);
326 } else if (isNode(pn,"createobject")) {
327 TypeDescriptor td=parseTypeDescriptor(pn);
328 Vector args=parseArgumentList(pn);
329 CreateObjectNode con=new CreateObjectNode(td);
330 for(int i=0;i<args.size();i++) {
331 con.addArgument((ExpressionNode)args.get(i));
333 /* Could have flag set here */
334 if (pn.getChild("flag_list")!=null) {
335 FlagEffects fe=new FlagEffects(null);
336 parseFlagEffect(fe, pn.getChild("flag_list"));
337 con.addFlagEffects(fe);
340 } else if (isNode(pn,"createarray")) {
341 System.out.println(pn.PPrint(3,true));
342 TypeDescriptor td=parseTypeDescriptor(pn);
343 Vector args=parseDimExprs(pn);
345 if (pn.getChild("dims_opt").getLiteral()!=null)
346 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
347 for(int i=0;i<(args.size()+num);i++)
348 td=td.makeArray(state);
349 CreateObjectNode con=new CreateObjectNode(td);
350 for(int i=0;i<args.size();i++) {
351 con.addArgument((ExpressionNode)args.get(i));
354 } else if (isNode(pn,"name")) {
355 NameDescriptor nd=parseName(pn);
356 return new NameNode(nd);
357 } else if (isNode(pn,"this")) {
358 NameDescriptor nd=new NameDescriptor("this");
359 return new NameNode(nd);
360 } else if (isNode(pn,"methodinvoke1")) {
361 NameDescriptor nd=parseName(pn.getChild("name"));
362 Vector args=parseArgumentList(pn);
363 MethodInvokeNode min=new MethodInvokeNode(nd);
364 for(int i=0;i<args.size();i++) {
365 min.addArgument((ExpressionNode)args.get(i));
368 } else if (isNode(pn,"methodinvoke2")) {
369 String methodid=pn.getChild("id").getTerminal();
370 ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
371 Vector args=parseArgumentList(pn);
372 MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
373 for(int i=0;i<args.size();i++) {
374 min.addArgument((ExpressionNode)args.get(i));
377 } else if (isNode(pn,"fieldaccess")) {
378 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild()); String fieldname=pn.getChild("field").getTerminal();
379 return new FieldAccessNode(en,fieldname);
380 } else if (isNode(pn,"arrayaccess")) {
381 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
382 ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
383 return new ArrayAccessNode(en,index);
384 } else if (isNode(pn,"cast1")) {
385 return new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
386 } else if (isNode(pn,"cast2")) {
387 return new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
389 System.out.println("---------------------");
390 System.out.println(pn.PPrint(3,true));
395 private Vector parseDimExprs(ParseNode pn) {
396 Vector arglist=new Vector();
397 ParseNode an=pn.getChild("dim_exprs");
398 if (an==null) /* No argument list */
400 ParseNodeVector anv=an.getChildren();
401 for(int i=0;i<anv.size();i++) {
402 arglist.add(parseExpression(anv.elementAt(i)));
407 private Vector parseArgumentList(ParseNode pn) {
408 Vector arglist=new Vector();
409 ParseNode an=pn.getChild("argument_list");
410 if (an==null) /* No argument list */
412 ParseNodeVector anv=an.getChildren();
413 for(int i=0;i<anv.size();i++) {
414 arglist.add(parseExpression(anv.elementAt(i)));
419 private Vector[] parseConsArgumentList(ParseNode pn) {
420 Vector arglist=new Vector();
421 Vector varlist=new Vector();
422 ParseNode an=pn.getChild("cons_argument_list");
423 if (an==null) /* No argument list */
424 return new Vector[] {varlist, arglist};
425 ParseNodeVector anv=an.getChildren();
426 for(int i=0;i<anv.size();i++) {
427 ParseNode cpn=anv.elementAt(i);
428 ParseNode var=cpn.getChild("var");
429 ParseNode exp=cpn.getChild("exp").getFirstChild();
430 varlist.add(var.getTerminal());
431 arglist.add(parseExpression(exp));
433 return new Vector[] {varlist, arglist};
436 private ExpressionNode parseAssignmentExpression(ParseNode pn) {
437 AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
438 ParseNodeVector pnv=pn.getChild("args").getChildren();
440 AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
445 private void parseMethodDecl(ClassDescriptor cn, ParseNode pn) {
446 ParseNode headern=pn.getChild("method_header");
447 ParseNode bodyn=pn.getChild("body");
448 MethodDescriptor md=parseMethodHeader(headern);
449 BlockNode bn=parseBlock(bodyn);
451 state.addTreeCode(md,bn);
454 private void parseConstructorDecl(ClassDescriptor cn, ParseNode pn) {
455 ParseNode mn=pn.getChild("modifiers");
456 Modifiers m=parseModifiersList(mn);
457 ParseNode cdecl=pn.getChild("constructor_declarator");
458 String name=cdecl.getChild("name").getChild("identifier").getTerminal();
459 MethodDescriptor md=new MethodDescriptor(m, name);
460 ParseNode paramnode=cdecl.getChild("parameters");
461 parseParameterList(md,paramnode);
462 ParseNode bodyn0=pn.getChild("body");
463 ParseNode bodyn=bodyn0.getChild("constructor_body");
465 BlockNode bn=parseBlock(bodyn);
466 state.addTreeCode(md,bn);
469 public BlockNode parseBlock(ParseNode pn) {
470 if (pn==null||isEmpty(pn.getTerminal()))
471 return new BlockNode();
472 ParseNode bsn=pn.getChild("block_statement_list");
473 return parseBlockHelper(bsn);
476 private BlockNode parseBlockHelper(ParseNode pn) {
477 ParseNodeVector pnv=pn.getChildren();
478 BlockNode bn=new BlockNode();
479 for(int i=0;i<pnv.size();i++) {
480 Vector bsv=parseBlockStatement(pnv.elementAt(i));
481 for(int j=0;j<bsv.size();j++) {
482 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
488 public BlockNode parseSingleBlock(ParseNode pn) {
489 BlockNode bn=new BlockNode();
490 Vector bsv=parseBlockStatement(pn);
491 for(int j=0;j<bsv.size();j++) {
492 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
494 bn.setStyle(BlockNode.NOBRACES);
498 public Vector parseBlockStatement(ParseNode pn) {
499 Vector blockstatements=new Vector();
500 if (isNode(pn,"local_variable_declaration")) {
501 TypeDescriptor t=parseTypeDescriptor(pn);
502 ParseNode vn=pn.getChild("variable_declarators_list");
503 ParseNodeVector pnv=vn.getChildren();
504 for(int i=0;i<pnv.size();i++) {
505 ParseNode vardecl=pnv.elementAt(i);
508 ParseNode tmp=vardecl;
509 TypeDescriptor arrayt=t;
510 while (tmp.getChild("single")==null) {
511 arrayt=arrayt.makeArray(state);
512 tmp=tmp.getChild("array");
514 String identifier=tmp.getChild("single").getTerminal();
516 ParseNode epn=vardecl.getChild("initializer");
519 ExpressionNode en=null;
521 en=parseExpression(epn.getFirstChild());
523 blockstatements.add(new DeclarationNode(new VarDescriptor(arrayt, identifier),en));
525 } else if (isNode(pn,"nop")) {
527 } else if (isNode(pn,"expression")) {
528 blockstatements.add(new BlockExpressionNode(parseExpression(pn.getFirstChild())));
529 } else if (isNode(pn,"ifstatement")) {
530 blockstatements.add(new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
531 parseSingleBlock(pn.getChild("statement").getFirstChild()),
532 pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null));
533 } else if (isNode(pn,"taskexit")) {
535 if (pn.getChild("flag_effects_list")!=null)
536 vfe=parseFlags(pn.getChild("flag_effects_list"));
538 if (pn.getChild("cons_checks")!=null)
539 ccs=parseChecks(pn.getChild("cons_checks"));
541 blockstatements.add(new TaskExitNode(vfe, ccs));
542 } else if (isNode(pn,"return")) {
543 if (isEmpty(pn.getTerminal()))
544 blockstatements.add(new ReturnNode());
546 ExpressionNode en=parseExpression(pn.getFirstChild());
547 blockstatements.add(new ReturnNode(en));
549 } else if (isNode(pn,"block_statement_list")) {
550 BlockNode bn=parseBlockHelper(pn);
551 blockstatements.add(new SubBlockNode(bn));
552 } else if (isNode(pn,"empty")) {
554 } else if (isNode(pn,"statement_expression_list")) {
555 ParseNodeVector pnv=pn.getChildren();
556 BlockNode bn=new BlockNode();
557 for(int i=0;i<pnv.size();i++) {
558 ExpressionNode en=parseExpression(pnv.elementAt(i));
559 blockstatements.add(new BlockExpressionNode(en));
561 bn.setStyle(BlockNode.EXPRLIST);
562 } else if (isNode(pn,"forstatement")) {
563 BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
564 BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
565 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
566 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
567 blockstatements.add(new LoopNode(init,condition,update,body));
568 } else if (isNode(pn,"whilestatement")) {
569 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
570 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
571 blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
572 } else if (isNode(pn,"dowhilestatement")) {
573 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
574 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
575 blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
577 System.out.println("---------------");
578 System.out.println(pn.PPrint(3,true));
581 return blockstatements;
584 public MethodDescriptor parseMethodHeader(ParseNode pn) {
585 ParseNode mn=pn.getChild("modifiers");
586 Modifiers m=parseModifiersList(mn);
588 ParseNode tn=pn.getChild("returntype");
589 TypeDescriptor returntype;
591 returntype=parseTypeDescriptor(tn);
593 returntype=new TypeDescriptor(TypeDescriptor.VOID);
595 ParseNode pmd=pn.getChild("method_declarator");
596 String name=pmd.getChild("name").getTerminal();
597 MethodDescriptor md=new MethodDescriptor(m, returntype, name);
599 ParseNode paramnode=pmd.getChild("parameters");
600 parseParameterList(md,paramnode);
604 public void parseParameterList(MethodDescriptor md, ParseNode pn) {
605 ParseNode paramlist=pn.getChild("formal_parameter_list");
608 ParseNodeVector pnv=paramlist.getChildren();
609 for(int i=0;i<pnv.size();i++) {
610 ParseNode paramn=pnv.elementAt(i);
611 TypeDescriptor type=parseTypeDescriptor(paramn);
613 ParseNode tmp=paramn;
614 while (tmp.getChild("single")==null) {
615 type=type.makeArray(state);
616 tmp=tmp.getChild("array");
618 String paramname=tmp.getChild("single").getTerminal();
620 md.addParameter(type,paramname);
624 public Modifiers parseModifiersList(ParseNode pn) {
625 Modifiers m=new Modifiers();
626 ParseNode modlist=pn.getChild("modifier_list");
628 ParseNodeVector pnv=modlist.getChildren();
629 for(int i=0;i<pnv.size();i++) {
630 ParseNode modn=pnv.elementAt(i);
631 if (isNode(modn,"public"))
632 m.addModifier(Modifiers.PUBLIC);
633 if (isNode(modn,"protected"))
634 m.addModifier(Modifiers.PROTECTED);
635 if (isNode(modn,"private"))
636 m.addModifier(Modifiers.PRIVATE);
637 if (isNode(modn,"static"))
638 m.addModifier(Modifiers.STATIC);
639 if (isNode(modn,"final"))
640 m.addModifier(Modifiers.FINAL);
641 if (isNode(modn,"native"))
642 m.addModifier(Modifiers.NATIVE);
648 private boolean isNode(ParseNode pn, String label) {
649 if (pn.getLabel().equals(label))
654 private static boolean isEmpty(ParseNode pn) {
655 if (pn.getLabel().equals("empty"))
661 private static boolean isEmpty(String s) {
662 if (s.equals("empty"))
668 /** Throw an exception if something is unexpected */
669 private void check(ParseNode pn, String label) {
671 throw new Error(pn+ "IE: Expected '" + label + "', got null");
673 if (! pn.getLabel().equals(label)) {
674 throw new Error(pn+ "IE: Expected '" + label + "', got '"+pn.getLabel()+"'");