Search in sources :

Example 41 with AgreeException

use of com.rockwellcollins.atc.agree.analysis.AgreeException 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 42 with AgreeException

use of com.rockwellcollins.atc.agree.analysis.AgreeException 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 43 with AgreeException

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

the class AgreeASTMapVisitor method visit.

@Override
public AgreeConnection visit(AgreeConnection e) {
    if (e instanceof AgreeAADLConnection) {
        AgreeAADLConnection aadlConn = (AgreeAADLConnection) e;
        AgreeNode sourceNode = null;
        if (aadlConn.sourceNode != null) {
            sourceNode = visitedNodes.get(aadlConn.sourceNode.compInst);
        }
        AgreeNode destinationNode = null;
        if (aadlConn.destinationNode != null) {
            destinationNode = visitedNodes.get(aadlConn.destinationNode.compInst);
        }
        AgreeVar sourVar = visit(aadlConn.sourceVarName);
        AgreeVar destVar = visit(aadlConn.destinationVarName);
        ConnectionType type = aadlConn.type;
        boolean latched = aadlConn.latched;
        boolean delayed = aadlConn.delayed;
        EObject reference = aadlConn.reference;
        return new AgreeAADLConnection(sourceNode, destinationNode, sourVar, destVar, type, latched, delayed, reference);
    } else if (e instanceof AgreeOverriddenConnection) {
        AgreeOverriddenConnection overriddenCon = (AgreeOverriddenConnection) e;
        AgreeStatement statement = visit(overriddenCon.statement);
        return new AgreeOverriddenConnection(statement, overriddenCon.aadlConn);
    }
    throw new AgreeException("Unhandled Agree connection type " + e.getClass());
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) AgreeAADLConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection) EObject(org.eclipse.emf.ecore.EObject) AgreeOverriddenConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeOverriddenConnection) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 44 with AgreeException

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

the class AgreeMenuListener method addViewSupportConsole.

private IAction addViewSupportConsole(String text, IMenuManager manager, AnalysisResult result) {
    return new Action(text) {

        @Override
        public void run() {
            Map<String, EObject> tempRefMap = linker.getReferenceMap(result.getParent());
            if (tempRefMap == null) {
                tempRefMap = linker.getReferenceMap(result);
            }
            final Map<String, EObject> refMap = tempRefMap;
            final MessageConsole console = findConsole("Support");
            Renaming tempRenaming = linker.getRenaming(result);
            while (tempRenaming == null) {
                AnalysisResult parent = result.getParent();
                if (parent == null) {
                    throw new AgreeException("Problem finding renaming");
                }
                tempRenaming = linker.getRenaming(parent);
            }
            final Renaming renaming = tempRenaming;
            showConsole(console);
            console.clearConsole();
            if (patternListener != null) {
                console.removePatternMatchListener(patternListener);
            }
            patternListener = new AgreePatternListener(refMap);
            console.addPatternMatchListener(patternListener);
            new Thread(() -> {
                if (renaming instanceof AgreeRenaming) {
                    writeIvcResult(result, console, (AgreeRenaming) renaming);
                }
            }).start();
        }
    };
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) MessageConsole(org.eclipse.ui.console.MessageConsole) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) EObject(org.eclipse.emf.ecore.EObject) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AnalysisResult(jkind.api.results.AnalysisResult) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) Renaming(jkind.api.results.Renaming)

Example 45 with AgreeException

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

the class LustreAstBuilder method getClockExpr.

protected static Expr getClockExpr(AgreeNode agreeNode, AgreeNode subNode) {
    IdExpr clockId = new IdExpr(subNode.clockVar.id);
    switch(agreeNode.timing) {
        case SYNC:
            return new BoolExpr(true);
        case ASYNC:
            return clockId;
        case LATCHED:
            Expr preClock = new UnaryExpr(UnaryOp.PRE, clockId);
            Expr notClock = new UnaryExpr(UnaryOp.NOT, clockId);
            Expr andExpr = new BinaryExpr(preClock, BinaryOp.AND, notClock);
            Expr clockExpr = new BinaryExpr(new BoolExpr(false), BinaryOp.ARROW, andExpr);
            return clockExpr;
        default:
            throw new AgreeException("unhandled timing type: '" + agreeNode.timing + "");
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) UnaryExpr(jkind.lustre.UnaryExpr)

Aggregations

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