Search in sources :

Example 1 with Type

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

the class RemoveCondacts method clockArrowsAndPres.

private Node clockArrowsAndPres(Node node, final IdExpr clock) {
    final VarDecl init = new VarDecl(namePrefix + "init", NamedType.BOOL);
    final List<Equation> preEquations = new ArrayList<>();
    final List<VarDecl> preLocals = new ArrayList<>();
    node = (Node) node.accept(new AstMapVisitor() {

        private int counter = 0;

        @Override
        public Expr visit(BinaryExpr e) {
            if (e.op == BinaryOp.ARROW) {
                return new IfThenElseExpr(new IdExpr(init.id), e.left.accept(this), e.right.accept(this));
            } else {
                return super.visit(e);
            }
        }

        @Override
        public Expr visit(UnaryExpr e) {
            if (e.op == UnaryOp.PRE) {
                String state = namePrefix + "state" + counter++;
                Type type = e.expr.accept(typeReconstructor);
                preLocals.add(new VarDecl(state, type));
                // state = if clock then expr else pre state
                preEquations.add(new Equation(new IdExpr(state), new IfThenElseExpr(clock, e.expr.accept(this), new UnaryExpr(UnaryOp.PRE, new IdExpr(state)))));
                return new UnaryExpr(UnaryOp.PRE, new IdExpr(state));
            } else {
                return super.visit(e);
            }
        }
    });
    NodeBuilder builder = new NodeBuilder(node);
    builder.addLocals(preLocals);
    builder.addLocal(init);
    builder.addEquations(preEquations);
    // init = true -> if pre clock then false else pre init
    builder.addEquation(new Equation(new IdExpr(init.id), new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, new IfThenElseExpr(new UnaryExpr(UnaryOp.PRE, clock), new BoolExpr(false), new UnaryExpr(UnaryOp.PRE, new IdExpr(init.id))))));
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) 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) AstMapVisitor(jkind.lustre.visitors.AstMapVisitor) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) 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)

Example 2 with Type

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

the class TcgXmlWriter method writeSignal.

private void writeSignal(int k, Signal<Value> signal) throws Exception {
    String name = escapeXml(signal.getName());
    // TODO: fix this with the type map!
    Type type;
    if (signal.getValues().isEmpty()) {
        throw new TcgException("Unable to assertain signal type in XmlWriter");
    } else {
        Map.Entry<Integer, Value> entry = signal.getValues().entrySet().iterator().next();
        Value v = entry.getValue();
        if (v instanceof IntegerValue) {
            type = NamedType.INT;
        } else if (v instanceof RealValue) {
            type = NamedType.REAL;
        } else if (v instanceof BooleanValue) {
            type = NamedType.BOOL;
        } else {
            throw new TcgException("Unexpected signal type in XmlWriter");
        }
    }
    out.println("      <Signal name=\"" + name + "\" type=\"" + type + "\">");
    for (int i = 0; i < k; i++) {
        out.println("        <Value time=\"" + i + "\">" + formatValue(signal.getValue(i)) + "</Value>");
    }
    out.println("      </Signal>");
}
Also used : RealValue(jkind.lustre.values.RealValue) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) IntegerValue(jkind.lustre.values.IntegerValue) BooleanValue(jkind.lustre.values.BooleanValue) RealValue(jkind.lustre.values.RealValue) IntegerValue(jkind.lustre.values.IntegerValue) Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue) Map(java.util.Map) TcgException(com.rockwellcollins.atc.tcg.TcgException)

Example 3 with Type

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

the class ExpressionFlattener method flattenEqualsExpression.

private void flattenEqualsExpression(final BinaryExpr expr, final List<BinaryExpr> results) {
    // Assume that both sides of the binary expression are the same type
    final Type leftType = expr.left.accept(typeReconstructor);
    if (leftType instanceof ArrayType) {
        flattenArrayEquality(expr, (ArrayType) leftType, results);
    } else if (leftType instanceof RecordType) {
        flattenRecordEquality(expr, (RecordType) leftType, results);
    } else if (leftType instanceof NamedType) {
        // Flatten both sides of the expression
        final Expr newLeft = flattenExpression(expr.left);
        final Expr newRight = flattenExpression(expr.right);
        if (newLeft != null && newRight != null) {
            results.add(new BinaryExpr(newLeft, expr.op, newRight));
        }
    }
}
Also used : ArrayType(jkind.lustre.ArrayType) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) ArrayType(jkind.lustre.ArrayType) RecordType(jkind.lustre.RecordType) BinaryExpr(jkind.lustre.BinaryExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) RecordExpr(jkind.lustre.RecordExpr) IntExpr(jkind.lustre.IntExpr) NamedType(jkind.lustre.NamedType) BinaryExpr(jkind.lustre.BinaryExpr)

Example 4 with Type

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

the class VariableMap method addEquality.

private void addEquality(final Expr idExpr1, final Expr idExpr2) {
    Objects.requireNonNull(idExpr1, "id1 must not be null");
    Objects.requireNonNull(idExpr2, "id2 must not be null");
    markVariableMapAsDirty();
    final Type id1ExprType = idExpr1.accept(typeReconstructor);
    if (id1ExprType instanceof NamedType) {
        // Named type equality
        final String id1 = idExpr1.toString();
        final String id2 = idExpr2.toString();
        final Variable var1 = variables.get(id1);
        final Variable var2 = variables.get(id2);
        if (var1 == null && var2 == null) {
            final Variable newVar = new Variable((NamedType) id1ExprType);
            newVar.ids.add(id1);
            newVar.ids.add(id2);
            variables.put(id1, newVar);
            variables.put(id2, newVar);
        } else if (var1 == null) {
            var2.ids.add(id1);
            variables.put(id1, var2);
        } else if (var2 == null) {
            var1.ids.add(id2);
            variables.put(id2, var1);
        } else {
            // Decide which variable to keep
            final Variable keepVar;
            final Variable removeVar;
            if (var1.ids.size() <= var2.ids.size()) {
                keepVar = var1;
                removeVar = var2;
            } else {
                keepVar = var2;
                removeVar = var1;
            }
            // Merge the remove var fields into the keep var
            keepVar.ids.addAll(removeVar.ids);
            keepVar.relatedExpressions.addAll(removeVar.relatedExpressions);
            // Update the variable map to only reference the keep var
            for (final String removeId : removeVar.ids) {
                variables.put(removeId, keepVar);
            }
        }
    }
}
Also used : Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) NamedType(jkind.lustre.NamedType)

Example 5 with Type

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

the class AgreeASTBuilder method caseUninterpretedFnDef.

@Override
public Expr caseUninterpretedFnDef(UninterpretedFnDef uFnDef) {
    String functionName = AgreeUtils.getNodeName(uFnDef).replace("::", "__");
    for (Function function : uninterpretedFunc) {
        if (function.id.equals(functionName)) {
            return null;
        }
    }
    List<VarDecl> inputs = agreeVarsFromArgs(uFnDef.getArgs(), null);
    Type outType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(uFnDef.getType()));
    if (outType != null) {
        VarDecl outVar = new VarDecl("_outvar", outType);
        List<VarDecl> outputs = Collections.singletonList(outVar);
        Function function = new Function(functionName, inputs, outputs);
        addToFunctionList(function);
    }
    return null;
}
Also used : Function(jkind.lustre.Function) 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) VarDecl(jkind.lustre.VarDecl)

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