Search in sources :

Example 1 with MATLABUInt32Type

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

MATLABFirstTimeVarInit (com.rockwellcollins.atc.agree.codegen.ast.MATLABFirstTimeVarInit)1 MATLABInt16Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABInt16Type)1 MATLABInt32Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABInt32Type)1 MATLABInt64Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABInt64Type)1 MATLABInt8Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABInt8Type)1 MATLABType (com.rockwellcollins.atc.agree.codegen.ast.MATLABType)1 MATLABUInt16Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt16Type)1 MATLABUInt32Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt32Type)1 MATLABUInt64Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt64Type)1 MATLABUInt8Type (com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt8Type)1 MATLABArrowFunctionCall (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrowFunctionCall)1 MATLABBinaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr)1 MATLABBinaryFunctionCall (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryFunctionCall)1 MATLABBinaryOp (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryOp)1 MATLABBoolExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr)1 MATLABExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr)1 MATLABTypeCastExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr)1