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 cn.addFlag(new FlagDescriptor(name));
252 private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
253 ParseNode mn=pn.getChild("modifier");
254 Modifiers m=parseModifiersList(mn);
256 ParseNode tn=pn.getChild("type");
257 TypeDescriptor t=parseTypeDescriptor(tn);
258 ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
259 ParseNodeVector pnv=vn.getChildren();
260 for(int i=0;i<pnv.size();i++) {
261 ParseNode vardecl=pnv.elementAt(i);
264 ParseNode tmp=vardecl;
265 TypeDescriptor arrayt=t;
266 while (tmp.getChild("single")==null) {
267 arrayt=arrayt.makeArray(state);
268 tmp=tmp.getChild("array");
270 String identifier=tmp.getChild("single").getTerminal();
272 ParseNode epn=vardecl.getChild("initializer");
274 ExpressionNode en=null;
276 en=parseExpression(epn.getFirstChild());
278 cn.addField(new FieldDescriptor(m,arrayt,identifier, en));
283 private ExpressionNode parseExpression(ParseNode pn) {
284 if (isNode(pn,"assignment"))
285 return parseAssignmentExpression(pn);
286 else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
287 isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
288 isNode(pn,"bitwise_and")||isNode(pn,"equal")||
289 isNode(pn,"not_equal")||isNode(pn,"comp_lt")||
290 isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
291 isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
292 isNode(pn,"rightshift")||isNode(pn,"sub")||
293 isNode(pn,"add")||isNode(pn,"mult")||
294 isNode(pn,"div")||isNode(pn,"mod")) {
295 ParseNodeVector pnv=pn.getChildren();
296 ParseNode left=pnv.elementAt(0);
297 ParseNode right=pnv.elementAt(1);
298 Operation op=new Operation(pn.getLabel());
299 return new OpNode(parseExpression(left),parseExpression(right),op);
300 } else if (isNode(pn,"unaryplus")||
301 isNode(pn,"unaryminus")||
303 ParseNode left=pn.getFirstChild();
304 Operation op=new Operation(pn.getLabel());
305 return new OpNode(parseExpression(left),op);
306 } else if (isNode(pn,"postinc")||
307 isNode(pn,"postdec")) {
308 ParseNode left=pn.getFirstChild();
309 AssignOperation op=new AssignOperation(pn.getLabel());
310 return new AssignmentNode(parseExpression(left),null,op);
312 } else if (isNode(pn,"preinc")||
313 isNode(pn,"predec")) {
314 ParseNode left=pn.getFirstChild();
315 AssignOperation op=isNode(pn,"preinc")?new AssignOperation(AssignOperation.PLUSEQ):new AssignOperation(AssignOperation.MINUSEQ);
316 return new AssignmentNode(parseExpression(left),
317 new LiteralNode("integer",new Integer(1)),op);
318 } else if (isNode(pn,"literal")) {
319 String literaltype=pn.getTerminal();
320 ParseNode literalnode=pn.getChild(literaltype);
321 Object literal_obj=literalnode.getLiteral();
322 return new LiteralNode(literaltype, literal_obj);
323 } else if (isNode(pn,"createobject")) {
324 TypeDescriptor td=parseTypeDescriptor(pn);
325 Vector args=parseArgumentList(pn);
326 CreateObjectNode con=new CreateObjectNode(td);
327 for(int i=0;i<args.size();i++) {
328 con.addArgument((ExpressionNode)args.get(i));
330 /* Could have flag set here */
331 if (pn.getChild("flag_list")!=null) {
332 FlagEffects fe=new FlagEffects(null);
333 parseFlagEffect(fe, pn.getChild("flag_list"));
334 con.addFlagEffects(fe);
337 } else if (isNode(pn,"createarray")) {
338 System.out.println(pn.PPrint(3,true));
339 TypeDescriptor td=parseTypeDescriptor(pn);
340 Vector args=parseDimExprs(pn);
342 if (pn.getChild("dims_opt").getLiteral()!=null)
343 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
344 for(int i=0;i<(args.size()+num);i++)
345 td=td.makeArray(state);
346 CreateObjectNode con=new CreateObjectNode(td);
347 for(int i=0;i<args.size();i++) {
348 con.addArgument((ExpressionNode)args.get(i));
351 } else if (isNode(pn,"name")) {
352 NameDescriptor nd=parseName(pn);
353 return new NameNode(nd);
354 } else if (isNode(pn,"this")) {
355 NameDescriptor nd=new NameDescriptor("this");
356 return new NameNode(nd);
357 } else if (isNode(pn,"methodinvoke1")) {
358 NameDescriptor nd=parseName(pn.getChild("name"));
359 Vector args=parseArgumentList(pn);
360 MethodInvokeNode min=new MethodInvokeNode(nd);
361 for(int i=0;i<args.size();i++) {
362 min.addArgument((ExpressionNode)args.get(i));
365 } else if (isNode(pn,"methodinvoke2")) {
366 String methodid=pn.getChild("id").getTerminal();
367 ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
368 Vector args=parseArgumentList(pn);
369 MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
370 for(int i=0;i<args.size();i++) {
371 min.addArgument((ExpressionNode)args.get(i));
374 } else if (isNode(pn,"fieldaccess")) {
375 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild()); String fieldname=pn.getChild("field").getTerminal();
376 return new FieldAccessNode(en,fieldname);
377 } else if (isNode(pn,"arrayaccess")) {
378 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
379 ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
380 return new ArrayAccessNode(en,index);
381 } else if (isNode(pn,"cast1")) {
382 return new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
383 } else if (isNode(pn,"cast2")) {
384 return new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
386 System.out.println("---------------------");
387 System.out.println(pn.PPrint(3,true));
392 private Vector parseDimExprs(ParseNode pn) {
393 Vector arglist=new Vector();
394 ParseNode an=pn.getChild("dim_exprs");
395 if (an==null) /* No argument list */
397 ParseNodeVector anv=an.getChildren();
398 for(int i=0;i<anv.size();i++) {
399 arglist.add(parseExpression(anv.elementAt(i)));
404 private Vector parseArgumentList(ParseNode pn) {
405 Vector arglist=new Vector();
406 ParseNode an=pn.getChild("argument_list");
407 if (an==null) /* No argument list */
409 ParseNodeVector anv=an.getChildren();
410 for(int i=0;i<anv.size();i++) {
411 arglist.add(parseExpression(anv.elementAt(i)));
416 private Vector[] parseConsArgumentList(ParseNode pn) {
417 Vector arglist=new Vector();
418 Vector varlist=new Vector();
419 ParseNode an=pn.getChild("cons_argument_list");
420 if (an==null) /* No argument list */
421 return new Vector[] {varlist, arglist};
422 ParseNodeVector anv=an.getChildren();
423 for(int i=0;i<anv.size();i++) {
424 ParseNode cpn=anv.elementAt(i);
425 ParseNode var=cpn.getChild("var");
426 ParseNode exp=cpn.getChild("exp").getFirstChild();
427 varlist.add(var.getTerminal());
428 arglist.add(parseExpression(exp));
430 return new Vector[] {varlist, arglist};
433 private ExpressionNode parseAssignmentExpression(ParseNode pn) {
434 AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
435 ParseNodeVector pnv=pn.getChild("args").getChildren();
437 AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
442 private void parseMethodDecl(ClassDescriptor cn, ParseNode pn) {
443 ParseNode headern=pn.getChild("method_header");
444 ParseNode bodyn=pn.getChild("body");
445 MethodDescriptor md=parseMethodHeader(headern);
446 BlockNode bn=parseBlock(bodyn);
448 state.addTreeCode(md,bn);
451 private void parseConstructorDecl(ClassDescriptor cn, ParseNode pn) {
452 ParseNode mn=pn.getChild("modifiers");
453 Modifiers m=parseModifiersList(mn);
454 ParseNode cdecl=pn.getChild("constructor_declarator");
455 String name=cdecl.getChild("name").getChild("identifier").getTerminal();
456 MethodDescriptor md=new MethodDescriptor(m, name);
457 ParseNode paramnode=cdecl.getChild("parameters");
458 parseParameterList(md,paramnode);
459 ParseNode bodyn0=pn.getChild("body");
460 ParseNode bodyn=bodyn0.getChild("constructor_body");
462 BlockNode bn=parseBlock(bodyn);
463 state.addTreeCode(md,bn);
466 public BlockNode parseBlock(ParseNode pn) {
467 if (pn==null||isEmpty(pn.getTerminal()))
468 return new BlockNode();
469 ParseNode bsn=pn.getChild("block_statement_list");
470 return parseBlockHelper(bsn);
473 private BlockNode parseBlockHelper(ParseNode pn) {
474 ParseNodeVector pnv=pn.getChildren();
475 BlockNode bn=new BlockNode();
476 for(int i=0;i<pnv.size();i++) {
477 Vector bsv=parseBlockStatement(pnv.elementAt(i));
478 for(int j=0;j<bsv.size();j++) {
479 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
485 public BlockNode parseSingleBlock(ParseNode pn) {
486 BlockNode bn=new BlockNode();
487 Vector bsv=parseBlockStatement(pn);
488 for(int j=0;j<bsv.size();j++) {
489 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
491 bn.setStyle(BlockNode.NOBRACES);
495 public Vector parseBlockStatement(ParseNode pn) {
496 Vector blockstatements=new Vector();
497 if (isNode(pn,"local_variable_declaration")) {
498 TypeDescriptor t=parseTypeDescriptor(pn);
499 ParseNode vn=pn.getChild("variable_declarators_list");
500 ParseNodeVector pnv=vn.getChildren();
501 for(int i=0;i<pnv.size();i++) {
502 ParseNode vardecl=pnv.elementAt(i);
505 ParseNode tmp=vardecl;
506 TypeDescriptor arrayt=t;
507 while (tmp.getChild("single")==null) {
508 arrayt=arrayt.makeArray(state);
509 tmp=tmp.getChild("array");
511 String identifier=tmp.getChild("single").getTerminal();
513 ParseNode epn=vardecl.getChild("initializer");
516 ExpressionNode en=null;
518 en=parseExpression(epn.getFirstChild());
520 blockstatements.add(new DeclarationNode(new VarDescriptor(arrayt, identifier),en));
522 } else if (isNode(pn,"nop")) {
524 } else if (isNode(pn,"expression")) {
525 blockstatements.add(new BlockExpressionNode(parseExpression(pn.getFirstChild())));
526 } else if (isNode(pn,"ifstatement")) {
527 blockstatements.add(new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
528 parseSingleBlock(pn.getChild("statement").getFirstChild()),
529 pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null));
530 } else if (isNode(pn,"taskexit")) {
532 if (pn.getChild("flag_effects_list")!=null)
533 vfe=parseFlags(pn.getChild("flag_effects_list"));
535 if (pn.getChild("cons_checks")!=null)
536 ccs=parseChecks(pn.getChild("cons_checks"));
538 blockstatements.add(new TaskExitNode(vfe, ccs));
539 } else if (isNode(pn,"return")) {
540 if (isEmpty(pn.getTerminal()))
541 blockstatements.add(new ReturnNode());
543 ExpressionNode en=parseExpression(pn.getFirstChild());
544 blockstatements.add(new ReturnNode(en));
546 } else if (isNode(pn,"block_statement_list")) {
547 BlockNode bn=parseBlockHelper(pn);
548 blockstatements.add(new SubBlockNode(bn));
549 } else if (isNode(pn,"empty")) {
551 } else if (isNode(pn,"statement_expression_list")) {
552 ParseNodeVector pnv=pn.getChildren();
553 BlockNode bn=new BlockNode();
554 for(int i=0;i<pnv.size();i++) {
555 ExpressionNode en=parseExpression(pnv.elementAt(i));
556 blockstatements.add(new BlockExpressionNode(en));
558 bn.setStyle(BlockNode.EXPRLIST);
559 } else if (isNode(pn,"forstatement")) {
560 BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
561 BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
562 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
563 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
564 blockstatements.add(new LoopNode(init,condition,update,body));
565 } else if (isNode(pn,"whilestatement")) {
566 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
567 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
568 blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
569 } else if (isNode(pn,"dowhilestatement")) {
570 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
571 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
572 blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
574 System.out.println("---------------");
575 System.out.println(pn.PPrint(3,true));
578 return blockstatements;
581 public MethodDescriptor parseMethodHeader(ParseNode pn) {
582 ParseNode mn=pn.getChild("modifiers");
583 Modifiers m=parseModifiersList(mn);
585 ParseNode tn=pn.getChild("returntype");
586 TypeDescriptor returntype;
588 returntype=parseTypeDescriptor(tn);
590 returntype=new TypeDescriptor(TypeDescriptor.VOID);
592 ParseNode pmd=pn.getChild("method_declarator");
593 String name=pmd.getChild("name").getTerminal();
594 MethodDescriptor md=new MethodDescriptor(m, returntype, name);
596 ParseNode paramnode=pmd.getChild("parameters");
597 parseParameterList(md,paramnode);
601 public void parseParameterList(MethodDescriptor md, ParseNode pn) {
602 ParseNode paramlist=pn.getChild("formal_parameter_list");
605 ParseNodeVector pnv=paramlist.getChildren();
606 for(int i=0;i<pnv.size();i++) {
607 ParseNode paramn=pnv.elementAt(i);
608 TypeDescriptor type=parseTypeDescriptor(paramn);
610 ParseNode tmp=paramn;
611 while (tmp.getChild("single")==null) {
612 type=type.makeArray(state);
613 tmp=tmp.getChild("array");
615 String paramname=tmp.getChild("single").getTerminal();
617 md.addParameter(type,paramname);
621 public Modifiers parseModifiersList(ParseNode pn) {
622 Modifiers m=new Modifiers();
623 ParseNode modlist=pn.getChild("modifier_list");
625 ParseNodeVector pnv=modlist.getChildren();
626 for(int i=0;i<pnv.size();i++) {
627 ParseNode modn=pnv.elementAt(i);
628 if (isNode(modn,"public"))
629 m.addModifier(Modifiers.PUBLIC);
630 if (isNode(modn,"protected"))
631 m.addModifier(Modifiers.PROTECTED);
632 if (isNode(modn,"private"))
633 m.addModifier(Modifiers.PRIVATE);
634 if (isNode(modn,"static"))
635 m.addModifier(Modifiers.STATIC);
636 if (isNode(modn,"final"))
637 m.addModifier(Modifiers.FINAL);
638 if (isNode(modn,"native"))
639 m.addModifier(Modifiers.NATIVE);
645 private boolean isNode(ParseNode pn, String label) {
646 if (pn.getLabel().equals(label))
651 private static boolean isEmpty(ParseNode pn) {
652 if (pn.getLabel().equals("empty"))
658 private static boolean isEmpty(String s) {
659 if (s.equals("empty"))
665 /** Throw an exception if something is unexpected */
666 private void check(ParseNode pn, String label) {
668 throw new Error(pn+ "IE: Expected '" + label + "', got null");
670 if (! pn.getLabel().equals(label)) {
671 throw new Error(pn+ "IE: Expected '" + label + "', got '"+pn.getLabel()+"'");