Skip to content

Commit 52a32a5

Browse files
committed
Fix Alias Qualified Name
1 parent 0320a0b commit 52a32a5

7 files changed

Lines changed: 26 additions & 20 deletions

File tree

liquidjava-verifier/src/main/java/liquidjava/processor/context/GhostFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public GhostFunction(GhostDTO f, Factory factory, String prefix) {
2828
public GhostFunction(String name, List<String> param_types, CtTypeReference<?> return_type, Factory factory,
2929
String prefix) {
3030
String klass = this.getParentClassName(prefix);
31+
String type = return_type.toString().equals(klass) ? prefix : return_type.toString();
3132
this.name = name;
32-
this.return_type = Utils.getType(return_type.toString().equals(klass) ? prefix : return_type.toString(),
33-
factory);
33+
this.return_type = Utils.getType(type, factory);
3434
this.param_types = new ArrayList<>();
3535
this.prefix = prefix;
3636
for (int i = 0; i < param_types.size(); i++) {

liquidjava-verifier/src/main/java/liquidjava/processor/facade/AliasDTO.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class AliasDTO {
1212
private List<String> varTypes;
1313
private List<String> varNames;
1414
private Expression expression;
15+
private String ref;
1516

1617
public AliasDTO(String name, List<CtTypeReference<?>> varTypes, List<String> varNames, Expression expression) {
1718
super();
@@ -26,7 +27,15 @@ public AliasDTO(String name2, List<String> varTypes2, List<String> varNames2, St
2627
this.name = name2;
2728
this.varTypes = varTypes2;
2829
this.varNames = varNames2;
29-
this.expression = RefinementsParser.createAST(ref, null); // is the parent class needed here?
30+
this.ref = ref;
31+
}
32+
33+
// Parse the alias expression using the given the prefix to ensure ghost names are qualified consistently with
34+
// where the alias is declared or used
35+
public void parse(String prefix) throws ParsingException {
36+
if (ref != null) {
37+
this.expression = RefinementsParser.createAST(ref, prefix);
38+
}
3039
}
3140

3241
public String getName() {

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/TypeChecker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ protected void handleAlias(String value, CtElement element) {
232232
path = ((CtInterface<?>) element).getQualifiedName();
233233
}
234234
if (klass != null && path != null) {
235+
a.parse(path);
235236
AliasWrapper aw = new AliasWrapper(a, factory, WILD_VAR, context, klass, path);
236237
context.addAlias(aw);
237238
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,10 @@ private static ObjectState getStates(CtAnnotation<? extends Annotation> ctAnnota
154154
String from = TypeCheckingUtils.getStringFromAnnotation(m.get("from"));
155155
String to = TypeCheckingUtils.getStringFromAnnotation(m.get("to"));
156156
ObjectState state = new ObjectState();
157-
if (from != null) // has From
158-
{
157+
if (from != null) { // has From
159158
state.setFrom(createStatePredicate(from, f.getTargetClass(), tc, e, false, prefix));
160159
}
161-
if (to != null) // has To
162-
{
160+
if (to != null) { // has To
163161
state.setTo(createStatePredicate(to, f.getTargetClass(), tc, e, true, prefix));
164162
}
165163

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import liquidjava.rj_language.parsing.RefinementsParser;
2626
import liquidjava.utils.Utils;
2727
import spoon.reflect.declaration.CtElement;
28-
import spoon.reflect.declaration.CtInterface;
2928
import spoon.reflect.declaration.CtType;
3029
import spoon.reflect.factory.Factory;
31-
import spoon.reflect.reference.CtTypeReference;
3230

3331
/**
3432
* Acts as a wrapper for Expression AST
@@ -38,7 +36,7 @@
3836
public class Predicate {
3937

4038
protected Expression exp;
41-
protected String parentClass;
39+
protected String prefix;
4240

4341
/** Create a predicate with the expression true */
4442
public Predicate() {
@@ -69,7 +67,7 @@ public Predicate(String ref, CtElement element, ErrorEmitter e) throws ParsingEx
6967
* @throws ParsingException
7068
*/
7169
public Predicate(String ref, CtElement element, ErrorEmitter e, String prefix) throws ParsingException {
72-
this.parentClass = prefix;
70+
this.prefix = prefix;
7371
exp = parse(ref, element, e);
7472
if (e.foundError()) {
7573
return;
@@ -86,16 +84,16 @@ public Predicate(Expression e) {
8684

8785
protected Expression parse(String ref, CtElement element, ErrorEmitter e) throws ParsingException {
8886
try {
89-
return RefinementsParser.createAST(ref, parentClass);
87+
return RefinementsParser.createAST(ref, prefix);
9088
} catch (ParsingException e1) {
9189
ErrorHandler.printSyntaxError(e1.getMessage(), ref, element, e);
9290
throw e1;
9391
}
9492
}
9593

96-
protected Expression innerParse(String ref, ErrorEmitter e, String parentClass) {
94+
protected Expression innerParse(String ref, ErrorEmitter e, String prefix) {
9795
try {
98-
return RefinementsParser.createAST(ref, parentClass);
96+
return RefinementsParser.createAST(ref, prefix);
9997
} catch (ParsingException e1) {
10098
ErrorHandler.printSyntaxError(e1.getMessage(), ref, e);
10199
}

liquidjava-verifier/src/main/java/liquidjava/rj_language/parsing/RefinementsParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
public class RefinementsParser {
1919

20-
public static Expression createAST(String toParse, String parentClass) throws ParsingException {
20+
public static Expression createAST(String toParse, String prefix) throws ParsingException {
2121
ParseTree pt = compile(toParse);
22-
CreateASTVisitor visitor = new CreateASTVisitor(parentClass);
22+
CreateASTVisitor visitor = new CreateASTVisitor(prefix);
2323
return visitor.create(pt);
2424
}
2525

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
*/
5858
public class CreateASTVisitor {
5959

60-
String parentClass;
60+
String prefix;
6161

62-
public CreateASTVisitor(String parentClass) {
63-
this.parentClass = parentClass;
62+
public CreateASTVisitor(String prefix) {
63+
this.prefix = prefix;
6464
}
6565

6666
public Expression create(ParseTree rc) {
@@ -162,7 +162,7 @@ private Expression functionCallCreate(FunctionCallContext rc) {
162162
if (rc.ghostCall() != null) {
163163
GhostCallContext gc = rc.ghostCall();
164164
List<Expression> le = getArgs(gc.args());
165-
String name = Utils.qualifyName(parentClass, gc.ID().getText());
165+
String name = Utils.qualifyName(prefix, gc.ID().getText());
166166
return new FunctionInvocation(name, le);
167167
} else {
168168
AliasCallContext gc = rc.aliasCall();

0 commit comments

Comments
 (0)