for (int i = 0; i < inputs.size(); ++i) {
if (nullContaminates(i)) {
ValueSource constSource = constSource(inputs, i);
if ((constSource != null) && constSource.isNull()) {
// Const null source on contaminating operand. Result is null.
return new TPreptimeValue(context.getOutputType(),
ValueSources.getNullSource(context.getOutputType()));
}
}
}
for (int i = 0; i < inputs.size(); ++i) {
if (constnessMatters(i)) {
Constantness constness = constness(context, i, inputs);
if (constness == Constantness.NOT_CONST)
return null;
if (constness == Constantness.CONST)
break;
assert constness == Constantness.UNKNOWN : constness;
}
}
// at this point, assume there's a constant value and we can evaluate it
finishPreptimePhase(context);
TExecutionContext execContext = context.createExecutionContext();
LazyList<ValueSource> inputValues = new LazyListBase<ValueSource>() {
@Override
public ValueSource get(int i) {
TPreptimeValue ptValue = inputs.get(i);
ValueSource source = ptValue.value();
assert allowNonConstsInEvaluation() || source != null
: "non-constant value where constant value expected";
return source;
}
@Override
public int size() {
return inputs.size();
}
};
Value outputValue = new Value(execContext.outputType());
evaluate(execContext, inputValues, outputValue);
return new TPreptimeValue(execContext.outputType(), outputValue);
}