10 private int m_taskexitnum;
12 public BuildIR(State state) {
14 this.m_taskexitnum = 0;
17 public void buildtree(ParseNode pn, Set toanalyze) {
18 parseFile(pn, toanalyze);
23 NameDescriptor packages;
25 /** Parse the classes in this file */
26 public void parseFile(ParseNode pn, Set toanalyze) {
27 singleimports=new Vector();
28 multiimports=new Vector();
30 ParseNode ipn=pn.getChild("imports").getChild("import_decls_list");
32 ParseNodeVector pnv=ipn.getChildren();
33 for(int i=0; i<pnv.size(); i++) {
34 ParseNode pnimport=pnv.elementAt(i);
35 NameDescriptor nd=parseName(pnimport.getChild("name"));
36 if (isNode(pnimport,"import_single"))
37 singleimports.add(nd);
42 ParseNode ppn=pn.getChild("packages").getChild("package");
44 packages=parseName(ppn.getChild("name"));
46 ParseNode tpn=pn.getChild("type_declaration_list");
48 ParseNodeVector pnv=tpn.getChildren();
49 for(int i=0; i<pnv.size(); i++) {
50 ParseNode type_pn=pnv.elementAt(i);
51 if (isEmpty(type_pn)) /* Skip the semicolon */
53 if (isNode(type_pn,"class_declaration")) {
54 ClassDescriptor cn=parseTypeDecl(type_pn);
55 parseInitializers(cn);
59 // for inner classes/enum
61 // TODO add version for normal Java later
62 HashSet tovisit = new HashSet();
63 Iterator it_icds = cn.getInnerClasses();
64 while(it_icds.hasNext()) {
65 tovisit.add(it_icds.next());
68 while(!tovisit.isEmpty()) {
69 ClassDescriptor cd = (ClassDescriptor)tovisit.iterator().next();
71 parseInitializers(cd);
72 if(toanalyze != null) {
77 Iterator it_ics = cd.getInnerClasses();
78 while(it_ics.hasNext()) {
79 tovisit.add(it_ics.next());
82 Iterator it_ienums = cd.getEnum();
83 while(it_ienums.hasNext()) {
84 ClassDescriptor iecd = (ClassDescriptor)it_ienums.next();
85 if(toanalyze != null) {
92 Iterator it_enums = cn.getEnum();
93 while(it_enums.hasNext()) {
94 ClassDescriptor ecd = (ClassDescriptor)it_enums.next();
95 if(toanalyze != null) {
101 } else if (isNode(type_pn,"task_declaration")) {
102 TaskDescriptor td=parseTaskDecl(type_pn);
106 } else if ((state.MGC) && isNode(type_pn,"interface_declaration")) {
107 // TODO add version for normal Java later
108 ClassDescriptor cn = parseInterfaceDecl(type_pn);
115 // TODO add version for normal Java later
116 Iterator it_enums = cn.getEnum();
117 while(it_enums.hasNext()) {
118 ClassDescriptor ecd = (ClassDescriptor)it_enums.next();
119 if(toanalyze != null) {
125 } else if ((state.MGC) && isNode(type_pn,"enum_declaration")) {
126 // TODO add version for normal Java later
127 ClassDescriptor cn = parseEnumDecl(null, type_pn);
132 throw new Error(type_pn.getLabel());
138 public void parseInitializers(ClassDescriptor cn){
139 Vector fv=cn.getFieldVec();
140 for(int i=0;i<fv.size();i++) {
141 FieldDescriptor fd=(FieldDescriptor)fv.get(i);
142 if(fd.getExpressionNode()!=null) {
143 Iterator methodit = cn.getMethods();
144 while(methodit.hasNext()){
145 MethodDescriptor currmd=(MethodDescriptor)methodit.next();
146 if(currmd.isConstructor()){
147 BlockNode bn=state.getMethodBody(currmd);
148 NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
149 AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
150 bn.addFirstBlockStatement(new BlockExpressionNode(an));
157 private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
158 ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
161 ecd.setSurroundingClass(cn.getSymbol());
162 ecd.setSurrounding(cn);
165 if (!(ecd.getSymbol().equals(TypeUtil.ObjectClass)||
166 ecd.getSymbol().equals(TypeUtil.TagClass))) {
167 ecd.setSuper(TypeUtil.ObjectClass);
169 ecd.setModifiers(parseModifiersList(pn.getChild("modifiers")));
170 parseEnumBody(ecd, pn.getChild("enumbody"));
174 private void parseEnumBody(ClassDescriptor cn, ParseNode pn) {
175 ParseNode decls=pn.getChild("enum_constants_list");
177 ParseNodeVector pnv=decls.getChildren();
178 for(int i=0; i<pnv.size(); i++) {
179 ParseNode decl=pnv.elementAt(i);
180 if (isNode(decl,"enum_constant")) {
181 parseEnumConstant(cn,decl);
182 } else throw new Error();
187 private void parseEnumConstant(ClassDescriptor cn, ParseNode pn) {
188 cn.addEnumConstant(pn.getChild("name").getTerminal());
191 public ClassDescriptor parseInterfaceDecl(ParseNode pn) {
192 ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
193 //cn.setAsInterface();
194 if (!isEmpty(pn.getChild("superIF").getTerminal())) {
195 /* parse inherited interface name */
196 ParseNode snlist=pn.getChild("superIF").getChild("extend_interface_list");
197 ParseNodeVector pnv=snlist.getChildren();
198 for(int i=0; i<pnv.size(); i++) {
199 ParseNode decl=pnv.elementAt(i);
200 if (isNode(decl,"type")) {
201 NameDescriptor nd=parseName(decl.getChild("class").getChild("name"));
202 cn.addSuperInterface(nd.toString());
206 cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
207 parseInterfaceBody(cn, pn.getChild("interfacebody"));
211 private void parseInterfaceBody(ClassDescriptor cn, ParseNode pn) {
212 assert(cn.isInterface());
213 ParseNode decls=pn.getChild("interface_member_declaration_list");
215 ParseNodeVector pnv=decls.getChildren();
216 for(int i=0; i<pnv.size(); i++) {
217 ParseNode decl=pnv.elementAt(i);
218 if (isNode(decl,"constant")) {
219 parseInterfaceConstant(cn,decl);
220 } else if (isNode(decl,"method")) {
221 parseInterfaceMethod(cn,decl.getChild("method_declaration"));
222 } else throw new Error();
227 private void parseInterfaceConstant(ClassDescriptor cn, ParseNode pn) {
229 parseFieldDecl(cn,pn.getChild("field_declaration"));
235 private void parseInterfaceMethod(ClassDescriptor cn, ParseNode pn) {
236 ParseNode headern=pn.getChild("header");
237 ParseNode bodyn=pn.getChild("body");
238 MethodDescriptor md=parseMethodHeader(headern.getChild("method_header"));
239 md.getModifiers().addModifier(Modifiers.PUBLIC);
240 md.getModifiers().addModifier(Modifiers.ABSTRACT);
242 BlockNode bn=parseBlock(bodyn);
244 state.addTreeCode(md,bn);
246 // this is a hack for investigating new language features
247 // at the AST level, someday should evolve into a nice compiler
249 //if( cn.getSymbol().equals( ***put a class in here like: "Test" ) &&
250 // md.getSymbol().equals( ***put your method in here like: "main" )
252 // bn.setStyle( BlockNode.NORMAL );
253 // System.out.println( bn.printNode( 0 ) );
256 } catch (Exception e) {
257 System.out.println("Error with method:"+md.getSymbol());
261 System.out.println("Error with method:"+md.getSymbol());
267 public TaskDescriptor parseTaskDecl(ParseNode pn) {
268 TaskDescriptor td=new TaskDescriptor(pn.getChild("name").getTerminal());
269 ParseNode bodyn=pn.getChild("body");
270 BlockNode bn=parseBlock(bodyn);
271 parseParameterList(td, pn);
272 state.addTreeCode(td,bn);
273 if (pn.getChild("flag_effects_list")!=null)
274 td.addFlagEffects(parseFlags(pn.getChild("flag_effects_list")));
278 public Vector parseFlags(ParseNode pn) {
279 Vector vfe=new Vector();
280 ParseNodeVector pnv=pn.getChildren();
281 for(int i=0; i<pnv.size(); i++) {
282 ParseNode fn=pnv.elementAt(i);
283 FlagEffects fe=parseFlagEffects(fn);
289 public FlagEffects parseFlagEffects(ParseNode pn) {
290 if (isNode(pn,"flag_effect")) {
291 String flagname=pn.getChild("name").getTerminal();
292 FlagEffects fe=new FlagEffects(flagname);
293 if (pn.getChild("flag_list")!=null)
294 parseFlagEffect(fe, pn.getChild("flag_list"));
295 if (pn.getChild("tag_list")!=null)
296 parseTagEffect(fe, pn.getChild("tag_list"));
298 } else throw new Error();
301 public void parseTagEffect(FlagEffects fes, ParseNode pn) {
302 ParseNodeVector pnv=pn.getChildren();
303 for(int i=0; i<pnv.size(); i++) {
304 ParseNode pn2=pnv.elementAt(i);
306 if (isNode(pn2,"not")) {
308 pn2=pn2.getChild("name");
310 String name=pn2.getTerminal();
311 fes.addTagEffect(new TagEffect(name,status));
315 public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
316 ParseNodeVector pnv=pn.getChildren();
317 for(int i=0; i<pnv.size(); i++) {
318 ParseNode pn2=pnv.elementAt(i);
320 if (isNode(pn2,"not")) {
322 pn2=pn2.getChild("name");
324 String name=pn2.getTerminal();
325 fes.addEffect(new FlagEffect(name,status));
329 public FlagExpressionNode parseFlagExpression(ParseNode pn) {
330 if (isNode(pn,"or")) {
331 ParseNodeVector pnv=pn.getChildren();
332 ParseNode left=pnv.elementAt(0);
333 ParseNode right=pnv.elementAt(1);
334 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_OR));
335 } else if (isNode(pn,"and")) {
336 ParseNodeVector pnv=pn.getChildren();
337 ParseNode left=pnv.elementAt(0);
338 ParseNode right=pnv.elementAt(1);
339 return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_AND));
340 } else if (isNode(pn, "not")) {
341 ParseNodeVector pnv=pn.getChildren();
342 ParseNode left=pnv.elementAt(0);
343 return new FlagOpNode(parseFlagExpression(left), new Operation(Operation.LOGIC_NOT));
345 } else if (isNode(pn,"name")) {
346 return new FlagNode(pn.getTerminal());
352 public Vector parseChecks(ParseNode pn) {
353 Vector ccs=new Vector();
354 ParseNodeVector pnv=pn.getChildren();
355 for(int i=0; i<pnv.size(); i++) {
356 ParseNode fn=pnv.elementAt(i);
357 ConstraintCheck cc=parseConstraintCheck(fn);
363 public ConstraintCheck parseConstraintCheck(ParseNode pn) {
364 if (isNode(pn,"cons_check")) {
365 String specname=pn.getChild("name").getChild("identifier").getTerminal();
366 Vector[] args=parseConsArgumentList(pn);
367 ConstraintCheck cc=new ConstraintCheck(specname);
368 for(int i=0; i<args[0].size(); i++) {
369 cc.addVariable((String)args[0].get(i));
370 cc.addArgument((ExpressionNode)args[1].get(i));
373 } else throw new Error();
376 public void parseParameterList(TaskDescriptor td, ParseNode pn) {
379 ParseNode paramlist=pn.getChild("task_parameter_list");
382 ParseNodeVector pnv=paramlist.getChildren();
383 for(int i=0; i<pnv.size(); i++) {
384 ParseNode paramn=pnv.elementAt(i);
385 if(paramn.getChild("optional")!=null) {
387 paramn = paramn.getChild("optional").getFirstChild();
388 System.out.println("OPTIONAL FOUND!!!!!!!");
389 } else { optional = false;
390 System.out.println("NOT OPTIONAL");}
392 TypeDescriptor type=parseTypeDescriptor(paramn);
394 String paramname=paramn.getChild("single").getTerminal();
395 FlagExpressionNode fen=null;
396 if (paramn.getChild("flag")!=null)
397 fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
399 ParseNode tagnode=paramn.getChild("tag");
401 TagExpressionList tel=null;
403 tel=parseTagExpressionList(tagnode);
406 td.addParameter(type,paramname,fen, tel, optional);
410 public TagExpressionList parseTagExpressionList(ParseNode pn) {
411 //BUG FIX: change pn.getChildren() to pn.getChild("tag_expression_list").getChildren()
412 //To test, feed in any input program that uses tags
413 ParseNodeVector pnv=pn.getChild("tag_expression_list").getChildren();
414 TagExpressionList tel=new TagExpressionList();
415 for(int i=0; i<pnv.size(); i++) {
416 ParseNode tn=pnv.elementAt(i);
417 String type=tn.getChild("type").getTerminal();
418 String name=tn.getChild("single").getTerminal();
419 tel.addTag(type, name);
424 public ClassDescriptor parseTypeDecl(ParseNode pn) {
425 ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
426 if (!isEmpty(pn.getChild("super").getTerminal())) {
427 /* parse superclass name */
428 ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
429 NameDescriptor nd=parseName(snn);
430 cn.setSuper(nd.toString());
432 if (!(cn.getSymbol().equals(TypeUtil.ObjectClass)||
433 cn.getSymbol().equals(TypeUtil.TagClass)))
434 cn.setSuper(TypeUtil.ObjectClass);
436 // check inherited interfaces
437 if (!isEmpty(pn.getChild("superIF").getTerminal())) {
438 /* parse inherited interface name */
439 ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
440 ParseNodeVector pnv=snlist.getChildren();
441 for(int i=0; i<pnv.size(); i++) {
442 ParseNode decl=pnv.elementAt(i);
443 if (isNode(decl,"type")) {
444 NameDescriptor nd=parseName(decl.getChild("class").getChild("name"));
445 cn.addSuperInterface(nd.toString());
449 cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
450 parseClassBody(cn, pn.getChild("classbody"));
454 private void parseClassBody(ClassDescriptor cn, ParseNode pn) {
455 ParseNode decls=pn.getChild("class_body_declaration_list");
457 ParseNodeVector pnv=decls.getChildren();
458 for(int i=0; i<pnv.size(); i++) {
459 ParseNode decl=pnv.elementAt(i);
460 if (isNode(decl,"member")) {
461 parseClassMember(cn,decl);
462 } else if (isNode(decl,"constructor")) {
463 parseConstructorDecl(cn,decl.getChild("constructor_declaration"));
464 } else if (isNode(decl, "static_block")) {
466 // TODO add version for normal Java later
467 parseStaticBlockDecl(cn, decl.getChild("static_block_declaration"));
469 throw new Error("Static blocks not implemented");
471 } else if (isNode(decl,"block")) {
472 } else throw new Error();
477 private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
478 ParseNode fieldnode=pn.getChild("field");
479 if (fieldnode!=null) {
480 parseFieldDecl(cn,fieldnode.getChild("field_declaration"));
483 ParseNode methodnode=pn.getChild("method");
484 if (methodnode!=null) {
485 parseMethodDecl(cn,methodnode.getChild("method_declaration"));
488 ParseNode innerclassnode=pn.getChild("inner_class_declaration");
489 if (innerclassnode!=null) {
491 parseInnerClassDecl(cn,innerclassnode);
494 // TODO add version for noraml Java later
495 throw new Error("Error: inner class in Class " + cn.getSymbol() + " is not supported yet");
498 ParseNode enumnode=pn.getChild("enum_declaration");
499 if (enumnode!=null) {
501 parseEnumDecl(cn,enumnode);
504 // TODO add version for noraml Java later
505 throw new Error("Error: enumerated type in Class " + cn.getSymbol() + " is not supported yet");
508 ParseNode flagnode=pn.getChild("flag");
509 if (flagnode!=null) {
510 parseFlagDecl(cn, flagnode.getChild("flag_declaration"));
513 // in case there are empty node
514 ParseNode emptynode=pn.getChild("empty");
515 if(emptynode != null) {
521 private ClassDescriptor parseInnerClassDecl(ClassDescriptor cn, ParseNode pn) {
522 ClassDescriptor icn=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
523 icn.setAsInnerClass();
524 icn.setSurroundingClass(cn.getSymbol());
525 icn.setSurrounding(cn);
526 cn.addInnerClass(icn);
527 if (!isEmpty(pn.getChild("super").getTerminal())) {
528 /* parse superclass name */
529 ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
530 NameDescriptor nd=parseName(snn);
531 icn.setSuper(nd.toString());
533 if (!(icn.getSymbol().equals(TypeUtil.ObjectClass)||
534 icn.getSymbol().equals(TypeUtil.TagClass)))
535 icn.setSuper(TypeUtil.ObjectClass);
537 // check inherited interfaces
538 if (!isEmpty(pn.getChild("superIF").getTerminal())) {
539 /* parse inherited interface name */
540 ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
541 ParseNodeVector pnv=snlist.getChildren();
542 for(int i=0; i<pnv.size(); i++) {
543 ParseNode decl=pnv.elementAt(i);
544 if (isNode(decl,"type")) {
545 NameDescriptor nd=parseName(decl.getChild("class").getChild("name"));
546 icn.addSuperInterface(nd.toString());
550 icn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
551 if(!icn.isStatic()) {
552 throw new Error("Error: inner class " + icn.getSymbol() + " in Class " +
553 cn.getSymbol() + " is not a nested class and is not supported yet!");
555 parseClassBody(icn, pn.getChild("classbody"));
559 private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
560 ParseNode tn=pn.getChild("type");
561 String type_st=tn.getTerminal();
562 if(type_st.equals("byte")) {
563 return state.getTypeDescriptor(TypeDescriptor.BYTE);
564 } else if(type_st.equals("short")) {
565 return state.getTypeDescriptor(TypeDescriptor.SHORT);
566 } else if(type_st.equals("boolean")) {
567 return state.getTypeDescriptor(TypeDescriptor.BOOLEAN);
568 } else if(type_st.equals("int")) {
569 return state.getTypeDescriptor(TypeDescriptor.INT);
570 } else if(type_st.equals("long")) {
571 return state.getTypeDescriptor(TypeDescriptor.LONG);
572 } else if(type_st.equals("char")) {
573 return state.getTypeDescriptor(TypeDescriptor.CHAR);
574 } else if(type_st.equals("float")) {
575 return state.getTypeDescriptor(TypeDescriptor.FLOAT);
576 } else if(type_st.equals("double")) {
577 return state.getTypeDescriptor(TypeDescriptor.DOUBLE);
578 } else if(type_st.equals("class")) {
579 ParseNode nn=tn.getChild("class");
580 return state.getTypeDescriptor(parseName(nn.getChild("name")));
581 } else if(type_st.equals("array")) {
582 ParseNode nn=tn.getChild("array");
583 TypeDescriptor td=parseTypeDescriptor(nn.getChild("basetype"));
584 Integer numdims=(Integer)nn.getChild("dims").getLiteral();
585 for(int i=0; i<numdims.intValue(); i++)
586 td=td.makeArray(state);
589 System.out.println(pn.PPrint(2, true));
594 private NameDescriptor parseName(ParseNode nn) {
595 ParseNode base=nn.getChild("base");
596 ParseNode id=nn.getChild("identifier");
598 return new NameDescriptor(id.getTerminal());
599 return new NameDescriptor(parseName(base.getChild("name")),id.getTerminal());
603 private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
604 String name=pn.getChild("name").getTerminal();
605 FlagDescriptor flag=new FlagDescriptor(name);
606 if (pn.getChild("external")!=null)
611 private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
612 ParseNode mn=pn.getChild("modifier");
613 Modifiers m=parseModifiersList(mn);
614 if((state.MGC) && cn.isInterface()) {
615 // TODO add version for normal Java later
616 // Can only be PUBLIC or STATIC or FINAL
617 if((m.isAbstract()) || (m.isAtomic()) || (m.isNative())
618 || (m.isSynchronized())) {
619 throw new Error("Error: field in Interface " + cn.getSymbol() + "can only be PUBLIC or STATIC or FINAL");
621 m.addModifier(Modifiers.PUBLIC);
622 m.addModifier(Modifiers.STATIC);
623 m.addModifier(Modifiers.FINAL);
626 ParseNode tn=pn.getChild("type");
627 TypeDescriptor t=parseTypeDescriptor(tn);
628 ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
629 ParseNodeVector pnv=vn.getChildren();
630 boolean isglobal=pn.getChild("global")!=null;
632 for(int i=0; i<pnv.size(); i++) {
633 ParseNode vardecl=pnv.elementAt(i);
634 ParseNode tmp=vardecl;
635 TypeDescriptor arrayt=t;
636 while (tmp.getChild("single")==null) {
637 arrayt=arrayt.makeArray(state);
638 tmp=tmp.getChild("array");
640 String identifier=tmp.getChild("single").getTerminal();
641 ParseNode epn=vardecl.getChild("initializer");
643 ExpressionNode en=null;
645 en=parseExpression(epn.getFirstChild());
647 cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal));
651 private ExpressionNode parseExpression(ParseNode pn) {
652 if (isNode(pn,"assignment"))
653 return parseAssignmentExpression(pn);
654 else if (isNode(pn,"logical_or")||isNode(pn,"logical_and")||
655 isNode(pn,"bitwise_or")||isNode(pn,"bitwise_xor")||
656 isNode(pn,"bitwise_and")||isNode(pn,"equal")||
657 isNode(pn,"not_equal")||isNode(pn,"comp_lt")||
658 isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
659 isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
660 isNode(pn,"rightshift")||isNode(pn,"sub")||
661 isNode(pn,"urightshift")||isNode(pn,"sub")||
662 isNode(pn,"add")||isNode(pn,"mult")||
663 isNode(pn,"div")||isNode(pn,"mod")) {
664 ParseNodeVector pnv=pn.getChildren();
665 ParseNode left=pnv.elementAt(0);
666 ParseNode right=pnv.elementAt(1);
667 Operation op=new Operation(pn.getLabel());
668 return new OpNode(parseExpression(left),parseExpression(right),op);
669 } else if (isNode(pn,"unaryplus")||
670 isNode(pn,"unaryminus")||
673 ParseNode left=pn.getFirstChild();
674 Operation op=new Operation(pn.getLabel());
675 return new OpNode(parseExpression(left),op);
676 } else if (isNode(pn,"postinc")||
677 isNode(pn,"postdec")) {
678 ParseNode left=pn.getFirstChild();
679 AssignOperation op=new AssignOperation(pn.getLabel());
680 return new AssignmentNode(parseExpression(left),null,op);
682 } else if (isNode(pn,"preinc")||
683 isNode(pn,"predec")) {
684 ParseNode left=pn.getFirstChild();
685 AssignOperation op=isNode(pn,"preinc") ? new AssignOperation(AssignOperation.PLUSEQ) : new AssignOperation(AssignOperation.MINUSEQ);
686 return new AssignmentNode(parseExpression(left),
687 new LiteralNode("integer",new Integer(1)),op);
688 } else if (isNode(pn,"literal")) {
689 String literaltype=pn.getTerminal();
690 ParseNode literalnode=pn.getChild(literaltype);
691 Object literal_obj=literalnode.getLiteral();
692 return new LiteralNode(literaltype, literal_obj);
693 } else if (isNode(pn,"createobject")) {
694 TypeDescriptor td=parseTypeDescriptor(pn);
696 Vector args=parseArgumentList(pn);
697 boolean isglobal=pn.getChild("global")!=null||
698 pn.getChild("scratch")!=null;
699 String disjointId=null;
700 if( pn.getChild("disjoint") != null) {
701 disjointId = pn.getChild("disjoint").getTerminal();
703 CreateObjectNode con=new CreateObjectNode(td, isglobal, disjointId);
704 for(int i=0; i<args.size(); i++) {
705 con.addArgument((ExpressionNode)args.get(i));
707 /* Could have flag set or tag added here */
708 if (pn.getChild("flag_list")!=null||pn.getChild("tag_list")!=null) {
709 FlagEffects fe=new FlagEffects(null);
710 if (pn.getChild("flag_list")!=null)
711 parseFlagEffect(fe, pn.getChild("flag_list"));
713 if (pn.getChild("tag_list")!=null)
714 parseTagEffect(fe, pn.getChild("tag_list"));
715 con.addFlagEffects(fe);
719 } else if (isNode(pn,"createarray")) {
720 //System.out.println(pn.PPrint(3,true));
721 boolean isglobal=pn.getChild("global")!=null||
722 pn.getChild("scratch")!=null;
723 String disjointId=null;
724 if( pn.getChild("disjoint") != null) {
725 disjointId = pn.getChild("disjoint").getTerminal();
727 TypeDescriptor td=parseTypeDescriptor(pn);
728 Vector args=parseDimExprs(pn);
730 if (pn.getChild("dims_opt").getLiteral()!=null)
731 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
732 for(int i=0; i<(args.size()+num); i++)
733 td=td.makeArray(state);
734 CreateObjectNode con=new CreateObjectNode(td, isglobal, disjointId);
735 for(int i=0; i<args.size(); i++) {
736 con.addArgument((ExpressionNode)args.get(i));
739 } if (isNode(pn,"createarray2") && state.MGC) {
740 TypeDescriptor td=parseTypeDescriptor(pn);
742 if (pn.getChild("dims_opt").getLiteral()!=null)
743 num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
744 for(int i=0; i<num; i++)
745 td=td.makeArray(state);
746 CreateObjectNode con=new CreateObjectNode(td, false, null);
747 // TODO array initializers
748 ParseNode ipn = pn.getChild("initializer");
749 Vector initializers=parseVariableInitializerList(ipn);
750 ArrayInitializerNode ain = new ArrayInitializerNode(initializers);
751 con.addArrayInitializer(ain);
753 } else if (isNode(pn,"name")) {
754 NameDescriptor nd=parseName(pn);
755 return new NameNode(nd);
756 } else if (isNode(pn,"this")) {
757 NameDescriptor nd=new NameDescriptor("this");
758 return new NameNode(nd);
759 } else if (isNode(pn,"isavailable")) {
760 NameDescriptor nd=new NameDescriptor(pn.getTerminal());
761 return new OpNode(new NameNode(nd),null,new Operation(Operation.ISAVAILABLE));
762 } else if (isNode(pn,"methodinvoke1")) {
763 NameDescriptor nd=parseName(pn.getChild("name"));
764 Vector args=parseArgumentList(pn);
765 MethodInvokeNode min=new MethodInvokeNode(nd);
766 for(int i=0; i<args.size(); i++) {
767 min.addArgument((ExpressionNode)args.get(i));
770 } else if (isNode(pn,"methodinvoke2")) {
771 String methodid=pn.getChild("id").getTerminal();
772 ExpressionNode exp=parseExpression(pn.getChild("base").getFirstChild());
773 Vector args=parseArgumentList(pn);
774 MethodInvokeNode min=new MethodInvokeNode(methodid,exp);
775 for(int i=0; i<args.size(); i++) {
776 min.addArgument((ExpressionNode)args.get(i));
779 } else if (isNode(pn,"fieldaccess")) {
780 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
781 String fieldname=pn.getChild("field").getTerminal();
782 return new FieldAccessNode(en,fieldname);
783 } else if (isNode(pn,"arrayaccess")) {
784 ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
785 ExpressionNode index=parseExpression(pn.getChild("index").getFirstChild());
786 return new ArrayAccessNode(en,index);
787 } else if (isNode(pn,"cast1")) {
789 return new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
790 } catch (Exception e) {
791 System.out.println(pn.PPrint(1,true));
795 } else if (isNode(pn,"cast2")) {
796 return new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
797 } else if (isNode(pn, "getoffset")) {
798 TypeDescriptor td=parseTypeDescriptor(pn);
799 String fieldname = pn.getChild("field").getTerminal();
800 //System.out.println("Checking the values of: "+ " td.toString()= " + td.toString()+ " fieldname= " + fieldname);
801 return new OffsetNode(td, fieldname);
802 } else if (isNode(pn, "tert")) {
803 return new TertiaryNode(parseExpression(pn.getChild("cond").getFirstChild()),
804 parseExpression(pn.getChild("trueexpr").getFirstChild()),
805 parseExpression(pn.getChild("falseexpr").getFirstChild()) );
806 } else if (isNode(pn, "instanceof")) {
807 ExpressionNode exp=parseExpression(pn.getChild("exp").getFirstChild());
808 TypeDescriptor t=parseTypeDescriptor(pn);
809 return new InstanceOfNode(exp,t);
810 } else if (isNode(pn, "array_initializer")) {
811 Vector initializers=parseVariableInitializerList(pn);
812 return new ArrayInitializerNode(initializers);
813 } else if (isNode(pn, "class_type") && state.MGC) {
814 TypeDescriptor td=parseTypeDescriptor(pn);
815 return new ClassTypeNode(td);
816 } else if (isNode(pn, "empty") && state.MGC) {
819 System.out.println("---------------------");
820 System.out.println(pn.PPrint(3,true));
825 private Vector parseDimExprs(ParseNode pn) {
826 Vector arglist=new Vector();
827 ParseNode an=pn.getChild("dim_exprs");
828 if (an==null) /* No argument list */
830 ParseNodeVector anv=an.getChildren();
831 for(int i=0; i<anv.size(); i++) {
832 arglist.add(parseExpression(anv.elementAt(i)));
837 private Vector parseArgumentList(ParseNode pn) {
838 Vector arglist=new Vector();
839 ParseNode an=pn.getChild("argument_list");
840 if (an==null) /* No argument list */
842 ParseNodeVector anv=an.getChildren();
843 for(int i=0; i<anv.size(); i++) {
844 arglist.add(parseExpression(anv.elementAt(i)));
849 private Vector[] parseConsArgumentList(ParseNode pn) {
850 Vector arglist=new Vector();
851 Vector varlist=new Vector();
852 ParseNode an=pn.getChild("cons_argument_list");
853 if (an==null) /* No argument list */
854 return new Vector[] {varlist, arglist};
855 ParseNodeVector anv=an.getChildren();
856 for(int i=0; i<anv.size(); i++) {
857 ParseNode cpn=anv.elementAt(i);
858 ParseNode var=cpn.getChild("var");
859 ParseNode exp=cpn.getChild("exp").getFirstChild();
860 varlist.add(var.getTerminal());
861 arglist.add(parseExpression(exp));
863 return new Vector[] {varlist, arglist};
866 private Vector parseVariableInitializerList(ParseNode pn) {
867 Vector varInitList=new Vector();
868 ParseNode vin=pn.getChild("var_init_list");
869 if (vin==null) /* No argument list */
871 ParseNodeVector vinv=vin.getChildren();
872 for(int i=0; i<vinv.size(); i++) {
873 varInitList.add(parseExpression(vinv.elementAt(i)));
878 private ExpressionNode parseAssignmentExpression(ParseNode pn) {
879 AssignOperation ao=new AssignOperation(pn.getChild("op").getTerminal());
880 ParseNodeVector pnv=pn.getChild("args").getChildren();
882 AssignmentNode an=new AssignmentNode(parseExpression(pnv.elementAt(0)),parseExpression(pnv.elementAt(1)),ao);
887 private void parseMethodDecl(ClassDescriptor cn, ParseNode pn) {
888 ParseNode headern=pn.getChild("method_header");
889 ParseNode bodyn=pn.getChild("body");
890 MethodDescriptor md=parseMethodHeader(headern);
892 BlockNode bn=parseBlock(bodyn);
894 state.addTreeCode(md,bn);
896 // this is a hack for investigating new language features
897 // at the AST level, someday should evolve into a nice compiler
899 //if( cn.getSymbol().equals( ***put a class in here like: "Test" ) &&
900 // md.getSymbol().equals( ***put your method in here like: "main" )
902 // bn.setStyle( BlockNode.NORMAL );
903 // System.out.println( bn.printNode( 0 ) );
906 } catch (Exception e) {
907 System.out.println("Error with method:"+md.getSymbol());
911 System.out.println("Error with method:"+md.getSymbol());
917 private void parseConstructorDecl(ClassDescriptor cn, ParseNode pn) {
918 ParseNode mn=pn.getChild("modifiers");
919 Modifiers m=parseModifiersList(mn);
920 ParseNode cdecl=pn.getChild("constructor_declarator");
921 boolean isglobal=cdecl.getChild("global")!=null;
922 String name=cdecl.getChild("name").getChild("identifier").getTerminal();
923 MethodDescriptor md=new MethodDescriptor(m, name, isglobal);
924 ParseNode paramnode=cdecl.getChild("parameters");
925 parseParameterList(md,paramnode);
926 ParseNode bodyn0=pn.getChild("body");
927 ParseNode bodyn=bodyn0.getChild("constructor_body");
930 if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
931 bn=parseBlock(bodyn);
934 if (bodyn!=null&&bodyn.getChild("superinvoke")!=null) {
935 ParseNode sin=bodyn.getChild("superinvoke");
936 NameDescriptor nd=new NameDescriptor("super");
937 Vector args=parseArgumentList(sin);
938 MethodInvokeNode min=new MethodInvokeNode(nd);
939 for(int i=0; i<args.size(); i++) {
940 min.addArgument((ExpressionNode)args.get(i));
942 BlockExpressionNode ben=new BlockExpressionNode(min);
943 bn.addFirstBlockStatement(ben);
945 } else if (bodyn!=null&&bodyn.getChild("explconstrinv")!=null) {
946 ParseNode eci=bodyn.getChild("explconstrinv");
947 NameDescriptor nd=new NameDescriptor(cn.getSymbol());
948 Vector args=parseArgumentList(eci);
949 MethodInvokeNode min=new MethodInvokeNode(nd);
950 for(int i=0; i<args.size(); i++) {
951 min.addArgument((ExpressionNode)args.get(i));
953 BlockExpressionNode ben=new BlockExpressionNode(min);
954 bn.addFirstBlockStatement(ben);
956 state.addTreeCode(md,bn);
959 private void parseStaticBlockDecl(ClassDescriptor cn, ParseNode pn) {
960 // Each class maintains one MethodDecscriptor which combines all its
961 // static blocks in their declaration order
962 boolean isfirst = false;
963 MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
965 // the first static block for this class
966 Modifiers m=new Modifiers();
967 m.addModifier(Modifiers.STATIC);
968 md = new MethodDescriptor(m, "staticblocks", false);
969 md.setAsStaticBlock();
972 ParseNode bodyn=pn.getChild("body");
976 cn.incStaticBlocks();
978 if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
979 bn=parseBlock(bodyn);
983 state.addTreeCode(md,bn);
985 BlockNode obn = state.getMethodBody(md);
986 for(int i = 0; i < bn.size(); i++) {
987 BlockStatementNode bsn = bn.get(i);
988 obn.addBlockStatement(bsn);
990 //TODO state.addTreeCode(md, obn);
995 public BlockNode parseBlock(ParseNode pn) {
996 this.m_taskexitnum = 0;
997 if (pn==null||isEmpty(pn.getTerminal()))
998 return new BlockNode();
999 ParseNode bsn=pn.getChild("block_statement_list");
1000 return parseBlockHelper(bsn);
1003 private BlockNode parseBlockHelper(ParseNode pn) {
1004 ParseNodeVector pnv=pn.getChildren();
1005 BlockNode bn=new BlockNode();
1006 for(int i=0; i<pnv.size(); i++) {
1007 Vector bsv=parseBlockStatement(pnv.elementAt(i));
1008 for(int j=0; j<bsv.size(); j++) {
1009 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
1015 public BlockNode parseSingleBlock(ParseNode pn) {
1016 BlockNode bn=new BlockNode();
1017 Vector bsv=parseBlockStatement(pn);
1018 for(int j=0; j<bsv.size(); j++) {
1019 bn.addBlockStatement((BlockStatementNode)bsv.get(j));
1021 bn.setStyle(BlockNode.NOBRACES);
1025 public Vector parseSESEBlock(Vector parentbs, ParseNode pn) {
1026 ParseNodeVector pnv=pn.getChildren();
1027 Vector bv=new Vector();
1028 for(int i=0; i<pnv.size(); i++) {
1029 bv.addAll(parseBlockStatement(pnv.elementAt(i)));
1034 public Vector parseBlockStatement(ParseNode pn) {
1035 Vector blockstatements=new Vector();
1036 if (isNode(pn,"tag_declaration")) {
1037 String name=pn.getChild("single").getTerminal();
1038 String type=pn.getChild("type").getTerminal();
1040 blockstatements.add(new TagDeclarationNode(name, type));
1041 } else if (isNode(pn,"local_variable_declaration")) {
1042 TypeDescriptor t=parseTypeDescriptor(pn);
1043 ParseNode vn=pn.getChild("variable_declarators_list");
1044 ParseNodeVector pnv=vn.getChildren();
1045 for(int i=0; i<pnv.size(); i++) {
1046 ParseNode vardecl=pnv.elementAt(i);
1049 ParseNode tmp=vardecl;
1050 TypeDescriptor arrayt=t;
1051 while (tmp.getChild("single")==null) {
1052 arrayt=arrayt.makeArray(state);
1053 tmp=tmp.getChild("array");
1055 String identifier=tmp.getChild("single").getTerminal();
1057 ParseNode epn=vardecl.getChild("initializer");
1060 ExpressionNode en=null;
1062 en=parseExpression(epn.getFirstChild());
1064 blockstatements.add(new DeclarationNode(new VarDescriptor(arrayt, identifier),en));
1066 } else if (isNode(pn,"nop")) {
1068 } else if (isNode(pn,"expression")) {
1069 blockstatements.add(new BlockExpressionNode(parseExpression(pn.getFirstChild())));
1070 } else if (isNode(pn,"ifstatement")) {
1071 blockstatements.add(new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
1072 parseSingleBlock(pn.getChild("statement").getFirstChild()),
1073 pn.getChild("else_statement")!=null ? parseSingleBlock(pn.getChild("else_statement").getFirstChild()) : null));
1074 } else if ((state.MGC) && (isNode(pn,"switch_statement"))) {
1075 // TODO add version for normal Java later
1076 blockstatements.add(new SwitchStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
1077 parseSingleBlock(pn.getChild("statement").getFirstChild())));
1078 } else if ((state.MGC) && (isNode(pn,"switch_block_list"))) {
1079 // TODO add version for normal Java later
1080 ParseNodeVector pnv=pn.getChildren();
1081 for(int i=0; i<pnv.size(); i++) {
1082 ParseNode sblockdecl=pnv.elementAt(i);
1084 if(isNode(sblockdecl, "switch_block")) {
1085 ParseNode lpn=sblockdecl.getChild("switch_labels").getChild("switch_label_list");
1086 ParseNodeVector labelv=lpn.getChildren();
1087 Vector<SwitchLabelNode> slv = new Vector<SwitchLabelNode>();
1088 for(int j=0; j<labelv.size(); j++) {
1089 ParseNode labeldecl=labelv.elementAt(j);
1090 if(isNode(labeldecl, "switch_label")) {
1091 slv.addElement(new SwitchLabelNode(parseExpression(labeldecl.getChild("constant_expression").getFirstChild()), false));
1092 } else if(isNode(labeldecl, "default_switch_label")) {
1093 slv.addElement(new SwitchLabelNode(null, true));
1097 blockstatements.add(new SwitchBlockNode(slv,
1098 parseSingleBlock(sblockdecl.getChild("switch_statements").getFirstChild())));
1102 } else if (state.MGC && isNode(pn, "trycatchstatement")) {
1103 // TODO add version for normal Java later
1104 // Do not fully support exceptions now. Only make sure that if there are no
1105 // exceptions thrown, the execution is right
1106 ParseNode tpn = pn.getChild("tryblock").getFirstChild();
1107 BlockNode bn=parseBlockHelper(tpn);
1108 blockstatements.add(new SubBlockNode(bn));
1110 ParseNode fbk = pn.getChild("finallyblock");
1112 ParseNode fpn = fbk.getFirstChild();
1113 BlockNode fbn=parseBlockHelper(fpn);
1114 blockstatements.add(new SubBlockNode(fbn));
1116 } else if (isNode(pn, "throwstatement")) {
1117 // TODO Simply return here
1118 blockstatements.add(new ReturnNode());
1119 } else if (isNode(pn,"taskexit")) {
1121 if (pn.getChild("flag_effects_list")!=null)
1122 vfe=parseFlags(pn.getChild("flag_effects_list"));
1124 if (pn.getChild("cons_checks")!=null)
1125 ccs=parseChecks(pn.getChild("cons_checks"));
1127 blockstatements.add(new TaskExitNode(vfe, ccs, this.m_taskexitnum++));
1128 } else if (isNode(pn,"atomic")) {
1129 BlockNode bn=parseBlockHelper(pn);
1130 blockstatements.add(new AtomicNode(bn));
1131 } else if (isNode(pn,"synchronized")) {
1132 BlockNode bn=parseBlockHelper(pn.getChild("block"));
1133 ExpressionNode en=parseExpression(pn.getChild("expr").getFirstChild());
1134 blockstatements.add(new SynchronizedNode(en, bn));
1135 } else if (isNode(pn,"return")) {
1136 if (isEmpty(pn.getTerminal()))
1137 blockstatements.add(new ReturnNode());
1139 ExpressionNode en=parseExpression(pn.getFirstChild());
1140 blockstatements.add(new ReturnNode(en));
1142 } else if (isNode(pn,"block_statement_list")) {
1143 BlockNode bn=parseBlockHelper(pn);
1144 blockstatements.add(new SubBlockNode(bn));
1145 } else if (isNode(pn,"empty")) {
1147 } else if (isNode(pn,"statement_expression_list")) {
1148 ParseNodeVector pnv=pn.getChildren();
1149 BlockNode bn=new BlockNode();
1150 for(int i=0; i<pnv.size(); i++) {
1151 ExpressionNode en=parseExpression(pnv.elementAt(i));
1152 blockstatements.add(new BlockExpressionNode(en));
1154 bn.setStyle(BlockNode.EXPRLIST);
1155 } else if (isNode(pn,"forstatement")) {
1156 BlockNode init=parseSingleBlock(pn.getChild("initializer").getFirstChild());
1157 BlockNode update=parseSingleBlock(pn.getChild("update").getFirstChild());
1158 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1159 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1160 blockstatements.add(new LoopNode(init,condition,update,body));
1161 } else if (isNode(pn,"whilestatement")) {
1162 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1163 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1164 blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
1165 } else if (isNode(pn,"dowhilestatement")) {
1166 ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
1167 BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
1168 blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
1169 } else if (isNode(pn,"sese")) {
1170 ParseNode pnID=pn.getChild("identifier");
1172 if( pnID != null ) { stID=pnID.getFirstChild().getTerminal(); }
1173 SESENode start=new SESENode(stID);
1174 SESENode end =new SESENode(stID);
1175 start.setEnd( end );
1176 end.setStart( start );
1177 blockstatements.add(start);
1178 blockstatements.addAll(parseSESEBlock(blockstatements,pn.getChild("body").getFirstChild()));
1179 blockstatements.add(end);
1180 } else if (isNode(pn,"continue")) {
1181 blockstatements.add(new ContinueBreakNode(false));
1182 } else if (isNode(pn,"break")) {
1183 blockstatements.add(new ContinueBreakNode(true));
1185 } else if (isNode(pn,"genreach")) {
1186 String graphName = pn.getChild("graphName").getTerminal();
1187 blockstatements.add( new GenReachNode( graphName ) );
1190 System.out.println("---------------");
1191 System.out.println(pn.PPrint(3,true));
1194 return blockstatements;
1197 public MethodDescriptor parseMethodHeader(ParseNode pn) {
1198 ParseNode mn=pn.getChild("modifiers");
1199 Modifiers m=parseModifiersList(mn);
1201 ParseNode tn=pn.getChild("returntype");
1202 TypeDescriptor returntype;
1204 returntype=parseTypeDescriptor(tn);
1206 returntype=new TypeDescriptor(TypeDescriptor.VOID);
1208 ParseNode pmd=pn.getChild("method_declarator");
1209 String name=pmd.getChild("name").getTerminal();
1210 MethodDescriptor md=new MethodDescriptor(m, returntype, name);
1212 ParseNode paramnode=pmd.getChild("parameters");
1213 parseParameterList(md,paramnode);
1217 public void parseParameterList(MethodDescriptor md, ParseNode pn) {
1218 ParseNode paramlist=pn.getChild("formal_parameter_list");
1219 if (paramlist==null)
1221 ParseNodeVector pnv=paramlist.getChildren();
1222 for(int i=0; i<pnv.size(); i++) {
1223 ParseNode paramn=pnv.elementAt(i);
1225 if (isNode(paramn, "tag_parameter")) {
1226 String paramname=paramn.getChild("single").getTerminal();
1227 TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG);
1228 md.addTagParameter(type, paramname);
1230 TypeDescriptor type=parseTypeDescriptor(paramn);
1232 ParseNode tmp=paramn;
1233 while (tmp.getChild("single")==null) {
1234 type=type.makeArray(state);
1235 tmp=tmp.getChild("array");
1237 String paramname=tmp.getChild("single").getTerminal();
1239 md.addParameter(type, paramname);
1244 public Modifiers parseModifiersList(ParseNode pn) {
1245 Modifiers m=new Modifiers();
1246 ParseNode modlist=pn.getChild("modifier_list");
1247 if (modlist!=null) {
1248 ParseNodeVector pnv=modlist.getChildren();
1249 for(int i=0; i<pnv.size(); i++) {
1250 ParseNode modn=pnv.elementAt(i);
1251 if (isNode(modn,"public"))
1252 m.addModifier(Modifiers.PUBLIC);
1253 else if (isNode(modn,"protected"))
1254 m.addModifier(Modifiers.PROTECTED);
1255 else if (isNode(modn,"private"))
1256 m.addModifier(Modifiers.PRIVATE);
1257 else if (isNode(modn,"static"))
1258 m.addModifier(Modifiers.STATIC);
1259 else if (isNode(modn,"final"))
1260 m.addModifier(Modifiers.FINAL);
1261 else if (isNode(modn,"native"))
1262 m.addModifier(Modifiers.NATIVE);
1263 else if (isNode(modn,"synchronized"))
1264 m.addModifier(Modifiers.SYNCHRONIZED);
1265 else if (isNode(modn,"atomic"))
1266 m.addModifier(Modifiers.ATOMIC);
1267 else if (isNode(modn,"abstract"))
1268 m.addModifier(Modifiers.ABSTRACT);
1269 else if (isNode(modn,"volatile"))
1270 m.addModifier(Modifiers.VOLATILE);
1271 else if (isNode(modn,"transient"))
1272 m.addModifier(Modifiers.TRANSIENT);
1273 else throw new Error("Unrecognized Modifier");
1279 private boolean isNode(ParseNode pn, String label) {
1280 if (pn.getLabel().equals(label))
1285 private static boolean isEmpty(ParseNode pn) {
1286 if (pn.getLabel().equals("empty"))
1292 private static boolean isEmpty(String s) {
1293 if (s.equals("empty"))
1299 /** Throw an exception if something is unexpected */
1300 private void check(ParseNode pn, String label) {
1302 throw new Error(pn+ "IE: Expected '" + label + "', got null");
1304 if (!pn.getLabel().equals(label)) {
1305 throw new Error(pn+ "IE: Expected '" + label + "', got '"+pn.getLabel()+"'");