folding for booleans now works
This commit is contained in:
parent
69a24132d3
commit
b6f5eaa3c8
@ -592,23 +592,51 @@ public class ConstantFolder implements ActualParameterVisitor<Void, AbstractSynt
|
||||
|
||||
if (o.decl == StdEnvironment.addDecl) {
|
||||
foldedValue = int1 + int2;
|
||||
} else if (o.decl == StdEnvironment.greaterDecl) {
|
||||
foldedValue = int1 > int2;
|
||||
} else if (o.decl == StdEnvironment.equalDecl) {
|
||||
foldedValue = int1 == int2;
|
||||
} else if (o.decl == StdEnvironment.lessDecl) {
|
||||
foldedValue = int1 < int2;
|
||||
} else if (o.decl == StdEnvironment.notgreaterDecl) {
|
||||
foldedValue = int1 <= int2;
|
||||
} else if (o.decl == StdEnvironment.notlessDecl) {
|
||||
foldedValue = int1 >= int2;
|
||||
} else if (o.decl == StdEnvironment.unequalDecl) {
|
||||
foldedValue = int1 /= int2;
|
||||
} else {
|
||||
}
|
||||
|
||||
|
||||
if (foldedValue.toString() == "true" || foldedValue.toString() == "false") {
|
||||
Identifier ti = new Identifier(foldedValue.toString(), node1.getPosition());
|
||||
|
||||
if (ti.spelling == "true") {
|
||||
System.out.println("True Decl thingy");
|
||||
ti.decl = StdEnvironment.trueDecl;
|
||||
SimpleVname sti = new SimpleVname(ti, node1.getPosition());
|
||||
VnameExpression esti = new VnameExpression(sti, node1.getPosition());
|
||||
esti.type = StdEnvironment.booleanType;
|
||||
return esti;
|
||||
|
||||
} else if (ti.spelling == "false") {
|
||||
System.out.println("False Decl thingy");
|
||||
ti.decl = StdEnvironment.falseDecl;
|
||||
SimpleVname sti = new SimpleVname(ti, node1.getPosition());
|
||||
VnameExpression esti = new VnameExpression(sti, node1.getPosition());
|
||||
esti.type = StdEnvironment.booleanType;
|
||||
return esti;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (foldedValue instanceof Integer) {
|
||||
IntegerLiteral il = new IntegerLiteral(foldedValue.toString(), node1.getPosition());
|
||||
IntegerExpression ie = new IntegerExpression(il, node1.getPosition());
|
||||
ie.type = StdEnvironment.integerType;
|
||||
return ie;
|
||||
} else if (foldedValue instanceof Boolean) {
|
||||
//Task 7?
|
||||
System.out.println("Boolean Expr. ");
|
||||
/* currently not handled! */
|
||||
}
|
||||
} else {
|
||||
//?
|
||||
|
||||
}
|
||||
|
||||
// any unhandled situation (i.e., not foldable) is ignored
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
BIN
booleanfold.tam
BIN
booleanfold.tam
Binary file not shown.
BIN
booleannotfold.tam
Normal file
BIN
booleannotfold.tam
Normal file
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user