use of com.rockwellcollins.atc.agree.agree.Abstraction in project AGREE by loonwerks.
the class CallRecursionHelper method caseCallExpr.
@Override
public Expr caseCallExpr(CallExpr object) {
DoubleDotRef id = object.getRef();
Abstraction callDef = null;
try {
callDef = (Abstraction) id.getElm();
// =======
// public Expr caseFnCallExpr(FnCallExpr object) {
//
// CallDef callDef = null;
//
// try {
// callDef = (CallDef) object.getFn().getBase();
// >>>>>>> origin/develop:fm-workbench/agree/com.rockwellcollins.atc.agree/src/com/rockwellcollins/atc/agree/validation/FnCallRecursionHelper.java
//
} catch (ClassCastException e) {
return null;
}
doSwitch(callDef);
return null;
}
use of com.rockwellcollins.atc.agree.agree.Abstraction 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.Abstraction in project AGREE by loonwerks.
the class AgreeValidator method checkAbstraction.
@Check(CheckType.FAST)
public void checkAbstraction(Abstraction callDef) {
// already been walked over
if (checkedRecCalls.contains(callDef)) {
return;
}
CallRecursionHelper recHelp = new CallRecursionHelper();
recHelp.doSwitch(callDef);
for (LinkedList<Abstraction> loop : recHelp.loops) {
StringBuilder loopStr = new StringBuilder();
String sep = "";
for (Abstraction tempAbstraction : loop) {
checkedRecCalls.add(tempAbstraction);
String callName = tempAbstraction.getName();
loopStr.append(sep);
loopStr.append(callName);
sep = " -> ";
}
error(callDef, "There exists a recursive dependency between the " + "following node or function calls : " + loopStr);
}
}
Aggregations