Skip to content

Commit e1f4805

Browse files
committed
Remove methods for #Condition and #Cycle in ConstantFolding
1 parent 402bd58 commit e1f4805

File tree

1 file changed

+0
-42
lines changed

1 file changed

+0
-42
lines changed

src/main/pt/up/fe/comp2023/optimization/ConstantFolding.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public boolean apply(){
2323
@Override
2424
protected void buildVisitor() {
2525
setDefaultVisit(this::setDefaultVisit);
26-
addVisit("Cycle", this::checkCycleCondition);
27-
addVisit("Condition", this::checkIfElseCondition);
2826
addVisit("ParenthesesExpr", this::computeParenthesesExprResult);
2927
addVisit("NegationExpr", this::negateBooleanExpr);
3028
addVisit("ArithmeticExpr", this::computeArithmeticExprResult);
@@ -39,46 +37,6 @@ private Void setDefaultVisit(JmmNode jmmNode, Void unused) {
3937
return null;
4038
}
4139

42-
private Void checkIfElseCondition(JmmNode jmmNode, Void unused) {
43-
JmmNode conditionNode = jmmNode.getJmmChild(0);
44-
JmmNode ifCode = jmmNode.getJmmChild(1);
45-
JmmNode elseCode = jmmNode.getJmmChild(2);
46-
visit(conditionNode);
47-
48-
if (conditionNode.getKind().equals("Boolean")) {
49-
// if condition value is true, the code inside the 'ifCode' is executed
50-
// else, the code inside the 'elseCode' is executed.
51-
JmmNode reachedCode = conditionNode.get("value").equals("true") ? ifCode : elseCode;
52-
replaceIfElseWithReachedCode(jmmNode, reachedCode);
53-
54-
for(JmmNode child : reachedCode.getChildren())
55-
visit(child);
56-
this.codeModified = true;
57-
}
58-
59-
//condition value is undefined
60-
else {
61-
visit(ifCode);
62-
visit(elseCode);
63-
}
64-
return null;
65-
}
66-
67-
private Void checkCycleCondition(JmmNode jmmNode, Void unused) {
68-
JmmNode conditionNode = jmmNode.getJmmChild(0);
69-
visit(conditionNode);
70-
71-
if (conditionNode.getKind().equals("Boolean") && conditionNode.get("value").equals("false")) { //Dead code
72-
jmmNode.delete();
73-
this.codeModified = true;
74-
}
75-
else { //Condition value is 'true' or undefined
76-
for (JmmNode child : jmmNode.getChildren())
77-
visit(child);
78-
}
79-
return null;
80-
}
81-
8240
private Void computeParenthesesExprResult(JmmNode jmmNode, Void unused) {
8341
JmmNode exprNode = jmmNode.getJmmChild(0);
8442
visit(exprNode);

0 commit comments

Comments
 (0)