Search in sources :

Example 1 with Term

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;
}
Also used : ArrayList(java.util.ArrayList) Atomic(org.btrplace.safeplace.spec.type.Atomic) Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) UserVar(org.btrplace.safeplace.spec.term.UserVar)

Example 2 with Term

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);
}
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) FunctionCall(org.btrplace.safeplace.spec.term.func.FunctionCall)

Example 3 with Term

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);
}
Also used : ValueAt(org.btrplace.safeplace.spec.term.func.ValueAt) Var(org.btrplace.safeplace.spec.term.Var) UserVar(org.btrplace.safeplace.spec.term.UserVar) ListType(org.btrplace.safeplace.spec.type.ListType) Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm)

Example 4 with Term

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

Example 5 with Term

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);
}
Also used : IntType(org.btrplace.safeplace.spec.type.IntType) Type(org.btrplace.safeplace.spec.type.Type) ListType(org.btrplace.safeplace.spec.type.ListType) NodeStateType(org.btrplace.safeplace.spec.type.NodeStateType) BoolType(org.btrplace.safeplace.spec.type.BoolType) StringType(org.btrplace.safeplace.spec.type.StringType) SetType(org.btrplace.safeplace.spec.type.SetType) VMStateType(org.btrplace.safeplace.spec.type.VMStateType) CstrSpecParser(org.btrplace.safeplace.spec.antlr.CstrSpecParser) ArrayList(java.util.ArrayList) ExplodedSet(org.btrplace.safeplace.spec.term.ExplodedSet) Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm)

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