Search in sources :

Example 1 with Abstraction

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;
}
Also used : DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) Abstraction(com.rockwellcollins.atc.agree.agree.Abstraction)

Example 2 with Abstraction

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 + "'");
        }
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) ArrayList(java.util.ArrayList) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) Abstraction(com.rockwellcollins.atc.agree.agree.Abstraction) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) AgreeTypeSystem.nameOfTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef) ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) RecordTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef) TypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement)

Example 3 with Abstraction

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);
    }
}
Also used : Abstraction(com.rockwellcollins.atc.agree.agree.Abstraction) Check(org.eclipse.xtext.validation.Check)

Aggregations

Abstraction (com.rockwellcollins.atc.agree.agree.Abstraction)3 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)2 ArrayTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef)1 RecordTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef)1 TypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef)1 AgreeTypeSystem.nameOfTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef)1 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)1 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)1 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)1 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)1 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)1 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)1 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)1 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)1 Expr (com.rockwellcollins.atc.agree.agree.Expr)1 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)1 FnDef (com.rockwellcollins.atc.agree.agree.FnDef)1 FoldLeftExpr (com.rockwellcollins.atc.agree.agree.FoldLeftExpr)1 FoldRightExpr (com.rockwellcollins.atc.agree.agree.FoldRightExpr)1