/** Parse the classes in this file */
public void parseFile(ParseNode pn) {
+ NameDescriptor packages;
+ Vector singleimports=new Vector();
+ Vector multiimports=new Vector();
+
+ ParseNode ipn=pn.getChild("imports").getChild("import_decls_list");
+ if (ipn!=null) {
+ ParseNodeVector pnv=ipn.getChildren();
+ for(int i=0;i<pnv.size();i++) {
+ ParseNode pnimport=pnv.elementAt(i);
+ NameDescriptor nd=parseName(pnimport.getChild("name"));
+ if (isNode(pnimport,"import_single"))
+ singleimports.add(nd);
+ else
+ multiimports.add(nd);
+ }
+ }
+ ParseNode ppn=pn.getChild("packages").getChild("package");
+ if (ppn!=null) {
+ packages=parseName(pn.getChild("name"));
+ }
ParseNode tpn=pn.getChild("type_declaration_list");
if (tpn!=null) {
ParseNodeVector pnv=tpn.getChildren();
if (isNode(pn,"flag_effect")) {
String flagname=pn.getChild("name").getTerminal();
FlagEffects fe=new FlagEffects(flagname);
- parseFlagEffect(fe, pn.getChild("flag_list"));
+ if (pn.getChild("flag_list")!=null)
+ parseFlagEffect(fe, pn.getChild("flag_list"));
+ if (pn.getChild("tag_list")!=null)
+ parseTagEffect(fe, pn.getChild("tag_list"));
return fe;
} else throw new Error();
}
+
+ public void parseTagEffect(FlagEffects fes, ParseNode pn) {
+ ParseNodeVector pnv=pn.getChildren();
+ for(int i=0;i<pnv.size();i++) {
+ ParseNode pn2=pnv.elementAt(i);
+ boolean status=true;
+ if (isNode(pn2,"not")) {
+ status=false;
+ pn2=pn2.getChild("name");
+ }
+ String name=pn2.getTerminal();
+ fes.addTagEffect(new TagEffect(name,status));
+ }
+ }
public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
ParseNodeVector pnv=pn.getChildren();
}
public FlagExpressionNode parseFlagExpression(ParseNode pn) {
- if (pn.getChild("or")!=null) {
- ParseNodeVector pnv=pn.getChild("or").getChildren();
+ if (isNode(pn,"or")) {
+ ParseNodeVector pnv=pn.getChildren();
ParseNode left=pnv.elementAt(0);
ParseNode right=pnv.elementAt(1);
return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_OR));
- } else if (pn.getChild("and")!=null) {
- ParseNodeVector pnv=pn.getChild("and").getChildren();
+ } else if (isNode(pn,"and")) {
+ ParseNodeVector pnv=pn.getChildren();
ParseNode left=pnv.elementAt(0);
ParseNode right=pnv.elementAt(1);
return new FlagOpNode(parseFlagExpression(left), parseFlagExpression(right), new Operation(Operation.LOGIC_AND));
- } else if (pn.getChild("not")!=null) {
- ParseNodeVector pnv=pn.getChild("not").getChildren();
+ } else if (isNode(pn, "not")) {
+ ParseNodeVector pnv=pn.getChildren();
ParseNode left=pnv.elementAt(0);
return new FlagOpNode(parseFlagExpression(left), new Operation(Operation.LOGIC_NOT));
- } else if (pn.getChild("name")!=null) {
- return new FlagNode(pn.getChild("name").getTerminal());
- } else throw new Error();
+ } else if (isNode(pn,"name")) {
+ return new FlagNode(pn.getTerminal());
+ } else {
+ throw new Error();
+ }
}
public Vector parseChecks(ParseNode pn) {
}
public void parseParameterList(TaskDescriptor td, ParseNode pn) {
+
+ boolean optional;
ParseNode paramlist=pn.getChild("task_parameter_list");
if (paramlist==null)
return;
- ParseNodeVector pnv=paramlist.getChildren();
- for(int i=0;i<pnv.size();i++) {
- ParseNode paramn=pnv.elementAt(i);
- TypeDescriptor type=parseTypeDescriptor(paramn);
+ ParseNodeVector pnv=paramlist.getChildren();
+ for(int i=0;i<pnv.size();i++) {
+ ParseNode paramn=pnv.elementAt(i);
+ if(paramn.getChild("optional")!=null){
+ optional = true;
+ paramn = paramn.getChild("optional").getFirstChild();
+ System.out.println("OPTIONAL FOUND!!!!!!!");
+ }
+ else { optional = false;
+ System.out.println("NOT OPTIONAL");
+ }
- ParseNode tmp=paramn;
- while (tmp.getChild("single")==null) {
- type=type.makeArray(state);
- tmp=tmp.getChild("array");
- }
- String paramname=tmp.getChild("single").getTerminal();
- FlagExpressionNode fen=parseFlagExpression(paramn.getChild("flag"));
-
- td.addParameter(type,paramname,fen);
- }
+ TypeDescriptor type=parseTypeDescriptor(paramn);
+
+ String paramname=paramn.getChild("single").getTerminal();
+ FlagExpressionNode fen=null;
+ if (paramn.getChild("flag")!=null)
+ fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
+
+ ParseNode tagnode=paramn.getChild("tag");
+
+ TagExpressionList tel=null;
+ if (tagnode!=null) {
+ tel=parseTagExpressionList(tagnode);
+ }
+
+ td.addParameter(type,paramname,fen, tel, optional);
+ }
+ }
+
+ public TagExpressionList parseTagExpressionList(ParseNode pn) {
+ //BUG FIX: change pn.getChildren() to pn.getChild("tag_expression_list").getChildren()
+ //To test, feed in any input program that uses tags
+ ParseNodeVector pnv=pn.getChild("tag_expression_list").getChildren();
+ TagExpressionList tel=new TagExpressionList();
+ for(int i=0;i<pnv.size();i++) {
+ ParseNode tn=pnv.elementAt(i);
+ String type=tn.getChild("type").getTerminal();
+ String name=tn.getChild("single").getTerminal();
+ tel.addTag(type, name);
+ }
+ return tel;
}
public ClassDescriptor parseTypeDecl(ParseNode pn) {
NameDescriptor nd=parseName(snn);
cn.setSuper(nd.toString());
} else {
- if (!cn.getSymbol().equals(TypeUtil.ObjectClass))
+ if (!(cn.getSymbol().equals(TypeUtil.ObjectClass)||
+ cn.getSymbol().equals(TypeUtil.TagClass)))
cn.setSuper(TypeUtil.ObjectClass);
}
cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
String name=pn.getChild("name").getTerminal();
- cn.addFlag(new FlagDescriptor(name));
+ FlagDescriptor flag=new FlagDescriptor(name);
+ if (pn.getChild("external")!=null)
+ flag.makeExternal();
+ cn.addFlag(flag);
}
private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
TypeDescriptor t=parseTypeDescriptor(tn);
ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
ParseNodeVector pnv=vn.getChildren();
+ boolean isglobal=pn.getChild("global")!=null;
+
for(int i=0;i<pnv.size();i++) {
ParseNode vardecl=pnv.elementAt(i);
-
-
ParseNode tmp=vardecl;
TypeDescriptor arrayt=t;
while (tmp.getChild("single")==null) {
tmp=tmp.getChild("array");
}
String identifier=tmp.getChild("single").getTerminal();
-
ParseNode epn=vardecl.getChild("initializer");
-
+
ExpressionNode en=null;
if (epn!=null)
en=parseExpression(epn.getFirstChild());
- cn.addField(new FieldDescriptor(m,arrayt,identifier, en));
+ cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal));
}
-
}
private ExpressionNode parseExpression(ParseNode pn) {
isNode(pn,"comp_lte")||isNode(pn,"comp_gt")||
isNode(pn,"comp_gte")||isNode(pn,"leftshift")||
isNode(pn,"rightshift")||isNode(pn,"sub")||
+ isNode(pn,"urightshift")||isNode(pn,"sub")||
isNode(pn,"add")||isNode(pn,"mult")||
isNode(pn,"div")||isNode(pn,"mod")) {
ParseNodeVector pnv=pn.getChildren();
return new OpNode(parseExpression(left),parseExpression(right),op);
} else if (isNode(pn,"unaryplus")||
isNode(pn,"unaryminus")||
- isNode(pn,"not")) {
+ isNode(pn,"not")||
+ isNode(pn,"comp")) {
ParseNode left=pn.getFirstChild();
Operation op=new Operation(pn.getLabel());
return new OpNode(parseExpression(left),op);
} else if (isNode(pn,"createobject")) {
TypeDescriptor td=parseTypeDescriptor(pn);
Vector args=parseArgumentList(pn);
- CreateObjectNode con=new CreateObjectNode(td);
+ boolean isglobal=pn.getChild("global")!=null;
+ CreateObjectNode con=new CreateObjectNode(td, isglobal);
for(int i=0;i<args.size();i++) {
con.addArgument((ExpressionNode)args.get(i));
}
- /* Could have flag set here */
- if (pn.getChild("flag_list")!=null) {
+ /* Could have flag set or tag added here */
+ if (pn.getChild("flag_list")!=null||pn.getChild("tag_list")!=null) {
FlagEffects fe=new FlagEffects(null);
- parseFlagEffect(fe, pn.getChild("flag_list"));
+ if (pn.getChild("flag_list")!=null)
+ parseFlagEffect(fe, pn.getChild("flag_list"));
+
+ if (pn.getChild("tag_list")!=null)
+ parseTagEffect(fe, pn.getChild("tag_list"));
con.addFlagEffects(fe);
}
+
return con;
} else if (isNode(pn,"createarray")) {
- System.out.println(pn.PPrint(3,true));
+ //System.out.println(pn.PPrint(3,true));
+ boolean isglobal=pn.getChild("global")!=null;
TypeDescriptor td=parseTypeDescriptor(pn);
Vector args=parseDimExprs(pn);
int num=0;
num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
for(int i=0;i<(args.size()+num);i++)
td=td.makeArray(state);
- CreateObjectNode con=new CreateObjectNode(td);
+ CreateObjectNode con=new CreateObjectNode(td, isglobal);
for(int i=0;i<args.size();i++) {
con.addArgument((ExpressionNode)args.get(i));
}
} else if (isNode(pn,"this")) {
NameDescriptor nd=new NameDescriptor("this");
return new NameNode(nd);
+ } else if (isNode(pn,"isavailable")) {
+ NameDescriptor nd=new NameDescriptor(pn.getTerminal());
+ return new OpNode(new NameNode(nd),null,new Operation(Operation.ISAVAILABLE));
} else if (isNode(pn,"methodinvoke1")) {
NameDescriptor nd=parseName(pn.getChild("name"));
Vector args=parseArgumentList(pn);
ParseNode mn=pn.getChild("modifiers");
Modifiers m=parseModifiersList(mn);
ParseNode cdecl=pn.getChild("constructor_declarator");
+ boolean isglobal=cdecl.getChild("global")!=null;
String name=cdecl.getChild("name").getChild("identifier").getTerminal();
- MethodDescriptor md=new MethodDescriptor(m, name);
+ MethodDescriptor md=new MethodDescriptor(m, name, isglobal);
ParseNode paramnode=cdecl.getChild("parameters");
parseParameterList(md,paramnode);
ParseNode bodyn0=pn.getChild("body");
ParseNode bodyn=bodyn0.getChild("constructor_body");
cn.addMethod(md);
- BlockNode bn=parseBlock(bodyn);
+ BlockNode bn=null;
+ if (bodyn!=null&&bodyn.getChild("block_statement_list")!=null)
+ bn=parseBlock(bodyn);
+ else
+ bn=new BlockNode();
+ if (bodyn!=null&&bodyn.getChild("superinvoke")!=null) {
+ ParseNode sin=bodyn.getChild("superinvoke");
+ NameDescriptor nd=new NameDescriptor("super");
+ Vector args=parseArgumentList(sin);
+ MethodInvokeNode min=new MethodInvokeNode(nd);
+ for(int i=0;i<args.size();i++) {
+ min.addArgument((ExpressionNode)args.get(i));
+ }
+ BlockExpressionNode ben=new BlockExpressionNode(min);
+ bn.addFirstBlockStatement(ben);
+ }
state.addTreeCode(md,bn);
}
public Vector parseBlockStatement(ParseNode pn) {
Vector blockstatements=new Vector();
- if (isNode(pn,"local_variable_declaration")) {
+ if (isNode(pn,"tag_declaration")) {
+ String name=pn.getChild("single").getTerminal();
+ String type=pn.getChild("type").getTerminal();
+
+ blockstatements.add(new TagDeclarationNode(name, type));
+ } else if (isNode(pn,"local_variable_declaration")) {
TypeDescriptor t=parseTypeDescriptor(pn);
ParseNode vn=pn.getChild("variable_declarators_list");
ParseNodeVector pnv=vn.getChildren();
ccs=parseChecks(pn.getChild("cons_checks"));
blockstatements.add(new TaskExitNode(vfe, ccs));
+ } else if (isNode(pn,"atomic")) {
+ BlockNode bn=parseBlockHelper(pn);
+ blockstatements.add(new AtomicNode(bn));
} else if (isNode(pn,"return")) {
if (isEmpty(pn.getTerminal()))
blockstatements.add(new ReturnNode());
ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
- } else {
+ } else {
System.out.println("---------------");
System.out.println(pn.PPrint(3,true));
throw new Error();
ParseNodeVector pnv=paramlist.getChildren();
for(int i=0;i<pnv.size();i++) {
ParseNode paramn=pnv.elementAt(i);
- TypeDescriptor type=parseTypeDescriptor(paramn);
- ParseNode tmp=paramn;
- while (tmp.getChild("single")==null) {
- type=type.makeArray(state);
- tmp=tmp.getChild("array");
+ if (isNode(paramn, "tag_parameter")) {
+ String paramname=paramn.getChild("single").getTerminal();
+ TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG);
+ md.addTagParameter(type, paramname);
+ } else {
+ TypeDescriptor type=parseTypeDescriptor(paramn);
+
+ ParseNode tmp=paramn;
+ while (tmp.getChild("single")==null) {
+ type=type.makeArray(state);
+ tmp=tmp.getChild("array");
+ }
+ String paramname=tmp.getChild("single").getTerminal();
+
+ md.addParameter(type, paramname);
}
- String paramname=tmp.getChild("single").getTerminal();
-
- md.addParameter(type,paramname);
}
}
ParseNode modn=pnv.elementAt(i);
if (isNode(modn,"public"))
m.addModifier(Modifiers.PUBLIC);
- if (isNode(modn,"protected"))
+ else if (isNode(modn,"protected"))
m.addModifier(Modifiers.PROTECTED);
- if (isNode(modn,"private"))
+ else if (isNode(modn,"private"))
m.addModifier(Modifiers.PRIVATE);
- if (isNode(modn,"static"))
+ else if (isNode(modn,"static"))
m.addModifier(Modifiers.STATIC);
- if (isNode(modn,"final"))
+ else if (isNode(modn,"final"))
m.addModifier(Modifiers.FINAL);
- if (isNode(modn,"native"))
+ else if (isNode(modn,"native"))
m.addModifier(Modifiers.NATIVE);
+ else if (isNode(modn,"synchronized"))
+ m.addModifier(Modifiers.SYNCHRONIZED);
+ else if (isNode(modn,"atomic"))
+ m.addModifier(Modifiers.ATOMIC);
+ else throw new Error("Unrecognized Modifier");
}
}
return m;