Search in sources :

Example 1 with UninterpretedFnDef

use of com.rockwellcollins.atc.agree.agree.UninterpretedFnDef in project AGREE by loonwerks.

the class AgreeValidator method checkMultiAssignEq.

private void checkMultiAssignEq(EObject src, List<Arg> lhsArgs, Expr rhsExpr) {
    if (rhsExpr == null) {
        return;
    }
    if (lhsArgs.size() == 1) {
        // we should only need to check for cycles for single equations
        String name = lhsArgs.get(0).getName();
        ExprCycleVisitor cycleVisitor = new ExprCycleVisitor(name);
        Set<EObject> cycleObjects = cycleVisitor.doSwitch(rhsExpr);
        if (cycleObjects == null) {
            throw new IllegalArgumentException("something went wrong with the cycle checker");
        }
        for (EObject obj : cycleObjects) {
            error(obj, "Cyclic reference to variable '" + name + "'");
        }
    }
    if (argsContainRangeValue(lhsArgs)) {
        error(src, "Equation statements cannot contain a ranged value and a right hand side expression");
    }
    List<TypeDef> agreeLhsTypes = new ArrayList<>();
    for (Arg arg : lhsArgs) {
        agreeLhsTypes.add(AgreeTypeSystem.typeDefFromType(arg.getType()));
    }
    List<TypeDef> agreeRhsTypes = new ArrayList<>();
    if (rhsExpr instanceof CallExpr) {
        NamedElement namedEl = ((CallExpr) rhsExpr).getRef().getElm();
        if (namedEl instanceof NodeDef) {
            NodeDef nodeDef = (NodeDef) namedEl;
            for (Arg var : nodeDef.getRets()) {
                agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(var.getType()));
            }
        } else if (namedEl instanceof FnDef) {
            FnDef fnDef = (FnDef) namedEl;
            agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(fnDef.getType()));
        } else if (namedEl instanceof UninterpretedFnDef) {
            UninterpretedFnDef uninterpretedFnDef = (UninterpretedFnDef) namedEl;
            agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(uninterpretedFnDef.getType()));
        } else {
            // parse error
            return;
        }
    } else {
        checkTypeExists(rhsExpr);
        TypeDef rhsType = AgreeTypeSystem.infer(rhsExpr);
        agreeRhsTypes.add(rhsType);
    }
    if (agreeLhsTypes.size() != agreeRhsTypes.size()) {
        error(src, "Equation assigns " + agreeLhsTypes.size() + " variables, but right side returns " + agreeRhsTypes.size() + " values");
        return;
    }
    for (int i = 0; i < agreeLhsTypes.size(); i++) {
        TypeDef lhsType = agreeLhsTypes.get(i);
        TypeDef rhsType = agreeRhsTypes.get(i);
        if (!AgreeTypeSystem.typesEqual(rhsType, lhsType)) {
            error(src, "The variable '" + lhsArgs.get(i).getName() + "' on the left side of equation is of type '" + nameOfTypeDef(lhsType) + "' but must be of type '" + nameOfTypeDef(rhsType) + "'");
        }
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) ArrayList(java.util.ArrayList) 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) ExprCycleVisitor(com.rockwellcollins.atc.agree.visitors.ExprCycleVisitor) 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) EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) NamedElement(org.osate.aadl2.NamedElement)

Example 2 with UninterpretedFnDef

use of com.rockwellcollins.atc.agree.agree.UninterpretedFnDef in project AGREE by loonwerks.

the class AgreeLinkingService method getElm.

private Element getElm(EObject context, EReference reference, String name) {
    String[] segments = name.split("::");
    if (segments.length >= 2) {
        String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
        String statementName = segments[segments.length - 1];
        Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
        PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
        if (propSet != null) {
            Element elm = propSet.findNamedElement(statementName);
            return elm;
        }
        AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
        if (aadlPackage == null) {
            for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
                if (rename.getName() != null && pkgName.equals(rename.getName())) {
                    aadlPackage = rename.getRenamedPackage();
                }
            }
        }
        if (aadlPackage != null) {
            for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
                AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
                for (SpecStatement spec : contract.getSpecs()) {
                    if (spec instanceof RecordDef) {
                        if (((RecordDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof FnDef) {
                        if (((FnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LibraryFnDef) {
                        if (((LibraryFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof UninterpretedFnDef) {
                        if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof NodeDef) {
                        if (((NodeDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LinearizationDef) {
                        if (((LinearizationDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof ConstStatement) {
                        if (((ConstStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof EnumStatement) {
                        if (((EnumStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                        EList<NamedID> enums = ((EnumStatement) spec).getEnums();
                        for (NamedID nid : enums) {
                            if (nid.getName().contentEquals(statementName)) {
                                return nid;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Element(org.osate.aadl2.Element) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) Namespace(org.osate.aadl2.Namespace) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EList(org.eclipse.emf.common.util.EList) PackageRename(org.osate.aadl2.PackageRename) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 3 with UninterpretedFnDef

use of com.rockwellcollins.atc.agree.agree.UninterpretedFnDef in project AGREE by loonwerks.

the class AgreeValidator method checkNodeStmt.

@Check(CheckType.FAST)
public void checkNodeStmt(NodeStmt nodeStmt) {
    List<NamedElmExpr> dotIds = EcoreUtil2.getAllContentsOfType(nodeStmt, NamedElmExpr.class);
    for (NamedElmExpr dotId : dotIds) {
        NamedElement id = dotId.getElm();
        // restrict the elements that are single names or the last projection.
        boolean restrictedElm = true;
        if (dotId.eContainer() instanceof SelectionExpr) {
            NamedElement ne = ((SelectionExpr) dotId.eContainer()).getField();
            restrictedElm = ne == id && !(dotId.eContainer().eContainer() instanceof SelectionExpr);
        }
        if (restrictedElm && !(id instanceof Arg) && !(id instanceof ConstStatement) && !(id instanceof NodeDef) && !(id instanceof FnDef) && !(id instanceof UninterpretedFnDef) && !(id instanceof DataSubcomponent) && !(id instanceof DoubleDotRef) && !(id instanceof DataImplementation) && !(id instanceof RecordDef) && !(id instanceof NamedID)) {
            error(dotId, "Only arguments, constants, and node calls allowed within a node");
        }
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) DataImplementation(org.osate.aadl2.DataImplementation) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Check(org.eclipse.xtext.validation.Check)

Example 4 with UninterpretedFnDef

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

FnDef (com.rockwellcollins.atc.agree.agree.FnDef)4 LibraryFnDef (com.rockwellcollins.atc.agree.agree.LibraryFnDef)4 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)4 UninterpretedFnDef (com.rockwellcollins.atc.agree.agree.UninterpretedFnDef)4 NamedElement (org.osate.aadl2.NamedElement)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 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)2 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)2 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)2 LinearizationDef (com.rockwellcollins.atc.agree.agree.LinearizationDef)2 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)2 NamedID (com.rockwellcollins.atc.agree.agree.NamedID)2 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)2 Abstraction (com.rockwellcollins.atc.agree.agree.Abstraction)1 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)1