use of gov.sandia.n2a.language.Visitor in project n2a by frothga.
the class JobC method prepareStaticObjects.
public void prepareStaticObjects(Operator op, final CRenderer context, final String pad) throws Exception {
Visitor visitor = new Visitor() {
public boolean visit(Operator op) {
if (op instanceof Output) {
Output o = (Output) op;
if (// column name is generated
o.operands.length < 3) {
String stringName = stringNames.get(op);
BackendDataC bed = (BackendDataC) context.part.backendData;
if (context.global ? bed.needGlobalPath : bed.needLocalPath) {
context.result.append(pad + "path (" + stringName + ");\n");
context.result.append(pad + stringName + " += \"." + o.variableName + "\";\n");
} else {
context.result.append(pad + stringName + " = \"" + o.variableName + "\";\n");
}
} else if (// mode flags are present
o.operands.length > 3) {
if (o.operands[0] instanceof Constant) {
// Detect raw flag
Operator op3 = o.operands[3];
if (op3 instanceof Constant) {
if (op3.toString().contains("raw")) {
String outputName = outputNames.get(o.operands[0].toString());
context.result.append(pad + outputName + "->raw = true;\n");
}
}
}
}
// Continue to drill down, because I/O functions can be nested.
return true;
}
if (op instanceof Input) {
Input i = (Input) op;
if (i.operands[0] instanceof Constant) {
String inputName = inputNames.get(i.operands[0].toString());
if (!context.global) {
context.result.append(pad + inputName + "->epsilon = " + resolve(context.bed.dt.reference, context, false) + " / 1000;\n");
}
// Detect time flag
String mode = "";
if (i.operands.length > 3) {
// just assuming it's a constant string
mode = i.operands[3].toString();
} else if (i.operands[1] instanceof Constant) {
Constant c = (Constant) i.operands[1];
if (c.value instanceof Text)
mode = c.toString();
}
if (mode.contains("time")) {
context.result.append(pad + inputName + "->time = true;\n");
}
}
return true;
}
return true;
}
};
op.visit(visitor);
}
Aggregations