use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class DivideOperator method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
BtrpOperand l = getChild(0).go(this);
BtrpOperand r = getChild(1).go(this);
if (l != IgnorableOperand.getInstance() && r != IgnorableOperand.getInstance()) {
try {
return l.div(r);
} catch (ArithmeticException e) {
return ignoreError(e);
}
}
return IgnorableOperand.getInstance();
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class EnumVar method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
String head = getChild(0).getText().substring(0, getChild(0).getText().length() - 1);
String tail = getChild(getChildCount() - 1).getText().substring(1);
BtrpSet res = null;
for (int i = 1; i < getChildCount() - 1; i++) {
BtrpOperand op = getChild(i).go(this);
if (op == IgnorableOperand.getInstance()) {
return op;
}
BtrpSet s = (BtrpSet) op;
for (BtrpOperand o : s.getValues()) {
// Compose
String id = head + o.toString() + tail;
// lookup
BtrpOperand var = syms.getSymbol(id);
if (var == null) {
return ignoreError(parent.getToken(), "Unknown variable '" + id + "'");
}
if (res == null) {
res = new BtrpSet(2, var.type());
}
res.getValues().add(var);
}
}
return res;
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class EnumVar method expand.
/**
* Expand the enumeration.
* Variables are not evaluated nor checked
*
* @return a set of string or an error
*/
public BtrpOperand expand() {
String head = getChild(0).getText().substring(0, getChild(0).getText().length() - 1);
String tail = getChild(getChildCount() - 1).getText().substring(1);
BtrpSet res = new BtrpSet(1, BtrpOperand.Type.STRING);
for (int i = 1; i < getChildCount() - 1; i++) {
BtrpOperand op = getChild(i).go(this);
if (op == IgnorableOperand.getInstance()) {
return op;
}
BtrpSet s = (BtrpSet) op;
for (BtrpOperand o : s.getValues()) {
// Compose
res.getValues().add(new BtrpString(head + o.toString() + tail));
}
}
return res;
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class EqComparisonOperator method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
BtrpOperand l = getChild(0).go(this);
BtrpOperand r = getChild(1).go(this);
if (!opposite) {
return l.eq(r);
}
return l.eq(r).not();
}
use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.
the class ExplodedSetTree method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
if (getChildCount() == 0) {
return ignoreError("Empty sets not allowed");
}
BtrpOperand t0 = getChild(0).go(this);
if (t0 == IgnorableOperand.getInstance()) {
return t0;
}
BtrpSet s = new BtrpSet(t0.degree() + 1, t0.type());
Set<BtrpOperand> viewed = new HashSet<>();
for (int i = 0; i < getChildCount(); i++) {
BtrpOperand tx = getChild(i).go(this);
// s.getIntValue().add() is not safe at all. So preconditions have to be check
if (tx == IgnorableOperand.getInstance()) {
return tx;
}
if (tx.degree() != s.degree() - 1) {
return ignoreError(tx + " has type '" + tx.prettyType() + "'. It should be a '" + DefaultBtrpOperand.prettyType(s.degree() - 1, s.type()) + "' to be insertable into a '" + s.prettyType() + "'");
}
if (tx.type() != s.type()) {
return ignoreError("Unable to add '" + tx.type() + "' elements in a set of '" + s.type() + "' elements");
}
if (viewed.add(tx)) {
s.getValues().add(tx);
} else {
return ignoreError(tx + " ignored");
}
}
return s;
}
Aggregations