zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #21128
[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:
Fixed bug in handling the type declaration of a window variable.
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/160731
Fixed bug in handling the type declaration of a window variable.
--
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/160731
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2013-04-24 02:25:42 +0000
+++ src/compiler/translator/translator.cpp 2013-04-24 17:52:34 +0000
@@ -12459,53 +12459,36 @@
SIMPLE_EXPR,
theCCB);
+ // Parameters, if any, have been translated into LET vars in a flwor expr.
+ // The UDF body, which in genral references these LET vars, must become the
+ // return expr of this flwor, and then, the flwor itself becomes the effective
+ // body of the udf.
if (flwor != NULL)
{
flwor->set_return_expr(body);
body = flwor;
- // Parameters and inscope vars have been wrapped into a flwor expression (see
- // begin_visit). We need to add these to the udf obj so that they will bound
- // at runtime. We must do this here (before we optimize the inline function
- // body, because optimization may remove clauses from the flwor expr
for (csize i = 0; i < flwor->num_clauses(); ++i)
{
- flwor_clause* lClause = flwor->get_clause(i);
- let_clause* letClause = dynamic_cast<let_clause*>(lClause);
- ZORBA_ASSERT(letClause != 0); // can only be a parameter bound using let
- var_expr* argVar = dynamic_cast<var_expr*>(letClause->get_expr());
+ let_clause* lc = static_cast<let_clause*>(flwor->get_clause(i));
+ var_expr* argVar = static_cast<var_expr*>(lc->get_expr());
+
+ // When the inline function item is (dynamically) invoked, the invoker can
+ // pass values of any type. So, contrary to static function calls, the code
+ // for arg-value type checking must be placed in the body of the udf itself,
+ // instead of the caller.
+ argVar->set_type(theRTM.ITEM_TYPE_STAR);
+ lc->set_expr(normalize_fo_arg(i, lc->get_expr(), udf.getp(), loc));
+
argVars.push_back(argVar);
-
- // Since the inline function items can be created in one place but then
- // invoked in many other places, it is not possible to perform function
- // call normalization. Instead the domain expressions of arg vars is
- // wrapped in type matches.
- letClause->set_expr(normalize_fo_arg(i,
- letClause->get_expr(),
- udf.getp(),
- loc));
}
}
- /* TODO: optimizing the HoF here is a very bad idea. This code can be safely removed
- anyways because the UDF optimization should take care of it.
- if (theCCB->theConfig.opt_level == CompilerCB::config::O1)
- {
- RewriterContext rCtx(theCCB,
- body,
- NULL,
- "Inline function",
- (theSctx->ordering_mode() == StaticContextConsts::ordered));
- GENV_COMPILERSUBSYS.getDefaultOptimizingRewriter()->rewrite(rCtx);
- body = rCtx.getRoot();
- }
- */
-
udf->setBody(body);
udf->setScriptingKind(body->get_scripting_detail());
udf->setArgVars(argVars);
- udf->setOptimized(true); // hof ????
+ udf->setOptimized(true); // TODO: this should not be set here HOF ????
// Get the function_item_expr and set its function to the udf created above.
function_item_expr* fiExpr = dynamic_cast<function_item_expr*>(theNodeStack.top());
@@ -12517,6 +12500,7 @@
udf->getName()->getStringValue().c_str());
}
+
/*******************************************************************************
FilterExpr ::= FilterExpr
(. (NCName | ParenthesizedExpr | VarRef | StringLiteral)
=== modified file 'src/runtime/sequences/sequences_impl.cpp'
--- src/runtime/sequences/sequences_impl.cpp 2013-04-24 17:26:02 +0000
+++ src/runtime/sequences/sequences_impl.cpp 2013-04-24 17:52:34 +0000
@@ -1865,28 +1865,31 @@
zorbatm::get_walltime_elapsed(t0, t1);
}
+
static void loadDocument(
- zstring const& aUri,
- static_context* aSctx,
- PlanState& aPlanState,
- QueryLoc const& loc,
- store::Item_t& oResult)
+ zstring const& aUri,
+ static_context* aSctx,
+ PlanState& aPlanState,
+ QueryLoc const& loc,
+ store::Item_t& oResult)
{
// Normalize input to handle filesystem paths, etc.
zstring lNormUri;
normalizeInputUri(aUri, aSctx, loc, &lNormUri);
// See if this (normalized) URI is already loaded in the store.
- try {
+ try
+ {
oResult = GENV_STORE.getDocument(lNormUri);
}
- catch (XQueryException& e) {
+ catch (XQueryException& e)
+ {
set_source(e, loc);
throw;
}
- if (oResult != NULL) {
+
+ if (oResult != NULL)
return;
- }
// Prepare a LoadProperties for loading the stream into the store
store::LoadProperties lLoadProperties;
@@ -1895,16 +1898,22 @@
// Resolve URI to a stream
zstring lErrorMessage;
- std::auto_ptr<internal::Resource> lResource = aSctx->resolve_uri
- (lNormUri, internal::EntityData::DOCUMENT, lErrorMessage);
+
+ std::auto_ptr<internal::Resource> lResource =
+ aSctx->resolve_uri(lNormUri, internal::EntityData::DOCUMENT, lErrorMessage);
+
internal::StreamResource* lStreamResource =
- dynamic_cast<internal::StreamResource*>(lResource.get());
- if (lStreamResource == NULL) {
+ dynamic_cast<internal::StreamResource*>(lResource.get());
+
+ if (lStreamResource == NULL)
+ {
throw XQUERY_EXCEPTION
(err::FODC0002, ERROR_PARAMS(aUri, lErrorMessage), ERROR_LOC(loc));
}
+
std::istream* lStream = lStreamResource->getStream();
- if (lStream == NULL) {
+ if (lStream == NULL)
+ {
throw XQUERY_EXCEPTION(err::FODC0002, ERROR_PARAMS( aUri ), ERROR_LOC(loc));
}
@@ -1914,22 +1923,28 @@
zorbatm::cputime t0user;
zorbatm::get_current_cputime (t0user);
zorbatm::get_current_walltime(t0);
- try {
+
+ try
+ {
store::Store& lStore = GENV.getStore();
zstring lBaseUri = aSctx->get_base_uri();
oResult = lStore.loadDocument(lBaseUri, lNormUri, *lStream, lLoadProperties);
fillTime(t0, t0user, aPlanState);
}
- catch (ZorbaException& e) {
+ catch (ZorbaException& e)
+ {
e.set_diagnostic(err::FODC0002);
set_source(e, loc);
throw;
}
- if (oResult == NULL) {
+
+ if (oResult == NULL)
+ {
throw XQUERY_EXCEPTION(err::FODC0002, ERROR_PARAMS( aUri ), ERROR_LOC(loc));
}
}
+
bool FnDocIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
store::Item_t uriItem;
Follow ups