Search in sources :

Example 6 with CallExpr

use of com.rockwellcollins.atc.agree.agree.CallExpr 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)

Aggregations

CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)6 NamedElement (org.osate.aadl2.NamedElement)4 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)3 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)3 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)3 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)3 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)3 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)3 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)3 PreExpr (com.rockwellcollins.atc.agree.agree.PreExpr)3 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)3 RecordLitExpr (com.rockwellcollins.atc.agree.agree.RecordLitExpr)3 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)3 ArrayList (java.util.ArrayList)3 ArrayTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef)2 RecordTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef)2 TypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef)2 AgreeTypeSystem.nameOfTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef)2 Arg (com.rockwellcollins.atc.agree.agree.Arg)2 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)2