Skip to content
Open
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
Expand Up @@ -20,9 +20,15 @@ public static int count(@Refinement("length(names) > 0") String[] names) {

static void sized(String[] names, @Refinement("_ == length(names)") int n) {}

static void rows(String[][] grid, @Refinement("_ == length(grid)") int n) {}

public static void initializers() {
sized(new String[] { "a", "b" }, 2);
String[] none = {};
sized(none, 0);
}

public static void dimensions() {
rows(new String[2][3], 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public static void first(@Refinement("length(names) >= 0") String[] names) {
@Refinement("_ > 0")
int size = names.length; // Expect: Refinement Error
}

static void rows(String[][] grid, @Refinement("_ == length(grid)") int n) {}

public static void grid() {
rows(new String[2][3], 3); // Expect: Refinement Error
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,18 @@ public <T> void visitCtNewArray(CtNewArray<T> newArray) {
BuiltinFunctionPredicate.length(Keys.WILDCARD, newArray), Predicate.createLit(length, Types.INT)));
return;
}
// TODO only working for 1 dimension
for (CtExpression<?> exp : l) {
Predicate c = getExpressionRefinements(exp);
String name = GeneratedNames.of(GeneratedNames.ARRAY_LENGTH, context.getCounter());
if (c.getVariableNames().contains(Keys.WILDCARD)) {
c = c.substituteVariable(Keys.WILDCARD, name);
} else {
c = Predicate.createEquals(Predicate.createVar(name), c);
}
context.addVarToContext(name, factory.Type().INTEGER_PRIMITIVE, c, exp);
Predicate ep;
ep = Predicate.createEquals(BuiltinFunctionPredicate.length(Keys.WILDCARD, newArray),
Predicate.createVar(name));

newArray.putMetadata(Keys.REFINEMENT, ep);
// the length is the first dimension: inner arrays are not modelled, nothing is known about their lengths
CtExpression<Integer> outerDimension = l.get(0);
Predicate c = getExpressionRefinements(outerDimension);
String name = GeneratedNames.of(GeneratedNames.ARRAY_LENGTH, context.getCounter());
if (c.getVariableNames().contains(Keys.WILDCARD)) {
c = c.substituteVariable(Keys.WILDCARD, name);
} else {
c = Predicate.createEquals(Predicate.createVar(name), c);
}
context.addVarToContext(name, factory.Type().INTEGER_PRIMITIVE, c, outerDimension);
newArray.putMetadata(Keys.REFINEMENT, Predicate
.createEquals(BuiltinFunctionPredicate.length(Keys.WILDCARD, newArray), Predicate.createVar(name)));
}

@Override
Expand Down
Loading