package IR.Tree;
import IR.*;
import Util.Lattice;
-
import java.util.*;
-
-
public class BuildIR {
State state;
}
}
-public void parseInitializers(ClassDescriptor cn){
- Vector fv=cn.getFieldVec();
+ public void parseInitializers(ClassDescriptor cn){
+ Vector fv=cn.getFieldVec();
int pos = 0;
- for(int i=0;i<fv.size();i++) {
+ for(int i=0;i<fv.size();i++) {
FieldDescriptor fd=(FieldDescriptor)fv.get(i);
if(fd.getExpressionNode()!=null) {
- Iterator methodit = cn.getMethods();
- while(methodit.hasNext()){
- MethodDescriptor currmd=(MethodDescriptor)methodit.next();
- if(currmd.isConstructor()){
- BlockNode bn=state.getMethodBody(currmd);
- NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
- AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
- bn.addBlockStatementAt(new BlockExpressionNode(an), pos);
- }
- }
- pos++;
+ Iterator methodit = cn.getMethods();
+ while(methodit.hasNext()){
+ MethodDescriptor currmd=(MethodDescriptor)methodit.next();
+ if(currmd.isConstructor()){
+ BlockNode bn=state.getMethodBody(currmd);
+ NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
+ AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
+ bn.addBlockStatementAt(new BlockExpressionNode(an), pos);
+ }
+ }
+ pos++;
}
- }
- }
-
+ }
+ }
+
private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
ecd.setAsEnum();
}
}
+ int innerCount=0;
+
private ExpressionNode parseExpression(ParseNode pn) {
if (isNode(pn,"assignment"))
return parseAssignmentExpression(pn);
con.addFlagEffects(fe);
}
+ return con;
+ } else if (isNode(pn,"createobjectcls")) {
+ //TODO::: FIX BUG!!! static fields in caller context need to become parameters
+ TypeDescriptor td=parseTypeDescriptor(pn);
+ innerCount++;
+ ClassDescriptor cnnew=new ClassDescriptor(td.getSymbol()+"$"+innerCount, false);
+ cnnew.setSuper(td.getSymbol());
+ parseClassBody(cnnew, pn.getChild("decl").getChild("classbody"));
+ Vector args=parseArgumentList(pn);
+
+ CreateObjectNode con=new CreateObjectNode(td, false, null);
+ con.setNumLine(pn.getLine());
+ for(int i=0; i<args.size(); i++) {
+ con.addArgument((ExpressionNode)args.get(i));
+ }
+
return con;
} else if (isNode(pn,"createarray")) {
//System.out.println(pn.PPrint(3,true));
terminal CATCH; // catch_clause
terminal FINALLY; // finally
terminal NEW; // class_instance_creation_expression
+terminal NEWFLAG; // class_instance_creation_expression
terminal PLUSPLUS; // postincrement_expression
terminal MINUSMINUS; // postdecrement_expression
terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
// | name DOT THIS
;
class_instance_creation_expression ::=
- NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
+ NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
pn.addChild(type);
pn.addChild(args);
pn.addChild(feo);
RESULT=pn;
+ :} |
+ NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {:
+ ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
+ pn.addChild(type);
+ pn.addChild(args);
+ RESULT=pn;
:}
//Global object
- | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
+ | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {:
ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
pn.addChild(type);
pn.addChild(args);
- pn.addChild(feo);
pn.addChild("global");
RESULT=pn;
:}
ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
pn.addChild(type);
pn.addChild(args);
- pn.addChild(feo);
pn.addChild("scratch");
RESULT=pn;
:}
// Objects we want to track in disjointness analysis
- | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
+ | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {:
ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
pn.addChild(type);
pn.addChild(args);
- pn.addChild(feo);
pn.addChild("disjoint").addChild(id);
RESULT=pn;
:}
- | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
+ | NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
pn.addChild(type);
pn.addChild(args);
pn.addChild(tl);
RESULT=pn;
:}
- | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
+ | NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
pn.addChild(type);
pn.addChild(args);
pn.addChild(tl);
RESULT=pn;
:}
-
-// | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
+ | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN class_body:body {:
+ ParseNode pn=new ParseNode("createobjectcls",parser.lexer.line_num);
+ pn.addChild(type);
+ pn.addChild(args);
+ pn.addChild("decl").addChild("classbody").addChild(body);
+ RESULT=pn;
+ :}
// | primary DOT NEW IDENTIFIER
// LPAREN argument_list_opt RPAREN {:
//