Search in sources :

Example 1 with MATLABType

use of com.rockwellcollins.atc.agree.codegen.ast.MATLABType in project AGREE by loonwerks.

the class LustreToMATLABExprVisitor method visit.

@Override
public MATLABExpr visit(RecordExpr e) {
    // Create a local variable with the record type id as prefix
    localVarIndex++;
    String localVarName = updateName(e.id + "_var" + localVarIndex, "");
    // add assignment to assign the fields of the variable
    // to the value specified in the RecordExpr
    SortedMap<String, MATLABExpr> fields = new TreeMap<>(new StringNaturalOrdering());
    Iterator<Entry<String, Expr>> iterator = e.fields.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, Expr> entry = iterator.next();
        // get the type for the field
        MATLABType type = recordTypeMap.get(e.id).get(updateName(entry.getKey(), e.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(entry.getValue().accept(this));
        fields.put(updateName(entry.getKey(), e.id), fieldExpr);
    }
    localBusVarInits.add(new MATLABLocalBusVarInit(localVarName, null, fields));
    // In the expression that uses the RecordExpr, just reference the local variable
    return new MATLABIdExpr(localVarName);
}
Also used : MATLABLocalBusVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) TreeMap(java.util.TreeMap) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) Entry(java.util.Map.Entry) 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) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr)

Example 2 with MATLABType

use of com.rockwellcollins.atc.agree.codegen.ast.MATLABType in project AGREE by loonwerks.

the class LustreToMATLABExprVisitor method visit.

@Override
public MATLABExpr visit(UnaryExpr e) {
    MATLABExpr expr = e.expr.accept(this);
    String opName = e.op.name();
    MATLABUnaryOp op = MATLABUnaryOp.fromName(opName);
    if (op == null) {
        if (opName.equals("PRE")) {
            if (expr instanceof MATLABIdExpr) {
                // function call for the following AGREE unary operator
                // PRE ("pre");
                String varName = ((MATLABIdExpr) expr).id;
                String preVarName = updateName("pre_" + varName, "");
                // no duplicate addition
                if (!persistentVarMap.containsKey(preVarName)) {
                    // init based on varName
                    if (inputSet.contains(varName)) {
                        persistentVarInits.add(new MATLABPreInputVarInit(preVarName, varName));
                        persistentVarMap.put(preVarName, new MATLABIdExpr(varName));
                    } else // if the var is a local variable
                    // the init needs to be associated with a default value of the type
                    // instead of varName, as the varName may be assigned in the same equation
                    // the preVar first gets used
                    {
                        // add preVar init based on default value of the type
                        if (localVarTypeMap.containsKey(varName)) {
                            MATLABType type = localVarTypeMap.get(varName);
                            persistentVarInits.add(new MATLABPreLocalVarInit(preVarName, new MATLABTypeInitExpr(type)));
                            persistentVarMap.put(preVarName, new MATLABIdExpr(varName));
                        } else {
                            throw new IllegalArgumentException();
                        }
                    }
                }
                return new MATLABIdExpr(preVarName);
            } else {
                throw new IllegalArgumentException();
            }
        } else {
            throw new IllegalArgumentException();
        }
    } else {
        return new MATLABUnaryExpr(op, expr);
    }
}
Also used : MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) MATLABUnaryExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABUnaryExpr) MATLABPreLocalVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABPreLocalVarInit) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) MATLABPreInputVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABPreInputVarInit) MATLABUnaryOp(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABUnaryOp) MATLABTypeInitExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeInitExpr) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType)

Example 3 with MATLABType

use of com.rockwellcollins.atc.agree.codegen.ast.MATLABType 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 4 with MATLABType

use of com.rockwellcollins.atc.agree.codegen.ast.MATLABType in project AGREE by loonwerks.

the class LustreToMATLABTranslator method translate.

