Search in sources :

Example 51 with AgreeVar

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

the class LustreCondactNodeVisitor method addInitEq.

private static void addInitEq(NodeBuilder builder) {
    builder.addLocal(new AgreeVar(initVarName, NamedType.BOOL, null));
    builder.addEquation(equation("initVar = clk and (true -> not pre(ticked));", to("initVar", initVarName), to("ticked", tickedVarName), to("clk", clockVarName)));
}
Also used : AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 52 with AgreeVar

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

the class LustreCondactNodeVisitor method translate.

public static Node translate(AgreeProgram agreeProgram, AgreeNode agreeNode, Node node) {
    if (node.outputs.size() != 1) {
        throw new AgreeException("We expect that this node only has a single output representing " + "all constraints for the contract");
    }
    LustreCondactNodeVisitor visitor = new LustreCondactNodeVisitor(agreeProgram, node);
    NodeBuilder builder = new NodeBuilder(node);
    builder.clearEquations();
    builder.addInput(new AgreeVar(clockVarName, NamedType.BOOL, null));
    addTickedEq(builder);
    addInitEq(builder);
    Expr holdExpr = new BoolExpr(true);
    // make clock hold exprs
    for (AgreeVar var : agreeNode.outputs) {
        Expr varId = new IdExpr(var.id);
        Expr preVar = new UnaryExpr(UnaryOp.PRE, varId);
        holdExpr = new BinaryExpr(holdExpr, BinaryOp.AND, new BinaryExpr(varId, BinaryOp.EQUAL, preVar));
    }
    holdExpr = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, holdExpr);
    for (int i = 0; i < agreeNode.assumptions.size(); i++) {
        Expr varId = new IdExpr(LustreAstBuilder.assumeSuffix + i);
        Expr preVar = new UnaryExpr(UnaryOp.PRE, varId);
        preVar = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, preVar);
        holdExpr = new BinaryExpr(holdExpr, BinaryOp.AND, new BinaryExpr(varId, BinaryOp.EQUAL, preVar));
    }
    holdExpr = expr("(not clk => holdExpr)", to("clk", clockVarName), to("holdExpr", holdExpr));
    // make the constraint for the initial outputs
    Expr initConstr = expr("not ticked => initExpr", to("ticked", tickedVarName), to("initExpr", agreeNode.initialConstraint));
    // re-write the old expression using the visitor
    for (Equation eq : node.equations) {
        if (eq.lhs.size() != 1) {
            throw new AgreeException("we expect that all eqs have a single lhs now");
        }
        IdExpr var = eq.lhs.get(0);
        boolean isLocal = false;
        for (VarDecl local : node.locals) {
            if (local.id.equals(var.id)) {
                isLocal = true;
                break;
            }
        }
        if (isLocal) {
            Expr newExpr = eq.expr.accept(visitor);
            newExpr = new IfThenElseExpr(new IdExpr(clockVarName), newExpr, new UnaryExpr(UnaryOp.PRE, var));
            builder.addEquation(new Equation(eq.lhs, newExpr));
        } else {
            // this is the only output
            Expr newExpr = eq.expr.accept(visitor);
            newExpr = new BinaryExpr(new IdExpr(clockVarName), BinaryOp.IMPLIES, newExpr);
            builder.addEquation(new Equation(eq.lhs, new BinaryExpr(initConstr, BinaryOp.AND, new BinaryExpr(holdExpr, BinaryOp.AND, newExpr))));
        }
    }
    // this var equations should be populated by the visitor call above
    builder.addEquations(visitor.stateVarEqs);
    builder.addLocals(visitor.stateVars);
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) VarDecl(jkind.lustre.VarDecl) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 53 with AgreeVar

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

the class LustreCondactNodeVisitor method visit.

@Override
public Expr visit(UnaryExpr e) {
    if (e.op == UnaryOp.PRE) {
        IdExpr stateVarId = stateVarMap.get(e.toString());
        if (stateVarId != null) {
            return stateVarId;
        }
        stateVarId = new IdExpr(statVarPrefix + numStateVars++);
        stateVarMap.put(e.toString(), stateVarId);
        Expr stateVarExpr = new UnaryExpr(UnaryOp.PRE, e.expr.accept(this));
        stateVarExpr = expr("if clk then stateVarExpr else (pre stateVar)", to("stateVar", stateVarId), to("stateVarExpr", stateVarExpr), to("clk", clockVarName));
        stateVars.add(new AgreeVar(stateVarId.id, e.accept(typeReconstructor), null));
        stateVarEqs.add(new Equation(stateVarId, stateVarExpr));
        return stateVarId;
    }
    return new UnaryExpr(e.op, e.expr.accept(this));
}
Also used : IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) Equation(jkind.lustre.Equation) UnaryExpr(jkind.lustre.UnaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 54 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar 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 55 with AgreeVar

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

the class AgreePatternTranslator method translateNode.

private AgreeNode translateNode(AgreeNode node, boolean isTopNode) {
    AgreeNodeBuilder builder = new AgreeNodeBuilder(node);
    // this has to be done first because the pattern translation
    // for guarantees/lemmas/assumptions add additional assertions
    builder.clearAssertions();
    createTimeFunctions(node, builder);
    for (AgreeStatement statement : node.assertions) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, false);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addAssertion(statement);
    }
    builder.clearGuarantees();
    for (AgreeStatement statement : node.guarantees) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, isTopNode);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addGuarantee(statement);
    }
    builder.clearLemmas();
    for (AgreeStatement statement : node.lemmas) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, isTopNode);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addLemma(statement);
    }
    builder.clearAssumptions();
    for (AgreeStatement statement : node.assumptions) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, !isTopNode);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addAssumption(statement);
    }
    builder.clearSubNodes();
    for (AgreeNode subNode : node.subNodes) {
        builder.addSubNode(new AgreePatternTranslator().translateNode(subNode, false));
    }
    builder.addInput(new AgreeVar(timeExpr.id, NamedType.REAL, null, node.compInst, null));
    return builder.build();
}
Also used : 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) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)69 IdExpr (jkind.lustre.IdExpr)49 Expr (jkind.lustre.Expr)45 NodeCallExpr (jkind.lustre.NodeCallExpr)42 BinaryExpr (jkind.lustre.BinaryExpr)41 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)39 BoolExpr (jkind.lustre.BoolExpr)38 UnaryExpr (jkind.lustre.UnaryExpr)37 ArrayList (java.util.ArrayList)28 IfThenElseExpr (jkind.lustre.IfThenElseExpr)25 VarDecl (jkind.lustre.VarDecl)19 Equation (jkind.lustre.Equation)15 RealExpr (jkind.lustre.RealExpr)15 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)14 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 IntExpr (jkind.lustre.IntExpr)13 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)12 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 NodeBuilder (jkind.lustre.builders.NodeBuilder)11 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)9