use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitTypedef.
@Override
public List<UserVar<?>> visitTypedef(@NotNull CstrSpecParser.TypedefContext ctx) {
Term<?> parent = (Term<?>) visit(ctx.term());
if (parent.type() instanceof Atomic) {
throw new SpecException(filename, ctx.op.getCharPositionInLine(), "The right-hand side must be a collection");
}
List<UserVar<?>> vars = new ArrayList<>();
for (TerminalNode n : ctx.ID()) {
String lbl = n.getText();
UserVar v = new UserVar(lbl, ctx.op.getText(), parent);
symbols.put(v);
vars.add(v);
}
return vars;
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitCall.
@Override
public FunctionCall visitCall(@NotNull CstrSpecParser.CallContext ctx) {
List<Term> ps = ctx.term().stream().map(t -> (Term<?>) visit(t)).collect(Collectors.toList());
Function f = resolveFunction(ctx.ID().getSymbol(), ps);
FunctionCall.Moment m = FunctionCall.Moment.ANY;
if (ctx.BEGIN() != null) {
m = FunctionCall.Moment.BEGIN;
}
return new FunctionCall(f, ps, m);
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitArrayTerm.
@Override
public Term<?> visitArrayTerm(@NotNull CstrSpecParser.ArrayTermContext ctx) {
String lbl = ctx.ID().getText();
Var v = symbols.getVar(lbl);
if (v == null) {
throw SpecException.unknownSymbol(filename, ctx.ID().getSymbol());
}
// Type check
if (!(v.type() instanceof ListType)) {
throw new SpecException(filename, ctx.ID().getSymbol().getCharPositionInLine(), "List expected. Got '" + v.type() + "')");
}
Term idx = (Term<?>) visit(ctx.term());
assertEqualsTypes(ctx.term().getStart(), IntType.getInstance(), idx.type());
return new ValueAt(v, idx);
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitListInComprehension.
@Override
public ListBuilder<?> visitListInComprehension(@NotNull CstrSpecParser.ListInComprehensionContext ctx) {
// Get the binder
List<UserVar<?>> v = visitTypedef(ctx.typedef());
Proposition p = Proposition.True;
if (ctx.COMMA() != null) {
p = (Proposition) visit(ctx.formula());
}
Term<?> t = (Term<?>) visit(ctx.term());
return new ListBuilder<>(t, v.get(0), p);
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitSetInExtension.
@Override
public ExplodedSet visitSetInExtension(@NotNull CstrSpecParser.SetInExtensionContext ctx) {
List<Term> s = new ArrayList<>();
Type ty = null;
for (CstrSpecParser.TermContext t : ctx.term()) {
Term<?> tr = (Term<?>) visit(t);
if (ty == null) {
ty = tr.type();
}
assertEqualsTypes(t.getStart(), ty, tr.type());
s.add(tr);
}
return new ExplodedSet(s, ty);
}
Aggregations