use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkInputsVsActuals.
public void checkInputsVsActuals(CallExpr call) {
DoubleDotRef dotId = call.getRef();
NamedElement namedEl = dotId.getElm();
if (!(namedEl instanceof Abstraction)) {
// this error will be caught elsewhere
return;
}
Abstraction callDef = (Abstraction) namedEl;
List<TypeDef> inDefTypes;
String callName;
// extract in/out arguments
if (callDef instanceof FnDef) {
FnDef fnDef = (FnDef) callDef;
inDefTypes = typeDefsFromArgs(fnDef.getArgs());
callName = fnDef.getName();
} else if (callDef instanceof NodeDef) {
NodeDef nodeDef = (NodeDef) callDef;
inDefTypes = typeDefsFromArgs(nodeDef.getArgs());
callName = nodeDef.getName();
} else if (callDef instanceof LinearizationDef) {
LinearizationDef linDef = (LinearizationDef) callDef;
inDefTypes = typeDefsFromArgs(linDef.getArgs());
callName = linDef.getName();
} else if (callDef instanceof LibraryFnDef) {
LibraryFnDef nativeDef = (LibraryFnDef) callDef;
inDefTypes = typeDefsFromArgs(nativeDef.getArgs());
callName = nativeDef.getName();
} else if (callDef instanceof UninterpretedFnDef) {
UninterpretedFnDef nativeDef = (UninterpretedFnDef) callDef;
inDefTypes = typeDefsFromArgs(nativeDef.getArgs());
callName = nativeDef.getName();
} else {
error(call, "Node, function or linearization definition name expected.");
return;
}
// extract args
List<TypeDef> argCallTypes = new ArrayList<>();
for (Expr expr : call.getArgs()) {
checkTypeExists(expr);
argCallTypes.add(AgreeTypeSystem.infer(expr));
}
if (inDefTypes.size() != argCallTypes.size()) {
error(call, "Function definition '" + callName + "' requires " + inDefTypes.size() + " arguments, but this function call provides " + argCallTypes.size() + " arguments");
return;
}
for (int i = 0; i < inDefTypes.size(); i++) {
TypeDef callType = argCallTypes.get(i);
TypeDef defType = inDefTypes.get(i);
if (!AgreeTypeSystem.typesEqual(defType, callType)) {
error(call, "Argument " + i + " of function call '" + callName + "' is of type '" + callType + "' but must be of type '" + defType + "'");
}
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkUnaryExpr.
@Check(CheckType.FAST)
public void checkUnaryExpr(UnaryExpr unaryExpr) {
checkTypeExists(unaryExpr.getExpr());
TypeDef typeRight = AgreeTypeSystem.infer(unaryExpr.getExpr());
String op = unaryExpr.getOp();
switch(op) {
case "-":
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.IntTypeDef, typeRight) && !AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.RealTypeDef, typeRight)) {
error(unaryExpr, "right side of unary expression '" + op + "' is of type '" + typeRight + "' but must be of type 'int' or 'real'");
}
break;
case "not":
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, typeRight)) {
error(unaryExpr, "right side of unary expression '" + op + "' is of type '" + typeRight + "' but must be of type 'bool'");
}
break;
default:
assert (false);
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkIfThenElseExpr.
@Check(CheckType.FAST)
public void checkIfThenElseExpr(IfThenElseExpr expr) {
if (isInLinearizationBody(expr)) {
error(expr, "If-then-else expressions not allowed in linearization body expressions");
return;
}
checkTypeExists(expr.getA());
TypeDef condType = AgreeTypeSystem.infer(expr.getA());
checkTypeExists(expr.getB());
TypeDef thenType = AgreeTypeSystem.infer(expr.getB());
checkTypeExists(expr.getC());
TypeDef elseType = AgreeTypeSystem.infer(expr.getC());
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, condType)) {
error(expr, "The condition of the if statement is of type '" + condType + "' but must be of type 'bool'");
}
if (!AgreeTypeSystem.typesEqual(elseType, thenType)) {
error(expr, "The 'then' and 'else' expressions are of non-matching types '" + thenType + "' and '" + elseType + "'");
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkPeriodicStatement.
@Check(CheckType.FAST)
public void checkPeriodicStatement(PeriodicStatement statement) {
Expr event = statement.getEvent();
Expr jitter = statement.getJitter();
Expr period = statement.getPeriod();
checkExprIsIdentifier(event);
TypeDef eventType = AgreeTypeSystem.infer(event);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, eventType)) {
error(event, "Expression is of type '" + eventType + "' but must be of type 'bool'");
}
if (jitter != null) {
if (!(jitter instanceof RealLitExpr || isTimingConst(jitter))) {
error(jitter, "The specified jitter must be a real literal");
} else {
Double val = getRealConstVal(jitter);
if (val < 0) {
error(jitter, "The specified jitter must be positive");
}
}
}
if (!(period instanceof RealLitExpr || isTimingConst(period))) {
error(period, "The specified period must be a real literal");
} else {
Double val = getRealConstVal(period);
if (val < 0) {
error(period, "The specified period must be positive");
}
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkReachable.
@Check(CheckType.FAST)
public void checkReachable(ReachableStatement reachable) {
Classifier comp = reachable.getContainingClassifier();
if (!(comp instanceof ComponentImplementation)) {
error(reachable, "Reachable statements are allowed only in component implementations");
}
// the expression could be null if a pattern is used
Expr expr = reachable.getExpr();
if (expr != null) {
TypeDef exprType = AgreeTypeSystem.infer(expr);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
error(reachable, "Expression for reachable statement is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'bool'");
}
}
if (reachable.getName() == null) {
info(reachable, "It is recommended that reachable statements be named." + " (Hint: an identifier may be placed between the \"reachable\" keyword and the quoted description.)");
}
}
Aggregations