Search in sources :

Example 6 with GuaranteeStatement

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

the class RenamingVisitor method getReferenceStr.

private String getReferenceStr(AgreeVar var) {
    String prefix = getCategory(rootInstance, var);
    if (prefix == null) {
        return null;
    }
    if (var.id.endsWith(AgreeASTBuilder.clockIDSuffix)) {
        return null;
    }
    String seperator = (prefix == "" ? "" : ".");
    EObject reference = var.reference;
    String suffix = "";
    if (var.id.endsWith(AgreeASTBuilder.eventSuffix + AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
        suffix = "._EVENT_._LATCHED_";
    } else if (var.id.endsWith(AgreeASTBuilder.eventSuffix)) {
        suffix = "._EVENT_";
    } else if (var.id.endsWith(AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
        suffix = "._LATCHED_";
    }
    if (reference instanceof GuaranteeStatement) {
        String id = ((GuaranteeStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return id + ((GuaranteeStatement) reference).getStr();
    } else if (reference instanceof AssumeStatement) {
        String id = ((AssumeStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return prefix + " assume: " + id + ((AssumeStatement) reference).getStr();
    } else if (reference instanceof LemmaStatement) {
        String id = ((LemmaStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return prefix + " lemma: " + id + ((LemmaStatement) reference).getStr();
    } else if (reference instanceof ReachableStatement) {
        renaming.addInvertedProperty(var.id);
        String id = ((ReachableStatement) reference).getName();
        if (id == null || id.isEmpty()) {
            id = "";
        } else {
            id = "[" + id + "] ";
        }
        return prefix + " reachable: " + id + ((ReachableStatement) reference).getStr();
    } else if (reference instanceof AssertStatement) {
        throw new AgreeException("We really didn't expect to see an assert statement here");
    } else if (reference instanceof Arg) {
        return prefix + seperator + ((Arg) reference).getName() + suffix;
    } else if (reference instanceof EqStatement) {
        return prefix + "eq " + String.join(", ", ((EqStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
    } else if (reference instanceof InputStatement) {
        return prefix + "agree_input " + String.join(", ", ((InputStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
    } else if (reference instanceof DataPort) {
        return prefix + seperator + ((DataPort) reference).getName() + suffix;
    } else if (reference instanceof EventPort) {
        return prefix + seperator + ((EventPort) reference).getName() + suffix;
    } else if (reference instanceof EventDataPort) {
        return prefix + seperator + ((EventDataPort) reference).getName() + suffix;
    } else if (reference instanceof FeatureGroup) {
        String featName = ((FeatureGroup) reference).getName();
        String varName = var.toString();
        featName = varName.substring(varName.indexOf(featName)).replace("__", ".");
        return prefix + seperator + featName;
    } else if (reference instanceof PropertyStatement) {
        return prefix + seperator + ((PropertyStatement) reference).getName();
    } else if (reference instanceof Property) {
        return "AADL property " + ((Property) reference).getName();
    } else if (reference instanceof GetPropertyExpr) {
        return "Get_Property(" + ((GetPropertyExpr) reference).getContainingClassifier().getName() + ", " + ((Property) ((GetPropertyExpr) reference).getProp()).getName() + ")";
    } else if (reference instanceof ComponentType || reference instanceof ComponentImplementation || reference instanceof SystemImplementation) {
        if (var.id.equals(LustreAstBuilder.assumeHistSufix)) {
            return "Subcomponent Assumptions";
        }
        return "Result";
    } else if (reference instanceof AgreeStatement) {
        return prefix + reference.toString();
    }
    throw new AgreeException("Unhandled reference type: '" + reference.getClass().getName() + "'");
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) AstIterVisitor(jkind.lustre.visitors.AstIterVisitor) Arg(com.rockwellcollins.atc.agree.agree.Arg) Program(jkind.lustre.Program) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) SystemImplementation(org.osate.aadl2.SystemImplementation) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Function(jkind.lustre.Function) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) ComponentType(org.osate.aadl2.ComponentType) SigType(com.rockwellcollins.atc.agree.analysis.AgreeLayout.SigType) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) PropertyStatement(com.rockwellcollins.atc.agree.agree.PropertyStatement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) FeatureGroup(org.osate.aadl2.FeatureGroup) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) AgreeInlineLatchedConnections(com.rockwellcollins.atc.agree.analysis.ast.visitors.AgreeInlineLatchedConnections) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) ReachableStatement(com.rockwellcollins.atc.agree.agree.ReachableStatement) EObject(org.eclipse.emf.ecore.EObject) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Collectors(java.util.stream.Collectors) EventPort(org.osate.aadl2.EventPort) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) LustreAstBuilder(com.rockwellcollins.atc.agree.analysis.translation.LustreAstBuilder) Node(jkind.lustre.Node) DataPort(org.osate.aadl2.DataPort) Property(org.osate.aadl2.Property) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) VarDecl(jkind.lustre.VarDecl) EventDataPort(org.osate.aadl2.EventDataPort) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) ComponentImplementation(org.osate.aadl2.ComponentImplementation) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) FeatureGroup(org.osate.aadl2.FeatureGroup) ComponentType(org.osate.aadl2.ComponentType) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EventPort(org.osate.aadl2.EventPort) SystemImplementation(org.osate.aadl2.SystemImplementation) EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement) PropertyStatement(com.rockwellcollins.atc.agree.agree.PropertyStatement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) EventDataPort(org.osate.aadl2.EventDataPort) Property(org.osate.aadl2.Property) ReachableStatement(com.rockwellcollins.atc.agree.agree.ReachableStatement)

Example 7 with GuaranteeStatement

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

the class AgreeMenuListener method addResultsLinkingMenu.

private void addResultsLinkingMenu(IMenuManager manager, AnalysisResult result) {
    if (result instanceof PropertyResult) {
        PropertyResult pr = (PropertyResult) result;
        Map<String, EObject> refMap = linker.getReferenceMap(pr.getParent());
        EObject property = refMap.get(pr.getName());
        if (property instanceof GuaranteeStatement) {
            manager.add(createHyperlinkAction("Go To Guarantee", property));
        }
        if (property instanceof LemmaStatement) {
            manager.add(createHyperlinkAction("Go To Lemma", property));
        }
        if (property instanceof AssumeStatement) {
            manager.add(createHyperlinkAction("Go To Assumption", property));
        }
        if (property instanceof CallExpr) {
            manager.add(createHyperlinkAction("Go To Node Call", property));
        }
        if (property instanceof AgreeStatement) {
            AgreeStatement statement = (AgreeStatement) property;
            if (statement.reference instanceof AgreePattern) {
                AgreePattern pattern = (AgreePattern) statement.reference;
                manager.add(createHyperlinkAction("Go To Pattern", pattern.reference));
            }
        }
    }
}
Also used : GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) EObject(org.eclipse.emf.ecore.EObject) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) PropertyResult(jkind.api.results.PropertyResult) AgreePattern(com.rockwellcollins.atc.agree.analysis.realtime.AgreePattern)

Example 8 with GuaranteeStatement

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

the class CreateSimulationProperties method transform.

public static SimulationProgram transform(final SimulationProgram program) {
    final Program lustreProgram = program.getLustreProgram();
    if (lustreProgram.nodes.size() != 1) {
        throw new IllegalArgumentException("Only lustre programs with exactly one node are supported");
    }
    final SimulationProgramBuilder builder = new SimulationProgramBuilder(program);
    final Node mainNode = lustreProgram.getMainNode();
    // Build a new main node which includes support statements
    final NodeBuilder lustreNodeBuilder = new NodeBuilder(mainNode);
    // Create simulation properties for each local variable that references a lemma, assume, guarantee, or assert statement
    lustreNodeBuilder.clearIvc();
    final Map<String, SimulationProperty> idToSimulationPropertyMap = new HashMap<>();
    // Create a mapping from the component instance/variable reference to a collection of Lustre Id's that will be used to create the simulation properties
    final Map<ComponentInstance, Map<EObject, Collection<String>>> componentInstanceToReferenceToVarIdMap = new HashMap<>();
    for (final VarDecl local : mainNode.locals) {
        if (local instanceof AgreeVar) {
            final AgreeVar var = (AgreeVar) local;
            if (var.reference instanceof LemmaStatement || var.reference instanceof AssumeStatement || var.reference instanceof GuaranteeStatement || var.reference instanceof AssertStatement) {
                final boolean createSimProp = (!(var.reference instanceof AssumeStatement) || var.compInst == var.compInst.getSystemInstance()) || var instanceof SimulationPropertyVar;
                if (createSimProp) {
                    Map<EObject, Collection<String>> referenceToVarIdMap = componentInstanceToReferenceToVarIdMap.get(var.compInst);
                    if (referenceToVarIdMap == null) {
                        referenceToVarIdMap = new HashMap<>();
                        componentInstanceToReferenceToVarIdMap.put(var.compInst, referenceToVarIdMap);
                    }
                    Collection<String> varIds = referenceToVarIdMap.get(var.reference);
                    if (varIds == null) {
                        varIds = new HashSet<>();
                        referenceToVarIdMap.put(var.reference, varIds);
                    }
                    varIds.add(var.id);
                }
            }
        }
    }
    // Create the simulation properties.
    // A single simulation property will be created for each component instance, reference combination.
    int propertyIndex = 0;
    for (final Entry<ComponentInstance, Map<EObject, Collection<String>>> componentInstanceToReferenceToVarIdMapEntry : componentInstanceToReferenceToVarIdMap.entrySet()) {
        final ComponentInstance propComponentInstance = componentInstanceToReferenceToVarIdMapEntry.getKey();
        for (Entry<EObject, Collection<String>> referenceToVarIdsEntry : componentInstanceToReferenceToVarIdMapEntry.getValue().entrySet()) {
            final EObject propReference = referenceToVarIdsEntry.getKey();
            final Collection<String> propLustreIds = referenceToVarIdsEntry.getValue();
            final String propertyDesc = getDescription(propComponentInstance, propReference);
            final String enablementVariableId;
            // Only properties which cause the simulation to be halted may be disabled.
            // That is: only top-level assumptions and non-top-level guarantees may be disabled
            final boolean disableable = (propReference instanceof GuaranteeStatement && propComponentInstance != propComponentInstance.getSystemInstance()) || (propReference instanceof AssumeStatement && propComponentInstance == propComponentInstance.getSystemInstance());
            if (disableable) {
                enablementVariableId = propertyEnablementPrefix + propertyIndex;
                lustreNodeBuilder.addLocal(new VarDecl(enablementVariableId, NamedType.BOOL));
            } else {
                enablementVariableId = null;
            }
            final SimulationProperty simProp = new SimulationProperty(propLustreIds, propertyDesc, propReference, enablementVariableId);
            builder.addSimulationProperty(simProp);
            propertyIndex++;
            for (final String propLustreId : propLustreIds) {
                idToSimulationPropertyMap.put(propLustreId, simProp);
                lustreNodeBuilder.addIvc(propLustreId);
            }
        }
    }
    // Edit main node to make simulation properties inside of assertions to be disableable
    final AstMapVisitor propertyVarDisableTransformation = new AstMapVisitor() {

        @Override
        public Expr visit(final IdExpr e) {
            final SimulationProperty simProp = idToSimulationPropertyMap.get(e.id);
            if (simProp != null && simProp.getEnablementVariableId() != null) {
                return new BinaryExpr(new UnaryExpr(UnaryOp.NOT, new IdExpr(simProp.getEnablementVariableId())), BinaryOp.OR, e);
            }
            return super.visit(e);
        }

        @Override
        public Equation visit(final Equation e) {
            // Don't transform the equations for simulation properties
            if (e.lhs.size() == 1 && idToSimulationPropertyMap.containsKey(e.lhs.get(0))) {
                return e;
            }
            return super.visit(e);
        }
    };
    // Transform assertions and equations
    lustreNodeBuilder.clearAssertions();
    for (final Expr assertion : mainNode.assertions) {
        lustreNodeBuilder.addAssertion(assertion.accept(propertyVarDisableTransformation));
    }
    lustreNodeBuilder.clearEquations();
    for (final Equation eq : mainNode.equations) {
        lustreNodeBuilder.addEquation((Equation) eq.accept(propertyVarDisableTransformation));
    }
    // Build a new program with the new main node
    final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(lustreProgram);
    lustreProgramBuilder.clearNodes();
    lustreProgramBuilder.addNode(lustreNodeBuilder.build());
    builder.setLustreProgram(lustreProgramBuilder.build());
    return builder.build();
}
Also used : HashMap(java.util.HashMap) INode(org.eclipse.xtext.nodemodel.INode) Node(jkind.lustre.Node) NodeBuilder(jkind.lustre.builders.NodeBuilder) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) VarDecl(jkind.lustre.VarDecl) EObject(org.eclipse.emf.ecore.EObject) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SimulationProperty(edu.uah.rsesc.aadlsimulator.agree.SimulationProperty) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) UnaryExpr(jkind.lustre.UnaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) AstMapVisitor(jkind.lustre.visitors.AstMapVisitor) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)8 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)6 EObject (org.eclipse.emf.ecore.EObject)5 LemmaStatement (com.rockwellcollins.atc.agree.agree.LemmaStatement)4 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)3 PropertyResult (jkind.api.results.PropertyResult)3 AssertStatement (com.rockwellcollins.atc.agree.agree.AssertStatement)2 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)2 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)2 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)2 AgreeRenaming (com.rockwellcollins.atc.agree.analysis.AgreeRenaming)2 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)2 Node (jkind.lustre.Node)2 Program (jkind.lustre.Program)2 VarDecl (jkind.lustre.VarDecl)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)1 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)1