use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AGREE by loonwerks.
the class AgreeValidator method checkNodeStmt.
@Check(CheckType.FAST)
public void checkNodeStmt(NodeStmt nodeStmt) {
List<NamedElmExpr> dotIds = EcoreUtil2.getAllContentsOfType(nodeStmt, NamedElmExpr.class);
for (NamedElmExpr dotId : dotIds) {
NamedElement id = dotId.getElm();
// restrict the elements that are single names or the last projection.
boolean restrictedElm = true;
if (dotId.eContainer() instanceof SelectionExpr) {
NamedElement ne = ((SelectionExpr) dotId.eContainer()).getField();
restrictedElm = ne == id && !(dotId.eContainer().eContainer() instanceof SelectionExpr);
}
if (restrictedElm && !(id instanceof Arg) && !(id instanceof ConstStatement) && !(id instanceof NodeDef) && !(id instanceof FnDef) && !(id instanceof UninterpretedFnDef) && !(id instanceof DataSubcomponent) && !(id instanceof DoubleDotRef) && !(id instanceof DataImplementation) && !(id instanceof RecordDef) && !(id instanceof NamedID)) {
error(dotId, "Only arguments, constants, and node calls allowed within a node");
}
}
}
use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AGREE by loonwerks.
the class AgreeValidator method evaluateIndexExpr.
// TODO: This is really minimal -- need to create a proper AGREE static expression evaluation infrastructure
private BigInteger evaluateIndexExpr(Expr expr) {
BigInteger result = null;
if (expr instanceof IntLitExpr) {
return new BigInteger(((IntLitExpr) expr).getVal());
} else if (expr instanceof UnaryExpr) {
UnaryExpr unaryExpr = (UnaryExpr) expr;
BigInteger val = evaluateIndexExpr(unaryExpr.getExpr());
if ("-".equals(unaryExpr.getOp()) && val != null) {
return val.negate();
}
} else if (expr instanceof BinaryExpr) {
BinaryExpr binaryExpr = (BinaryExpr) expr;
BigInteger leftVal = evaluateIndexExpr(binaryExpr.getLeft());
BigInteger rightVal = evaluateIndexExpr(binaryExpr.getRight());
if (leftVal != null && rightVal != null) {
if ("+".equals(binaryExpr.getOp())) {
return leftVal.add(rightVal);
} else if ("-".equals(binaryExpr.getOp())) {
return leftVal.subtract(rightVal);
} else if ("*".equals(binaryExpr.getOp())) {
return leftVal.multiply(rightVal);
} else if ("/".equals(binaryExpr.getOp()) || "div".equals(binaryExpr.getOp())) {
return leftVal.divide(rightVal);
} else if ("mod".equals(binaryExpr.getOp())) {
return leftVal.mod(rightVal);
}
}
} else if (expr instanceof NamedElmExpr) {
return evaluateIndexNamedElement(((NamedElmExpr) expr).getElm());
} else if (expr instanceof SelectionExpr) {
return evaluateIndexNamedElement(((SelectionExpr) expr).getField());
}
return result;
}
use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AGREE by loonwerks.
the class AgreeValidator method isTimingConst.
/**
* Is a given expression a usable timing constant
*
* Determine whether the given expression is a constant that may be a
* statically evaluated such that can be used to set the timing model
*
* @param expr
* @return true if acceptable timing constant, false otherwise
*/
protected boolean isTimingConst(Expr expr) {
if (expr instanceof SelectionExpr) {
SelectionExpr id = (SelectionExpr) expr;
NamedElement finalId = id.getField();
return (finalId instanceof ConstStatement);
} else if (expr instanceof EnumLitExpr) {
return true;
}
return false;
}
Aggregations