Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testSuite.classes.boolean_ghost_correct;

import liquidjava.specification.Ghost;
import liquidjava.specification.StateRefinement;

@Ghost("boolean open")
public class SimpleStateMachine {

@StateRefinement(from = "!open(this)", to = "open(this)")
void open() {}

@StateRefinement(from = "open(this)")
void execute() {}

@StateRefinement(from = "open(this)", to = "!open(this)")
void close() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package testSuite.classes.boolean_ghost_correct;

public class SimpleTest {
public static void main(String[] args) {
SimpleStateMachine ssm = new SimpleStateMachine();
ssm.open();
ssm.execute();
ssm.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testSuite.classes.boolean_ghost_error;

import liquidjava.specification.Ghost;
import liquidjava.specification.StateRefinement;

@Ghost("boolean open")
public class SimpleStateMachine {

@StateRefinement(from = "!open(this)", to = "open(this)")
void open() {}

@StateRefinement(from = "open(this)")
void execute() {}

@StateRefinement(from = "open(this)", to = "!open(this)")
void close() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package testSuite.classes.boolean_ghost_error;

public class SimpleTest {
public static void main(String[] args) {
SimpleStateMachine ssm = new SimpleStateMachine();
ssm.open();
ssm.close();
ssm.execute(); // error, not open
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testSuite.classes.scoreboard_error;

import liquidjava.specification.Ghost;
import liquidjava.specification.StateRefinement;

@Ghost("double value")
public class Scoreboard {

@StateRefinement(from = "value(this) < 1.0", to = "value(this) == value(old(this)) + 0.1")
public void inc() {}

@StateRefinement(from = "value(this) > 0.0", to = "value(this) == value(old(this)) - 0.1")
public void dec() {}

@StateRefinement(from = "value(this) > 0.0")
public void finish() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package testSuite.classes.scoreboard_error;

public class SimpleTest {
public static void main(String[] args) {
Scoreboard sb = new Scoreboard();
sb.inc();
sb.dec();
sb.dec(); // error, underflow
sb.finish();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package testSuite.classes.vending_machine_correct;

public class SimpleTest {
public static void main(String[] args) {
VendingMachine vm = new VendingMachine(); // 30 cents to buy
vm.insertTenCents();
vm.insertTenCents();
vm.insertTenCents();
vm.buy();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package testSuite.classes.vending_machine_correct;

import liquidjava.specification.Ghost;
import liquidjava.specification.StateRefinement;

@Ghost("double value")
public class VendingMachine {

@StateRefinement(from = "value(this) >= 0.0", to = "value(this) == value(old(this)) + 0.1")
void insertTenCents() {}

@StateRefinement(from = "value(this) >= 0.3")
void buy() {}
}
1 change: 1 addition & 0 deletions liquidjava-verifier/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spooned
.antlr
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public static void setDefaultState(RefinedFunction f, TypeChecker tc) {
Predicate c = new Predicate();
List<GhostFunction> sets = getDifferentSets(tc, klass); // ??
for (GhostFunction sg : sets) {
if (sg.getReturnType().toString().equals("int")) {
Predicate p = Predicate.createEquals(Predicate.createInvocation(sg.getQualifiedName(), s),
Predicate.createLit("0", Utils.INT));
c = Predicate.createConjunction(c, p);
} else {
// TODO: Implement other stuff
throw new RuntimeException("Ghost Functions not implemented for other types than int -> implement in"
+ " AuxStateHandler defaultState");
}
String retType = sg.getReturnType().toString();
Predicate typePredicate = switch (retType) {
case "int" -> Predicate.createLit("0", Utils.INT);
case "boolean" -> Predicate.createLit("false", Utils.BOOLEAN);
case "double" -> Predicate.createLit("0.0", Utils.DOUBLE);
default -> throw new RuntimeException("Ghost not implemented for type " + retType);
};
Predicate p = Predicate.createEquals(Predicate.createInvocation(sg.getName(), s), typePredicate);
c = Predicate.createConjunction(c, p);
}
ObjectState os = new ObjectState();
os.setTo(c);
Expand Down