zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #20640
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/hof-next into lp:zorba.
Commit message:
fixes for fn:function-lookup + HOF cleanup
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/159229
fixes for fn:function-lookup + HOF cleanup
--
https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/159229
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp 2013-04-10 21:01:35 +0000
+++ src/compiler/codegen/plan_visitor.cpp 2013-04-16 20:07:32 +0000
@@ -477,6 +477,8 @@
{
if (!v.get_is_global_var()[i])
fnInfo->theScopedVarsIterators.push_back(pop_itstack());
+ else if (fnInfo->theScopedVarsValues[i] != NULL)
+ pop_itstack();
}
std::reverse(fnInfo->theScopedVarsIterators.begin(),
@@ -558,14 +560,7 @@
bool isPartialApply = false;
- // the arguments are reversed on the stack
- if (v.get_dot_var())
- {
- PlanIter_t iter = pop_itstack();
- argIters.push_back(iter);
- }
-
- for (size_t i = 0; i < numArgs-1; ++i)
+ for (csize i = 0; i < numArgs-1; ++i)
{
if (v.get_args()[i]->get_expr_kind() == argument_placeholder_expr_kind)
isPartialApply = true;
@@ -577,10 +572,7 @@
std::reverse(argIters.begin(), argIters.end());
- push_itstack(new DynamicFnCallIterator(sctx, qloc,
- argIters,
- v.get_dot_var() ? 1 : 0,
- isPartialApply));
+ push_itstack(new DynamicFnCallIterator(sctx, qloc, argIters, isPartialApply));
}
=== modified file 'src/compiler/expression/expr_clone.cpp'
--- src/compiler/expression/expr_clone.cpp 2013-03-27 09:00:05 +0000
+++ src/compiler/expression/expr_clone.cpp 2013-04-16 20:07:32 +0000
@@ -358,19 +358,12 @@
newArgs.push_back((*ite)->clone(udf, subst));
}
- expr* newDotVar = NULL;
- if (e->theDotVar)
- {
- newDotVar = e->theDotVar->clone(udf, subst);
- }
-
newExpr = theCCB->theEM->
create_dynamic_function_invocation_expr(theSctx,
udf,
theLoc,
e->theExpr->clone(udf, subst),
- newArgs,
- newDotVar);
+ newArgs);
break;
}
case argument_placeholder_expr_kind:
@@ -389,7 +382,6 @@
e->theFunctionItemInfo->theFunction,
e->theFunctionItemInfo->theArity,
e->is_inline(),
- e->needs_context_item(),
e->is_coercion());
std::vector<expr*>::const_iterator varIter =
=== modified file 'src/compiler/expression/expr_iter.cpp'
--- src/compiler/expression/expr_iter.cpp 2013-03-26 21:26:20 +0000
+++ src/compiler/expression/expr_iter.cpp 2013-04-16 20:07:32 +0000
@@ -706,10 +706,12 @@
theArgsIter = fiExpr->theFunctionItemInfo->theScopedVarsValues.begin();
theArgsEnd = fiExpr->theFunctionItemInfo->theScopedVarsValues.end();
+
for (; theArgsIter != theArgsEnd; ++theArgsIter)
{
- if ( ! *theArgsIter) // TODO: the vars values for prolog variables is null, so they have to be skipped, or the optimizer will trip and fall off. Maybe null vars values need not be remembered
+ if ( ! *theArgsIter)
continue;
+
EXPR_ITER_NEXT(*theArgsIter);
}
@@ -733,9 +735,6 @@
EXPR_ITER_NEXT(*theArgsIter);
}
- if (dfiExpr->theDotVar)
- EXPR_ITER_NEXT(dfiExpr->theDotVar);
-
EXPR_ITER_END();
return;
}
=== modified file 'src/compiler/expression/expr_manager.cpp'
--- src/compiler/expression/expr_manager.cpp 2013-03-27 09:00:05 +0000
+++ src/compiler/expression/expr_manager.cpp 2013-04-16 20:07:32 +0000
@@ -790,11 +790,10 @@
user_function* udf,
const QueryLoc& loc,
expr* anExpr,
- const std::vector<expr*>& args,
- expr* dotVar)
+ const std::vector<expr*>& args)
{
CREATE_AND_RETURN_EXPR(dynamic_function_invocation_expr, sctx, udf, loc,
- anExpr, args, dotVar);
+ anExpr, args);
}
@@ -813,13 +812,12 @@
user_function* udf,
const QueryLoc& loc,
function* f,
- uint32_t arity,
+ csize arity,
bool isInline,
- bool needsContextItem,
bool isCoercion)
{
CREATE_AND_RETURN_EXPR(function_item_expr, sctx, udf, loc,
- f, arity, isInline, needsContextItem, isCoercion);
+ f, arity, isInline, isCoercion);
}
@@ -828,11 +826,10 @@
user_function* udf,
const QueryLoc& loc,
bool isInline,
- bool needsContextItem,
bool isCoercion)
{
CREATE_AND_RETURN_EXPR(function_item_expr, sctx, udf, loc,
- isInline, needsContextItem, isCoercion);
+ isInline, isCoercion);
}
=== modified file 'src/compiler/expression/expr_manager.h'
--- src/compiler/expression/expr_manager.h 2013-03-27 09:00:05 +0000
+++ src/compiler/expression/expr_manager.h 2013-04-16 20:07:32 +0000
@@ -481,21 +481,20 @@
user_function* udf,
const QueryLoc& loc,
expr* anExpr,
- const std::vector<expr*>& args,
- expr* dotVar);
+ const std::vector<expr*>& args);
argument_placeholder_expr* create_argument_placeholder_expr(
static_context* sctx,
user_function* udf,
const QueryLoc& loc);
- function_item_expr* create_function_item_expr(static_context* sctx,
+ function_item_expr* create_function_item_expr(
+ static_context* sctx,
user_function* udf,
const QueryLoc& loc,
function* f,
- uint32_t arity,
+ csize arity,
bool isInline,
- bool needsContextItem,
bool isCoercion);
function_item_expr* create_function_item_expr(
@@ -503,7 +502,6 @@
user_function* udf,
const QueryLoc& loc,
bool isInline,
- bool needsContextItem,
bool isCoercion);
ftcontains_expr* create_ftcontains_expr(
=== modified file 'src/compiler/expression/expr_put.cpp'
--- src/compiler/expression/expr_put.cpp 2013-04-15 11:53:46 +0000
+++ src/compiler/expression/expr_put.cpp 2013-04-16 20:07:32 +0000
@@ -539,7 +539,7 @@
os << " " << theFunctionItemInfo->theQName->getStringValue()
<< "#" << theFunctionItemInfo->theArity << " [\n";
- for (ulong i = 0; i < theFunctionItemInfo->theScopedVarsValues.size(); i++)
+ for (csize i = 0; i < theFunctionItemInfo->theScopedVarsValues.size(); ++i)
{
os << indent << "using $"
<< theFunctionItemInfo->theScopedVarsNames[i]->getStringValue()
@@ -570,12 +570,6 @@
for (csize i = 0; i < theArgs.size(); ++i)
theArgs[i]->put(os);
- if (theDotVar)
- {
- os << indent << "using $";
- theDotVar->put(os);
- }
-
END_PUT();
}
=== modified file 'src/compiler/expression/function_item_expr.cpp'
--- src/compiler/expression/function_item_expr.cpp 2013-04-15 20:40:36 +0000
+++ src/compiler/expression/function_item_expr.cpp 2013-04-16 20:07:32 +0000
@@ -40,13 +40,11 @@
user_function* udf,
const QueryLoc& loc,
expr* anExpr,
- const std::vector<expr*>& args,
- expr* dotVar)
+ const std::vector<expr*>& args)
:
expr(ccb, sctx, udf, loc, dynamic_function_invocation_expr_kind),
theExpr(anExpr),
- theArgs(args),
- theDotVar(dotVar)
+ theArgs(args)
{
assert(anExpr != 0);
compute_scripting_kind();
@@ -92,7 +90,6 @@
function* f,
csize arity,
bool isInline,
- bool needsContextItem,
bool isCoercion)
:
expr(ccb, sctx, udf, loc, function_item_expr_kind),
@@ -102,7 +99,6 @@
f->getName(),
arity,
isInline,
- needsContextItem,
isCoercion))
{
assert(f != NULL);
@@ -116,7 +112,6 @@
user_function* udf,
const QueryLoc& loc,
bool isInline,
- bool needsContextItem,
bool isCoercion)
:
expr(ccb, sctx, udf, loc, function_item_expr_kind),
@@ -126,7 +121,6 @@
NULL,
0,
isInline,
- needsContextItem,
isCoercion))
{
compute_scripting_kind();
=== modified file 'src/compiler/expression/function_item_expr.h'
--- src/compiler/expression/function_item_expr.h 2013-04-10 21:01:35 +0000
+++ src/compiler/expression/function_item_expr.h 2013-04-16 20:07:32 +0000
@@ -74,8 +74,6 @@
--------
The arg exprs to pass to the function.
- theDotVars:
- -----------
********************************************************************************/
class dynamic_function_invocation_expr : public expr
{
@@ -86,7 +84,6 @@
protected:
expr * theExpr;
std::vector<expr*> theArgs;
- expr * theDotVar;
protected:
dynamic_function_invocation_expr(
@@ -95,16 +92,13 @@
user_function* udf,
const QueryLoc& loc,
expr* anExpr,
- const std::vector<expr*>& args,
- expr* dotVar);
+ const std::vector<expr*>& args);
public:
const expr* get_function() const { return theExpr; }
const std::vector<expr*>& get_args() const { return theArgs; }
- expr* get_dot_var() const { return theDotVar; }
-
void compute_scripting_kind();
void accept(expr_visitor&);
@@ -140,7 +134,6 @@
function* f,
csize arity,
bool isInline,
- bool needsContextItem,
bool isCoercion);
function_item_expr(
@@ -149,7 +142,6 @@
user_function* udf,
const QueryLoc& loc,
bool isInline,
- bool needsContextItem,
bool isCoercion);
virtual ~function_item_expr();
@@ -184,14 +176,10 @@
const store::Item_t& get_qname() const { return theFunctionItemInfo->theQName; }
- uint32_t get_arity() const { return theFunctionItemInfo->theArity; }
+ csize get_arity() const { return theFunctionItemInfo->theArity; }
bool is_inline() const { return theFunctionItemInfo->theIsInline; }
- bool needs_context_item() const { return theFunctionItemInfo->theNeedsContextItem; }
-
- void set_needs_ctx_item(bool v) { theFunctionItemInfo->theNeedsContextItem = v; }
-
bool is_coercion() const { return theFunctionItemInfo->theIsCoercion; }
void compute_scripting_kind();
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2013-04-16 06:45:24 +0000
+++ src/compiler/translator/translator.cpp 2013-04-16 20:07:32 +0000
@@ -1556,7 +1556,7 @@
coersionFlwor->add_clause(fiClause);
function_item_expr* inlineFuncExpr =
- CREATE(function_item)(theRootSctx, theUDF, loc, true, false, true);
+ CREATE(function_item)(theRootSctx, theUDF, loc, true, true);
coersionFlwor->set_return_expr(inlineFuncExpr);
@@ -1598,8 +1598,7 @@
loc,
CREATE(wrapper)(theRootSctx, theUDF, loc,
fiSubstVar),
- arguments,
- NULL);
+ arguments);
if (returnType->isBuiltinAtomicAny())
{
@@ -11554,8 +11553,7 @@
expr* dynamic_fncall =
CREATE(dynamic_function_invocation)(theRootSctx, theUDF, loc,
arguments[0],
- fncall_args,
- NULL);
+ fncall_args);
flwor->set_return_expr(dynamic_fncall);
@@ -11584,8 +11582,7 @@
expr* dynamic_fncall =
CREATE(dynamic_function_invocation)(theRootSctx, theUDF, loc,
arguments[0],
- fncall_args,
- NULL);
+ fncall_args);
expr* if_expr =
CREATE(if)(theRootSctx, theUDF, loc,
@@ -11705,10 +11702,6 @@
}
}
- expr* dotVar = NULL;
- if (lookup_var(getDotVarName(), loc, false))
- dotVar = DOT_REF;
-
// Implementing implicit iteration over the sequence returned by the source expr
flwor_expr* flworExpr = wrap_expr_in_flwor(sourceExpr, false);
@@ -11767,8 +11760,7 @@
expr* dynFuncInvocation =
CREATE(dynamic_function_invocation)(theRootSctx, theUDF, loc,
flworVarExpr,
- arguments,
- dotVar);
+ arguments);
flworExpr->set_return_expr(dynFuncInvocation);
}
@@ -11828,7 +11820,7 @@
expr* body;
function_item_expr* fiExpr =
- CREATE(function_item)(theRootSctx, theUDF, loc, false, false, false);
+ CREATE(function_item)(theRootSctx, theUDF, loc, false, false);
function* f = theSctx->lookup_fn(qnameItem, arity, loc);
@@ -11987,6 +11979,61 @@
break;
}
+ case FunctionConsts::FN_FUNCTION_LOOKUP_2:
+ {
+ expr* ctxItemVRef = NULL;
+ expr* ctxPosVRef = NULL;
+ expr* ctxSizeVRef = NULL;
+
+ var_expr* ctxItemVar = lookup_var(getDotVarName(), loc, false);
+ var_expr* ctxPosVar = lookup_var(getDotPosVarName(), loc, false);
+ var_expr* ctxSizeVar = lookup_var(getLastIdxVarName(), loc, false);
+
+ if (ctxItemVar)
+ ctxItemVRef = DOT_REF;
+
+ if (ctxPosVar)
+ ctxPosVRef = DOT_POS_REF;
+
+ if (ctxSizeVar)
+ ctxSizeVRef = DOT_SIZE_REF;
+
+ push_scope();
+
+ var_expr* substItemVar = bind_var(loc, getDotVarName(), var_expr::hof_var);
+ var_expr* substPosVar = bind_var(loc, getDotPosVarName(), var_expr::hof_var);
+ var_expr* substSizeVar = bind_var(loc, getLastIdxVarName(), var_expr::hof_var);
+
+ if (ctxItemVar)
+ substItemVar->set_unique_id(ctxItemVar->get_unique_id());
+
+ if (ctxPosVar)
+ substPosVar->set_unique_id(ctxPosVar->get_unique_id());
+
+ if (ctxSizeVar)
+ substSizeVar->set_unique_id(ctxSizeVar->get_unique_id());
+
+ fiExpr->add_variable(ctxItemVRef,
+ substItemVar,
+ substItemVar->get_name(),
+ ctxItemVar->get_kind() == var_expr::prolog_var ? 1 : 0);
+
+ fiExpr->add_variable(ctxPosVRef,
+ substPosVar,
+ substPosVar->get_name(),
+ ctxPosVar->get_kind() == var_expr::prolog_var ? 1 : 0);
+
+ fiExpr->add_variable(ctxSizeVRef,
+ substSizeVar,
+ substSizeVar->get_name(),
+ ctxSizeVar->get_kind() == var_expr::prolog_var ? 1 : 0);
+
+ body = generate_fn_body(f, foArgs, loc);
+
+ pop_scope();
+
+ break;
+ }
default:
{
body = generate_fn_body(f, foArgs, loc);
@@ -12031,7 +12078,7 @@
push_scope();
function_item_expr* fiExpr =
- CREATE(function_item)(theRootSctx, theUDF, loc, true, false, false);
+ CREATE(function_item)(theRootSctx, theUDF, loc, true, false);
push_nodestack(fiExpr);
=== modified file 'src/runtime/hof/dynamic_fncall_iterator.cpp'
--- src/runtime/hof/dynamic_fncall_iterator.cpp 2013-03-27 05:06:29 +0000
+++ src/runtime/hof/dynamic_fncall_iterator.cpp 2013-04-16 20:07:32 +0000
@@ -102,7 +102,6 @@
serialize_baseclass(ar,
(NaryBaseIterator<DynamicFnCallIterator, DynamicFnCallIteratorState>*)this);
- ar & theDotVarsCount;
ar & theIsPartialApply;
}
@@ -212,11 +211,7 @@
fnItem = static_cast<FunctionItem*>(targetItem.getp());
- if ((!fnItem->needsContextItem() &&
- theChildren.size() - 1 - theDotVarsCount != fnItem->getArity())
- ||
- (fnItem->needsContextItem()
- && theChildren.size() - 1 != fnItem->getArity()))
+ if (theChildren.size() - 1 != fnItem->getArity())
{
RAISE_ERROR(err::XPTY0004, loc,
ERROR_PARAMS("dynamic function invoked with incorrect number of arguments"));
@@ -224,7 +219,7 @@
if (theIsPartialApply)
{
- for (csize i = 1, pos = 0; i < theChildren.size() - theDotVarsCount; ++i)
+ for (csize i = 1, pos = 0; i < theChildren.size(); ++i)
{
if (dynamic_cast<ArgumentPlaceholderIterator*>(theChildren[i].getp()) == NULL)
{
@@ -276,11 +271,11 @@
#ifdef ZORBA_WITH_JSON
else if (targetItem->isJSONObject() || targetItem->isJSONArray())
{
- if (theChildren.size() - theDotVarsCount > 2)
+ if (theChildren.size() > 2)
{
RAISE_ERROR_NO_PARAMS(jerr::JNTY0018, loc);
}
- else if (theChildren.size() - theDotVarsCount == 2)
+ else if (theChildren.size() == 2)
{
isObjectNav = targetItem->isJSONObject();
selectorError = false;
=== modified file 'src/runtime/hof/dynamic_fncall_iterator.h'
--- src/runtime/hof/dynamic_fncall_iterator.h 2013-03-26 23:32:03 +0000
+++ src/runtime/hof/dynamic_fncall_iterator.h 2013-04-16 20:07:32 +0000
@@ -90,10 +90,7 @@
DynamicFnCallIteratorState>
{
protected:
- // This variable counts the number of children that hold DOT variables. They
- // are placed at the end of the children array.
- unsigned int theDotVarsCount;
- bool theIsPartialApply;
+ bool theIsPartialApply;
public:
SERIALIZABLE_CLASS(DynamicFnCallIterator);
@@ -108,12 +105,10 @@
static_context* sctx,
const QueryLoc& loc,
std::vector<PlanIter_t>& args,
- unsigned int dotVarsCount,
bool isPartialApply,
xqtref_t coercionTargetType = NULL)
:
NaryBaseIterator<DynamicFnCallIterator, DynamicFnCallIteratorState>(sctx, loc, args),
- theDotVarsCount(dotVarsCount),
theIsPartialApply(isPartialApply)
{
}
=== modified file 'src/runtime/hof/fn_hof_functions_impl.cpp'
--- src/runtime/hof/fn_hof_functions_impl.cpp 2013-04-16 09:21:11 +0000
+++ src/runtime/hof/fn_hof_functions_impl.cpp 2013-04-16 20:07:32 +0000
@@ -108,7 +108,7 @@
try
{
static_context_t impSctx = theSctx->create_child_context();
- ccb->theSctxMap[ccb->theSctxMap.size()] = impSctx;
+ ccb->theSctxMap[ccb->theSctxMap.size() + 1] = impSctx;
std::auto_ptr<dynamic_context> fiDctx;
fiDctx.reset(new dynamic_context(planState.theGlobalDynCtx));
=== modified file 'src/runtime/hof/function_item.cpp'
--- src/runtime/hof/function_item.cpp 2013-04-15 11:53:46 +0000
+++ src/runtime/hof/function_item.cpp 2013-04-16 20:07:32 +0000
@@ -56,9 +56,8 @@
const QueryLoc& loc,
function* func,
store::Item_t qname,
- uint32_t arity,
+ csize arity,
bool isInline,
- bool needsContextItem,
bool isCoercion)
:
theLoc(loc),
@@ -67,7 +66,6 @@
theQName(qname),
theArity(arity),
theIsInline(isInline),
- theNeedsContextItem(needsContextItem),
theIsCoercion(isCoercion)
{
#if 0
@@ -122,7 +120,6 @@
ar & theQName;
ar & theArity;
ar & theIsInline;
- ar & theNeedsContextItem;
ar & theIsCoercion;
// These are not serialized
@@ -219,13 +216,13 @@
}
-uint32_t FunctionItem::getArity() const
+csize FunctionItem::getArity() const
{
return theArity;
}
-uint32_t FunctionItem::getStartArity() const
+csize FunctionItem::getStartArity() const
{
return theFunctionItemInfo->theArity;
}
@@ -302,7 +299,6 @@
NULL,
theFunctionItemInfo->theLoc,
false,
- false,
false);
PlanIter_t udfCallIterator = theFunctionItemInfo->theFunction->
=== modified file 'src/runtime/hof/function_item.h'
--- src/runtime/hof/function_item.h 2013-04-15 20:40:36 +0000
+++ src/runtime/hof/function_item.h 2013-04-16 20:07:32 +0000
@@ -112,9 +112,8 @@
static_context* theClosureSctx;
function_t theFunction;
store::Item_t theQName;
- unsigned int theArity;
+ csize theArity;
bool theIsInline;
- bool theNeedsContextItem;
bool theIsCoercion;
std::vector<expr*> theScopedVarsValues;
@@ -138,9 +137,8 @@
const QueryLoc& loc,
function* func,
store::Item_t qname,
- uint32_t arity,
+ csize arity,
bool isInline,
- bool needsContextItem,
bool isCoercion);
virtual ~FunctionItemInfo();
@@ -166,7 +164,7 @@
protected:
FunctionItemInfo_t theFunctionItemInfo;
- unsigned int theArity; // The arity of the function
+ csize theArity; // The arity of the function
// item will decrease when a
// partial application is used.
@@ -213,7 +211,7 @@
const store::Item_t getFunctionName() const;
- unsigned int getArity() const;
+ csize getArity() const;
// returns the arity of the function before any partial application
unsigned int getStartArity() const;
@@ -222,8 +220,6 @@
bool isInline() const { return theFunctionItemInfo->theIsInline; }
- bool needsContextItem() const { return theFunctionItemInfo->theNeedsContextItem; }
-
bool isCoercion() const { return theFunctionItemInfo->theIsCoercion; }
zstring show() const;
Follow ups
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: noreply, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Zorba Build Bot, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Zorba Build Bot, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Markos Zaharioudakis, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Zorba Build Bot, 2013-04-16
-
Re: [Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Zorba Build Bot, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Markos Zaharioudakis, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Zorba Build Bot, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Zorba Build Bot, 2013-04-16
-
Re: [Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Zorba Build Bot, 2013-04-16
-
[Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Markos Zaharioudakis, 2013-04-16
-
Re: [Merge] lp:~zorba-coders/zorba/hof-next into lp:zorba
From: Markos Zaharioudakis, 2013-04-16