Search in sources :

Example 21 with Type

use of jkind.lustre.Type 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 22 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class AgreeASTBuilder method getConnectionEndType.

private Type getConnectionEndType(ConnectionEnd port) {
    NamedElement dataClass = getConnectionEndDataClass(port);
    if (dataClass == null) {
        return null;
    }
    // EGM: array-backend
    // Type lustreType = AgreeTypeUtils.getType(dataClass, typeMap, globalTypes);
    Type lustreType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromNE(dataClass));
    return lustreType;
}
Also used : ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) NamedElement(org.osate.aadl2.NamedElement)

Example 23 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class AgreeASTMapVisitor method visit.

@Override
public AgreeVar visit(AgreeVar e) {
    String name = e.id;
    Type type = e.type.accept(lustreTypeMapVisitor);
    EObject reference = e.reference;
    ComponentInstance compInst = e.compInst;
    FeatureInstance featInst = e.featInst;
    return new AgreeVar(name, type, reference, compInst, featInst);
}
Also used : Type(jkind.lustre.Type) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) EObject(org.eclipse.emf.ecore.EObject) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 24 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class LustreToMATLABTranslator method translate.

public static MATLABPrimaryFunction translate(Node lustreNode, AgreeProgram agreeProgram) {
    IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
    intTypeStr = prefs.getString(PreferenceConstants.PREF_INT);
    realTypeStr = prefs.getString(PreferenceConstants.PREF_REAL);
    List<MATLABIdExpr> inputs = new ArrayList<>();
    List<MATLABStatement> statements = new ArrayList<>();
    List<MATLABFunction> functions = new ArrayList<>();
    List<MATLABPersistentVarDecl> persistentVarDecl = new ArrayList<>();
    List<MATLABPort> ports = new ArrayList<>();
    LustreToMATLABExprVisitor exprVisitor = new LustreToMATLABExprVisitor();
    LustreToMATLABTypeVisitor typeVisitor = new LustreToMATLABTypeVisitor();
    // get function name
    String functionName = "check_" + lustreNode.id;
    // add record types
    for (Type type : agreeProgram.globalTypes) {
        if (type instanceof RecordType) {
            RecordType recordType = (RecordType) type;
            SortedMap<String, MATLABType> fields = new TreeMap<>(new StringNaturalOrdering());
            Iterator<Entry<String, Type>> iterator = recordType.fields.entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, Type> entry = iterator.next();
                fields.put(exprVisitor.updateName(entry.getKey(), recordType.id), entry.getValue().accept(typeVisitor));
            }
            exprVisitor.recordTypeMap.put(recordType.id, fields);
        }
    }
    // add input and output ports for subsystem to verify
    for (VarDecl inputVar : lustreNode.inputs) {
        String varName = null;
        if (!inputVar.id.equals("time")) {
            // update name
            varName = exprVisitor.updateName(inputVar.id, "");
            // add inputs
            inputs.add(new MATLABIdExpr(varName));
            // translate the Lustre expression to MATLAB expression
            // add input Ids to inputList of the exprVisitor
            // to help identify local variables
            exprVisitor.inputSet.add(inputVar.id);
            // get inputVar and type
            AgreeVar agreeVar = (AgreeVar) inputVar;
            Type type = agreeVar.type;
            if (type instanceof RecordType || type instanceof NamedType) {
                MATLABType portType = (agreeVar.type).accept(typeVisitor);
                SortedMap<String, MATLABType> fields = null;
                // get the fields if it is a RecordType
                if (type instanceof RecordType) {
                    fields = exprVisitor.recordTypeMap.get(((RecordType) type).id);
                }
                // if it is from AADL feature, get the feature instance
                if (agreeVar.featInst != null) {
                    FeatureInstance featInst = agreeVar.featInst;
                    ports.add(new MATLABPort(featInst.getName(), featInst.getDirection().getName(), portType, fields));
                } else // if it is not from AADL feature, but an eq variable from
                // AGREE
                // set them as output variables from the subsystem
                {
                    ports.add(new MATLABPort(inputVar.id, "out", portType, fields));
                }
            }
        }
    }
    // add local variable and their types
    for (VarDecl localVar : lustreNode.locals) {
        // get local var Name and Type
        exprVisitor.localVarTypeMap.put(exprVisitor.updateName(localVar.id, ""), localVar.type.accept(typeVisitor));
    }
    // translate equations to assignments
    if (!lustreNode.equations.isEmpty()) {
        for (Equation equation : lustreNode.equations) {
            // get the variable to assign
            String varId = exprVisitor.updateName(equation.lhs.get(0).id, "");
            MATLABIdExpr varToAssign = new MATLABIdExpr(varId);
            // get the type for the local variable
            // MATLABType type = exprVisitor.localVarTypeMap.get(varId);
            // translate expressions
            MATLABExpr expr = exprVisitor.visit(equation.expr);
            // conduct explicit type cast if it's a constant of double type or int type
            // no need to type cast for assignment from an input variable
            // or operations (including functions) involving known types
            MATLABTypeCastExprVisitor typeCastVisitor = new MATLABTypeCastExprVisitor();
            expr = typeCastVisitor.visit(expr);
            // add any new preVar init from exprVisitor
            Iterator<MATLABPersistentVarInit> persistentVarInitIterator = exprVisitor.persistentVarInits.iterator();
            while (persistentVarInitIterator.hasNext()) {
                MATLABPersistentVarInit persistentVarInit = persistentVarInitIterator.next();
                // add new preVar init to the statements before the assignment
                statements.add(persistentVarInit);
                // remove the new preVar init from exprVisitor
                persistentVarInitIterator.remove();
            }
            // add any new local Bus var init from exprVisitor
            Iterator<MATLABLocalBusVarInit> busVarInitIterator = exprVisitor.localBusVarInits.iterator();
            while (busVarInitIterator.hasNext()) {
                MATLABLocalBusVarInit busVarInit = busVarInitIterator.next();
                // add new local Bus var init to the statements before the assignment
                statements.add(busVarInit);
                // remove the new local Bus var init from exprVisitor
                busVarInitIterator.remove();
            }
            // add assignment
            MATLABAssignment assignment = new MATLABAssignment(varToAssign, expr);
            statements.add(assignment);
        }
    }
    // add persistentVar decl and assignments
    Iterator<Entry<String, MATLABExpr>> it = exprVisitor.persistentVarMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, MATLABExpr> pair = it.next();
        String varToAssign = pair.getKey();
        MATLABExpr expr = pair.getValue();
        statements.add(new MATLABAssignment(new MATLABIdExpr(varToAssign), expr));
        persistentVarDecl.add(new MATLABPersistentVarDecl(varToAssign));
    }
    // translate assertions
    for (Expr assertionExpr : lustreNode.assertions) {
        MATLABExpr expr = exprVisitor.visit(assertionExpr);
        // add assertions
        MATLABAssumption assumption = new MATLABAssumption(expr);
        statements.add(assumption);
    }
    // translate properties
    for (String propertyStr : lustreNode.properties) {
        propertyStr = exprVisitor.updateName(propertyStr, "");
        MATLABProperty property = new MATLABProperty(propertyStr);
        statements.add(property);
    }
    // add definitions for the functions that have been called
    for (Map.Entry<String, MATLABFunction> functionEntry : exprVisitor.functionMap.entrySet()) {
        MATLABFunction function = functionEntry.getValue();
        if (function.functionCalled) {
            functions.add(function);
        }
    }
    // Create primary function AST
    MATLABPrimaryFunction primaryFunction = new MATLABPrimaryFunction(functionName, inputs, persistentVarDecl, statements, functions, ports);
    return primaryFunction;
}
Also used : MATLABPersistentVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABPersistentVarInit) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) NamedType(jkind.lustre.NamedType) ArrayList(java.util.ArrayList) MATLABAssignment(com.rockwellcollins.atc.agree.codegen.ast.MATLABAssignment) Entry(java.util.Map.Entry) RecordType(jkind.lustre.RecordType) StringNaturalOrdering(jkind.util.StringNaturalOrdering) MATLABPersistentVarDecl(com.rockwellcollins.atc.agree.codegen.ast.MATLABPersistentVarDecl) VarDecl(jkind.lustre.VarDecl) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) LustreToMATLABExprVisitor(com.rockwellcollins.atc.agree.codegen.visitors.LustreToMATLABExprVisitor) MATLABLocalBusVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit) MATLABTypeCastExprVisitor(com.rockwellcollins.atc.agree.codegen.visitors.MATLABTypeCastExprVisitor) MATLABPersistentVarDecl(com.rockwellcollins.atc.agree.codegen.ast.MATLABPersistentVarDecl) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) LustreToMATLABTypeVisitor(com.rockwellcollins.atc.agree.codegen.visitors.LustreToMATLABTypeVisitor) MATLABPort(com.rockwellcollins.atc.agree.codegen.ast.MATLABPort) Equation(jkind.lustre.Equation) TreeMap(java.util.TreeMap) MATLABPrimaryFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABPrimaryFunction) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) MATLABAssumption(com.rockwellcollins.atc.agree.codegen.ast.MATLABAssumption) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) Expr(jkind.lustre.Expr) MATLABStatement(com.rockwellcollins.atc.agree.codegen.ast.MATLABStatement) MATLABFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABFunction) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) MATLABProperty(com.rockwellcollins.atc.agree.codegen.ast.MATLABProperty)

