Search in sources :

Example 31 with AgreeException

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

the class AgreeASTBuilder method caseFoldRightExpr.

@Override
public Expr caseFoldRightExpr(FoldRightExpr expr) {
    AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
    int size = 0;
    if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
    } else {
        throw new AgreeException("ERROR: caseFoldRightExpr");
    }
    Expr array = doSwitch(expr.getArray());
    Expr accExpr = doSwitch(expr.getInitial());
    NamedID binding = expr.getBinding();
    NamedID accBinding = expr.getAccumulator();
    for (int i = size - 1; i >= 0; i--) {
        Expr arrayAccess = new ArrayAccessExpr(array, i);
        accExpr = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess)).accept(new SubstitutionVisitor(accBinding.getName(), accExpr));
    }
    return accExpr;
}
Also used : AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) 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) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) 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) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) NamedID(com.rockwellcollins.atc.agree.agree.NamedID)

Example 32 with AgreeException

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

the class AgreeASTBuilder method getAgreeNode.

private AgreeNode getAgreeNode(ComponentInstance compInst, boolean isTop) {
    List<AgreeVar> inputs = new ArrayList<>();
    List<AgreeVar> outputs = new ArrayList<>();
    List<AgreeVar> locals = new ArrayList<>();
    List<AgreeAADLConnection> aadlConnections = new ArrayList<>();
    List<AgreeOverriddenConnection> userDefinedConections = new ArrayList<>();
    List<AgreeConnection> connections = new ArrayList<>();
    List<AgreeNode> subNodes = new ArrayList<>();
    List<AgreeStatement> assertions = new ArrayList<>();
    List<AgreeStatement> assumptions = new ArrayList<>();
    List<AgreeStatement> guarantees = new ArrayList<>();
    List<AgreeStatement> lemmas = new ArrayList<>();
    List<AgreeEquation> localEquations = new ArrayList<>();
    List<AgreeStatement> patternProps = Collections.emptyList();
    timeOfVarMap = new HashMap<>();
    timeRiseVarMap = new HashMap<>();
    timeFallVarMap = new HashMap<>();
    unspecifiedAadlProperties = new HashMap<>();
    Expr clockConstraint = new BoolExpr(true);
    Expr initialConstraint = new BoolExpr(true);
    String id = compInst.getName();
    AgreeVar clockVar = new AgreeVar(id + clockIDSuffix, NamedType.BOOL, compInst.getSubcomponent(), compInst, null);
    EObject reference = isTop ? compInst.getComponentClassifier() : compInst.getSubcomponent();
    TimingModel timing = null;
    boolean foundSubNode = false;
    boolean hasDirectAnnex = false;
    boolean hasSubcomponents = false;
    ComponentClassifier compClass = compInst.getComponentClassifier();
    Set<ComponentType> effectiveTypes = new HashSet<>();
    Map<String, jkind.lustre.Expr> portRewriteMap = new HashMap<>();
    if (compClass instanceof ComponentImplementation) {
        boolean latched = false;
        ComponentImplementation cc = (ComponentImplementation) compClass;
        effectiveTypes.addAll(getEffectiveComponentTypes(cc.getType()));
        if (isTop || isMonolithic) {
            while (cc != null) {
                AgreeContractSubclause annex = getAgreeAnnex(cc);
                for (ComponentInstance subInst : compInst.getComponentInstances()) {
                    hasSubcomponents = true;
                    curInst = subInst;
                    AgreeNode subNode = getAgreeNode(subInst, false);
                    if (subNode != null && subNodes.stream().noneMatch(it -> it.reference.equals(subNode.reference))) {
                        foundSubNode = true;
                        subNodes.add(subNode);
                    }
                }
                if (annex != null) {
                    hasDirectAnnex = true;
                    AgreeContract contract = (AgreeContract) annex.getContract();
                    curInst = compInst;
                    assertions.addAll(getAssertionStatements(contract.getSpecs()));
                    getEquationStatements(contract.getSpecs(), portRewriteMap).addAllTo(locals, assertions, guarantees);
                    assertions.addAll(getPropertyStatements(contract.getSpecs()));
                    assertions.addAll(getAssignmentStatements(contract.getSpecs()));
                    userDefinedConections.addAll(getConnectionStatements(contract.getSpecs()));
                    lemmas.addAll(getLemmaStatements(contract.getSpecs()));
                    lemmas.addAll(getReachableStatements(contract.getSpecs(), portRewriteMap));
                    addLustreNodes(contract.getSpecs());
                    gatherLustreTypes(contract.getSpecs());
                    // the clock constraints contain other nodes that we add
                    clockConstraint = getClockConstraint(contract.getSpecs(), subNodes);
                    timing = getTimingModel(contract.getSpecs());
                    outputs.addAll(getEquationVars(contract.getSpecs(), compInst));
                    for (SpecStatement spec : contract.getSpecs()) {
                        if (spec instanceof LatchedStatement) {
                            latched = true;
                            break;
                        }
                    }
                }
                // Find extended effective types
                effectiveTypes.addAll(getEffectiveComponentTypes(cc.getType()));
                cc = cc.getExtended();
            }
            EList<ConnectionInstance> connectionInstances = compInst.getAllEnclosingConnectionInstances();
            List<ConnectionInstance> foo = new ArrayList<>();
            compInst.getAllComponentInstances().forEach(ci -> ci.allEnclosingConnectionInstances().forEach(foo::add));
            aadlConnections.addAll(getConnectionsFromInstances(connectionInstances, compInst, subNodes, latched));
            connections.addAll(filterConnections(aadlConnections, userDefinedConections));
        }
        ComponentType compType = ((ComponentImplementation) compClass).getType();
        AgreeContractSubclause compImpAnnex = getAgreeAnnex(compClass);
        if (compImpAnnex != null) {
            AgreeContract contract = (AgreeContract) compImpAnnex.getContract();
            for (SpecStatement spec : contract.getSpecs()) {
                if (spec instanceof LiftContractStatement) {
                    Subcomponent sub = ((ComponentImplementation) compClass).getOwnedSubcomponents().get(0);
                    ComponentType ct = sub.getComponentType();
                    for (Connection conn : ((ComponentImplementation) compClass).getAllConnections()) {
                        NamedElement sourceNe = conn.getSource().getConnectionEnd();
                        NamedElement destNe = conn.getDestination().getConnectionEnd();
                        String sourceStr = sourceNe.getName().replace("::", "__");
                        String destStr = destNe.getName().replace("::", "__");
                        if (ct == sourceNe.getContainingClassifier()) {
                            portRewriteMap.put(sourceStr, new IdExpr(destStr));
                        } else if (ct == destNe.getContainingClassifier()) {
                            portRewriteMap.put(destStr, new IdExpr(sourceStr));
                        }
                    }
                    effectiveTypes.addAll(getEffectiveComponentTypes(ct));
                }
            }
        }
        // make compClass the type so we can get it's other contract elements
        compClass = compType;
    } else if (compClass instanceof ComponentType) {
        effectiveTypes.addAll(getEffectiveComponentTypes((ComponentType) compClass));
    } else {
        throw new AgreeException("Internal error: attempt to run AGREE analysis on instance " + compInst.getFullName() + " not instance of ComponentImplementation or ComponentType.");
    }
    curInst = compInst;
    if (timing == null) {
        timing = TimingModel.SYNC;
    }
    for (ComponentType compType : effectiveTypes) {
        AgreeContractSubclause annex = getAgreeAnnex(compType);
        if (annex != null) {
            hasDirectAnnex = true;
            AgreeContract contract = (AgreeContract) annex.getContract();
            // this makes files for monolithic verification a bit smaller
            if (!isMonolithic || isTop || !hasSubcomponents) {
                assumptions.addAll(getAssumptionStatements(contract.getSpecs(), portRewriteMap));
                guarantees.addAll(getGuaranteeStatements(contract.getSpecs(), portRewriteMap));
                lemmas.addAll(getReachableStatements(contract.getSpecs(), portRewriteMap));
            }
            // Count eq statements with expressions as assertions
            getEquationStatements(contract.getSpecs(), portRewriteMap).addAllTo(locals, assertions, guarantees);
            assertions.addAll(getPropertyStatements(contract.getSpecs()));
            outputs.addAll(getEquationVars(contract.getSpecs(), compInst));
            getAgreeInputVars(contract.getSpecs(), compInst).addAllTo(inputs, assumptions, guarantees);
            initialConstraint = getInitialConstraint(contract.getSpecs());
            addLustreNodes(contract.getSpecs());
            gatherLustreTypes(contract.getSpecs());
        }
    }
    gatherUnspecifiedAadlProperties(unspecifiedAadlProperties, inputs, assumptions, guarantees);
    if (!(foundSubNode || hasDirectAnnex)) {
        return null;
    }
    gatherOutputsInputsAndTypes(outputs, inputs, compInst.getFeatureInstances(), assumptions, guarantees);
    AgreeNodeBuilder builder = new AgreeNodeBuilder(id);
    builder.addInput(inputs);
    builder.addOutput(outputs);
    builder.addLocal(locals);
    builder.addLocalEquation(localEquations);
    builder.addConnection(connections);
    builder.addSubNode(subNodes);
    // Clean up any vacuous true predicates
    Predicate<AgreeStatement> isBoolExprAndisTrue = st -> (st.expr instanceof BoolExpr) && ((BoolExpr) st.expr).value;
    assertions.removeIf(isBoolExprAndisTrue);
    assumptions.removeIf(isBoolExprAndisTrue);
    guarantees.removeIf(isBoolExprAndisTrue);
    builder.addAssertion(assertions);
    builder.addAssumption(assumptions);
    builder.addGuarantee(guarantees);
    builder.addLemma(lemmas);
    builder.addPatternProp(patternProps);
    builder.setClockConstraint(clockConstraint);
    builder.setInitialConstraint(initialConstraint);
    builder.setClockVar(clockVar);
    builder.setReference(reference);
    builder.setTiming(timing);
    builder.setCompInst(compInst);
    builder.addTimeOf(timeOfVarMap);
    builder.addTimeRise(timeRiseVarMap);
    builder.addTimeFall(timeFallVarMap);
    AgreeNode result = builder.build();
    renamings.put(id, compInst.getName());
    refMap.put(id, compInst);
    return linearizationRewriter.visit(result);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) AnnexUtil(org.osate.annexsupport.AnnexUtil) AadlBoolean(org.osate.aadl2.AadlBoolean) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) BigDecimal(java.math.BigDecimal) PropertyExpression(org.osate.aadl2.PropertyExpression) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) AgreeAutomaterRegistry(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry) Map(java.util.Map) Expr(jkind.lustre.Expr) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) BigInteger(java.math.BigInteger) CastExpr(jkind.lustre.CastExpr) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) ConnectionEnd(org.osate.aadl2.ConnectionEnd) CalenStatement(com.rockwellcollins.atc.agree.agree.CalenStatement) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) PatternStatement(com.rockwellcollins.atc.agree.agree.PatternStatement) MNSynchronyElement(com.rockwellcollins.atc.agree.analysis.MNSynchronyElement) Set(java.util.Set) ComponentRef(com.rockwellcollins.atc.agree.agree.ComponentRef) AadlPackage(org.osate.aadl2.AadlPackage) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) AgreePatternTranslator(com.rockwellcollins.atc.agree.analysis.realtime.AgreePatternTranslator) PropertyDoesNotApplyToHolderException(org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException) AgreeCalendarUtils(com.rockwellcollins.atc.agree.analysis.AgreeCalendarUtils) MNSynchStatement(com.rockwellcollins.atc.agree.agree.MNSynchStatement) Node(jkind.lustre.Node) ConnectionStatement(com.rockwellcollins.atc.agree.agree.ConnectionStatement) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreeUtils(com.rockwellcollins.atc.agree.analysis.AgreeUtils) AgreeSporadicPattern(com.rockwellcollins.atc.agree.analysis.realtime.AgreeSporadicPattern) NodeCallExpr(jkind.lustre.NodeCallExpr) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) AgreePackage(com.rockwellcollins.atc.agree.agree.AgreePackage) AgreePeriodicPattern(com.rockwellcollins.atc.agree.analysis.realtime.AgreePeriodicPattern) Feature(org.osate.aadl2.Feature) RealExpr(jkind.lustre.RealExpr) ComponentImplementation(org.osate.aadl2.ComponentImplementation) IdGatherer(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdGatherer) Type(jkind.lustre.Type) ArrayList(java.util.ArrayList) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ArrayExpr(jkind.lustre.ArrayExpr) LiftContractStatement(com.rockwellcollins.atc.agree.agree.LiftContractStatement) AgreeCauseEffectPattern(com.rockwellcollins.atc.agree.analysis.realtime.AgreeCauseEffectPattern) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) Aadl2Package(org.osate.aadl2.Aadl2Package) Subcomponent(org.osate.aadl2.Subcomponent) BinaryOp(jkind.lustre.BinaryOp) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FeatureGroup(org.osate.aadl2.FeatureGroup) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral) NamedType(jkind.lustre.NamedType) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) AgreeInlineLatchedConnections(com.rockwellcollins.atc.agree.analysis.ast.visitors.AgreeInlineLatchedConnections) ReachableStatement(com.rockwellcollins.atc.agree.agree.ReachableStatement) PropertyConstant(org.osate.aadl2.PropertyConstant) AgreePatternBuilder(com.rockwellcollins.atc.agree.analysis.realtime.AgreePatternBuilder) Aadl2GlobalScopeUtil(org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil) EventPort(org.osate.aadl2.EventPort) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FeatureGroupType(org.osate.aadl2.FeatureGroupType) PortConnection(org.osate.aadl2.PortConnection) FunctionCallExpr(jkind.lustre.FunctionCallExpr) RealCast(com.rockwellcollins.atc.agree.agree.RealCast) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) DataPort(org.osate.aadl2.DataPort) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) VarDecl(jkind.lustre.VarDecl) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) AnnexSubclause(org.osate.aadl2.AnnexSubclause) BooleanLiteral(org.osate.aadl2.BooleanLiteral) IfThenElseExpr(jkind.lustre.IfThenElseExpr) NamedElement(org.osate.aadl2.NamedElement) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) RealLiteral(org.osate.aadl2.RealLiteral) NodeStmt(com.rockwellcollins.atc.agree.agree.NodeStmt) AsynchStatement(com.rockwellcollins.atc.agree.agree.AsynchStatement) NamedValue(org.osate.aadl2.NamedValue) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) TupleExpr(jkind.lustre.TupleExpr) PropertyUtils(org.osate.xtext.aadl2.properties.util.PropertyUtils) UnaryExpr(jkind.lustre.UnaryExpr) AgreeMakeClockedLustreNodes(com.rockwellcollins.atc.agree.analysis.ast.visitors.AgreeMakeClockedLustreNodes) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) ComponentType(org.osate.aadl2.ComponentType) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) IntExpr(jkind.lustre.IntExpr) UnaryOp(jkind.lustre.UnaryOp) LatchedStatement(com.rockwellcollins.atc.agree.agree.LatchedStatement) AadlReal(org.osate.aadl2.AadlReal) AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) Predicate(java.util.function.Predicate) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement) NodeEq(com.rockwellcollins.atc.agree.agree.NodeEq) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) NodeLemma(com.rockwellcollins.atc.agree.agree.NodeLemma) LinearizationRewriter(com.rockwellcollins.atc.agree.analysis.linearization.LinearizationRewriter) EObject(org.eclipse.emf.ecore.EObject) Connection(org.osate.aadl2.Connection) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) List(java.util.List) Property(org.osate.aadl2.Property) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) Entry(java.util.Map.Entry) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) SynchStatement(com.rockwellcollins.atc.agree.agree.SynchStatement) AgreeAutomater(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater) ExtensionRegistry(com.rockwellcollins.atc.agree.analysis.extentions.ExtensionRegistry) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) AadlInteger(org.osate.aadl2.AadlInteger) StringLiteral(org.osate.aadl2.StringLiteral) Arg(com.rockwellcollins.atc.agree.agree.Arg) TypeTable(com.rockwellcollins.atc.agree.analysis.TypeTable) Activator(com.rockwellcollins.atc.agree.analysis.Activator) FloorCast(com.rockwellcollins.atc.agree.agree.FloorCast) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) HashMap(java.util.HashMap) NodeBuilder(jkind.lustre.builders.NodeBuilder) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) HashSet(java.util.HashSet) DataSubcomponent(org.osate.aadl2.DataSubcomponent) InitialStatement(com.rockwellcollins.atc.agree.agree.InitialStatement) Function(jkind.lustre.Function) LustreExprFactory(com.rockwellcollins.atc.agree.analysis.translation.LustreExprFactory) PropertyStatement(com.rockwellcollins.atc.agree.agree.PropertyStatement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeLogger(com.rockwellcollins.atc.agree.analysis.AgreeLogger) ThisRef(com.rockwellcollins.atc.agree.agree.ThisRef) AssignStatement(com.rockwellcollins.atc.agree.agree.AssignStatement) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) Equation(jkind.lustre.Equation) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) EList(org.eclipse.emf.common.util.EList) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeSwitch(com.rockwellcollins.atc.agree.agree.util.AgreeSwitch) PreferenceConstants(com.rockwellcollins.atc.agree.analysis.preferences.PreferenceConstants) DataClassifier(org.osate.aadl2.DataClassifier) EventDataPort(org.osate.aadl2.EventDataPort) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) Collections(java.util.Collections) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) BoolExpr(jkind.lustre.BoolExpr) ComponentClassifier(org.osate.aadl2.ComponentClassifier) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) LiftContractStatement(com.rockwellcollins.atc.agree.agree.LiftContractStatement) HashSet(java.util.HashSet) AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) ComponentType(org.osate.aadl2.ComponentType) IdExpr(jkind.lustre.IdExpr) PortConnection(org.osate.aadl2.PortConnection) Connection(org.osate.aadl2.Connection) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) 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) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) 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) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) 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) LatchedStatement(com.rockwellcollins.atc.agree.agree.LatchedStatement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) NamedElement(org.osate.aadl2.NamedElement)