public static MATLABPrimaryFunction translate(Node lustreNode, AgreeProgram agreeProgram) {
    IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
    intTypeStr = prefs.getString(PreferenceConstants.PREF_INT);
    realTypeStr = prefs.getString(PreferenceConstants.PREF_REAL);
    List<MATLABIdExpr> inputs = new ArrayList<>();
    List<MATLABStatement> statements = new ArrayList<>();
    List<MATLABFunction> functions = new ArrayList<>();
    List<MATLABPersistentVarDecl> persistentVarDecl = new ArrayList<>();
    List<MATLABPort> ports = new ArrayList<>();
    LustreToMATLABExprVisitor exprVisitor = new LustreToMATLABExprVisitor();
    LustreToMATLABTypeVisitor typeVisitor = new LustreToMATLABTypeVisitor();
    // get function name
    String functionName = "check_" + lustreNode.id;
    // add record types
    for (Type type : agreeProgram.globalTypes) {
        if (type instanceof RecordType) {
            RecordType recordType = (RecordType) type;
            SortedMap<String, MATLABType> fields = new TreeMap<>(new StringNaturalOrdering());
            Iterator<Entry<String, Type>> iterator = recordType.fields.entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, Type> entry = iterator.next();
                fields.put(exprVisitor.updateName(entry.getKey(), recordType.id), entry.getValue().accept(typeVisitor));
            }
            exprVisitor.recordTypeMap.put(recordType.id, fields);
        }
    }
    // add input and output ports for subsystem to verify
    for (VarDecl inputVar : lustreNode.inputs) {
        String varName = null;
        if (!inputVar.id.equals("time")) {
            // update name
            varName = exprVisitor.updateName(inputVar.id, "");
            // add inputs
            inputs.add(new MATLABIdExpr(varName));
            // translate the Lustre expression to MATLAB expression
            // add input Ids to inputList of the exprVisitor
            // to help identify local variables
            exprVisitor.inputSet.add(inputVar.id);
            // get inputVar and type
            AgreeVar agreeVar = (AgreeVar) inputVar;
            Type type = agreeVar.type;
            if (type instanceof RecordType || type instanceof NamedType) {
                MATLABType portType = (agreeVar.type).accept(typeVisitor);
                SortedMap<String, MATLABType> fields = null;
                // get the fields if it is a RecordType
                if (type instanceof RecordType) {
                    fields = exprVisitor.recordTypeMap.get(((RecordType) type).id);
                }
                // if it is from AADL feature, get the feature instance
                if (agreeVar.featInst != null) {
                    FeatureInstance featInst = agreeVar.featInst;
                    ports.add(new MATLABPort(featInst.getName(), featInst.getDirection().getName(), portType, fields));
                } else // if it is not from AADL feature, but an eq variable from
                // AGREE
                // set them as output variables from the subsystem
                {
                    ports.add(new MATLABPort(inputVar.id, "out", portType, fields));
                }
            }
        }
    }
    // add local variable and their types
    for (VarDecl localVar : lustreNode.locals) {
        // get local var Name and Type
        exprVisitor.localVarTypeMap.put(exprVisitor.updateName(localVar.id, ""), localVar.type.accept(typeVisitor));
    }
    // translate equations to assignments
    if (!lustreNode.equations.isEmpty()) {
        for (Equation equation : lustreNode.equations) {
            // get the variable to assign
            String varId = exprVisitor.updateName(equation.lhs.get(0).id, "");
            MATLABIdExpr varToAssign = new MATLABIdExpr(varId);
            // get the type for the local variable
            // MATLABType type = exprVisitor.localVarTypeMap.get(varId);
            // translate expressions
            MATLABExpr expr = exprVisitor.visit(equation.expr);
            // conduct explicit type cast if it's a constant of double type or int type
            // no need to type cast for assignment from an input variable
            // or operations (including functions) involving known types
            MATLABTypeCastExprVisitor typeCastVisitor = new MATLABTypeCastExprVisitor();
            expr = typeCastVisitor.visit(expr);
            // add any new preVar init from exprVisitor
            Iterator<MATLABPersistentVarInit> persistentVarInitIterator = exprVisitor.persistentVarInits.iterator();
            while (persistentVarInitIterator.hasNext()) {
                MATLABPersistentVarInit persistentVarInit = persistentVarInitIterator.next();
                // add new preVar init to the statements before the assignment
                statements.add(persistentVarInit);
                // remove the new preVar init from exprVisitor
                persistentVarInitIterator.remove();
            }
            // add any new local Bus var init from exprVisitor
            Iterator<MATLABLocalBusVarInit> busVarInitIterator = exprVisitor.localBusVarInits.iterator();
            while (busVarInitIterator.hasNext()) {
                MATLABLocalBusVarInit busVarInit = busVarInitIterator.next();
                // add new local Bus var init to the statements before the assignment
                statements.add(busVarInit);
                // remove the new local Bus var init from exprVisitor
                busVarInitIterator.remove();
            }
            // add assignment
            MATLABAssignment assignment = new MATLABAssignment(varToAssign, expr);
            statements.add(assignment);
        }
    }
    // add persistentVar decl and assignments
    Iterator<Entry<String, MATLABExpr>> it = exprVisitor.persistentVarMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, MATLABExpr> pair = it.next();
        String varToAssign = pair.getKey();
        MATLABExpr expr = pair.getValue();
        statements.add(new MATLABAssignment(new MATLABIdExpr(varToAssign), expr));
        persistentVarDecl.add(new MATLABPersistentVarDecl(varToAssign));
    }
    // translate assertions
    for (Expr assertionExpr : lustreNode.assertions) {
        MATLABExpr expr = exprVisitor.visit(assertionExpr);
        // add assertions
        MATLABAssumption assumption = new MATLABAssumption(expr);
        statements.add(assumption);
    }
    // translate properties
    for (String propertyStr : lustreNode.properties) {
        propertyStr = exprVisitor.updateName(propertyStr, "");
        MATLABProperty property = new MATLABProperty(propertyStr);
        statements.add(property);
    }
    // add definitions for the functions that have been called
    for (Map.Entry<String, MATLABFunction> functionEntry : exprVisitor.functionMap.entrySet()) {
        MATLABFunction function = functionEntry.getValue();
        if (function.functionCalled) {
            functions.add(function);
        }
    }
    // Create primary function AST
    MATLABPrimaryFunction primaryFunction = new MATLABPrimaryFunction(functionName, inputs, persistentVarDecl, statements, functions, ports);
    return primaryFunction;
}
Also used : MATLABPersistentVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABPersistentVarInit) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) NamedType(jkind.lustre.NamedType) ArrayList(java.util.ArrayList) MATLABAssignment(com.rockwellcollins.atc.agree.codegen.ast.MATLABAssignment) Entry(java.util.Map.Entry) RecordType(jkind.lustre.RecordType) StringNaturalOrdering(jkind.util.StringNaturalOrdering) MATLABPersistentVarDecl(com.rockwellcollins.atc.agree.codegen.ast.MATLABPersistentVarDecl) VarDecl(jkind.lustre.VarDecl) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) LustreToMATLABExprVisitor(com.rockwellcollins.atc.agree.codegen.visitors.LustreToMATLABExprVisitor) MATLABLocalBusVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit) MATLABTypeCastExprVisitor(com.rockwellcollins.atc.agree.codegen.visitors.MATLABTypeCastExprVisitor) MATLABPersistentVarDecl(com.rockwellcollins.atc.agree.codegen.ast.MATLABPersistentVarDecl) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) LustreToMATLABTypeVisitor(com.rockwellcollins.atc.agree.codegen.visitors.LustreToMATLABTypeVisitor) MATLABPort(com.rockwellcollins.atc.agree.codegen.ast.MATLABPort) Equation(jkind.lustre.Equation) TreeMap(java.util.TreeMap) MATLABPrimaryFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABPrimaryFunction) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) MATLABAssumption(com.rockwellcollins.atc.agree.codegen.ast.MATLABAssumption) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) MATLABIdExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) Expr(jkind.lustre.Expr) MATLABStatement(com.rockwellcollins.atc.agree.codegen.ast.MATLABStatement) MATLABFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABFunction) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) MATLABProperty(com.rockwellcollins.atc.agree.codegen.ast.MATLABProperty)

