Search in sources :

Example 1 with RecordUpdateExpr

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

the class LustreToMATLABExprVisitor method visit.

@Override
public MATLABExpr visit(RecordUpdateExpr e) {
    MATLABIdExpr recordIdExpr = (MATLABIdExpr) e.record.accept(this);
    // Assign the specific field of the variable created from the recordExpr associated with it
    // to the value specified in the RecordUpdateExpr
    SortedMap<String, MATLABExpr> fields = new TreeMap<>(new StringNaturalOrdering());
    // get the type for the field
    Expr curExpr = e;
    while (curExpr instanceof RecordUpdateExpr) {
        curExpr = ((RecordUpdateExpr) curExpr).record;
    }
    MATLABType type = null;
    String recordName = "";
    if (curExpr instanceof RecordExpr) {
        recordName = ((RecordExpr) curExpr).id;
        if (recordTypeMap.get(recordName) != null) {
            String fieldName = e.field;
            fieldName = updateName(fieldName, recordName);
            type = recordTypeMap.get(recordName).get(fieldName);
        }
    } else {
        recordName = recordIdExpr.id;
    }
    // conduct explicit type cast if a field value is a constant of double type or int type
    MATLABTypeCastExprVisitor typeCastVisitor = new MATLABTypeCastExprVisitor(type);
    MATLABExpr fieldExpr = typeCastVisitor.visit(e.value.accept(this));
    fields.put(updateName(e.field, recordName), fieldExpr);
    String originalVar = null;
    if (e.record instanceof IdExpr) {
        originalVar = updateName(e.record.toString(), "");
    } else {
        originalVar = updateName(recordIdExpr.id.split("_var")[0] + "_var" + localVarIndex, "");
    }
    localVarIndex++;
    String newVar = updateName(recordIdExpr.id.split("_var")[0] + "_var" + localVarIndex, "");
    localBusVarInits.add(new MATLABLocalBusVarInit(originalVar, newVar, fields));
    // In the expression that uses the RecordUpdateExpr, just reference the variable
    return new MATLABIdExpr(newVar);
}
Also used : MATLABLocalBusVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) IdExpr(jkind.lustre.IdExpr) TreeMap(java.util.TreeMap) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) MATLABTypeInitExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeInitExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) MATLABUnaryExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABUnaryExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) CondactExpr(jkind.lustre.CondactExpr) MATLABBinaryExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) IntExpr(jkind.lustre.IntExpr) MATLABDoubleExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABDoubleExpr) MATLABBusElementExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBusElementExpr) MATLABTypeCastExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) RecordExpr(jkind.lustre.RecordExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) MATLABBoolExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayExpr(jkind.lustre.ArrayExpr) MATLABIntExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIntExpr) MATLABArrayAccessExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrayAccessExpr) IdExpr(jkind.lustre.IdExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) StringNaturalOrdering(jkind.util.StringNaturalOrdering) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) RecordExpr(jkind.lustre.RecordExpr)

Example 2 with RecordUpdateExpr

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

the class ExpressionFlattener method flattenRecordExpression.

private static void flattenRecordExpression(final Expr expr, final RecordType recordType, final Map<String, Expr> results) {
    if (expr instanceof RecordUpdateExpr) {
        final RecordUpdateExpr updateExpr = (RecordUpdateExpr) expr;
        // Handle base record
        flattenRecordExpression(updateExpr.record, recordType, results);
        // Handle the update
        results.put(updateExpr.field, updateExpr.value);
    } else if (expr instanceof RecordExpr) {
        final RecordExpr recordExpr = (RecordExpr) expr;
        results.putAll(recordExpr.fields);
    } else {
        // IdExpr
        for (final String field : recordType.fields.keySet()) {
            results.put(field, new RecordAccessExpr(expr, field));
        }
    }
}
Also used : RecordAccessExpr(jkind.lustre.RecordAccessExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) RecordExpr(jkind.lustre.RecordExpr)

Aggregations

RecordAccessExpr (jkind.lustre.RecordAccessExpr)2 RecordExpr (jkind.lustre.RecordExpr)2 RecordUpdateExpr (jkind.lustre.RecordUpdateExpr)2 MATLABLocalBusVarInit (com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit)1 MATLABType (com.rockwellcollins.atc.agree.codegen.ast.MATLABType)1 MATLABArrayAccessExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrayAccessExpr)1 MATLABBinaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr)1 MATLABBoolExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr)1 MATLABBusElementExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBusElementExpr)1 MATLABDoubleExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABDoubleExpr)1 MATLABExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr)1 MATLABIdExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr)1 MATLABIntExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIntExpr)1 MATLABTypeCastExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr)1 MATLABTypeInitExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeInitExpr)1 MATLABUnaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABUnaryExpr)1 TreeMap (java.util.TreeMap)1 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)1 ArrayExpr (jkind.lustre.ArrayExpr)1 ArrayUpdateExpr (jkind.lustre.ArrayUpdateExpr)1