Example 33 with AgreeException

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

the class AgreeASTBuilder method caseFlatmapExpr.

@Override
public Expr caseFlatmapExpr(FlatmapExpr expr) {
    AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
    int size = 0;
    if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
    } else {
        throw new AgreeException("ERROR: caseFlatmapExpr");
    }
    Expr array = doSwitch(expr.getArray());
    NamedID binding = expr.getBinding();
    List<Expr> elems = new ArrayList<>();
    for (int i = 0; i < size; ++i) {
        Expr arrayAccess = new ArrayAccessExpr(array, i);
        Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
        AgreeTypeSystem.TypeDef innerArrType = AgreeTypeSystem.infer(expr.getExpr());
        if (innerArrType instanceof AgreeTypeSystem.ArrayTypeDef) {
            int innerSize = ((AgreeTypeSystem.ArrayTypeDef) innerArrType).size;
            for (int j = 0; j < innerSize; j++) {
                Expr innerAccess = new ArrayAccessExpr(body, j);
                elems.add(innerAccess);
            }
        }
    }
    return new ArrayExpr(elems);
}
Also used : AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) ArrayExpr(jkind.lustre.ArrayExpr) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) 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) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) 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) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayList(java.util.ArrayList) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) NamedID(com.rockwellcollins.atc.agree.agree.NamedID)

