Search in sources :

Example 6 with Output

use of gov.sandia.n2a.language.function.Output 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);
}
Also used : Operator(gov.sandia.n2a.language.Operator) Input(gov.sandia.n2a.language.function.Input) Visitor(gov.sandia.n2a.language.Visitor) Constant(gov.sandia.n2a.language.Constant) Output(gov.sandia.n2a.language.function.Output) Text(gov.sandia.n2a.language.type.Text)

Aggregations

Operator (gov.sandia.n2a.language.Operator)6 Visitor (gov.sandia.n2a.language.Visitor)6 Output (gov.sandia.n2a.language.function.Output)6 AccessVariable (gov.sandia.n2a.language.AccessVariable)4 Variable (gov.sandia.n2a.eqset.Variable)3 Constant (gov.sandia.n2a.language.Constant)3 Input (gov.sandia.n2a.language.function.Input)3 Text (gov.sandia.n2a.language.type.Text)3 EquationSet (gov.sandia.n2a.eqset.EquationSet)2 BuildMatrix (gov.sandia.n2a.language.BuildMatrix)2 ReadMatrix (gov.sandia.n2a.language.function.ReadMatrix)2 ArrayList (java.util.ArrayList)2 InstanceTemporaries (gov.sandia.n2a.backend.internal.InstanceTemporaries)1 Population (gov.sandia.n2a.backend.internal.Population)1 Symbol (gov.sandia.n2a.backend.xyce.netlist.Symbol)1 XyceRenderer (gov.sandia.n2a.backend.xyce.netlist.XyceRenderer)1 EquationEntry (gov.sandia.n2a.eqset.EquationEntry)1 AccountableConnection (gov.sandia.n2a.eqset.EquationSet.AccountableConnection)1 ConnectionBinding (gov.sandia.n2a.eqset.EquationSet.ConnectionBinding)1 VariableReference (gov.sandia.n2a.eqset.VariableReference)1