Search in sources :

Example 6 with Term

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());
    }
}
Also used : In(org.btrplace.safeplace.spec.prop.In) NIn(org.btrplace.safeplace.spec.prop.NIn) CstrSpecParser(org.btrplace.safeplace.spec.antlr.CstrSpecParser) NoPackings(org.btrplace.safeplace.spec.prop.NoPackings) Lt(org.btrplace.safeplace.spec.prop.Lt) Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm) Eq(org.btrplace.safeplace.spec.prop.Eq) NEq(org.btrplace.safeplace.spec.prop.NEq) NIn(org.btrplace.safeplace.spec.prop.NIn) NInc(org.btrplace.safeplace.spec.prop.NInc) NoPackings(org.btrplace.safeplace.spec.prop.NoPackings) Packings(org.btrplace.safeplace.spec.prop.Packings) Leq(org.btrplace.safeplace.spec.prop.Leq) NEq(org.btrplace.safeplace.spec.prop.NEq) NInc(org.btrplace.safeplace.spec.prop.NInc) Inc(org.btrplace.safeplace.spec.prop.Inc)

Example 7 with Term

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);
}
Also used : IntType(org.btrplace.safeplace.spec.type.IntType) Type(org.btrplace.safeplace.spec.type.Type) ConstraintCall(org.btrplace.safeplace.spec.term.ConstraintCall) Eq(org.btrplace.safeplace.spec.prop.Eq) NoPackings(org.btrplace.safeplace.spec.prop.NoPackings) Constant(org.btrplace.safeplace.spec.term.Constant) ExplodedSet(org.btrplace.safeplace.spec.term.ExplodedSet) Token(org.antlr.v4.runtime.Token) NotNull(org.antlr.v4.runtime.misc.NotNull) Iff(org.btrplace.safeplace.spec.prop.Iff) SetPlus(org.btrplace.safeplace.spec.term.SetPlus) ListType(org.btrplace.safeplace.spec.type.ListType) ValueAt(org.btrplace.safeplace.spec.term.func.ValueAt) Var(org.btrplace.safeplace.spec.term.Var) NodeStateType(org.btrplace.safeplace.spec.type.NodeStateType) In(org.btrplace.safeplace.spec.prop.In) Lt(org.btrplace.safeplace.spec.prop.Lt) IntMinus(org.btrplace.safeplace.spec.term.IntMinus) Term(org.btrplace.safeplace.spec.term.Term) Leq(org.btrplace.safeplace.spec.prop.Leq) BoolType(org.btrplace.safeplace.spec.type.BoolType) Collectors(java.util.stream.Collectors) SetBuilder(org.btrplace.safeplace.spec.term.SetBuilder) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) StringType(org.btrplace.safeplace.spec.type.StringType) List(java.util.List) Proposition(org.btrplace.safeplace.spec.prop.Proposition) ForAll(org.btrplace.safeplace.spec.prop.ForAll) Exists(org.btrplace.safeplace.spec.prop.Exists) SetMinus(org.btrplace.safeplace.spec.term.SetMinus) Implies(org.btrplace.safeplace.spec.prop.Implies) CstrSpecParser(org.btrplace.safeplace.spec.antlr.CstrSpecParser) NIn(org.btrplace.safeplace.spec.prop.NIn) IntPlus(org.btrplace.safeplace.spec.term.IntPlus) ArrayList(java.util.ArrayList) ListBuilder(org.btrplace.safeplace.spec.term.ListBuilder) NEq(org.btrplace.safeplace.spec.prop.NEq) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Or(org.btrplace.safeplace.spec.prop.Or) UserVar(org.btrplace.safeplace.spec.term.UserVar) FunctionCall(org.btrplace.safeplace.spec.term.func.FunctionCall) Function(org.btrplace.safeplace.spec.term.func.Function) And(org.btrplace.safeplace.spec.prop.And) SetType(org.btrplace.safeplace.spec.type.SetType) ProtectedProposition(org.btrplace.safeplace.spec.prop.ProtectedProposition) Packings(org.btrplace.safeplace.spec.prop.Packings) Mult(org.btrplace.safeplace.spec.term.Mult) NInc(org.btrplace.safeplace.spec.prop.NInc) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm) VMStateType(org.btrplace.safeplace.spec.type.VMStateType) Inc(org.btrplace.safeplace.spec.prop.Inc) Atomic(org.btrplace.safeplace.spec.type.Atomic) CstrSpecBaseVisitor(org.btrplace.safeplace.spec.antlr.CstrSpecBaseVisitor) Function(org.btrplace.safeplace.spec.term.func.Function) Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm) ConstraintCall(org.btrplace.safeplace.spec.term.ConstraintCall)

Example 8 with Term

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());
}
Also used : IntMinus(org.btrplace.safeplace.spec.term.IntMinus) Mult(org.btrplace.safeplace.spec.term.Mult) SetType(org.btrplace.safeplace.spec.type.SetType) SetMinus(org.btrplace.safeplace.spec.term.SetMinus) Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm) SetPlus(org.btrplace.safeplace.spec.term.SetPlus) IntPlus(org.btrplace.safeplace.spec.term.IntPlus)

Example 9 with Term

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);
}
Also used : Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm) Proposition(org.btrplace.safeplace.spec.prop.Proposition) ProtectedProposition(org.btrplace.safeplace.spec.prop.ProtectedProposition) SetBuilder(org.btrplace.safeplace.spec.term.SetBuilder) UserVar(org.btrplace.safeplace.spec.term.UserVar)

Example 10 with Term

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);
}
Also used : Term(org.btrplace.safeplace.spec.term.Term)

Aggregations

Term (org.btrplace.safeplace.spec.term.Term)10 ProtectedTerm (org.btrplace.safeplace.spec.term.ProtectedTerm)9 UserVar (org.btrplace.safeplace.spec.term.UserVar)6 ArrayList (java.util.ArrayList)4 CstrSpecParser (org.btrplace.safeplace.spec.antlr.CstrSpecParser)4 Proposition (org.btrplace.safeplace.spec.prop.Proposition)4 ProtectedProposition (org.btrplace.safeplace.spec.prop.ProtectedProposition)4 SetType (org.btrplace.safeplace.spec.type.SetType)4 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)3 Eq (org.btrplace.safeplace.spec.prop.Eq)3 In (org.btrplace.safeplace.spec.prop.In)3 Inc (org.btrplace.safeplace.spec.prop.Inc)3 Leq (org.btrplace.safeplace.spec.prop.Leq)3 Lt (org.btrplace.safeplace.spec.prop.Lt)3 NEq (org.btrplace.safeplace.spec.prop.NEq)3 NIn (org.btrplace.safeplace.spec.prop.NIn)3 NInc (org.btrplace.safeplace.spec.prop.NInc)3 ExplodedSet (org.btrplace.safeplace.spec.term.ExplodedSet)3 ListType (org.btrplace.safeplace.spec.type.ListType)3 List (java.util.List)2