use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitTermComparison.
@Override
public Proposition visitTermComparison(@NotNull CstrSpecParser.TermComparisonContext c) {
CstrSpecParser.ComparisonContext ctx = c.comparison();
Term t1 = (Term<?>) visit(ctx.t1);
Term t2 = (Term<?>) visit(ctx.t2);
switch(ctx.op.getType()) {
case CstrSpecParser.INCL:
assertEqualsTypes(ctx.op, t1.type(), t2.type());
return new Inc(t1, t2);
case CstrSpecParser.NOT_INCL:
assertEqualsTypes(ctx.op, t1.type(), t2.type());
return new NInc(t1, t2);
case CstrSpecParser.EQ:
assertEqualsTypes(ctx.op, t1.type(), t2.type());
return new Eq(t1, t2);
case CstrSpecParser.NOT_EQ:
assertEqualsTypes(ctx.op, t1.type(), t2.type());
return new NEq(t1, t2);
case CstrSpecParser.LT:
assertEqualsTypes(ctx.op, IntType.getInstance(), t1.type(), t2.type());
return new Lt(t1, t2);
case CstrSpecParser.LEQ:
assertEqualsTypes(ctx.op, IntType.getInstance(), t1.type(), t2.type());
return new Leq(t1, t2);
case CstrSpecParser.GT:
assertEqualsTypes(ctx.op, IntType.getInstance(), t1.type(), t2.type());
return new Lt(t2, t1);
case CstrSpecParser.GEQ:
assertEqualsTypes(ctx.op, IntType.getInstance(), t1.type(), t2.type());
return new Leq(t2, t1);
case CstrSpecParser.IN:
assertIn(ctx.op, t1, t2);
return new In(t1, t2);
case CstrSpecParser.NOT_IN:
assertIn(ctx.op, t1, t2);
return new NIn(t1, t2);
case CstrSpecParser.PART:
assertIn(ctx.op, t2, t1);
return new Packings(t1, t2);
case CstrSpecParser.NOT_PART:
assertIn(ctx.op, t2, t1);
return new NoPackings(t1, t2);
default:
throw SpecException.unsupportedOperation(filename, t1.type(), ctx.op, t2.type());
}
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitCstrCall.
@Override
public ConstraintCall visitCstrCall(@NotNull CstrSpecParser.CstrCallContext ctx) {
List<Term> ps = ctx.call().term().stream().map(t -> (Term<?>) visit(t)).collect(Collectors.toList());
Function f = resolveFunction(ctx.call().ID().getSymbol(), ps);
return new ConstraintCall(f, ps);
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitTermOp.
@Override
public Term<?> visitTermOp(@NotNull CstrSpecParser.TermOpContext ctx) {
Term t1 = (Term<?>) visit(ctx.t1);
Term t2 = (Term<?>) visit(ctx.t2);
assertEqualsTypes(ctx.op, t1.type(), t2.type());
switch(ctx.op.getType()) {
case CstrSpecParser.PLUS:
if (t1.type() == IntType.getInstance()) {
return new IntPlus(t1, t2);
} else if (t1.type() instanceof SetType) {
return new SetPlus(t1, t2);
}
break;
case CstrSpecParser.MINUS:
if (t1.type() == IntType.getInstance()) {
return new IntMinus(t1, t2);
} else if (t1.type() instanceof SetType) {
return new SetMinus(t1, t2);
}
break;
case CstrSpecParser.MULT:
return new Mult(t1, t2);
default:
}
throw SpecException.unsupportedOperation(filename, t1.type(), ctx.op, t2.type());
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class MyCstrSpecVisitor method visitSetInComprehension.
@Override
public SetBuilder<?> visitSetInComprehension(@NotNull CstrSpecParser.SetInComprehensionContext 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 SetBuilder<>(t, v.get(0), p);
}
use of org.btrplace.safeplace.spec.term.Term in project scheduler by btrplace.
the class FunctionCall method eval.
@Override
public T eval(Context m, Object... objs) {
Object[] values = new Object[args.size()];
int i = 0;
for (Term t : args) {
values[i++] = t.eval(m);
}
if (moment.equals(Moment.BEGIN)) {
return c.eval(m.getRootContext(), values);
}
return c.eval(m, values);
}
Aggregations