use of org.btrplace.safeplace.spec.term.func.Function 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;
}
use of org.btrplace.safeplace.spec.term.func.Function 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.func.Function in project scheduler by btrplace.
the class SpecScanner method scan.
/**
* @throws SpecException
*/
public List<org.btrplace.safeplace.spec.Constraint> scan() throws IllegalAccessException, InstantiationException, IOException {
List<CoreConstraint> coreAnnots = Collections.synchronizedList(new ArrayList<>());
List<Class<? extends Function>> funcs = Collections.synchronizedList(new ArrayList<>());
scanner.matchClassesImplementing(Function.class, funcs::add);
scanner.matchClassesWithAnnotation(CoreConstraint.class, c -> coreAnnots.add(c.getAnnotation(CoreConstraint.class)));
scanner.matchClassesWithAnnotation(CoreConstraints.class, c -> {
CoreConstraint[] x = c.getAnnotationsByType(CoreConstraint.class);
coreAnnots.addAll(Arrays.asList(x));
});
scanner.matchClassesWithAnnotation(SideConstraint.class, c -> sides.add(new Side(c.getAnnotation(SideConstraint.class), (Class<? extends SatConstraint>) c)));
scanner.scan(Runtime.getRuntime().availableProcessors() - 1);
for (Class<? extends Function> f : funcs) {
if (!f.equals(Constraint.class)) {
functions.add(f.newInstance());
}
}
scanner.matchClassesImplementing(Function.class, c -> {
try {
functions.add(c.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalArgumentException(e);
}
});
List<org.btrplace.safeplace.spec.Constraint> cstrs = new ArrayList<>();
for (CoreConstraint c : coreAnnots) {
cstrs.add(parseCore2(c));
}
List<org.btrplace.safeplace.spec.Constraint> l = new ArrayList<>();
for (Side s : resolveDependencies(sides)) {
org.btrplace.safeplace.spec.Constraint c = parseSide(s, l);
l.add(c);
}
cstrs.addAll(l);
return cstrs;
}
use of org.btrplace.safeplace.spec.term.func.Function 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);
}
Aggregations