use of com.rockwellcollins.atc.agree.agree.NodeDef in project AGREE by loonwerks.
the class AgreeValidator method checkCallExpr.
@Check(CheckType.FAST)
public void checkCallExpr(CallExpr call) {
NamedElement fn = call.getRef().getElm();
if (isInLinearizationBody(call)) {
if (fn instanceof NodeDef) {
error(call, "Node definitions cannot be applied in a linearization definition");
// =======
// public void checkFnCallExpr(FnCallExpr fnCall) {
// NamedElement fn = (fnCall.getFn().getBase());
// if (isInLinearizationBody(fnCall)) {
// if (fn instanceof NodeDefExpr) {
// error(fnCall, "Node definitions cannot be applied in a linearization definition");
// >>>>>>> origin/develop
}
} else {
if (fn instanceof LibraryFnDef) {
if (fn.getElementRoot().getName().equalsIgnoreCase("dreal")) {
warning(call, "dReal library functions require the use of the dReal solver");
} else {
error(call, "Library functions cannot be called from the logic");
}
}
}
checkInputsVsActuals(call);
}
use of com.rockwellcollins.atc.agree.agree.NodeDef in project AGREE by loonwerks.
the class AgreeValidator method checkNodeEq.
@Check(CheckType.FAST)
public void checkNodeEq(NodeEq nodeEq) {
EObject container = nodeEq.eContainer();
NodeBodyExpr containingNodeBodyExpr;
NodeDef containingNodeDef;
if (container instanceof NodeBodyExpr) {
containingNodeBodyExpr = (NodeBodyExpr) container;
} else {
error(nodeEq, "Node equation must be contained in a node body.");
return;
}
if (container != null) {
container = container.eContainer();
}
if (container instanceof NodeDef) {
containingNodeDef = (NodeDef) container;
} else {
error(nodeEq, "Node equation must be contained in a node definition.");
return;
}
List<Arg> locals = containingNodeBodyExpr.getLocs();
List<Arg> returns = containingNodeDef.getRets();
int lhsIndex = 0;
for (Arg lhs : nodeEq.getLhs()) {
if (!locals.contains(lhs) && !returns.contains(lhs)) {
error("LHS '" + lhs.getName() + "' of node equation must be a node return variable or local variable.", nodeEq, AgreePackage.Literals.NODE_EQ__LHS, lhsIndex);
}
++lhsIndex;
}
checkMultiAssignEq(nodeEq, nodeEq.getLhs(), nodeEq.getExpr());
}
use of com.rockwellcollins.atc.agree.agree.NodeDef 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.agree.NodeDef in project AGREE by loonwerks.
the class AgreeValidator method getParentNames.
private Set<String> getParentNames(ComponentImplementation ci) {
Set<String> result = new HashSet<>();
ComponentType ct = ci.getType();
for (AgreeSubclause subclause : EcoreUtil2.getAllContentsOfType(ct, AgreeSubclause.class)) {
List<NamedElement> es = EcoreUtil2.getAllContentsOfType(subclause, NamedElement.class);
for (NamedElement e : es) {
if (!(e.eContainer() instanceof NodeDef || e.eContainer() instanceof LinearizationDef || e.eContainer() instanceof RecordDef || e instanceof NamedSpecStatement)) {
result.add(e.getName());
}
}
}
return result;
}
Aggregations