Example 5 with MATLABType

use of com.rockwellcollins.atc.agree.codegen.ast.MATLABType in project AGREE by loonwerks.

the class LustreToMATLABExprVisitor method visit.

@Override
public MATLABExpr visit(BinaryExpr e) {
    MATLABExpr leftExpr = e.left.accept(this);
    String opName = e.op.name();
    String opFuncStr = e.op.toString();
    MATLABBinaryOp op = MATLABBinaryOp.fromName(opName);
    MATLABExpr rightExpr = e.right.accept(this);
    if (op == null) {
        if (opName.equals("INT_DIVIDE")) {
            MATLABType type = null;
            switch(LustreToMATLABTranslator.intTypeStr) {
                case PreferenceConstants.INT_INT8:
                    type = new MATLABInt8Type();
                    break;
                case PreferenceConstants.INT_UINT8:
                    type = new MATLABUInt8Type();
                    break;
                case PreferenceConstants.INT_INT16:
                    type = new MATLABInt16Type();
                    break;
                case PreferenceConstants.INT_UINT16:
                    type = new MATLABUInt16Type();
                    break;
                case PreferenceConstants.INT_INT32:
                    type = new MATLABInt32Type();
                    break;
                case PreferenceConstants.INT_UINT32:
                    type = new MATLABUInt32Type();
                    break;
                case PreferenceConstants.INT_INT64:
                    type = new MATLABInt64Type();
                    break;
                case PreferenceConstants.INT_UINT64:
                    type = new MATLABUInt64Type();
                    break;
                default:
                    throw new IllegalArgumentException("Unknown int type: " + LustreToMATLABTranslator.intTypeStr);
            }
            MATLABTypeCastExpr castLeftExpr = new MATLABTypeCastExpr(type, leftExpr);
            MATLABTypeCastExpr castRightExpr = new MATLABTypeCastExpr(type, rightExpr);
            MATLABBinaryOp castOp = MATLABBinaryOp.fromName("DIVIDE");
            return new MATLABBinaryExpr(castLeftExpr, castOp, castRightExpr);
        } else {
            String functionName = null;
            if (opName.equals("IMPLIES")) {
                functionName = "impliesFunction";
                // mark that this function is getting called
                functionMap.get(functionName).functionCalled = true;
                return new MATLABBinaryFunctionCall(functionMap.get(functionName).name, leftExpr, rightExpr);
            } else if (opName.equals("ARROW")) {
                functionName = "arrowFunction";
                // mark that this function is getting called
                functionMap.get(functionName).functionCalled = true;
                String firstTimeVar = ((MATLABArrowFunction) functionMap.get(functionName)).firstTimeVar;
                // no duplicate addition
                if (!persistentVarMap.containsKey(firstTimeVar)) {
                    persistentVarMap.put(firstTimeVar, new MATLABBoolExpr(false));
                    persistentVarInits.add(new MATLABFirstTimeVarInit(firstTimeVar));
                }
                return new MATLABArrowFunctionCall(functionMap.get(functionName).name, firstTimeVar, leftExpr, rightExpr);
            } else if (opName.equals("EQUAL")) {
                return new MATLABBinaryFunctionCall("isequal", leftExpr, rightExpr);
            } else {
                return new MATLABBinaryFunctionCall(opFuncStr, leftExpr, rightExpr);
            }
        }
    } else {
        return new MATLABBinaryExpr(leftExpr, op, rightExpr);
    }
}
Also used : MATLABInt16Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt16Type) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) MATLABBinaryExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr) MATLABUInt64Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt64Type) MATLABInt32Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt32Type) MATLABUInt16Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt16Type) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) MATLABTypeCastExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr) MATLABBinaryFunctionCall(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryFunctionCall) MATLABInt8Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt8Type) MATLABInt64Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt64Type) MATLABArrowFunctionCall(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrowFunctionCall) MATLABFirstTimeVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABFirstTimeVarInit) MATLABUInt32Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt32Type) MATLABUInt8Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt8Type) MATLABBinaryOp(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryOp) MATLABBoolExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr)

Aggregations

MATLABType (com.rockwellcollins.atc.agree.codegen.ast.MATLABType)6 MATLABExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr)5 MATLABIdExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr)4 MATLABLocalBusVarInit (com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit)3 MATLABBinaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr)3 MATLABBoolExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr)3 MATLABTypeCastExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr)3 MATLABTypeInitExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeInitExpr)3 MATLABUnaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABUnaryExpr)3 Entry (java.util.Map.Entry)3 TreeMap (java.util.TreeMap)3 MATLABArrayAccessExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrayAccessExpr)2 MATLABBusElementExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBusElementExpr)2 MATLABDoubleExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABDoubleExpr)2 MATLABIntExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIntExpr)2 SortedMap (java.util.SortedMap)2 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)2 ArrayExpr (jkind.lustre.ArrayExpr)2 ArrayUpdateExpr (jkind.lustre.ArrayUpdateExpr)2 BinaryExpr (jkind.lustre.BinaryExpr)2