Example 25 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class VariableMap method addRelatedExpression.

private void addRelatedExpression(final Expr idExpr, final BinaryExpr relatedExpr) {
    Objects.requireNonNull(relatedExpr, "relatedExpr must not be null");
    final Type type = idExpr.accept(typeReconstructor);
    if (type instanceof NamedType) {
        // Only add the related expression if the expression can be used to solve the variable.
        if ((type != NamedType.BOOL && !leftOfCurrentRelatedExpressionIsBoolean) || (type == NamedType.BOOL && leftOfCurrentRelatedExpressionIsBoolean)) {
            final Variable var = getOrCreate(idExpr, (NamedType) type);
            var.relatedExpressions.add(relatedExpr);
            markVariableMapAsDirty();
        }
    }
}
Also used : Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) NamedType(jkind.lustre.NamedType)

Aggregations

Type (jkind.lustre.Type)33 NamedType (jkind.lustre.NamedType)29 RecordType (jkind.lustre.RecordType)16 ArrayList (java.util.ArrayList)12 Expr (jkind.lustre.Expr)12 IdExpr (jkind.lustre.IdExpr)11 RecordAccessExpr (jkind.lustre.RecordAccessExpr)11 ConnectionType (com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType)10 ComponentType (org.osate.aadl2.ComponentType)10 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)8 NodeCallExpr (jkind.lustre.NodeCallExpr)8 VarDecl (jkind.lustre.VarDecl)8 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)8 FeatureGroupType (org.osate.aadl2.FeatureGroupType)8 IfThenElseExpr (jkind.lustre.IfThenElseExpr)7 IntExpr (jkind.lustre.IntExpr)7 UnaryExpr (jkind.lustre.UnaryExpr)7 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)6