Search in sources :

Example 16 with NodeDef

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

Example 17 with NodeDef

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());
}
Also used : NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) Check(org.eclipse.xtext.validation.Check)

Example 18 with NodeDef

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 + "'");
        }
    }
}
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 19 with NodeDef

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;
}
Also used : AgreeSubclause(com.rockwellcollins.atc.agree.agree.AgreeSubclause) ComponentType(org.osate.aadl2.ComponentType) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) HashSet(java.util.HashSet)

Aggregations

NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)19 NamedElement (org.osate.aadl2.NamedElement)10 Arg (com.rockwellcollins.atc.agree.agree.Arg)7 Check (org.eclipse.xtext.validation.Check)7 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)6 LibraryFnDef (com.rockwellcollins.atc.agree.agree.LibraryFnDef)6 FnDef (com.rockwellcollins.atc.agree.agree.FnDef)5 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)5 RecordDef (com.rockwellcollins.atc.agree.agree.RecordDef)5 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)4 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)4 Expr (com.rockwellcollins.atc.agree.agree.Expr)4 LinearizationDef (com.rockwellcollins.atc.agree.agree.LinearizationDef)4 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)4 UninterpretedFnDef (com.rockwellcollins.atc.agree.agree.UninterpretedFnDef)4 ArrayList (java.util.ArrayList)4 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)3 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)3 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)3 EObject (org.eclipse.emf.ecore.EObject)3