Search in sources :

Example 21 with IdExpr

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

the class AgreeASTBuilder method caseGetPropertyExpr.

@Override
public Expr caseGetPropertyExpr(GetPropertyExpr expr) {
    NamedElement propName = expr.getProp();
    PropertyExpression propVal;
    if (propName instanceof Property) {
        ComponentRef cr = expr.getComponentRef();
        NamedElement compName = null;
        if (cr instanceof DoubleDotRef) {
            compName = ((DoubleDotRef) cr).getElm();
        } else if (cr instanceof ThisRef) {
            compName = curInst;
        }
        Property prop = (Property) propName;
        propVal = AgreeUtils.getPropExpression(compName, prop);
        if (propVal == null) {
            if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_UNSPECIFIED_AADL_PROPERTIES)) {
                String propInputName = unspecifiedAadlPropertyPrefix + compName.getName() + dotChar + prop.getName();
                unspecifiedAadlProperties.put(propInputName, expr);
                return new IdExpr(propInputName);
            } else {
                throw new AgreeException("Could not locate property value '" + prop.getQualifiedName() + "' in component '" + compName.getName() + "'.  Is it possible " + "that a 'this' statement is used in a context in which it wasn't supposed to?" + "  Analysis of unspecified AADL properties as inputs may be enabled in the AGREE preferences.");
            }
        }
    } else {
        propVal = AgreeUtils.getPropExpression((PropertyConstant) propName);
        if (propVal == null) {
            throw new AgreeException("Could not locate property value '" + propName.getQualifiedName());
        }
    }
    Expr res = null;
    if (propVal != null) {
        if (propVal instanceof StringLiteral) {
            // nodeStr += value.getValue() + ")";
            throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of string type");
        } else if (propVal instanceof NamedValue) {
            // EnumerationLiteral enVal = (EnumerationLiteral) absVal;
            throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of enumeration type");
        } else if (propVal instanceof BooleanLiteral) {
            BooleanLiteral value = (BooleanLiteral) propVal;
            res = new BoolExpr(value.getValue());
        } else if (propVal instanceof IntegerLiteral) {
            IntegerLiteral value = (IntegerLiteral) propVal;
            res = new IntExpr(BigInteger.valueOf((long) value.getScaledValue()));
        } else {
            assert (propVal instanceof RealLiteral);
            RealLiteral value = (RealLiteral) propVal;
            res = new RealExpr(BigDecimal.valueOf(value.getValue()));
        }
    }
    assert (res != null);
    return res;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BooleanLiteral(org.osate.aadl2.BooleanLiteral) NamedValue(org.osate.aadl2.NamedValue) PropertyConstant(org.osate.aadl2.PropertyConstant) RealLiteral(org.osate.aadl2.RealLiteral) 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) StringLiteral(org.osate.aadl2.StringLiteral) ThisRef(com.rockwellcollins.atc.agree.agree.ThisRef) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) PropertyExpression(org.osate.aadl2.PropertyExpression) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) IntExpr(jkind.lustre.IntExpr) ComponentRef(com.rockwellcollins.atc.agree.agree.ComponentRef) NamedElement(org.osate.aadl2.NamedElement) Property(org.osate.aadl2.Property) RealExpr(jkind.lustre.RealExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 22 with IdExpr

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

the class AgreeASTBuilder method caseFnDef.

@Override
public Expr caseFnDef(FnDef fnDef) {
    String nodeName = AgreeUtils.getNodeName(fnDef).replace("::", "__");
    for (Node node : globalNodes) {
        if (node.id.equals(nodeName)) {
            return null;
        }
    }
    List<VarDecl> inputs = agreeVarsFromArgs(fnDef.getArgs(), null);
    Expr bodyExpr = doSwitch(fnDef.getExpr());
    // EGM: array-backend
    // Type outType = getNamedType(AgreeTypeUtils.getTypeName(fnDef.getType(), typeMap, globalTypes));
    Type outType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(fnDef.getType()));
    if (outType != null) {
        VarDecl outVar = new VarDecl("_outvar", outType);
        List<VarDecl> outputs = Collections.singletonList(outVar);
        Equation eq = new Equation(new IdExpr("_outvar"), bodyExpr);
        List<Equation> eqs = Collections.singletonList(eq);
        NodeBuilder builder = new NodeBuilder(nodeName);
        builder.addInputs(inputs);
        builder.addOutputs(outputs);
        builder.addEquations(eqs);
        Node node = builder.build();
        addToNodeList(node);
    }
    return null;
}
Also used : 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) 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) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) Node(jkind.lustre.Node) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Example 23 with IdExpr

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

