tCtx = tCtx.pushContext();
int pushCount = 0;
for (QuantifiedVarDeclNode qvdNode : qeNode.getVariables()) {
ILogicalExpression seq = vre(translateExpression(qvdNode.getSequence(), tCtx));
tCtx.pushVariableScope();
LogicalVariable forLVar = newLogicalVariable();
UnnestOperator unnest = new UnnestOperator(forLVar, mutable(ufce(BuiltinOperators.ITERATE, seq)));
SequenceType forVarType = SequenceType.create(AnyItemType.INSTANCE, Quantifier.QUANT_ONE);
if (qvdNode.getType() != null) {
forVarType = createSequenceType(qvdNode.getType());
}
XQueryVariable forVar = new XQueryVariable(createQName(qvdNode.getVariable()), forVarType, forLVar);
tCtx.varScope.registerVariable(forVar);
unnest.getInputs().add(mutable(tCtx.op));
tCtx.op = unnest;
++pushCount;
}
ILogicalExpression satExpr = sfce(BuiltinFunctions.FN_BOOLEAN_1,
vre(translateExpression(qeNode.getSatisfiesExpr(), tCtx)));
if (qeNode.getQuant() == QuantifierType.EVERY) {
satExpr = sfce(BuiltinFunctions.FN_NOT_1, satExpr);
}
SelectOperator select = new SelectOperator(mutable(satExpr), false, null);
select.getInputs().add(mutable(tCtx.op));
tCtx.op = select;
List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
List<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
LogicalVariable var = newLogicalVariable();
vars.add(var);
exprs.add(mutable(afce(BuiltinOperators.SEQUENCE, false,
ce(SequenceType.create(BuiltinTypeRegistry.XS_BOOLEAN, Quantifier.QUANT_ONE), Boolean.TRUE))));
AggregateOperator aop = new AggregateOperator(vars, exprs);
aop.getInputs().add(mutable(tCtx.op));
tCtx.op = aop;
for (int i = 0; i < pushCount; ++i) {
tCtx.popVariableScope();
}
tCtx = tCtx.popContext();
LogicalVariable lVar = createAssignment(
sfce(qeNode.getQuant() == QuantifierType.EVERY ? BuiltinFunctions.FN_EMPTY_1
: BuiltinFunctions.FN_EXISTS_1, vre(var)), tCtx);
return lVar;
}