public XQExpression visit(FLWRExpr flwr, XQueryContext ctxt) throws XQueryException {
boolean isLoopInvariant = true;
// #1 for loop
List<Binding> bindings = flwr.getClauses();
for(int i = 0; i < bindings.size(); i++) {
Binding b = bindings.get(i);
int type = b.getExpressionType();
if(flwr.isTransformed()) {
if(type == Binding.FOR_CLAUSE) {
// no need to analyze
return flwr;
} else {
LetClause lc = (LetClause) b;
lc.visit(this, ctxt);
if(lc.isLoopInvariant()) {
_pullup.put(lc, bindings);
}
}
} else {
if(type == Binding.FOR_CLAUSE) {
ForClause forClause = (ForClause) b;
int loopDepth = forClause.getLoopDepth();
if(loopDepth <= 1) {
_protectHook = true;
}
forClause.visit(this, ctxt);
_protectHook = false;
} else {
b.visit(this, ctxt);
}
}
isLoopInvariant &= b.isLoopInvariant();
}
// #2 return
XQExpression filteredRet = flwr.getFilteredReturnExpr();
if(filteredRet != null) {
XQExpression filteredRet2 = filteredRet.visit(this, ctxt);