Search in sources :

Example 6 with SpecStatement

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

the class AgreeASTBuilder method getAssertionStatements.

private List<AgreeStatement> getAssertionStatements(EList<SpecStatement> specs) {
    List<AgreeStatement> asserts = new ArrayList<>();
    for (SpecStatement spec : specs) {
        if (spec instanceof AssertStatement) {
            AssertStatement assertState = (AssertStatement) spec;
            String str = assertState.getStr();
            if (assertState.getExpr() != null) {
                asserts.add(new AgreeStatement(str, doSwitch(assertState.getExpr()), assertState));
            } else {
                PatternStatement pattern = assertState.getPattern();
                asserts.add(new AgreePatternBuilder(str, assertState, this).doSwitch(pattern));
            }
        }
    }
    return asserts;
}
Also used : PatternStatement(com.rockwellcollins.atc.agree.agree.PatternStatement) ArrayList(java.util.ArrayList) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreePatternBuilder(com.rockwellcollins.atc.agree.analysis.realtime.AgreePatternBuilder)

Example 7 with SpecStatement

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

the class AgreeValidator method checkLatchedExpr.

@Check(CheckType.FAST)
public void checkLatchedExpr(LatchedExpr latched) {
    // get container
    EObject container = latched.eContainer();
    AgreeContract contract = null;
    while (!(container instanceof ComponentClassifier)) {
        if (container instanceof AgreeContract) {
            contract = (AgreeContract) container;
        }
        container = container.eContainer();
    }
    if (container instanceof ComponentImplementation) {
        boolean foundLatchedStatement = false;
        for (SpecStatement spec : contract.getSpecs()) {
            if (spec instanceof LatchedStatement) {
                foundLatchedStatement = true;
                break;
            }
        }
        if (!foundLatchedStatement) {
            error(latched, "Latched expressions can appear only in component implementations " + "that contain a latched synchrony statement");
        }
    } else {
        error(latched, "Latched expressions can appear only in component implementations");
    }
    Expr expr = latched.getExpr();
    Expr nestId = null;
    if (expr instanceof NamedElmExpr) {
        nestId = expr;
    } else if (expr instanceof EventExpr) {
        EventExpr eventExpr = (EventExpr) expr;
        nestId = eventExpr.getPort();
    }
    if (nestId != null) {
        NamedElement namedEl = null;
        if (nestId instanceof NamedElmExpr) {
            namedEl = ((NamedElmExpr) nestId).getElm();
        } else if (nestId instanceof SelectionExpr) {
            namedEl = ((SelectionExpr) nestId).getField();
        }
        if ((namedEl instanceof DataPort) && ((DataPort) namedEl).isIn()) {
            return;
        } else if ((namedEl instanceof EventDataPort) && ((EventDataPort) namedEl).isIn()) {
            return;
        } else {
            // check to see if it is an "agree_input"
            EObject namedElContainer = namedEl.eContainer();
            if (namedElContainer instanceof InputStatement) {
                return;
            }
        }
    }
    error(latched, "Latched expressions are valid only for input data ports or event expressions over input event data ports");
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) 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) EObject(org.eclipse.emf.ecore.EObject) LatchedStatement(com.rockwellcollins.atc.agree.agree.LatchedStatement) EventDataPort(org.osate.aadl2.EventDataPort) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Check(org.eclipse.xtext.validation.Check)

Example 8 with SpecStatement

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

the class AgreeValidator method checkNameOverlap.

