Skip to content

Commit ce4e764

Browse files
committed
Set this As Default Argument in Ghost Invocations
1 parent d906b45 commit ce4e764

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package testSuite.classes.input_reader_correct;
22

3-
@SuppressWarnings("unused")
3+
import java.io.InputStreamReader;
4+
45
public class Test {
56
public static void main(String[] args) throws Exception {
6-
// Arrays are not well supported in LiquidJava
7-
8-
// InputStreamReader isr = new InputStreamReader(new FileInputStream("test1.txt"));
9-
// @Refinement("_ > -9")
10-
// int a = isr.read();
11-
// char[] arr = new char[20];
12-
// int b = isr.read(arr, 10, 5);
13-
// System.out.println(arr);
14-
// isr.close();
7+
InputStreamReader is = new InputStreamReader(System.in);
8+
is.read();
9+
is.read();
10+
is.close();
1511
}
1612
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package testSuite.classes.input_reader_correct_default_this;
2+
3+
import java.io.InputStream;
4+
import liquidjava.specification.ExternalRefinementsFor;
5+
import liquidjava.specification.Ghost;
6+
import liquidjava.specification.Refinement;
7+
import liquidjava.specification.RefinementPredicate;
8+
import liquidjava.specification.StateRefinement;
9+
10+
// https://docs.oracle.com/javase/7/docs/api/java/io/InputStreamReader.html
11+
@ExternalRefinementsFor("java.io.InputStreamReader")
12+
public interface InputStreamReaderRefs {
13+
14+
@RefinementPredicate("boolean open(InputStreamReader i)")
15+
@StateRefinement(to = "open()")
16+
public void InputStreamReader(InputStream in);
17+
18+
@StateRefinement(from = "open()", to = "open()")
19+
@Refinement("(_ >= -1) && (_ <= 127)")
20+
public int read();
21+
22+
@StateRefinement(from = "open()", to = "!open()")
23+
public void close();
24+
25+
@StateRefinement(from = "open()", to = "open()")
26+
@Refinement("_ >= -1")
27+
public int read(
28+
@Refinement("length(cbuf) > 0") char[] cbuf,
29+
@Refinement("_ >= 0") int offset,
30+
@Refinement("(_ >= 0) && (_ + offset) <= length(cbuf)") int length);
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package testSuite.classes.input_reader_correct_default_this;
2+
3+
import java.io.InputStreamReader;
4+
5+
public class Test {
6+
public static void main(String[] args) throws Exception {
7+
InputStreamReader is = new InputStreamReader(System.in);
8+
is.read();
9+
is.read();
10+
is.close();
11+
}
12+
}

liquidjava-example/src/main/java/testSuite/classes/input_reader_error/Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
public class Test {
77

88
public static void main(String[] args) throws IOException {
9-
// java.io.InputStreamReader.InputStreamReader
109
InputStreamReader is = new InputStreamReader(System.in);
1110
is.read();
1211
is.read();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ public static Predicate createVar(String name) {
261261
return new Predicate(new Var(name));
262262
}
263263

264-
public static Predicate createInvocation(String name, Predicate... Predicates) {
264+
public static Predicate createInvocation(String name, Predicate... predicates) {
265265
List<Expression> le = new ArrayList<>();
266-
for (Predicate c : Predicates)
266+
for (Predicate c : predicates)
267267
le.add(c.getExpression());
268268
return new Predicate(new FunctionInvocation(name, le));
269269
}

liquidjava-verifier/src/main/java/liquidjava/rj_language/visitors/CreateASTVisitor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,13 @@ else if (rc instanceof VarContext) {
161161
private Expression functionCallCreate(FunctionCallContext rc) {
162162
if (rc.ghostCall() != null) {
163163
GhostCallContext gc = rc.ghostCall();
164-
List<Expression> le = getArgs(gc.args());
165164
String name = Utils.qualifyName(prefix, gc.ID().getText());
166-
return new FunctionInvocation(name, le);
165+
List<Expression> args = getArgs(gc.args());
166+
if (args.isEmpty()) {
167+
// if no args provided, add "this" as default
168+
args.add(new Var("this"));
169+
}
170+
return new FunctionInvocation(name, args);
167171
} else {
168172
AliasCallContext gc = rc.aliasCall();
169173
List<Expression> le = getArgs(gc.args());

0 commit comments

Comments
 (0)