Skip to content

Commit c3d05d1

Browse files
committed
Build Derivation with Linked List
1 parent cd52d41 commit c3d05d1

3 files changed

Lines changed: 48 additions & 14 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/rj_language/Predicate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import liquidjava.rj_language.ast.LiteralReal;
2222
import liquidjava.rj_language.ast.UnaryExpression;
2323
import liquidjava.rj_language.ast.Var;
24+
import liquidjava.rj_language.opt.DerivationNode;
2425
import liquidjava.rj_language.opt.ExpressionSimplifier;
2526
import liquidjava.rj_language.parsing.ParsingException;
2627
import liquidjava.rj_language.parsing.RefinementsParser;
@@ -213,7 +214,7 @@ public Expression getExpression() {
213214
return exp;
214215
}
215216

216-
public Expression simplify() {
217+
public DerivationNode simplify() {
217218
return ExpressionSimplifier.simplify(exp.clone());
218219
}
219220

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package liquidjava.rj_language.opt;
2+
3+
import liquidjava.rj_language.ast.Expression;
4+
5+
public class DerivationNode {
6+
7+
private DerivationNode from;
8+
private Expression exp;
9+
10+
public DerivationNode(Expression exp) {
11+
this.exp = exp;
12+
}
13+
14+
public DerivationNode getFrom() {
15+
return from;
16+
}
17+
18+
public void setFrom(DerivationNode from) {
19+
this.from = from;
20+
}
21+
22+
public DerivationNode addNode(Expression exp) {
23+
DerivationNode newNode = new DerivationNode(exp);
24+
newNode.setFrom(this);
25+
return newNode;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return String.format("%s <=\n%s", exp, from);
31+
}
32+
}

liquidjava-verifier/src/main/java/liquidjava/rj_language/opt/ExpressionSimplifier.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,33 @@
44

55
public class ExpressionSimplifier {
66

7-
public static Expression simplify(Expression exp) {
8-
System.out.println(exp);
9-
Expression current = simplifyExp(exp.clone());
10-
System.out.println(current);
7+
public static DerivationNode simplify(Expression exp) {
8+
DerivationNode currentNode = new DerivationNode(exp);
9+
Expression currentExp = simplifyExp(exp.clone());
10+
currentNode = currentNode.addNode(currentExp);
1111
boolean changed = true;
1212

1313
while (changed) {
1414
changed = false;
1515

16-
Expression propagated = ConstantPropagation.propagate(current.clone());
17-
if (!propagated.equals(current)) {
18-
current = simplifyExp(propagated);
19-
System.out.println(current);
16+
Expression propagated = ConstantPropagation.propagate(currentExp.clone());
17+
if (!propagated.equals(currentExp)) {
18+
currentExp = simplifyExp(propagated);
19+
currentNode = currentNode.addNode(currentExp);
2020
changed = true;
2121
continue;
2222
}
2323

24-
Expression folded = ConstantFolding.fold(current.clone());
25-
if (!folded.equals(current)) {
26-
current = simplifyExp(folded);
27-
System.out.println(current);
24+
Expression folded = ConstantFolding.fold(currentExp.clone());
25+
if (!folded.equals(currentExp)) {
26+
currentExp = simplifyExp(folded);
27+
currentNode = currentNode.addNode(currentExp);
28+
System.out.println(currentExp);
2829
changed = true;
2930
continue;
3031
}
3132
}
32-
return current;
33+
return currentNode;
3334
}
3435

3536
private static Expression simplifyExp(Expression exp) {

0 commit comments

Comments
 (0)