Search in sources :

Example 16 with Type

use of jkind.lustre.Type in project AMASE by loonwerks.

the class FaultASTBuilder method createCommNode.

/**
 * Create Lustre node for asymmetric fault connection nodes.
 *
 * @param node AgreeNode corresponds to the "sender" node that has the fan out connections.
 * 			   This is needed to access the type of connection for input/output of this node.
 * @param fstmt FaultStatement associated with the sender component output.
 * @param fault	Fault built from fault statement.
 * @param nodeName Name of asymmetric node.
 * @param connNumber How many connections from sender to receivers (used in naming).
 * @return Node : lustre node of this communication node.
 */
private Node createCommNode(AgreeNode node, FaultStatement fstmt, Fault fault, String nodeName, int connNumber) {
    // 1. Create unique node name
    NodeBuilder newNode = new NodeBuilder(nodeName);
    // 2. Get the output/input type from the node and the fstmt
    List<AgreeVar> nodeOutputs = node.outputs;
    AgreeVar outputOfInterest = null;
    // Assume asymmetric fault first in list.
    // Will have to display this to user somewhere.
    List<NamedElement> nomFaultConn = new ArrayList<NamedElement>();
    // Get the nominal connection
    for (FaultSubcomponent fs : fstmt.getFaultDefinitions()) {
        if (fs instanceof OutputStatement) {
            nomFaultConn = ((OutputStatement) fs).getNom_conn();
        }
    }
    // Get the agree node output that this fault is connected to
    for (AgreeVar agreeVar : nodeOutputs) {
        String temp = agreeVar.id;
        if (temp.contentEquals(nomFaultConn.get(0).getName())) {
            // This agreeVar is the sender var we want to save for the
            // later mapping to the receiver var.
            outputOfInterest = agreeVar;
        }
    }
    // Now the same type on the AgreeNode outputOfInterest
    // is the same as what we will create for the type of
    // both input and output of commNode.
    Type type = outputOfInterest.type;
    newNode = createInputForCommNode(newNode, fault, outputOfInterest.type, nodeName);
    newNode = createOutputForCommNode(newNode);
    newNode = createLocalsForCommNode(newNode, fault);
    newNode = createEquationsForCommNode(newNode, fault, type, nodeName);
    return newNode.build();
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FaultSubcomponent(edu.umn.cs.crisys.safety.safety.FaultSubcomponent) ArrayList(java.util.ArrayList) NodeBuilder(jkind.lustre.builders.NodeBuilder) NamedElement(org.osate.aadl2.NamedElement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) OutputStatement(edu.umn.cs.crisys.safety.safety.OutputStatement)

Example 17 with Type

use of jkind.lustre.Type in project AMASE by loonwerks.

the class AsymFaultASTBuilder method addFaultsToCommNode.

/**
 * Creates a lustre node with all fault node calls defined for a particular agree
 * node output. Returns completed Lustre node.
 *
 * @param agreeNode The AgreeNode which has the fault list associated with an output.
 * @param faults The List<Fault> that is on an output of the agree node.
 * @param senderOutput DataPortImpl is the agreeNode output that these faults are connected to.
 * @param nodeName String of the name of the node to be created.
 * @param i The unique id number associated with the node to be created.
 * @return Node to be inserted into Lustre.
 */
private Node addFaultsToCommNode(AgreeNode agreeNode, List<Fault> faults, DataPortImpl senderOutput, String nodeName, int i) {
    // Create unique node name
    NodeBuilder newNode = new NodeBuilder(nodeName);
    List<AgreeVar> nodeOutputs = agreeNode.outputs;
    AgreeVar outputOfInterest = null;
    // Get name of output according to senderOutput data port impl
    String nameOfOutput = senderOutput.getName();
    // Find the output in agree node outputs in order to access type.
    for (AgreeVar agreeVar : nodeOutputs) {
        String temp = agreeVar.id;
        if (temp.contentEquals(nameOfOutput)) {
            // This agreeVar is the sender var we want to save for the
            // later mapping to the receiver var.
            outputOfInterest = agreeVar;
        }
    }
    if (outputOfInterest == null) {
        new SafetyException("Cannot locate output for asymmetric fault in Agree: " + senderOutput.getName());
    }
    // Now the same type on the AgreeNode outputOfInterest
    // is the same as what we will create for the type of
    // both input and output of commNode.
    Type type = outputOfInterest.type;
    newNode = createInputForCommNode(agreeNode, newNode, faults, outputOfInterest.type, nodeName);
    newNode = super.createOutputForCommNode(newNode);
    newNode = createLocalsForCommNode(newNode, faults);
    newNode = createEquationsForCommNode(newNode, faults, type, nodeName);
    return newNode.build();
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) NodeBuilder(jkind.lustre.builders.NodeBuilder) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 18 with Type

use of jkind.lustre.Type in project AMASE by loonwerks.

the class AsymFaultASTBuilder method addFaultNodeArgsToList.

/**
 * Goes through the fault and adds all arguments to the fault node into a local list.
 * These are saved in the order the node must be called.
 * The list is also saved in the class list of list: nodeArguments. These are used
 * in the node call expression formation.
 *
 * @param newNode NodeBuilder has inputs created in this method corresponding to the
 * 			fault node arguments it uses.
 * @param fault Fault that holds fault node definition.
 * @return
 */
private List<AgreeVar> addFaultNodeArgsToList(NodeBuilder newNode, Fault fault) {
    List<AgreeVar> localsForCommNode = new ArrayList<AgreeVar>();
    List<Expr> nodeArgList = new ArrayList<Expr>();
    // Double check size of faultInputList, must be more than 1.
    if (fault.faultInputMap.size() <= 0) {
        return localsForCommNode;
    } else {
        for (VarDecl inputVar : fault.faultNode.inputs) {
            String key = inputVar.id;
            if (key.equals("trigger")) {
                continue;
            }
            if (key.equalsIgnoreCase("val_in")) {
                // First add nominal output to argument list.
                nodeArgList.add(new IdExpr("__fault__nominal__output"));
            } else {
                // The value is the same as the fault output type.
                if (fault.faultInputMap.get(key) instanceof IdExpr) {
                    IdExpr value = (IdExpr) fault.faultInputMap.get(key);
                    // Get type by accessing this in fault node input list.
                    Type type = null;
                    for (VarDecl vars : fault.faultNode.inputs) {
                        if (value.id.equals(vars.id)) {
                            type = vars.type;
                            break;
                        }
                    }
                    // be a safety eq statement.
                    if (type == null) {
                        for (AgreeVar vars : fault.safetyEqVars) {
                            if (value.id.equals(vars.id)) {
                                type = vars.type;
                                break;
                            }
                        }
                    }
                    // There must have been an error.
                    if (type == null) {
                        new SafetyException("Error in defining fault node arguments for fault " + fault.id);
                    }
                    AgreeVar local = new AgreeVar(value.id, type, fault.faultStatement);
                    IdExpr newIdForList = new IdExpr(local.id);
                    nodeArgList.add(newIdForList);
                    localsForCommNode.add(local);
                    newNode.createInput(local.id, type);
                } else {
                    // If it is not IdExpr, assume that it is Real/Bool/IntExpr
                    // Added directly to fault node call.
                    nodeArgList.add(fault.faultInputMap.get(key));
                }
            }
        }
    }
    // Lastly, add the trigger
    nodeArgList.add(new IdExpr("__fault__trigger__" + fault.id));
    nodeArguments.put(fault, nodeArgList);
    return localsForCommNode;
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) ArrayList(java.util.ArrayList) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 19 with Type

use of jkind.lustre.Type in project AMASE by loonwerks.

the class FaultASTBuilder method addInputListAndEqAsserts.

/**
 * In the case when the fault node has multiple arguments, these must be added
 * to the locals list for this commNode, added to the list of locals for main node
 * information, and all safetyEqAsserts corresponding to them added to equations as well.
 * This method performs those actions.
 *
 * Size of fault.faultInputMap was checked before this method was called.
 * That means that there are more than two arguments to the fault node.
 * The first argument is taken care of previously (__fault__nominal__output).
 * The last argument is also taken care of (fault__trigger).
 * We do the rest here.
 *
 * @param node NodeBuilder will have input added to it.
 * @param fault Fault that was made from this fstmt.
 * @return  List<AgreeVar> List of ordered args for the node call.
 */
private List<AgreeVar> addInputListAndEqAsserts(NodeBuilder node, Fault fault) {
    List<AgreeVar> localsForCommNode = new ArrayList<AgreeVar>();
    nodeArgs.clear();
    // Double check size of faultInputList, must be more than 1.
    if (fault.faultInputMap.size() <= 0) {
        return localsForCommNode;
    } else {
        for (VarDecl inputVar : fault.faultNode.inputs) {
            String key = inputVar.id;
            if (key.equals("trigger")) {
                continue;
            }
            if (key.equalsIgnoreCase("val_in")) {
                // First add nominal output to argument list.
                nodeArgs.add(new IdExpr("__fault__nominal__output"));
            } else {
                // The value is the same as the fault output type.
                if (fault.faultInputMap.get(key) instanceof IdExpr) {
                    IdExpr value = (IdExpr) fault.faultInputMap.get(key);
                    // Get type by accessing this in fault node input list.
                    Type type = null;
                    for (VarDecl vars : fault.faultNode.inputs) {
                        if (value.id.equals(vars.id)) {
                            type = vars.type;
                            break;
                        }
                    }
                    // be a safety eq statement.
                    if (type == null) {
                        for (AgreeVar vars : fault.safetyEqVars) {
                            if (value.id.equals(vars.id)) {
                                type = vars.type;
                                break;
                            }
                        }
                    }
                    // There must have been an error.
                    if (type == null) {
                        new SafetyException("Error in defining fault node arguments for the fault " + fault.id + ".");
                    }
                    AgreeVar local = new AgreeVar(value.id, type, fault.faultStatement);
                    IdExpr newIdForList = new IdExpr(local.id);
                    nodeArgs.add(newIdForList);
                    localsForCommNode.add(local);
                    node.createInput(local.id, type);
                } else {
                    // If it is not IdExpr, assume that it is Real/Bool/IntExpr
                    // Added directly to fault node call.
                    nodeArgs.add(fault.faultInputMap.get(key));
                }
            }
        }
    }
    // Check for any SafetyEqStmts and add these to input
    if (!fault.safetyEqVars.isEmpty()) {
        for (AgreeVar eqVar : fault.safetyEqVars) {
            AgreeVar newIn = new AgreeVar(eqVar.id, eqVar.type, fault.faultStatement);
            if (!localsForCommNode.contains(newIn)) {
                localsForCommNode.add(newIn);
                node.createInput(eqVar.id, eqVar.type);
            }
        }
    }
    // Lastly, add the trigger
    nodeArgs.add(new IdExpr("fault__trigger__" + fault.id));
    return localsForCommNode;
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) ArrayList(java.util.ArrayList) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 20 with Type

use of jkind.lustre.Type in project AGREE by loonwerks.

the class AgreeASTBuilder method gatherUnspecifiedAadlProperties.

private void gatherUnspecifiedAadlProperties(Map<String, GetPropertyExpr> unspecifiedAadlProperties, List<AgreeVar> inputs, List<AgreeStatement> assumptions, List<AgreeStatement> guarantees) {
    for (Entry<String, GetPropertyExpr> entry : unspecifiedAadlProperties.entrySet()) {
        String propInputName = entry.getKey();
        GetPropertyExpr expr = entry.getValue();
        Property prop = (Property) expr.getProp();
        Expr propInputIdExpr = new IdExpr(propInputName);
        Type type;
        Expr bound = null;
        if (prop.getReferencedPropertyType() instanceof AadlBoolean) {
            type = NamedType.BOOL;
        } else if (prop.getReferencedPropertyType() instanceof AadlInteger) {
            AadlInteger aadlInteger = (AadlInteger) prop.getReferencedPropertyType();
            type = NamedType.INT;
            if (aadlInteger.getRange() != null) {
                PropertyExpression lowerBound = aadlInteger.getRange().getLowerBound();
                PropertyExpression upperBound = aadlInteger.getRange().getUpperBound();
                Expr lowVal = new IntExpr(BigDecimal.valueOf(((IntegerLiteral) lowerBound).getScaledValue()).toBigInteger());
                Expr highVal = new IntExpr(BigDecimal.valueOf(((IntegerLiteral) upperBound).getScaledValue()).toBigInteger());
                Expr lowBound = new BinaryExpr(lowVal, BinaryOp.LESSEQUAL, propInputIdExpr);
                Expr highBound = new BinaryExpr(propInputIdExpr, BinaryOp.LESSEQUAL, highVal);
                bound = LustreExprFactory.makeANDExpr(lowBound, highBound);
            }
        } else if (prop.getReferencedPropertyType() instanceof AadlReal) {
            AadlReal aadlReal = (AadlReal) prop.getReferencedPropertyType();
            type = NamedType.REAL;
            if (aadlReal.getRange() != null) {
                PropertyExpression lowerBound = aadlReal.getRange().getLowerBound();
                PropertyExpression upperBound = aadlReal.getRange().getUpperBound();
                Expr lowVal = new RealExpr(BigDecimal.valueOf(((RealLiteral) lowerBound).getValue()));
                Expr highVal = new RealExpr(BigDecimal.valueOf(((RealLiteral) upperBound).getValue()));
                Expr lowBound = new BinaryExpr(lowVal, BinaryOp.LESSEQUAL, propInputIdExpr);
                Expr highBound = new BinaryExpr(propInputIdExpr, BinaryOp.LESSEQUAL, highVal);
                bound = LustreExprFactory.makeANDExpr(lowBound, highBound);
            }
        } else {
            throw new AgreeException("Could not locate property value '\" + prop.getFullName() + \"' in component '\"\n" + "//						+ compName.getName() + \"'.   Analysis on abstract values not supported for " + "AADL property type " + prop.getReferencedPropertyType() + ".");
        }
        AgreeVar propInputVar = new AgreeVar(propInputName, type, expr, curInst, null);
        Expr constraint = getUnchangingConstraintExpr(propInputIdExpr);
        if (bound != null) {
            constraint = LustreExprFactory.makeANDExpr(constraint, bound);
        }
        inputs.add(propInputVar);
        assumptions.add(new AgreeStatement("", constraint, prop));
    }
}
Also used : AadlReal(org.osate.aadl2.AadlReal) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealLiteral(org.osate.aadl2.RealLiteral) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) AadlBoolean(org.osate.aadl2.AadlBoolean) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) PropertyExpression(org.osate.aadl2.PropertyExpression) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AadlInteger(org.osate.aadl2.AadlInteger) IntExpr(jkind.lustre.IntExpr) Property(org.osate.aadl2.Property) RealExpr(jkind.lustre.RealExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Aggregations

Type (jkind.lustre.Type)33 NamedType (jkind.lustre.NamedType)29 RecordType (jkind.lustre.RecordType)16 ArrayList (java.util.ArrayList)12 Expr (jkind.lustre.Expr)12 IdExpr (jkind.lustre.IdExpr)11 RecordAccessExpr (jkind.lustre.RecordAccessExpr)11 ConnectionType (com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType)10 ComponentType (org.osate.aadl2.ComponentType)10 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)8 NodeCallExpr (jkind.lustre.NodeCallExpr)8 VarDecl (jkind.lustre.VarDecl)8 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)8 FeatureGroupType (org.osate.aadl2.FeatureGroupType)8 IfThenElseExpr (jkind.lustre.IfThenElseExpr)7 IntExpr (jkind.lustre.IntExpr)7 UnaryExpr (jkind.lustre.UnaryExpr)7 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)6