use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeValidator method checkLinearizationInterval.
@Check(CheckType.FAST)
public void checkLinearizationInterval(LinearizationInterval linInterval) {
final String message = "Linearization interval endpoints must be constant expressions of real type";
Expr startExpr = linInterval.getStart();
Expr endExpr = linInterval.getEnd();
TypeDef startExprType = AgreeTypeSystem.infer(startExpr);
TypeDef endExprType = AgreeTypeSystem.infer(endExpr);
// The type of the interval start and end must be of real type
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.RealTypeDef, startExprType)) {
error(startExpr, message + ", found type " + startExprType + ".");
}
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.RealTypeDef, endExprType)) {
error(endExpr, message + ", found type " + endExprType + ".");
}
// The interval start and end expressions must be constant
if (!exprIsConst(startExpr)) {
error(endExpr, message + ", found non-constant expression.");
}
if (!exprIsConst(startExpr)) {
error(endExpr, message + ", found non-constant expression.");
}
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeValidator method checkWheneverBecomesTrueStatement.
@Check(CheckType.FAST)
public void checkWheneverBecomesTrueStatement(WheneverBecomesTrueStatement whenever) {
Expr cause = whenever.getCause();
Expr effect = whenever.getEffect();
checkExprIsIdentifier(cause);
checkExprIsIdentifier(effect);
TypeDef type = AgreeTypeSystem.infer(cause);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(cause, "The cause of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
}
type = AgreeTypeSystem.infer(effect);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(effect, "The effect of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
}
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeValidator method checkWheneverHoldsStatement.
@Check(CheckType.FAST)
public void checkWheneverHoldsStatement(WheneverHoldsStatement whenever) {
Expr cause = whenever.getCause();
Expr effect = whenever.getEffect();
checkExprIsIdentifier(cause);
checkExprIsIdentifier(effect);
TypeDef type = AgreeTypeSystem.infer(cause);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(cause, "The cause of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
}
type = AgreeTypeSystem.infer(effect);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(effect, "The effect of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
}
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeValidator method checkWhenHoldsStatement.
@Check(CheckType.FAST)
public void checkWhenHoldsStatement(WhenHoldsStatement when) {
Expr condition = when.getCondition();
Expr event = when.getEvent();
TimeInterval condInterval = when.getConditionInterval();
checkExprIsIdentifier(condition);
checkExprIsIdentifier(event);
if (condInterval != null) {
Expr lowExpr = condInterval.getLow();
if (lowExpr instanceof RealLitExpr) {
RealLitExpr realExpr = (RealLitExpr) lowExpr;
if (!realExpr.getVal().equals("0.0")) {
error(lowExpr, "The lower bound of this interval must be zero");
}
}
} else {
error(when, "Statement most of a cause interval");
}
TypeDef type = AgreeTypeSystem.infer(condition);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(condition, "The condition of a when statement is of type '" + type + "'" + " but must be of type 'bool'");
}
type = AgreeTypeSystem.infer(event);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(event, "The effect of a when statement is of type '" + type + "'" + " but must be of type 'bool'");
}
}
use of com.rockwellcollins.atc.agree.agree.Expr 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 + "'");
}
}
}
Aggregations