Search in sources :

Example 1 with Type

use of org.btrplace.safeplace.spec.type.Type in project scheduler by btrplace.

the class MyCstrSpecVisitor method resolveFunction.

private Function resolveFunction(Token t, List<Term> args) {
    Function f = symbols.getFunction(t.getText());
    if (f == null) {
        throw SpecException.unknownSymbol(filename, t);
    }
    Type[] expected = f.signature();
    if (expected.length != args.size()) {
        throw SpecException.badFunctionCall(filename, t, f, args);
    }
    for (int i = 0; i < expected.length; i++) {
        if (!expected[i].equals(args.get(i).type())) {
            throw SpecException.badFunctionCall(filename, t, f, args);
        }
    }
    return f;
}
Also used : Function(org.btrplace.safeplace.spec.term.func.Function) 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)

Example 2 with Type

use of org.btrplace.safeplace.spec.type.Type 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)

Example 3 with Type

use of org.btrplace.safeplace.spec.type.Type in project scheduler by btrplace.

the class SpecVerifier method fillArguments.

public void fillArguments(Context mo, TestCase tc) {
    Constraint c = tc.constraint();
    List<Constant> values = tc.args();
    // Check signature
    if (values.size() != c.args().size()) {
        throw new IllegalArgumentException(c.toString(values) + " cannot match " + c.signatureToString());
    }
    for (int i = 0; i < values.size(); i++) {
        UserVar<?> var = c.args().get(i);
        Type t = values.get(i).type();
        if (!var.type().equals(t)) {
            throw new IllegalArgumentException(c.toString(values) + " cannot match " + c.signatureToString());
        }
        mo.setValue(var.label(), values.get(i).eval(mo));
    }
}
Also used : Type(org.btrplace.safeplace.spec.type.Type) Constraint(org.btrplace.safeplace.spec.Constraint) Constant(org.btrplace.safeplace.spec.term.Constant) Constraint(org.btrplace.safeplace.spec.Constraint)

Example 4 with Type

use of org.btrplace.safeplace.spec.type.Type in project scheduler by btrplace.

the class Constant method fromJSON.

public static Constant fromJSON(JSONObject o) {
    Type t = Type.decode(o.getAsString("type"));
    Object r = t.fromJSON(o.get("value"));
    return new Constant(r, t);
}
Also used : Type(org.btrplace.safeplace.spec.type.Type) JSONObject(net.minidev.json.JSONObject)

Example 5 with Type

use of org.btrplace.safeplace.spec.type.Type in project scheduler by btrplace.

the class MyCstrSpecVisitor method assertIn.

private void assertIn(Token to, Term<?> t1, Term<?> t2) {
    Type t = t2.type();
    if (!(t instanceof SetType)) {
        throw new SpecException(filename, to.getCharPositionInLine(), "The right-hand side must be a collection. Got '" + t2.type() + "'");
    }
    SetType st = (SetType) t;
    if (!st.enclosingType().equals(t1.type())) {
        throw new SpecException(filename, to.getCharPositionInLine(), "Type mismatch. Expected '" + st.enclosingType() + "' for left-hand side. Got '" + t1.type() + "'");
    }
}
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) SetType(org.btrplace.safeplace.spec.type.SetType)

Aggregations

Type (org.btrplace.safeplace.spec.type.Type)5 BoolType (org.btrplace.safeplace.spec.type.BoolType)3 IntType (org.btrplace.safeplace.spec.type.IntType)3 ListType (org.btrplace.safeplace.spec.type.ListType)3 NodeStateType (org.btrplace.safeplace.spec.type.NodeStateType)3 SetType (org.btrplace.safeplace.spec.type.SetType)3 StringType (org.btrplace.safeplace.spec.type.StringType)3 VMStateType (org.btrplace.safeplace.spec.type.VMStateType)3 ArrayList (java.util.ArrayList)1 JSONObject (net.minidev.json.JSONObject)1 Constraint (org.btrplace.safeplace.spec.Constraint)1 CstrSpecParser (org.btrplace.safeplace.spec.antlr.CstrSpecParser)1 Constant (org.btrplace.safeplace.spec.term.Constant)1 ExplodedSet (org.btrplace.safeplace.spec.term.ExplodedSet)1 ProtectedTerm (org.btrplace.safeplace.spec.term.ProtectedTerm)1 Term (org.btrplace.safeplace.spec.term.Term)1 Function (org.btrplace.safeplace.spec.term.func.Function)1