the class AgreeCalendarUtils method queueMultiplexNode.

public static Node queueMultiplexNode(String nodeName, Type type, int numInputs) {
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> outputs = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<IdExpr> clks = new ArrayList<>();
    List<IdExpr> ins = new ArrayList<>();
    List<Equation> eqs = new ArrayList<>();
    for (int i = 0; i < numInputs; i++) {
        IdExpr inId = new IdExpr("in" + i);
        IdExpr clkId = new IdExpr("out" + i);
        ins.add(inId);
        clks.add(clkId);
        inputs.add(new VarDecl(inId.id, type));
        inputs.add(new VarDecl(clkId.id, NamedType.BOOL));
    }
    IdExpr output = new IdExpr("output");
    outputs.add(new VarDecl(output.id, type));
    // the output expression
    // just an arbitrary value
    Expr outExpr = ins.get(0);
    for (int i = 0; i < numInputs; i++) {
        outExpr = new IfThenElseExpr(clks.get(i), ins.get(i), outExpr);
    }
    Equation outEq = new Equation(output, outExpr);
    eqs.add(outEq);
    NodeBuilder builder = new NodeBuilder(nodeName);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(eqs);
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 24 with IdExpr

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

the class AgreeCalendarUtils method getExplicitCalendarNode.

public static Node getExplicitCalendarNode(String nodeName, List<IdExpr> calendar, List<Expr> clocks) {
    // filter the calendar if some clocks are not present
    List<IdExpr> filteredCalendar = new ArrayList<>();
    Map<String, List<Integer>> clockTickMap = new HashMap<>();
    for (IdExpr calId : calendar) {
        for (Expr clockExpr : clocks) {
            IdExpr clockId = (IdExpr) clockExpr;
            if (calId.id.equals(clockId.id)) {
                filteredCalendar.add(clockId);
                break;
            }
        }
    }
    int i = 0;
    for (IdExpr clockId : filteredCalendar) {
        List<Integer> ticks = clockTickMap.get(clockId.id);
        if (ticks == null) {
            ticks = new ArrayList<>();
            clockTickMap.put(clockId.id, ticks);
        }
        ticks.add(i++);
    }
    for (Expr clockExpr : clocks) {
        IdExpr clockId = (IdExpr) clockExpr;
        if (clockTickMap.get(clockId.id) == null) {
            throw new AgreeException("Clock Id '" + clockId.id + "' is not present in calendar statement");
        }
    }
    // add all of the clocks to to the inputs of the node
    List<VarDecl> inputs = new ArrayList<>();
    for (Expr clockExpr : clocks) {
        VarDecl input = new VarDecl(((IdExpr) clockExpr).id, NamedType.BOOL);
        inputs.add(input);
    }
    // the output is the variable asserting the calendar
    List<VarDecl> outputs = new ArrayList<>();
    IdExpr outputAssert = new IdExpr("__CALENDAR_ASSERTION");
    outputs.add(new VarDecl(outputAssert.id, NamedType.BOOL));
    // create a variable that counts through the calendar elements
    List<VarDecl> locals = new ArrayList<>();
    VarDecl clockCounterVar = new VarDecl("__CALANDER_COUNTER", NamedType.INT);
    locals.add(clockCounterVar);
    List<Equation> equations = new ArrayList<>();
    // create the expression for the counter variable
    IdExpr clockCountId = new IdExpr(clockCounterVar.id);
    IntExpr calendarSize = new IntExpr(BigInteger.valueOf(filteredCalendar.size() - 1));
    Expr preClockCount = new UnaryExpr(UnaryOp.PRE, clockCountId);
    Expr preLast = new BinaryExpr(preClockCount, BinaryOp.EQUAL, calendarSize);
    Expr prePlus = new BinaryExpr(preClockCount, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
    Expr ifClock = new IfThenElseExpr(preLast, new IntExpr(BigInteger.ZERO), prePlus);
    Expr clockArrow = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, ifClock);
    Equation clockCountEq = new Equation(clockCountId, clockArrow);
    equations.add(clockCountEq);
    // create constraints for which calendar element is ticking
    Expr calendarConstraint = new BoolExpr(true);
    for (Expr clockExpr : clocks) {
        IdExpr clockId = (IdExpr) clockExpr;
        List<Integer> ticks = clockTickMap.get(clockId.id);
        Expr clockTicking = new BoolExpr(false);
        for (Integer tick : ticks) {
            Expr clockIsTickValue = new BinaryExpr(clockCountId, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(tick.longValue())));
            clockTicking = new BinaryExpr(clockTicking, BinaryOp.OR, clockIsTickValue);
        }
        Expr ifExpr = new IfThenElseExpr(clockTicking, clockId, new UnaryExpr(UnaryOp.NOT, clockId));
        calendarConstraint = new BinaryExpr(calendarConstraint, BinaryOp.AND, ifExpr);
    }
    Equation outEq = new Equation(outputAssert, calendarConstraint);
    equations.add(outEq);
    NodeBuilder builder = new NodeBuilder(nodeName);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) HashMap(java.util.HashMap) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BigInteger(java.math.BigInteger) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) ArrayList(java.util.ArrayList) List(java.util.List) IntExpr(jkind.lustre.IntExpr)

Example 25 with IdExpr

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

the class AgreeCalendarUtils method getCalendarNode.

public static Node getCalendarNode(String name, String dfaName, int numClks) {
    Expr nodeExpr = null;
    String clkVarPrefix = "_clk_";
    IdExpr outVar = new IdExpr("_out");
    // make the inputs and outputs
    List<VarDecl> inputs = new ArrayList<>();
    List<IdExpr> clks = new ArrayList<>();
    for (int i = 0; i < numClks; i++) {
        inputs.add(new VarDecl(clkVarPrefix + i, NamedType.BOOL));
        clks.add(new IdExpr(clkVarPrefix + i));
    }
    List<VarDecl> outputs = new ArrayList<>();
    outputs.add(new VarDecl(outVar.id, NamedType.BOOL));
    for (int i = 0; i < clks.size() - 1; i++) {
        Expr clk0 = clks.get(i);
        for (int j = i + 1; j < clks.size(); j++) {
            Expr clk1 = clks.get(j);
            Expr dfaExpr = getDFAExpr(dfaName, clk0, clk1);
            if (nodeExpr == null) {
                nodeExpr = dfaExpr;
            } else {
                nodeExpr = new BinaryExpr(nodeExpr, BinaryOp.AND, dfaExpr);
            }
        }
    }
    Equation nodeEq = new Equation(outVar, nodeExpr);
    NodeBuilder builder = new NodeBuilder(name);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addEquations(Collections.singletonList(nodeEq));
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Aggregations

IdExpr (jkind.lustre.IdExpr)133 BinaryExpr (jkind.lustre.BinaryExpr)96 Expr (jkind.lustre.Expr)95 BoolExpr (jkind.lustre.BoolExpr)82 NodeCallExpr (jkind.lustre.NodeCallExpr)81 UnaryExpr (jkind.lustre.UnaryExpr)75 IfThenElseExpr (jkind.lustre.IfThenElseExpr)64 IntExpr (jkind.lustre.IntExpr)53 ArrayList (java.util.ArrayList)52 Equation (jkind.lustre.Equation)46 VarDecl (jkind.lustre.VarDecl)41 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)38 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)37 RecordAccessExpr (jkind.lustre.RecordAccessExpr)37 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)29 RealExpr (jkind.lustre.RealExpr)29 NodeBuilder (jkind.lustre.builders.NodeBuilder)29 TupleExpr (jkind.lustre.TupleExpr)25 ArrayExpr (jkind.lustre.ArrayExpr)14 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)13