Search in sources :

Example 1 with AssertStatement

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

the class CreateLocalVariablesForPropertyExpressions method transform.

public static SimulationProgram transform(final SimulationProgram program) {
    final Program lustreProgram = program.getLustreProgram();
    final SimulationProgramBuilder builder = new SimulationProgramBuilder(program);
    // Build mappings between Agree Statements, expressions, and Agree Nodes
    final Map<Expr, AgreeStatement> exprToStatementMap = new HashMap<>();
    final Map<AgreeStatement, AgreeNode> agreeStatementToAgreeNodeMap = new HashMap<>();
    for (final AgreeNode agreeNode : program.getAllAgreeNodes()) {
        for (final AgreeStatement statement : agreeNode.assertions) {
            if (statement.reference instanceof AssertStatement) {
                exprToStatementMap.put(statement.expr, statement);
                agreeStatementToAgreeNodeMap.put(statement, agreeNode);
            }
        }
        for (final AgreeStatement statement : agreeNode.assumptions) {
            exprToStatementMap.put(statement.expr, statement);
            agreeStatementToAgreeNodeMap.put(statement, agreeNode);
        }
        for (final AgreeStatement statement : agreeNode.guarantees) {
            exprToStatementMap.put(statement.expr, statement);
            agreeStatementToAgreeNodeMap.put(statement, agreeNode);
        }
    }
    // Create local variables for assert statements, assumptions, and guarantees
    final ProgramBuilder lustreBuilder = new ProgramBuilder(lustreProgram).clearNodes();
    for (final Node lustreNode : lustreProgram.nodes) {
        lustreBuilder.addNode(VariableCreator.transform(lustreNode, exprToStatementMap, agreeStatementToAgreeNodeMap));
    }
    builder.setLustreProgram(lustreBuilder.build());
    return builder.build();
}
Also used : Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) CondactExpr(jkind.lustre.CondactExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) RecordExpr(jkind.lustre.RecordExpr) HashMap(java.util.HashMap) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement)

Example 2 with AssertStatement

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

the class AgreeASTBuilder method getAssertionStatements.

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

Example 3 with AssertStatement

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

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

AssertStatement (com.rockwellcollins.atc.agree.agree.AssertStatement)4 Node (jkind.lustre.Node)3 Program (jkind.lustre.Program)3 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)2 GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)2 LemmaStatement (com.rockwellcollins.atc.agree.agree.LemmaStatement)2 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)2 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)2 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)2 SimulationProgramBuilder (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder)2 HashMap (java.util.HashMap)2 BinaryExpr (jkind.lustre.BinaryExpr)2 Expr (jkind.lustre.Expr)2 IdExpr (jkind.lustre.IdExpr)2 UnaryExpr (jkind.lustre.UnaryExpr)2 VarDecl (jkind.lustre.VarDecl)2 EObject (org.eclipse.emf.ecore.EObject)2 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)1