zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #15056
[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.
Commit message:
Cleaned up eval expr
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/127096
Cleaned up eval expr
--
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/127096
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp 2012-09-17 00:36:37 +0000
+++ src/compiler/codegen/plan_visitor.cpp 2012-09-29 07:14:23 +0000
@@ -2074,23 +2074,35 @@
{
CODEGEN_TRACE_OUT("");
- csize numVars = v.var_count();
+ csize numVars = v.num_vars();
checked_vector<PlanIter_t> args;
args.reserve(numVars+1);
- std::vector<store::Item_t> varNames(numVars);
- std::vector<xqtref_t> varTypes(numVars);
std::vector<int> isGlobalVar(numVars);
- for (csize i = 0; i < numVars; ++i)
+ for (csize i = numVars; i > 0; --i)
{
- varNames[i] = v.get_var(i)->get_name();
- varTypes[i] = v.get_var(i)->get_type();
- isGlobalVar[i] = (v.get_arg_expr(i) == NULL);
-
- if (!isGlobalVar[i])
+ isGlobalVar[i-1] = false;
+
+ expr* arg = v.get_arg_expr(i-1);
+
+ if (arg->get_expr_kind() == var_expr_kind)
+ {
+ var_expr* varArg = static_cast<var_expr*>(arg);
+
+ if (varArg->get_kind() == var_expr::prolog_var)
+ isGlobalVar[i-1] = true;
+ }
+
+ if (!isGlobalVar[i-1])
+ {
args.push_back(pop_itstack());
+ }
+ else
+ {
+ pop_itstack();
+ }
}
args.push_back(pop_itstack());
@@ -2102,8 +2114,8 @@
push_itstack(new EvalIterator(sctx,
qloc,
args,
- varNames,
- varTypes,
+ v.get_var_names(),
+ v.get_var_types(),
isGlobalVar,
v.get_inner_scripting_kind(),
localBindings,
=== modified file 'src/compiler/expression/expr.cpp'
--- src/compiler/expression/expr.cpp 2012-09-28 10:54:54 +0000
+++ src/compiler/expression/expr.cpp 2012-09-29 07:14:23 +0000
@@ -1168,7 +1168,7 @@
lTryCatch->add_catch_expr((*lIter)->clone(subst));
}
- for (uint32_t i = 0; i < clause_count(); ++i)
+ for (csize i = 0; i < clause_count(); ++i)
{
lTryCatch->add_clause(theCatchClauses[i]->clone(subst));
}
@@ -1181,7 +1181,6 @@
********************************************************************************/
eval_expr::eval_expr(
- CompilerCB* creating_ccb,
CompilerCB* ccb,
static_context* sctx,
const QueryLoc& loc,
@@ -1189,7 +1188,7 @@
expr_script_kind_t scriptingKind,
namespace_context* nsCtx)
:
- namespace_context_base_expr(creating_ccb, sctx, loc, eval_expr_kind, nsCtx),
+ namespace_context_base_expr(ccb, sctx, loc, eval_expr_kind, nsCtx),
theExpr(e),
theInnerScriptingKind(scriptingKind),
theDoNodeCopy(false)
@@ -1225,20 +1224,25 @@
expr* eval_expr::cloneImpl(substitution_t& s) const
{
- eval_expr* new_eval = theCCB->theEM->create_eval_expr(
- NULL,
- theSctx,
- theLoc,
- theExpr->clone(s),
- theInnerScriptingKind,
- theNSCtx.getp());
+ eval_expr* new_eval = theCCB->theEM->
+ create_eval_expr(theSctx,
+ theLoc,
+ theExpr->clone(s),
+ theInnerScriptingKind,
+ theNSCtx.getp());
+
new_eval->setNodeCopy(theDoNodeCopy);
- for (csize i = 0; i < theVars.size(); ++i)
+ new_eval->theOuterVarNames = theOuterVarNames;
+ new_eval->theOuterVarTypes = theOuterVarTypes;
+
+ csize numVars = theOuterVarNames.size();
+
+ new_eval->theArgs.resize(numVars);
+
+ for (csize i = 0; i < numVars; ++i)
{
- var_expr* cloneVar = dynamic_cast<var_expr*>(theVars[i]->clone(s));
- assert(cloneVar != NULL);
- new_eval->add_var(cloneVar, (theArgs[i] ? theArgs[i]->clone(s) : NULL));
+ new_eval->theArgs[i] = theArgs[i]->clone(s);
}
return new_eval;
=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h 2012-09-28 10:54:54 +0000
+++ src/compiler/expression/expr.h 2012-09-29 07:14:23 +0000
@@ -1087,16 +1087,21 @@
--------
The expr that computes the query string to be evaluated by eval.
- theVars:
- --------
- There is one "eval" var (of kind var_expr::eval_var) for each var that is in
- scope where the call to the eval function appears at.
+ theOuterVarNames:
+ -----------------
+ The names of all the in-scope variables at the place where the call to the
+ eval function appears at.
+
+ theOuterVarTypes:
+ -----------------
+ The types of all the in-scope variables at the place where the call to the
+ eval function appears at.
theArgs:
--------
- The domain expr of each eval var. Initially, the domain expr of an eval var
- is always another var. However, that other var may be later inlined, so in
- general, the domain expr of an eval var may be any expr.
+ For each in-scope var, the vector contains an expr that returns the value of
+ the var. The expr is either a reference to the var itself, or the domain expr
+ of that var, if that var was inlined.
theInnerScriptingKind:
----------------------
@@ -1112,17 +1117,20 @@
friend class ExprManager;
protected:
- expr* theExpr;
-
- std::vector<var_expr*> theVars;
- std::vector<expr*> theArgs;
+ expr * theExpr;
+
+ std::vector<store::Item_t> theOuterVarNames;
+
+ std::vector<xqtref_t> theOuterVarTypes;
+
+ std::vector<expr*> theArgs;
expr_script_kind_t theInnerScriptingKind;
+
bool theDoNodeCopy;
protected:
eval_expr(
- CompilerCB* creating_ccb,
CompilerCB* ccb,
static_context* sctx,
const QueryLoc& loc,
@@ -1135,14 +1143,17 @@
expr* get_arg_expr(csize i) { return theArgs[i]; }
- csize var_count() const { return theVars.size(); }
-
- const var_expr* get_var(csize i) const { return theVars[i]; }
-
- void add_var(var_expr* var, expr* arg)
+ csize num_vars() const { return theOuterVarNames.size(); }
+
+ const std::vector<store::Item_t>& get_var_names() const { return theOuterVarNames; }
+
+ const std::vector<xqtref_t>& get_var_types() const { return theOuterVarTypes; }
+
+ void add_var(var_expr* var)
{
- theVars.push_back(var);
- theArgs.push_back(arg);
+ theOuterVarNames.push_back(var->get_name());
+ theOuterVarTypes.push_back(var->get_return_type());
+ theArgs.push_back(var);
}
expr_script_kind_t get_inner_scripting_kind() const;
@@ -1188,7 +1199,7 @@
expr* theExpr;
checked_vector<var_expr*> theVars;
std::vector<expr*> theArgs;
- bool theIsVarDeclaration;
+ bool theIsVarDeclaration;
protected:
debugger_expr(
=== modified file 'src/compiler/expression/expr_manager.cpp'
--- src/compiler/expression/expr_manager.cpp 2012-09-19 18:18:02 +0000
+++ src/compiler/expression/expr_manager.cpp 2012-09-29 07:14:23 +0000
@@ -529,14 +529,13 @@
eval_expr* ExprManager::create_eval_expr(
- CompilerCB* ccb,
static_context* sctx,
const QueryLoc& loc,
expr* e,
expr_script_kind_t scriptingKind,
namespace_context* nsCtx)
{
- CREATE_AND_RETURN_EXPR(eval_expr, ccb, sctx, loc, e, scriptingKind, nsCtx);
+ CREATE_AND_RETURN_EXPR(eval_expr, sctx, loc, e, scriptingKind, nsCtx);
}
#ifdef ZORBA_WITH_DEBUGGER
=== modified file 'src/compiler/expression/expr_manager.h'
--- src/compiler/expression/expr_manager.h 2012-09-19 18:18:02 +0000
+++ src/compiler/expression/expr_manager.h 2012-09-29 07:14:23 +0000
@@ -255,7 +255,6 @@
function_trace_expr* create_function_trace_expr(expr* aExpr);
eval_expr* create_eval_expr(
- CompilerCB* ccb,
static_context* sctx,
const QueryLoc& loc,
expr* e,
=== modified file 'src/compiler/expression/expr_put.cpp'
--- src/compiler/expression/expr_put.cpp 2012-09-28 07:26:34 +0000
+++ src/compiler/expression/expr_put.cpp 2012-09-29 07:14:23 +0000
@@ -435,6 +435,7 @@
END_PUT();
}
+
ostream& promote_expr::put(ostream& os) const
{
os << indent << "promote_expr " << theTargetType->toString()
@@ -443,7 +444,8 @@
END_PUT();
}
-ostream& trycatch_expr::put( ostream& os) const
+
+ostream& trycatch_expr::put(ostream& os) const
{
BEGIN_PUT( trycatch_expr );
@@ -463,21 +465,29 @@
return os;
}
+
ostream& eval_expr::put(ostream& os) const
{
BEGIN_PUT( eval_expr );
+
for (csize i = 0; i < theArgs.size(); i++)
{
- os << indent << "using $" << theVars[i]->get_name()->getStringValue() << " := [";
- os << endl << inc_indent;
+ os << indent << "using $"
+ << theOuterVarNames[i]->getStringValue()
+ << " := [" << endl << inc_indent;
+
if (theArgs[i])
theArgs[i]->put(os);
+
os << dec_indent << indent << "]" << endl;
}
- theExpr->put (os);
+
+ theExpr->put(os);
+
END_PUT();
}
+
ostream& function_trace_expr::put(ostream& os) const
{
BEGIN_PUT(function_trace_expr);
=== modified file 'src/compiler/expression/var_expr.h'
--- src/compiler/expression/var_expr.h 2012-09-20 17:43:35 +0000
+++ src/compiler/expression/var_expr.h 2012-09-29 07:14:23 +0000
@@ -124,7 +124,7 @@
{
unknown_var = 0,
- eval_var,
+ eval_var, // TODO: remove (it is used only in the debugger_expr)
for_var,
let_var,
=== modified file 'src/compiler/rewriter/rules/nodeid_rules.cpp'
--- src/compiler/rewriter/rules/nodeid_rules.cpp 2012-09-18 18:38:16 +0000
+++ src/compiler/rewriter/rules/nodeid_rules.cpp 2012-09-29 07:14:23 +0000
@@ -926,7 +926,7 @@
// Conservatively assume that, when executed, the eval query will apply
// a "node-id-sensitive" operation on each of the in-scope variables, so
// these variables must be bound to statndalone trees.
- csize numEvalVars = e->var_count();
+ csize numEvalVars = e->num_vars();
for (csize i = 0; i < numEvalVars; ++i)
{
@@ -939,22 +939,7 @@
theSourceFinder->findNodeSources(arg, &udfCaller, sources);
markSources(sources);
}
-#if 1
- std::vector<VarInfo*> globalVars;
- node->get_sctx()->getVariables(globalVars, false, true);
-
- FOR_EACH(std::vector<VarInfo*>, ite, globalVars)
- {
- var_expr* globalVar = (*ite)->getVar();
-
- if (globalVar == NULL)
- continue;
-
- std::vector<expr*> sources;
- theSourceFinder->findNodeSources(globalVar, &udfCaller, sources);
- markSources(sources);
- }
-#endif
+
break;
}
@@ -1154,7 +1139,6 @@
case var_expr::pos_var:
case var_expr::score_var:
case var_expr::count_var:
- case var_expr::eval_var:
default:
{
ZORBA_ASSERT(false);
@@ -1314,7 +1298,7 @@
{
eval_expr* e = static_cast<eval_expr*>(node);
- csize numVars = e->var_count();
+ csize numVars = e->num_vars();
for (csize i = 0; i < numVars; ++i)
{
@@ -1325,16 +1309,7 @@
markForSerialization(arg);
}
-#if 1
- std::vector<VarInfo*> globalVars;
- e->get_sctx()->getVariables(globalVars, true, true);
- FOR_EACH(std::vector<VarInfo*>, ite, globalVars)
- {
- var_expr* globalVar = (*ite)->getVar();
- markForSerialization(globalVar);
- }
-#endif
return;
}
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2012-09-28 10:54:54 +0000
+++ src/compiler/translator/translator.cpp 2012-09-29 07:14:23 +0000
@@ -10787,13 +10787,13 @@
scriptingKind = SEQUENTIAL_FUNC_EXPR;
}
- eval_expr* evalExpr =
- theExprManager->create_eval_expr(theCCB,
- theRootSctx,
- loc,
- foExpr->get_arg(0),
- scriptingKind,
- theNSCtx);
+ eval_expr* evalExpr = theExprManager->
+ create_eval_expr(theRootSctx,
+ loc,
+ foExpr->get_arg(0),
+ scriptingKind,
+ theNSCtx);
+
resultExpr = evalExpr;
std::vector<VarInfo*> inscopeVars;
@@ -10803,22 +10803,7 @@
for (csize i = 0; i < numVars; ++i)
{
- var_expr* ve = inscopeVars[i]->getVar();
-
- var_expr* evalVar = create_var(loc,
- ve->get_name(),
- var_expr::eval_var,
- ve->get_return_type());
-
- // At this point, the domain expr of an eval var is always another var.
- // However, that other var may be later inlined, so in general, the domain
- // expr of an eval var may be any expr.
- expr* valueExpr = NULL;
-
- if (ve->get_kind() != var_expr::prolog_var)
- valueExpr = ve;
-
- evalExpr->add_var(evalVar, valueExpr);
+ evalExpr->add_var(inscopeVars[i]->getVar());
}
break;
@@ -10870,7 +10855,8 @@
}
// create a flwor with LETs to hold the parameters
- flwor_expr* flworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
+ flwor_expr* flworExpr = theExprManager->
+ create_flwor_expr(theRootSctx, loc, false);
// wrap function's QName
expr* qnameExpr = wrap_in_type_promotion(arguments[0],
@@ -10931,8 +10917,8 @@
GET_BUILTIN_FUNCTION(FN_LOCAL_NAME_FROM_QNAME_1),
temp_vars[0]);
- localExpr =
- theExprManager->create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(FN_STRING_1), localExpr);
+ localExpr = theExprManager->
+ create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(FN_STRING_1), localExpr);
// qnameExpr := concat("Q{",
// namespaceExpr,
@@ -10946,61 +10932,33 @@
concat_args.push_back(localExpr);
concat_args.push_back(theExprManager->create_const_expr(theRootSctx, loc, query_params));
- qnameExpr = theExprManager->create_fo_expr(theRootSctx,
- loc,
- GET_BUILTIN_FUNCTION(FN_CONCAT_N),
- concat_args);
+ qnameExpr = theExprManager->
+ create_fo_expr(theRootSctx,
+ loc,
+ GET_BUILTIN_FUNCTION(FN_CONCAT_N),
+ concat_args);
- eval_expr* evalExpr =
- theExprManager->create_eval_expr(theCCB,
- theRootSctx,
- loc,
- qnameExpr,
- scriptingKind,
- theNSCtx);
+ eval_expr* evalExpr = theExprManager->
+ create_eval_expr(theRootSctx,
+ loc,
+ qnameExpr,
+ scriptingKind,
+ theNSCtx);
flworExpr->set_return_expr(evalExpr);
resultExpr = flworExpr;
-#if 0
- std::vector<VarInfo*> inscopeVars;
- theSctx->getVariables(inscopeVars);
-
- csize numVars = inscopeVars.size();
-
- for (csize i = 0; i < numVars; ++i)
- {
- var_expr* ve = inscopeVars[i]->getVar();
-
- if (ve->get_kind() == var_expr::prolog_var)
- continue;
-
- var_expr* evalVar = create_var(loc,
- ve->get_name(),
- var_expr::eval_var,
- ve->get_return_type());
-
- expr* valueExpr = ve;
- evalExpr->add_var(evalVar, valueExpr);
- }
-#endif
-
for (csize i = 0; i < temp_vars.size(); ++i)
{
- var_expr* evalVar = create_var(loc,
- temp_vars[i]->get_name(),
- var_expr::eval_var,
- temp_vars[i]->get_return_type());
-
- expr* valueExpr = temp_vars[i];
- evalExpr->add_var(evalVar, valueExpr);
+ evalExpr->add_var(temp_vars[i]);
}
break;
}
- default: {}
-
+ default:
+ {
+ }
} // switch
f->processPragma(resultExpr, theScopedPragmas);
Follow ups