@Check(CheckType.FAST)
public void checkNameOverlap(AgreeContract contract) {
    Set<SynchStatement> syncs = new HashSet<>();
    Set<InitialStatement> inits = new HashSet<>();
    List<ConnectionStatement> conns = new ArrayList<>();
    // check that there are zero or more synchrony statements
    for (SpecStatement spec : contract.getSpecs()) {
        if (spec instanceof SynchStatement) {
            syncs.add((SynchStatement) spec);
        } else if (spec instanceof CalenStatement) {
            syncs.add((CalenStatement) spec);
        } else if (spec instanceof InitialStatement) {
            inits.add((InitialStatement) spec);
        } else if (spec instanceof ConnectionStatement) {
            conns.add((ConnectionStatement) spec);
        }
    }
    if (syncs.size() > 1) {
        for (SynchStatement sync : syncs) {
            error(sync, "Multiple synchrony or calender statements in a single contract");
        }
    }
    if (inits.size() > 1) {
        for (InitialStatement init : inits) {
            error(init, "Multiple initially statements in a single contract");
        }
    }
    for (int i = 0; i < conns.size(); i++) {
        ConnectionStatement connStat0 = conns.get(i);
        NamedElement conn0 = connStat0.getConn();
        for (int j = i + 1; j < conns.size(); j++) {
            ConnectionStatement connStat1 = conns.get(j);
            NamedElement conn1 = connStat1.getConn();
            if (conn0 == null || conn1 == null) {
                break;
            }
            if (conn0.equals(conn1)) {
                error(connStat0, "Multiple connection overrides for connection: '" + conn0.getName() + "'");
                error(connStat1, "Multiple connection overrides for connection: '" + conn1.getName() + "'");
            }
        }
    }
    ComponentImplementation ci = EcoreUtil2.getContainerOfType(contract, ComponentImplementation.class);
    if (ci == null) {
        return;
    }
    Set<String> parentNames = getParentNames(ci);
    for (AgreeSubclause subclause : EcoreUtil2.getAllContentsOfType(ci, AgreeSubclause.class)) {
        List<NamedElement> es = EcoreUtil2.getAllContentsOfType(subclause, NamedElement.class);
        for (NamedElement e : es) {
            if (!(e.eContainer() instanceof NodeDef || e instanceof NamedSpecStatement)) {
                // ignore elements in node defs
                if (parentNames.contains(e.getName())) {
                    // =======
                    // if (!(e.eContainer() instanceof NodeDefExpr)) { // ignore elements in node defs
                    // if (e.getName() != null && parentNames.contains(e.getName())) {
                    // >>>>>>> origin/develop
                    error(e, e.getName() + " already defined in component type contract");
                }
            }
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) AgreeSubclause(com.rockwellcollins.atc.agree.agree.AgreeSubclause) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) ConnectionStatement(com.rockwellcollins.atc.agree.agree.ConnectionStatement) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) InitialStatement(com.rockwellcollins.atc.agree.agree.InitialStatement) CalenStatement(com.rockwellcollins.atc.agree.agree.CalenStatement) MNSynchStatement(com.rockwellcollins.atc.agree.agree.MNSynchStatement) SynchStatement(com.rockwellcollins.atc.agree.agree.SynchStatement) NamedElement(org.osate.aadl2.NamedElement) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 9 with SpecStatement

use of com.rockwellcollins.atc.agree.agree.SpecStatement 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 10 with SpecStatement

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

the class AgreeScopeProvider method getNamedElementsFromSpecs.

private Map<String, NamedElement> getNamedElementsFromSpecs(EList<SpecStatement> specs) {
    Map<String, NamedElement> nelms = new HashMap<>();
    for (SpecStatement spec : specs) {
        if (spec instanceof NamedElement) {
            nelms.put(((NamedElement) spec).getName(), (NamedElement) spec);
        }
        if (spec instanceof EqStatement) {
            EqStatement eq = (EqStatement) spec;
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(eq.getLhs());
            nelms.putAll(toNamedElementMap(nes));
        } else if (spec instanceof ConstStatement) {
            ConstStatement c = (ConstStatement) spec;
            nelms.put(c.getName(), c);
        } else if (spec instanceof InputStatement) {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((InputStatement) spec).getLhs());
            nelms.putAll(toNamedElementMap(nes));
        } else if (spec instanceof EnumStatement) {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((EnumStatement) spec).getEnums());
            nelms.putAll(toNamedElementMap(nes));
        }
    }
    return nelms;
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) HashMap(java.util.HashMap) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)25 ArrayList (java.util.ArrayList)17 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)9 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)8 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)8 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)7 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)7 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)7 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)7 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)7 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)7 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)7 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)7 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)7 FoldLeftExpr (com.rockwellcollins.atc.agree.agree.FoldLeftExpr)7 FoldRightExpr (com.rockwellcollins.atc.agree.agree.FoldRightExpr)7 ForallExpr (com.rockwellcollins.atc.agree.agree.ForallExpr)7 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)7 IndicesExpr (com.rockwellcollins.atc.agree.agree.IndicesExpr)7 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)7