Example 34 with AgreeException

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

the class AgreeASTBuilder method caseFoldLeftExpr.

@Override
public Expr caseFoldLeftExpr(FoldLeftExpr expr) {
    AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
    int size = 0;
    if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
    } else {
        throw new AgreeException("ERROR: caseFoldLeftExpr");
    }
    Expr array = doSwitch(expr.getArray());
    Expr accExpr = doSwitch(expr.getInitial());
    NamedID binding = expr.getBinding();
    NamedID accBinding = expr.getAccumulator();
    for (int i = 0; i < size; i++) {
        Expr arrayAccess = new ArrayAccessExpr(array, i);
        accExpr = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess)).accept(new SubstitutionVisitor(accBinding.getName(), accExpr));
    }
    return accExpr;
}
Also used : AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) 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) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) 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) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) NamedID(com.rockwellcollins.atc.agree.agree.NamedID)

Example 35 with AgreeException

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

the class AgreeASTBuilder method caseForallExpr.

@Override
public Expr caseForallExpr(ForallExpr expr) {
    com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
    Expr array = doSwitch(arrayExpr);
    AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
    int size = 0;
    if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
        size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
    } else {
        throw new AgreeException("ERROR: caseForallExpr - '" + agreeType.getClass() + "' not handled");
    }
    NamedID binding = expr.getBinding();
    Expr final_expr = new BoolExpr(true);
    for (int i = 0; i < size; ++i) {
        Expr arrayAccess = new ArrayAccessExpr(array, i);
        Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
        final_expr = LustreExprFactory.makeANDExpr(final_expr, body);
    }
    return final_expr;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) SubstitutionVisitor(jkind.translation.SubstitutionVisitor) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) 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) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) 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) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) 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) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) 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) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Aggregations

AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)47 IdExpr (jkind.lustre.IdExpr)23 Expr (jkind.lustre.Expr)21 BinaryExpr (jkind.lustre.BinaryExpr)19 BoolExpr (jkind.lustre.BoolExpr)18 NodeCallExpr (jkind.lustre.NodeCallExpr)18 UnaryExpr (jkind.lustre.UnaryExpr)18 ArrayList (java.util.ArrayList)16 IntExpr (jkind.lustre.IntExpr)15 ComponentImplementation (org.osate.aadl2.ComponentImplementation)13 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)12 IfThenElseExpr (jkind.lustre.IfThenElseExpr)12 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)11 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)11 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)11 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)11 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)10 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)10 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)10 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)10