Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/hof-next into lp:zorba.
Commit message: some more hof cleanup Requested reviews: Markos Zaharioudakis (markos-za) For more details, see: https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/155684 some more hof cleanup -- https://code.launchpad.net/~zorba-coders/zorba/hof-next/+merge/155684 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-03-27 07:55:14 +0000 +++ src/compiler/codegen/plan_visitor.cpp 2013-03-27 09:33:25 +0000 @@ -472,9 +472,6 @@ fnInfo->theCCB = theCCB; fnInfo->theMustDeleteCCB = false; fnInfo->theLoc = qloc; - fnInfo->theFunction = v.get_function(); - fnInfo->theQName = v.get_qname(); - fnInfo->theArity = v.get_arity(); if (v.is_inline()) { @@ -484,7 +481,8 @@ fnInfo->theScopedVarsIterators.push_back(pop_itstack()); } - std::reverse(fnInfo->theScopedVarsIterators.begin(), fnInfo->theScopedVarsIterators.end()); + std::reverse(fnInfo->theScopedVarsIterators.begin(), + fnInfo->theScopedVarsIterators.end()); } @@ -494,30 +492,22 @@ csize numOuterVars = fnInfo->theScopedVarsNames.size(); for (csize i = 0; i < numOuterVars; ++i) { - var_expr* ve = theCCB->theEM->create_var_expr(fnInfo->theClosureSctx, - NULL, - qloc, - var_expr::hof_var, - fnInfo->theScopedVarsNames[i].getp()); - if (!fnInfo->theIsGlobalVar[i]) { ++curChild; - if (fnInfo->theSubstVarsValues[i] != NULL - && + if (fnInfo->theSubstVarsValues[i] != NULL && fnInfo->theSubstVarsValues[i]->get_unique_id() == 0) { fnInfo->theSubstVarsValues[i]->set_var_info(NULL); fnInfo->theSubstVarsValues[i]->set_unique_id(theNextDynamicVarId++); } - ve->set_unique_id(fnInfo->theSubstVarsValues[i]->get_unique_id()); fnInfo->theVarId[i] = fnInfo->theSubstVarsValues[i]->get_unique_id(); } else { - static_context* outerSctx = fnInfo->theClosureSctx->get_parent(); + static_context* outerSctx = fnInfo->theClosureSctx; VarInfo* outerGlobalVar = outerSctx->lookup_var(fnInfo->theScopedVarsNames[i]); @@ -536,15 +526,12 @@ } } - if (fnInfo->theSubstVarsValues[i] != NULL - && + if (fnInfo->theSubstVarsValues[i] != NULL && fnInfo->theSubstVarsValues[i]->get_unique_id() == 0) { fnInfo->theSubstVarsValues[i]->set_unique_id(outerGlobalVarId); } - ve->set_unique_id(outerGlobalVarId); - fnInfo->theVarId[i] = outerGlobalVarId; } } // for === modified file 'src/compiler/expression/expr_clone.cpp' --- src/compiler/expression/expr_clone.cpp 2013-03-26 21:26:20 +0000 +++ src/compiler/expression/expr_clone.cpp 2013-03-27 09:33:25 +0000 @@ -387,7 +387,6 @@ udf, get_loc(), e->theFunctionItemInfo->theFunction, - e->theFunctionItemInfo->theFunction->getName(), e->theFunctionItemInfo->theArity, e->is_inline(), e->needs_context_item(), === modified file 'src/compiler/expression/expr_manager.cpp' --- src/compiler/expression/expr_manager.cpp 2013-03-23 15:20:54 +0000 +++ src/compiler/expression/expr_manager.cpp 2013-03-27 09:33:25 +0000 @@ -813,14 +813,13 @@ user_function* udf, const QueryLoc& loc, function* f, - store::Item* qname, uint32_t arity, bool isInline, bool needsContextItem, bool isCoercion) { CREATE_AND_RETURN_EXPR(function_item_expr, sctx, udf, loc, - f, qname, arity, isInline, needsContextItem, isCoercion); + f, arity, isInline, needsContextItem, isCoercion); } === modified file 'src/compiler/expression/expr_manager.h' --- src/compiler/expression/expr_manager.h 2013-03-23 15:20:54 +0000 +++ src/compiler/expression/expr_manager.h 2013-03-27 09:33:25 +0000 @@ -493,7 +493,6 @@ user_function* udf, const QueryLoc& loc, function* f, - store::Item* qname, uint32_t arity, bool isInline, bool needsContextItem, === modified file 'src/compiler/expression/expr_type.cpp' --- src/compiler/expression/expr_type.cpp 2013-03-16 08:48:16 +0000 +++ src/compiler/expression/expr_type.cpp 2013-03-27 09:33:25 +0000 @@ -653,12 +653,15 @@ case function_item_expr_kind: { theType = rtm.ANY_FUNCTION_TYPE_ONE; + function_item_expr* fiExpr = static_cast<function_item_expr*>(this); + if (fiExpr->get_function() != NULL) { const xqtref_t& retType = fiExpr->get_function()->getSignature().returnType(); std::vector<xqtref_t> paramTypes; - for (csize i=0; i<fiExpr->get_function()->getSignature().paramCount(); i++ ) + + for (csize i = 0; i < fiExpr->get_function()->getSignature().paramCount(); ++i) paramTypes.push_back(fiExpr->get_function()->getSignature()[i]); theType = new FunctionXQType(&rtm, paramTypes, retType, TypeConstants::QUANT_ONE); === modified file 'src/compiler/expression/function_item_expr.cpp' --- src/compiler/expression/function_item_expr.cpp 2013-03-26 21:26:20 +0000 +++ src/compiler/expression/function_item_expr.cpp 2013-03-27 09:33:25 +0000 @@ -90,8 +90,7 @@ user_function* udf, const QueryLoc& loc, function* f, - store::Item* qname, - uint32_t arity, + csize arity, bool isInline, bool needsContextItem, bool isCoercion) @@ -100,7 +99,7 @@ theFunctionItemInfo(new FunctionItemInfo(sctx, loc, f, - qname, + f->getName(), arity, isInline, needsContextItem, @@ -130,7 +129,7 @@ needsContextItem, isCoercion)) { - theScriptingKind = SIMPLE_EXPR; + compute_scripting_kind(); } @@ -139,6 +138,13 @@ } +void function_item_expr::compute_scripting_kind() +{ + // ???? TODO + theScriptingKind = SIMPLE_EXPR; +} + + void function_item_expr::add_variable( expr* var, var_expr* substVar, @@ -158,13 +164,6 @@ } -void function_item_expr::compute_scripting_kind() -{ - // ???? TODO - theScriptingKind = SIMPLE_EXPR; -} - - store::Item_t function_item_expr::create_inline_fname(const QueryLoc& loc) { store::Item_t name; @@ -177,7 +176,7 @@ } -DEF_EXPR_ACCEPT (function_item_expr); +DEF_EXPR_ACCEPT(function_item_expr); }//end of namespace === modified file 'src/compiler/expression/function_item_expr.h' --- src/compiler/expression/function_item_expr.h 2013-03-26 23:32:03 +0000 +++ src/compiler/expression/function_item_expr.h 2013-03-27 09:33:25 +0000 @@ -138,8 +138,7 @@ user_function* udf, const QueryLoc& loc, function* f, - store::Item* aQName, - uint32_t aArity, + csize arity, bool isInline, bool needsContextItem, bool isCoercion); === modified file 'src/compiler/translator/translator.cpp' --- src/compiler/translator/translator.cpp 2013-03-27 05:06:29 +0000 +++ src/compiler/translator/translator.cpp 2013-03-27 09:33:25 +0000 @@ -1568,8 +1568,6 @@ // bind the function item variable in the inner flwor flwor_expr* inner_flwor = CREATE(flwor)(theRootSctx, theUDF, loc, false); - var_expr* inner_arg_var = create_var(loc, fnItem_var->get_name(), var_expr::let_var); - inner_arg_var->set_param_pos(inner_flwor->num_clauses()); // Handle parameters. For each parameter, a let binding is added to the inner flwor. std::vector<expr*> arguments; // Arguments to the dynamic function call @@ -11934,7 +11932,6 @@ expr* fiExpr = CREATE(function_item)(theRootSctx, theUDF, loc, f, - f->getName(), arity, false, // not inline needs_context_item, @@ -11964,39 +11961,6 @@ push_nodestack(fiExpr); - // Translate the return tyoe - xqtref_t returnType = theRTM.ITEM_TYPE_STAR; - if (v.getReturnType() != 0) - { - v.getReturnType()->accept(*this); - returnType = pop_tstack(); - } - - // Translate the type declarations for the function params - rchandle<ParamList> params = v.getParamList(); - std::vector<xqtref_t> paramTypes; - - if (params != 0) - { - std::vector<rchandle<Param> >::const_iterator lIt = params->begin(); - for(; lIt != params->end(); ++lIt) - { - const Param* param = lIt->getp(); - const SequenceType* paramType = param->get_typedecl(); - if (paramType == 0) - { - paramTypes.push_back(theRTM.ITEM_TYPE_STAR); - } - else - { - paramType->accept(*this); - paramTypes.push_back(pop_tstack()); - } - } - } - - flwor_expr* flwor = NULL; - // Handle function parameters. Translation of the params, if any, results to // a flwor expr with one let binding for each function parameter: // @@ -12005,6 +11969,8 @@ // let $xN as TN := _xN // // where each _xi is an arg var. + rchandle<ParamList> params = v.getParamList(); + flwor_expr* flwor = NULL; if (params) { params->accept(*this); @@ -12015,8 +11981,7 @@ flwor = CREATE(flwor)(theRootSctx, theUDF, loc, false); } - // Handle inscope variables. For each inscope var, a let binding is added to - // the flwor. + // Handle inscope variables. std::vector<VarInfo*>::iterator ite = scopedVars.begin(); for(; ite != scopedVars.end(); ++ite) @@ -12045,16 +12010,14 @@ else throw; } + + fiExpr->add_variable(varExpr, subst_var, varExpr->get_name(), 0); } else { subst_var = varExpr; + fiExpr->add_variable(NULL, subst_var, varExpr->get_name(), 1); } - - if (kind == var_expr::prolog_var) - fiExpr->add_variable(NULL, subst_var, varExpr->get_name(), 1 /*var is global if it's a prolog var*/); - else - fiExpr->add_variable(varExpr, subst_var, varExpr->get_name(), 0); } if (flwor->num_clauses() > 0) @@ -12203,10 +12166,6 @@ if (theCCB->theConfig.translate_cb != NULL && theCCB->theConfig.optimize_cb == NULL) theCCB->theConfig.translate_cb(udf->getBody(), udf->getName()->getStringValue().c_str()); - - if (theCCB->theConfig.optimize_cb != NULL) - theCCB->theConfig.optimize_cb(udf->getBody(), - udf->getName()->getStringValue().c_str()); } /******************************************************************************* === modified file 'src/runtime/core/fncall_iterator.cpp' --- src/runtime/core/fncall_iterator.cpp 2013-03-17 13:55:28 +0000 +++ src/runtime/core/fncall_iterator.cpp 2013-03-27 09:33:25 +0000 @@ -122,25 +122,30 @@ /******************************************************************************* Called by the openImpl method of UDFunctionCallIterator. ********************************************************************************/ -void UDFunctionCallIteratorState::open(PlanState& planState, user_function* udf, bool theIsDynamic, store::ItemHandle<FunctionItem>& theFunctionItem) +void UDFunctionCallIteratorState::open( + PlanState& planState, + user_function* udf, + bool theIsDynamic, + store::ItemHandle<FunctionItem>& theFunctionItem) { thePlan = udf->getPlan(thePlanStateSize).getp(); thePlanStateSize = thePlan->getStateSizeOfSubtree(); - // Must allocate new dctx, as child of the "current" dctx, because the udf - // may be a recursive udf with local block vars, all of which have the same - // dynamic-context id, but they are distinct vars. + // Must allocate new dctx because the udf may be a recursive udf with local + // block vars, all of which have the same dynamic-context id, but they are + // distinct vars. if (theIsDynamic) { if (theFunctionItem->getDctx() == NULL) theFunctionItem->setDctx(new dynamic_context(planState.theGlobalDynCtx)); + theLocalDCtx = new dynamic_context(theFunctionItem->getDctx()); } else { - theLocalDCtx = new dynamic_context(planState.theGlobalDynCtx); + theLocalDCtx = new dynamic_context(planState.theGlobalDynCtx); } thePlanState = new PlanState(theIsDynamic ? theFunctionItem->getDctx() : planState.theGlobalDynCtx, === modified file 'src/runtime/core/fncall_iterator.h' --- src/runtime/core/fncall_iterator.h 2013-03-26 23:32:03 +0000 +++ src/runtime/core/fncall_iterator.h 2013-03-27 09:33:25 +0000 @@ -134,8 +134,8 @@ typedef std::vector<LetVarIter_t> ArgVarRefs; protected: - user_function * theUDF; - bool theIsDynamic; + user_function * theUDF; + bool theIsDynamic; store::ItemHandle<FunctionItem> theFunctionItem; public: @@ -149,10 +149,10 @@ public: UDFunctionCallIterator( - static_context* sctx, - const QueryLoc& loc, - std::vector<PlanIter_t>& args, - const user_function* aUDF); + static_context* sctx, + const QueryLoc& loc, + std::vector<PlanIter_t>& args, + const user_function* aUDF); bool isUpdating() const; === modified file 'src/runtime/hof/function_item.h' --- src/runtime/hof/function_item.h 2013-03-27 07:55:14 +0000 +++ src/runtime/hof/function_item.h 2013-03-27 09:33:25 +0000 @@ -170,7 +170,7 @@ class FunctionItem : public store::Item, public zorba::serialization::SerializeBaseClass { protected: - FunctionItemInfo_t theFunctionItemInfo; + FunctionItemInfo_t theFunctionItemInfo; unsigned int theArity; // The arity of the function // item will decrease when a === modified file 'src/zorbaserialization/serialize_zorba_types.cpp' --- src/zorbaserialization/serialize_zorba_types.cpp 2013-03-26 23:32:03 +0000 +++ src/zorbaserialization/serialize_zorba_types.cpp 2013-03-27 09:33:25 +0000 @@ -45,6 +45,7 @@ #include "zorbatypes/decimal.h" #include "functions/function.h" + #include "runtime/hof/function_item.h" #include "context/static_context.h"
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp