return o.toString();
}
- /* public static String valueOf(int x) {
- int length=0;
- int tmp=x;
- do {
- tmp=tmp/10;
- length=length+1;
- } while(tmp!=0);
- char chararray[]=new chararray[length];
- do {
- length--;
- chararray[length]=x%10;
- x=x/10;
- } while (length!=0);
- return new String(chararray);
- }*/
-
+ public static String valueOf(int x) {
+ int length=0;
+ int tmp;
+ if (x<0)
+ tmp=-x;
+ else
+ tmp=x;
+ do {
+ tmp=tmp/10;
+ length=length+1;
+ } while(tmp!=0);
+
+ char chararray[];
+ if (x<0)
+ chararray=new char[length+1];
+ else
+ chararray=new char[length];
+ if (x<0) {
+ chararray[0]='-';
+ }
+ do {
+ chararray[--length]=(char)(x%10+'0');
+ x=x/10;
+ } while (length!=0);
+ return new String(chararray);
+ }
}
public class System {
- /* public static void printInt(int x) {
+ public static void printInt(int x) {
String s=String.valueOf(x);
printString(s);
- }*/
+ }
public static native void printString(String s);
- public static native void printInt(int x);
}
private void generateFlatSetElementNode(FlatMethod fm, FlatSetElementNode fsen, PrintWriter output) {
//TODO: need dynamic check to make sure this assignment is actually legal
//Because Object[] could actually be something more specific...ie. Integer[]
+
TypeDescriptor elementtype=fsen.getDst().getType().dereference();
String type="";
output.println(generateTemp(fm, fln.getDst())+"=1;");
else
output.println(generateTemp(fm, fln.getDst())+"=0;");
+ } else if (fln.getType().isChar()) {
+ output.println(generateTemp(fm, fln.getDst())+"='"+fln.getValue()+"';");
} else
output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+";");
}
}
private NodePair flattenAssignmentNode(AssignmentNode an,TempDescriptor out_temp) {
- // Two cases:
+ // Three cases:
// left side is variable
// left side is field
+ // left side is array
Operation base=an.getOperation().getBaseOp();
TempDescriptor src_tmp=TempDescriptor.tempFactory("src",an.getSrc().getType());
}
if (an.getDest().kind()==Kind.FieldAccessNode) {
+ //We are assigning an object field
FieldAccessNode fan=(FieldAccessNode)an.getDest();
ExpressionNode en=fan.getExpression();
TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
last.addNext(np_baseexp.getBegin());
FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
np_baseexp.getEnd().addNext(fsfn);
- return new NodePair(np_src.getBegin(), fsfn);
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fsfn.addNext(fon2);
+ return new NodePair(np_src.getBegin(), fon2);
} else if (an.getDest().kind()==Kind.ArrayAccessNode) {
+ //We are assigning an array element
ArrayAccessNode aan=(ArrayAccessNode)an.getDest();
ExpressionNode en=aan.getExpression();
ExpressionNode enindex=aan.getIndex();
np_baseexp.getEnd().addNext(np_indexexp.getBegin());
FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
np_indexexp.getEnd().addNext(fsen);
- return new NodePair(np_src.getBegin(), fsen);
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fsen.addNext(fon2);
+ return new NodePair(np_src.getBegin(), fon2);
} else if (an.getDest().kind()==Kind.NameNode) {
+ //We could be assigning a field or variable
NameNode nn=(NameNode)an.getDest();
if (nn.getExpression()!=null) {
+ //It is a field
FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
ExpressionNode en=fan.getExpression();
TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
last.addNext(np_baseexp.getBegin());
FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
np_baseexp.getEnd().addNext(fsfn);
- return new NodePair(np_src.getBegin(), fsfn);
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fsfn.addNext(fon2);
+ return new NodePair(np_src.getBegin(), fon2);
} else {
if (nn.getField()!=null) {
+ //It is a field
FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
last.addNext(fsfn);
- return new NodePair(np_src.getBegin(), fsfn);
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fsfn.addNext(fon2);
+ return new NodePair(np_src.getBegin(), fon2);
} else {
+ //It is a variable
FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
last.addNext(fon);
- return new NodePair(np_src.getBegin(),fon);
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fon.addNext(fon2);
+ return new NodePair(np_src.getBegin(),fon2);
}
}
}
op.getOp()==Operation.PREDEC) {
LiteralNode ln=new LiteralNode("int",new Integer(1));
ln.setType(new TypeDescriptor(TypeDescriptor.INT));
- AssignmentNode an=new AssignmentNode(on.getLeft(),ln,
- new AssignOperation((op.getOp()==Operation.POSTINC||op.getOp()==Operation.PREINC)?AssignOperation.PLUSEQ:AssignOperation.MINUSEQ));
+
+ AssignmentNode an=new AssignmentNode(on.getLeft(),
+ new OpNode(on.getLeft(),ln,
+ new Operation((op.getOp()==Operation.POSTINC||op.getOp()==Operation.PREINC)?Operation.PLUS:Operation.MINUS))
+ );
if (op.getOp()==Operation.POSTINC||
op.getOp()==Operation.POSTDEC) {
+ //Can't do, this could have side effects
NodePair left=flattenExpressionNode(on.getLeft(),out_temp);
NodePair assign=flattenAssignmentNode(an,temp_left);
left.getEnd().addNext(assign.getBegin());
private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
ParseNode tn=pn.getChild("type");
+
String type_st=tn.getTerminal();
if(type_st.equals("byte")) {
return state.getTypeDescriptor(TypeDescriptor.BYTE);
public ParseNode addChild( ParseNode child ) {
if (child == null) {
- throw new NullPointerException("Can't add null node to parse tree");
+ throw new NullPointerException("Can't add null node to parse tree: "+getLabel());
}
children.addElement (child);
return true;
return false;
- } else throw new Error();
+ } else if (possiblesuper.isPrimitive()&&(!possiblesuper.isArray())&&
+ (cd2.isArray()||cd2.isPtr()))
+ return false;
+ else if (cd2.isPrimitive()&&(!cd2.isArray())&&
+ (possiblesuper.isArray()||possiblesuper.isPtr()))
+ return false;
+ else
+ throw new Error();
}
} while (!(ie instanceof Token));
endpos = lineL.head + line_pos - 1;
- //System.out.println(ie.toString()); // uncomment to debug lexer.
+ // System.out.println(ie.toString()); // uncomment to debug lexer.
java_cup.runtime.Symbol sym = ((Token)ie).token();
// fix up left/right positions.
sym.left = startpos; sym.right = endpos;
static final String[] keywords = new String[] {
"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char",
"class", "const", "continue", "default", "do", "double", "else", "enum",
- "extends", "final", "finally", "float", "for", "goto", "if",
+ "extends", "final", "finally",
+ "flag", //keyword for failure aware computation
+ "float", "for", "goto", "if",
"implements", "import", "instanceof", "int", "interface", "long",
"native", "new", "package", "private", "protected", "public",
- "return", "short", "static", "strictfp", "super", "switch",
- "synchronized", "this", "throw", "throws", "transient", "try", "void",
- "volatile", "while",
- //keywords for failure aware computation
- "flag", "tag", "task", "taskexit"};
+ "return", "short", "static", "strictfp", "super", "switch", "synchronized",
+ "tag", "task", "taskexit", //keywords for failure aware computation
+ "this", "throw", "throws", "transient", "try", "void",
+ "volatile", "while"};
Token getIdentifier() {
// Get id string.
StringBuffer sb = new StringBuffer().append(consume());
Lex.Lexer l = new Lex.Lexer(fr);
java_cup.runtime.lr_parser g;
g = new Parse.Parser(l);
- ParseNode p=(ParseNode) g.debug_parse().value;
+ ParseNode p=(ParseNode) g./*debug_*/parse().value;
state.addParseNode(p);
if (l.numErrors()!=0) {
System.out.println("Error parsing Object.java");
ParseNode pn=(new ParseNode("type")).addChild("array");
pn.addChild("basetype").addChild(prim);
pn.addChild("dims").setLiteral(dims);
- RESULT=pn;
+ RESULT=pn.getRoot();
:}
| name:name dims:dims {:
ParseNode pn=(new ParseNode("type")).addChild("array");
pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
pn.addChild("dims").setLiteral(dims);
- RESULT=pn;
+ RESULT=pn.getRoot();
:}
;
| empty_statement:st {: RESULT=st; :}
| expression_statement:st {: RESULT=st; :}
// | switch_statement
- | do_statement
+ | do_statement:dos {:RESULT=dos; :}
| break_statement:st {: RESULT=st; :}
| continue_statement:st {: RESULT=st; :}
| return_statement:st {: RESULT=st; :}
;
dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
;
-dims_opt ::= {: RESULT=null; :}
+dims_opt ::= {: RESULT=new Integer(0); :}
| dims:dims {: RESULT = dims; :}
;
-dims ::= LBRACK RBRACK {: RESULT=new Integer(0); :}
+dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
| dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
;
return (int) ___this___;
}
-void ___System______printInt____I(int x) {
+/*void ___System______printInt____I(int x) {
printf("%d",x);
-}
+ }*/
void ___System______printString____L___String___(struct ___String___ * s) {
struct ArrayObject * chararray=s->___string___;