use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class ExportStatement method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
Set<String> scope = new HashSet<>();
List<BtrpOperand> toAdd = new ArrayList<>();
for (int i = 0; i < getChildCount(); i++) {
if (getChild(i).getType() == ANTLRBtrplaceSL2Parser.ENUM_VAR) {
BtrpOperand r = getChild(i).go(this);
if (r == IgnorableOperand.getInstance()) {
return r;
}
for (BtrpOperand o : ((BtrpSet) r).getValues()) {
toAdd.add(o);
}
} else if (getChild(i).getType() == ANTLRBtrplaceSL2Parser.VARIABLE) {
toAdd.add(getChild(i).go(this));
} else if (getChild(i).getType() == ANTLRBtrplaceSL2Parser.TIMES) {
scope.add("*");
} else if (getChild(i).getType() == ANTLRBtrplaceSL2Parser.IDENTIFIER) {
scope.add(getChild(i).getText());
} else {
BtrpOperand e = getChild(i).go(this);
if (e == IgnorableOperand.getInstance()) {
return e;
}
toAdd.addAll(flatten(e));
}
}
try {
for (BtrpOperand op : toAdd) {
script.addExportable(op.label(), op, scope);
}
} catch (UnsupportedOperationException ex) {
return ignoreError(ex);
}
return IgnorableOperand.getInstance();
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class ForStatement method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
// First child is variable, second is set we iterate over, third is a block
if (this.getChildCount() != 3) {
return ignoreError("Malformed iteration loop");
}
table.pushTable();
String inVar = getChild(0).getText();
if (table.isDeclared(inVar)) {
return ignoreError("Variable " + inVar + " already declared");
}
BtrpOperand c = getChild(1).go(this);
if (c == IgnorableOperand.getInstance()) {
return c;
}
if (c.degree() < 1) {
return ignoreError("The literal to iterate one must be a set");
}
BtrpSet set = (BtrpSet) c;
for (Object elem : set.getValues()) {
table.declare(inVar, (BtrpOperand) elem);
getChild(2).go(this);
// TODO a good solution to avoid to iterate once an iteration fail?
}
if (!table.popTable()) {
return ignoreError("Unable to Pop the symbol table");
}
return IgnorableOperand.getInstance();
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class IfStatement method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
BtrpOperand expr = getChild(0).go(this);
if (expr.equals(BtrpNumber.TRUE)) {
sTable.pushTable();
getChild(1).go(this);
sTable.popTable();
} else if (getChildCount() == 3) {
sTable.pushTable();
getChild(2).go(this);
sTable.popTable();
} else {
return ignoreError(expr + ": not an expression");
}
return IgnorableOperand.getInstance();
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class ImportStatement method go.
@Override
@SuppressWarnings("squid:S1166")
public BtrpOperand go(BtrPlaceTree parent) {
String id = scriptId();
List<Script> res;
try {
res = includes.getScripts(id);
script.getDependencies().addAll(res);
} catch (ScriptBuilderException e) {
int nb = e.getErrorReporter().getErrors().size();
return ignoreError(Integer.toString(nb) + " error(s) imported through '" + id + "'");
}
if (res.isEmpty()) {
return ignoreError(getChild(0).getToken(), "Unable to locate '" + id + "'");
}
if (id.endsWith(".*")) {
// Prepare the global variable.
BtrpSet global = new BtrpSet(1, BtrpOperand.Type.VM);
global.setLabel("$".concat(id.substring(0, id.length() - 2)));
if (global.size() > 0 && !symTable.declareImmutable(global.label(), global)) {
return ignoreError("Unable to add variable '" + global.label() + "'");
}
}
for (Script v : res) {
for (BtrpOperand op : v.getImportables(script.id())) {
String fqn = v.fullyQualifiedSymbolName(op.label());
if (!symTable.declareImmutable(fqn, op)) {
return ignoreError("Unable to import '" + fqn + "': already declared");
}
}
}
return IgnorableOperand.getInstance();
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class NonStrictComparisonOperator method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
BtrpOperand l = getChild(0).go(this);
BtrpOperand r = getChild(1).go(this);
if (!reverse) {
return l.geq(r);
}
return r.geq(l);
}
Aggregations