_t = _t.getNextSibling();
_t = __t146;
_t = _t.getNextSibling();
if ( inputState.guessing==0 ) {
RetrieveDesc rd = op.getRetrieveDesc();
if ((begin.getType() == VALUE) && (end.getType() == VALUE))
{
// Optimization: begin and end are constant values =>
// calculate start and length of SQL SUBSTRING function
// at compile time.
// Note, Semantic ensures begin and end are int or Integer values.
int beginValue = (begin.getValue() != null) ?
((Integer)begin.getValue()).intValue() : 0;
int endValue = (end.getValue() != null) ?
((Integer)end.getValue()).intValue() : 0;
if (beginValue < 0)
{
errorMsg.error(begin.getLine(), begin.getColumn(),
I18NHelper.getMessage(messages,
"jqlc.codegeneration.substring.beginnegative", // NOI18N
String.valueOf(beginValue)));
}
else if (endValue < beginValue)
{
errorMsg.error(op.getLine(), op.getColumn(),
I18NHelper.getMessage(messages,
"jqlc.codegeneration.substring.beginlargerend", // NOI18N
String.valueOf(beginValue), String.valueOf(endValue)));
}
// SQL length = end - begin
rd.addConstraint(null, RetrieveDesc.OP_VALUE,
new Integer(endValue-beginValue));
// SQL start index = begin + 1
rd.addConstraint(null, RetrieveDesc.OP_VALUE,
new Integer(beginValue+1));
}
else
{
// At least one of begin or end is a non constant value =>
// generate the arguments start and length of the SQL SUBSTRING
// function as binary plus/minus expressions.
// The next 3 line denote the SQL length = end - begin
expression(begin);
expression(end);
rd.addConstraint(null, RetrieveDesc.OP_SUB, null);
// The next 3 lines denote the SQL start index = begin + 1
rd.addConstraint(null, RetrieveDesc.OP_VALUE, new Integer(1));
expression(begin);
rd.addConstraint(null, RetrieveDesc.OP_ADD, null);
}
// now push the string on the constraint stack
expression(string);
rd.addConstraint(null, RetrieveDesc.OP_SUBSTRING, null);
}
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {