Skip to content

Commit 69b00ca

Browse files
Ghost boolean (#46)
1 parent 368df95 commit 69b00ca

File tree

10 files changed

+117
-9
lines changed

10 files changed

+117
-9
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package testSuite.classes.boolean_ghost_correct;
2+
3+
import liquidjava.specification.Ghost;
4+
import liquidjava.specification.StateRefinement;
5+
6+
@Ghost("boolean open")
7+
public class SimpleStateMachine {
8+
9+
@StateRefinement(from = "!open(this)", to = "open(this)")
10+
void open() {}
11+
12+
@StateRefinement(from = "open(this)")
13+
void execute() {}
14+
15+
@StateRefinement(from = "open(this)", to = "!open(this)")
16+
void close() {}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package testSuite.classes.boolean_ghost_correct;
2+
3+
public class SimpleTest {
4+
public static void main(String[] args) {
5+
SimpleStateMachine ssm = new SimpleStateMachine();
6+
ssm.open();
7+
ssm.execute();
8+
ssm.close();
9+
}
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package testSuite.classes.boolean_ghost_error;
2+
3+
import liquidjava.specification.Ghost;
4+
import liquidjava.specification.StateRefinement;
5+
6+
@Ghost("boolean open")
7+
public class SimpleStateMachine {
8+
9+
@StateRefinement(from = "!open(this)", to = "open(this)")
10+
void open() {}
11+
12+
@StateRefinement(from = "open(this)")
13+
void execute() {}
14+
15+
@StateRefinement(from = "open(this)", to = "!open(this)")
16+
void close() {}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package testSuite.classes.boolean_ghost_error;
2+
3+
public class SimpleTest {
4+
public static void main(String[] args) {
5+
SimpleStateMachine ssm = new SimpleStateMachine();
6+
ssm.open();
7+
ssm.close();
8+
ssm.execute(); // error, not open
9+
}
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package testSuite.classes.scoreboard_error;
2+
3+
import liquidjava.specification.Ghost;
4+
import liquidjava.specification.StateRefinement;
5+
6+
@Ghost("double value")
7+
public class Scoreboard {
8+
9+
@StateRefinement(from = "value(this) < 1.0", to = "value(this) == value(old(this)) + 0.1")
10+
public void inc() {}
11+
12+
@StateRefinement(from = "value(this) > 0.0", to = "value(this) == value(old(this)) - 0.1")
13+
public void dec() {}
14+
15+
@StateRefinement(from = "value(this) > 0.0")
16+
public void finish() {}
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package testSuite.classes.scoreboard_error;
2+
3+
public class SimpleTest {
4+
public static void main(String[] args) {
5+
Scoreboard sb = new Scoreboard();
6+
sb.inc();
7+
sb.dec();
8+
sb.dec(); // error, underflow
9+
sb.finish();
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package testSuite.classes.vending_machine_correct;
2+
3+
public class SimpleTest {
4+
public static void main(String[] args) {
5+
VendingMachine vm = new VendingMachine(); // 30 cents to buy
6+
vm.insertTenCents();
7+
vm.insertTenCents();
8+
vm.insertTenCents();
9+
vm.buy();
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package testSuite.classes.vending_machine_correct;
2+
3+
import liquidjava.specification.Ghost;
4+
import liquidjava.specification.StateRefinement;
5+
6+
@Ghost("double value")
7+
public class VendingMachine {
8+
9+
@StateRefinement(from = "value(this) >= 0.0", to = "value(this) == value(old(this)) + 0.1")
10+
void insertTenCents() {}
11+
12+
@StateRefinement(from = "value(this) >= 0.3")
13+
void buy() {}
14+
}

liquidjava-verifier/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
spooned
2+
.antlr

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/object_checkers/AuxStateHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ public static void setDefaultState(RefinedFunction f, TypeChecker tc) {
7777
Predicate c = new Predicate();
7878
List<GhostFunction> sets = getDifferentSets(tc, klass); // ??
7979
for (GhostFunction sg : sets) {
80-
if (sg.getReturnType().toString().equals("int")) {
81-
Predicate p = Predicate.createEquals(Predicate.createInvocation(sg.getQualifiedName(), s),
82-
Predicate.createLit("0", Utils.INT));
83-
c = Predicate.createConjunction(c, p);
84-
} else {
85-
// TODO: Implement other stuff
86-
throw new RuntimeException("Ghost Functions not implemented for other types than int -> implement in"
87-
+ " AuxStateHandler defaultState");
88-
}
80+
String retType = sg.getReturnType().toString();
81+
Predicate typePredicate = switch (retType) {
82+
case "int" -> Predicate.createLit("0", Utils.INT);
83+
case "boolean" -> Predicate.createLit("false", Utils.BOOLEAN);
84+
case "double" -> Predicate.createLit("0.0", Utils.DOUBLE);
85+
default -> throw new RuntimeException("Ghost not implemented for type " + retType);
86+
};
87+
Predicate p = Predicate.createEquals(Predicate.createInvocation(sg.getName(), s), typePredicate);
88+
c = Predicate.createConjunction(c, p);
8989
}
9090
ObjectState os = new ObjectState();
9191
os.setTo(c);

0 commit comments

Comments
 (0)