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