Search in sources :

Example 36 with AgreeException

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

the class AgreeASTBuilder method getConnectionsFromInstances.

private List<AgreeAADLConnection> getConnectionsFromInstances(EList<ConnectionInstance> connectionInstances, ComponentInstance compInst, List<AgreeNode> subnodes, boolean latched) {
    List<AgreeAADLConnection> result = new ArrayList<>();
    for (ConnectionInstance connectionInstance : connectionInstances) {
        boolean isDelayed = isDelayed(connectionInstance, compInst);
        for (ConnectionReference connectionReference : connectionInstance.getConnectionReferences()) {
            ConnectionInstanceEnd sourceEndInstance = connectionReference.getSource();
            ConnectionInstanceEnd destinationEndInstance = connectionReference.getDestination();
            ComponentInstance sourceComponentInstance = sourceEndInstance.getComponentInstance();
            ComponentInstance destinationComponentInstance = destinationEndInstance.getComponentInstance();
            if (!compInst.equals(sourceComponentInstance) && !compInst.getComponentInstances().contains(sourceComponentInstance)) {
                // This connection reference connects to component instances not germane to this level of hierarchy
                continue;
            }
            if (!compInst.equals(destinationComponentInstance) && !compInst.getComponentInstances().contains(destinationComponentInstance)) {
                // This connection reference connects to component instances not germane to this level of hierarchy
                continue;
            }
            // make connections only to subcomponents that have annexes
            if (!compInst.equals(sourceComponentInstance) && compInst.getAllComponentInstances().contains(sourceComponentInstance)) {
                if (!AgreeUtils.containsTransitiveAgreeAnnex(sourceComponentInstance, isMonolithic)) {
                    continue;
                }
            }
            if (!compInst.equals(destinationComponentInstance) && compInst.getAllComponentInstances().contains(destinationComponentInstance)) {
                if (!AgreeUtils.containsTransitiveAgreeAnnex(destinationComponentInstance, isMonolithic)) {
                    continue;
                }
            }
            AgreeNode sourceNode = agreeNodeFromNamedEl(subnodes, sourceComponentInstance);
            AgreeNode destinationNode = agreeNodeFromNamedEl(subnodes, destinationComponentInstance);
            ConnectionEnd sourceConnectionEnd;
            if (sourceEndInstance instanceof FeatureInstance) {
                sourceConnectionEnd = ((FeatureInstance) sourceEndInstance).getFeature();
            } else {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects from a " + sourceEndInstance.getClass().getName());
                continue;
            }
            ConnectionEnd destinationConnectionEnd;
            if (destinationEndInstance instanceof FeatureInstance) {
                destinationConnectionEnd = ((FeatureInstance) destinationEndInstance).getFeature();
            } else {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a " + destinationEndInstance.getClass().getName());
                continue;
            }
            // TODO: Paranoia? Is this redundant with the previous lines?
            if (sourceConnectionEnd instanceof DataSubcomponent || destinationConnectionEnd instanceof DataSubcomponent) {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a data subcomponent");
                continue;
            }
            // Handle prefixing elements of feature groups
            String sourcePrefix = null;
            if (sourceConnectionEnd instanceof FeatureGroup) {
                sourcePrefix = sourceConnectionEnd.getName();
            }
            String destinationPrefix = null;
            if (destinationConnectionEnd instanceof FeatureGroup) {
                destinationPrefix = destinationConnectionEnd.getName();
            }
            List<AgreeVar> sourceVars = getAgreePortNames(sourceConnectionEnd, sourcePrefix, sourceNode == null ? null : sourceNode.compInst);
            List<AgreeVar> destinationVars = getAgreePortNames(destinationConnectionEnd, destinationPrefix, destinationNode == null ? null : destinationNode.compInst);
            if (sourceVars.size() != destinationVars.size()) {
                throw new AgreeException("The number of AGREE variables differ for connection '" + connectionInstance.getQualifiedName() + "'. Do the types of the source and destination differ? Perhaps one is an implementation and the other is a type?");
            }
            for (int i = 0; i < sourceVars.size(); i++) {
                AgreeVar sourceVar = sourceVars.get(i);
                AgreeVar destinationVar = destinationVars.get(i);
                if (!matches((ConnectionEnd) sourceVar.reference, (ConnectionEnd) destinationVar.reference)) {
                    AgreeLogger.logWarning("Connection '" + connectionInstance.getQualifiedName() + "' has ports '" + sourceVar.id.replace(dotChar, ".") + "' and '" + destinationVar.id.replace(dotChar, ".") + "' of differing type");
                    continue;
                }
                if (!sourceVar.type.equals(destinationVar.type)) {
                    throw new AgreeException("Type mismatch during connection generation");
                }
                ConnectionType connType;
                if (sourceVar.id.endsWith(eventSuffix)) {
                    connType = ConnectionType.EVENT;
                } else {
                    connType = ConnectionType.DATA;
                }
                AgreeAADLConnection agreeConnection = new AgreeAADLConnection(sourceNode, destinationNode, sourceVar, destinationVar, connType, latched, isDelayed, connectionReference.getConnection());
                result.add(agreeConnection);
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ConnectionEnd(org.osate.aadl2.ConnectionEnd) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 37 with AgreeException

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

the class AgreeASTBuilder method filterConnections.

private List<AgreeConnection> filterConnections(List<AgreeAADLConnection> aadlConnections, List<AgreeOverriddenConnection> userDefinedConections) {
    List<AgreeConnection> conns = new ArrayList<>();
    // connection twice
    for (AgreeAADLConnection aadlConn : aadlConnections) {
        EObject aadlRef = aadlConn.reference;
        AgreeConnection replacementConn = aadlConn;
        for (AgreeOverriddenConnection agreeConn : userDefinedConections) {
            EObject agreeRef = agreeConn.aadlConn;
            if (aadlRef == agreeRef) {
                replacementConn = agreeConn;
                break;
            }
        }
        if (!conns.contains(replacementConn)) {
            conns.add(replacementConn);
        }
    }
    // throw errors for non-override connections with multiple fanin
    Set<AgreeVar> destinations = new HashSet<>();
    for (AgreeConnection conn : conns) {
        if (conn instanceof AgreeAADLConnection) {
            AgreeAADLConnection aadlConn = (AgreeAADLConnection) conn;
            if (!destinations.add(aadlConn.destinationVarName)) {
                String message = "Multiple connections to feature '" + (aadlConn.reference instanceof PortConnection ? ((PortConnection) aadlConn.reference).getDestination().getConnectionEnd().getQualifiedName() : aadlConn.destinationVarName) + "'. Remove the additional AADL connections or override them with a connection statement " + "in the AGREE annex.";
                throw new AgreeException(message);
            }
        }
    }
    return conns;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) PortConnection(org.osate.aadl2.PortConnection) HashSet(java.util.HashSet)

Example 38 with AgreeException

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

the class VerifyHandler method wrapVerificationResult.

protected void wrapVerificationResult(ComponentInstance si, CompositeAnalysisResult wrapper) {
    AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, isMonolithic());
    // generate different lustre depending on which model checker we are
    // using
    Program program;
    if (AgreeUtils.usingKind2()) {
        if (!isMonolithic()) {
            throw new AgreeException("Kind2 now only supports monolithic verification");
        }
        program = LustreContractAstBuilder.getContractLustreProgram(agreeProgram);
    } else {
        program = LustreAstBuilder.getAssumeGuaranteeLustreProgram(agreeProgram);
    }
    List<Pair<String, Program>> consistencies = LustreAstBuilder.getConsistencyChecks(agreeProgram);
    wrapper.addChild(createVerification("Contract Guarantees", si, program, agreeProgram, AnalysisType.AssumeGuarantee));
    for (Pair<String, Program> consistencyAnalysis : consistencies) {
        wrapper.addChild(createVerification(consistencyAnalysis.getFirst(), si, consistencyAnalysis.getSecond(), agreeProgram, AnalysisType.Consistency));
    }
}
Also used : Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Pair(org.eclipse.xtext.util.Pair)

Example 39 with AgreeException

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

the class VerifyHandler method createVerification.

private AnalysisResult createVerification(String resultName, ComponentInstance compInst, Program lustreProgram, AgreeProgram agreeProgram, AnalysisType analysisType) {
    // ///////
    // Logger logger = Logger.getLogger("MyLog");
    // FileHandler fh;
    // try {
    // This block configure the logger with handler and formatter
    // fh = new FileHandler("/home/thomas/zzz.log");
    // logger.addHandler(fh);
    // SimpleFormatter formatter = new SimpleFormatter();
    // fh.setFormatter(formatter);
    // logger.info("Agree Program:");
    // AgreeASTPrettyprinter pp = new AgreeASTPrettyprinter();
    // pp.visit(agreeProgram);
    // logger.info(pp.toString());
    // } catch (SecurityException ex) {
    // ex.printStackTrace();
    // }
    // catch (IOException ex) {
    // ex.printStackTrace();
    // }
    // //////////////
    AgreeAutomaterRegistry aAReg = (AgreeAutomaterRegistry) ExtensionRegistry.getRegistry(ExtensionRegistry.AGREE_AUTOMATER_EXT_ID);
    List<AgreeAutomater> automaters = aAReg.getAgreeAutomaters();
    AgreeRenaming renaming = new AgreeRenaming();
    AgreeLayout layout = new AgreeLayout();
    Node mainNode = null;
    for (Node node : lustreProgram.nodes) {
        if (node.id.equals(lustreProgram.main)) {
            mainNode = node;
            break;
        }
    }
    if (mainNode == null) {
        throw new AgreeException("Could not find main lustre node after translation");
    }
    List<String> properties = new ArrayList<>();
    RenamingVisitor.addRenamings(lustreProgram, renaming, compInst, layout);
    addProperties(renaming, properties, mainNode, agreeProgram);
    for (AgreeAutomater aa : automaters) {
        renaming = aa.rename(renaming);
        layout = aa.transformLayout(layout);
    }
    JKindResult result;
    switch(analysisType) {
        case Consistency:
            result = new ConsistencyResult(resultName, mainNode.properties, Collections.singletonList(true), renaming);
            break;
        case Realizability:
            result = new JRealizabilityResult(resultName, renaming);
            break;
        case AssumeGuarantee:
            final Set<String> invertedProperties = renaming.getInvertedProperties();
            List<Boolean> invertedPropertyMask = mainNode.properties.stream().map(p -> invertedProperties.contains(p)).collect(Collectors.toList());
            result = new JKindResult(resultName, properties, invertedPropertyMask, renaming);
            break;
        default:
            throw new AgreeException("Unhandled Analysis Type");
    }
    queue.add(result);
    ComponentImplementation compImpl = AgreeUtils.getInstanceImplementation(compInst);
    linker.setProgram(result, lustreProgram);
    linker.setComponent(result, compImpl);
    linker.setContract(result, getContract(compImpl));
    linker.setLayout(result, layout);
    linker.setReferenceMap(result, renaming.getRefMap());
    linker.setLog(result, AgreeLogger.getLog());
    linker.setRenaming(result, renaming);
    // System.out.println(program);
    return result;
}
Also used : AnnexUtil(org.osate.annexsupport.AnnexUtil) Element(org.osate.aadl2.Element) Program(jkind.lustre.Program) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AnalysisResult(jkind.api.results.AnalysisResult) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) IStatus(org.eclipse.core.runtime.IStatus) AgreeAutomaterRegistry(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry) Classifier(org.osate.aadl2.Classifier) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) ComponentType(org.osate.aadl2.ComponentType) RenamingVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.RenamingVisitor) IViewPart(org.eclipse.ui.IViewPart) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) PrintWriter(java.io.PrintWriter) SystemInstance(org.osate.aadl2.instance.SystemInstance) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) AadlPackage(org.osate.aadl2.AadlPackage) PreferencesUtil(com.rockwellcollins.atc.agree.analysis.preferences.PreferencesUtil) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LustreAstBuilder(com.rockwellcollins.atc.agree.analysis.translation.LustreAstBuilder) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Node(jkind.lustre.Node) List(java.util.List) AgreeUtils(com.rockwellcollins.atc.agree.analysis.AgreeUtils) JRealizabilityApi(jkind.api.JRealizabilityApi) Queue(java.util.Queue) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeAutomater(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater) ExtensionRegistry(com.rockwellcollins.atc.agree.analysis.extentions.ExtensionRegistry) Dialog(org.osate.ui.dialogs.Dialog) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) AgreePackage(com.rockwellcollins.atc.agree.agree.AgreePackage) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) AgreeSubclause(com.rockwellcollins.atc.agree.agree.AgreeSubclause) Activator(com.rockwellcollins.atc.agree.analysis.Activator) LustreContractAstBuilder(com.rockwellcollins.atc.agree.analysis.translation.LustreContractAstBuilder) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) HashMap(java.util.HashMap) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) AtomicReference(java.util.concurrent.atomic.AtomicReference) Message(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter.Message) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Pair(org.eclipse.xtext.util.Pair) AgreeResultsLinker(com.rockwellcollins.atc.agree.analysis.views.AgreeResultsLinker) JKindResult(jkind.api.results.JKindResult) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeLogger(com.rockwellcollins.atc.agree.analysis.AgreeLogger) AgreeResultsView(com.rockwellcollins.atc.agree.analysis.views.AgreeResultsView) KindApi(jkind.api.KindApi) JRealizabilityResult(jkind.api.results.JRealizabilityResult) Shell(org.eclipse.swt.widgets.Shell) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) JKindException(jkind.JKindException) StringWriter(java.io.StringWriter) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) JKindApi(jkind.api.JKindApi) AgreeFileUtil(com.rockwellcollins.atc.agree.analysis.saving.AgreeFileUtil) QueuingAnalysisErrorReporter(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter) PreferenceConstants(com.rockwellcollins.atc.agree.analysis.preferences.PreferenceConstants) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AnnexSubclause(org.osate.aadl2.AnnexSubclause) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) ComponentImplementation(org.osate.aadl2.ComponentImplementation) JRealizabilityResult(jkind.api.results.JRealizabilityResult) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) JKindResult(jkind.api.results.JKindResult) AgreeAutomaterRegistry(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) AgreeAutomater(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 40 with AgreeException

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

the class Util method getDoubleValue.

public static Double getDoubleValue(Expr expr) {
    Double result = Double.valueOf(0.0);
    assert (AgreeJavaValidator.exprIsConst(expr));
    if (expr instanceof NamedElement) {
        if (expr instanceof ConstStatement) {
            result = getDoubleValue(((ConstStatement) expr).getExpr());
        }
    } else if (expr instanceof SelectionExpr) {
        NamedElement finalId = ((SelectionExpr) expr).getField();
        if (finalId instanceof ConstStatement) {
            result = getDoubleValue(((ConstStatement) finalId).getExpr());
        }
    } else if (expr instanceof RealLitExpr) {
        result = Double.valueOf(((RealLitExpr) expr).getVal());
    } else if (expr instanceof IntLitExpr) {
        result = Double.valueOf(((IntLitExpr) expr).getVal());
    } else if (expr instanceof BinaryExpr) {
        BinaryExpr binExpr = (BinaryExpr) expr;
        Double left = getDoubleValue(binExpr.getLeft());
        Double right = getDoubleValue(binExpr.getRight());
        switch(binExpr.getOp()) {
            case "+":
                result = left + right;
                break;
            case "-":
                result = left - right;
                break;
            case "*":
                result = left * right;
                break;
            case "/":
                result = left / right;
                break;
            case "^":
                result = Math.pow(left, right);
                break;
            default:
                throw new AgreeException("binary expression is not evaluable as integer constant");
        }
        return result;
    } else if (expr instanceof UnaryExpr) {
        UnaryExpr unExpr = (UnaryExpr) expr;
        Double right = getDoubleValue(unExpr.getExpr());
        switch(unExpr.getOp()) {
            case "-":
                result = -right;
                break;
            default:
                throw new AgreeException("unary expression is not evaluable as integer constant");
        }
    } else {
        throw new AgreeException("expression is not evaluable as integer constant");
    }
    return result;
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) NamedElement(org.osate.aadl2.NamedElement) UnaryExpr(com.rockwellcollins.atc.agree.agree.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