LogicalVariable forLVar = newLogicalVariable();
LogicalVariable posLVar = fvdNode.getPosVar() != null ? newLogicalVariable() : null;
UnnestOperator unnest = new UnnestOperator(forLVar,
mutable(ufce(BuiltinOperators.ITERATE, seq)), posLVar, BuiltinTypeRegistry.XS_INTEGER,
new VXQueryPositionWriter());
SequenceType forVarType = SequenceType.create(AnyItemType.INSTANCE, Quantifier.QUANT_ONE);
if (fvdNode.getType() != null) {
forVarType = createSequenceType(fvdNode.getType());
}
XQueryVariable forVar = new XQueryVariable(createQName(fvdNode.getForVar()), forVarType,
forLVar);
tCtx.varScope.registerVariable(forVar);
XQueryVariable posVar = null;
if (fvdNode.getPosVar() != null) {
posVar = new XQueryVariable(createQName(fvdNode.getPosVar()), SequenceType.create(
BuiltinTypeRegistry.XS_INTEGER, Quantifier.QUANT_ONE), posLVar);
tCtx.varScope.registerVariable(posVar);
}
assert fvdNode.getScoreVar() == null;
unnest.getInputs().add(mutable(tCtx.op));
tCtx.op = unnest;
++pushCount;
}
break;
}
case LET_CLAUSE: {
LetClauseNode lcNode = (LetClauseNode) cNode;
for (LetVarDeclNode lvdNode : lcNode.getVariables()) {
LogicalVariable seqVar = translateExpression(lvdNode.getSequence(), tCtx);
tCtx.pushVariableScope();
SequenceType letVarType = SequenceType.create(AnyItemType.INSTANCE, Quantifier.QUANT_ONE);
if (lvdNode.getType() != null) {
letVarType = createSequenceType(lvdNode.getType());
}
XQueryVariable letVar = new XQueryVariable(createQName(lvdNode.getLetVar()), letVarType, seqVar);
tCtx.varScope.registerVariable(letVar);