use of com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt8Type 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);
}
}
Aggregations