Merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 11081
Merged at revision: 11412
Proposed branch: lp:~zorba-coders/zorba/markos-scratch
Merge into: lp:zorba
Diff against target: 2244 lines (+797/-606)
15 files modified
include/zorba/pregenerated/diagnostic_list.h (+4/-0)
modules/w3c/pregenerated/xqt-errors.xq (+19/-0)
src/compiler/expression/script_exprs.cpp (+11/-0)
src/compiler/expression/script_exprs.h (+2/-0)
src/compiler/translator/prolog_graph.cpp (+11/-4)
src/compiler/translator/prolog_graph.h (+1/-1)
src/compiler/translator/translator.cpp (+721/-591)
src/context/static_context.h (+1/-1)
src/diagnostics/diagnostic_en.xml (+17/-0)
src/diagnostics/pregenerated/diagnostic_list.cpp (+6/-0)
src/diagnostics/pregenerated/dict_en.cpp (+2/-0)
test/fots/CMakeLists.txt (+0/-6)
test/rbkt/Queries/CMakeLists.txt (+0/-1)
test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011.spec (+1/-1)
test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011a.spec (+1/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/markos-scratch
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Review via email: mp+161273@code.launchpad.net

Commit message

fixed various issues related to context item declarations

Description of the change

fixed various issues related to context item declarations

To post a comment you must log in.
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job markos-scratch-2013-04-27T03-44-48.15Z is finished.
  The final status was:

  175 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/markos-scratch into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job markos-scratch-2013-04-27T13-45-58.538Z is finished.
  The final status was:

  1 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

11081. By Markos Zaharioudakis

fixed failing tests

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job markos-scratch-2013-04-27T14-51-44.94Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
2--- include/zorba/pregenerated/diagnostic_list.h 2013-04-23 13:12:58 +0000
3+++ include/zorba/pregenerated/diagnostic_list.h 2013-04-27 14:33:25 +0000
4@@ -160,6 +160,8 @@
5
6 extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0111;
7
8+extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0113;
9+
10 extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0114;
11
12 extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0120;
13@@ -186,6 +188,8 @@
14
15 extern ZORBA_DLL_PUBLIC XQueryErrorCode XQDY0044;
16
17+extern ZORBA_DLL_PUBLIC XQueryErrorCode XQDY0054;
18+
19 extern ZORBA_DLL_PUBLIC XQueryErrorCode XQDY0061;
20
21 extern ZORBA_DLL_PUBLIC XQueryErrorCode XQDY0064;
22
23=== modified file 'modules/w3c/pregenerated/xqt-errors.xq'
24--- modules/w3c/pregenerated/xqt-errors.xq 2013-04-23 13:12:58 +0000
25+++ modules/w3c/pregenerated/xqt-errors.xq 2013-04-27 14:33:25 +0000
26@@ -683,6 +683,15 @@
27
28 (:~
29 :
30+ : Specifying a VarValue or VarDefaultValue for a context item declaration
31+ : in a library module is a static error.
32+ :
33+ : @see http://www.w3.org/2005/xqt-errors
34+:)
35+declare variable $err:XQST0113 as xs:QName := fn:QName($err:NS, "err:XQST0113");
36+
37+(:~
38+ :
39 : It is a static error for a decimal format declaration to define the
40 : same property more than once.
41 :
42@@ -816,6 +825,16 @@
43
44 (:~
45 :
46+ : It is a dynamic error if a cycle is encountered in the definition of a
47+ : module's dynamic context components, for example because of a cycle in
48+ : variable declarations.
49+ :
50+ : @see http://www.w3.org/2005/xqt-errors
51+:)
52+declare variable $err:XQDY0054 as xs:QName := fn:QName($err:NS, "err:XQDY0054");
53+
54+(:~
55+ :
56 : It is a dynamic error if the operand of a validate expression is a
57 : document node whose children do not consist of exactly one element node
58 : and zero or more comment and processing instruction nodes, in any order.
59
60=== modified file 'src/compiler/expression/script_exprs.cpp'
61--- src/compiler/expression/script_exprs.cpp 2013-02-21 16:34:45 +0000
62+++ src/compiler/expression/script_exprs.cpp 2013-04-27 14:33:25 +0000
63@@ -303,6 +303,17 @@
64 }
65
66
67+void var_set_expr::set_expr(expr* e)
68+{
69+ assert(theExpr == NULL);
70+
71+ theExpr = e;
72+ theVarExpr->add_set_expr(this);
73+
74+ compute_scripting_kind();
75+}
76+
77+
78 void var_set_expr::compute_scripting_kind()
79 {
80 checkNonUpdating(theExpr);
81
82=== modified file 'src/compiler/expression/script_exprs.h'
83--- src/compiler/expression/script_exprs.h 2013-02-21 16:34:45 +0000
84+++ src/compiler/expression/script_exprs.h 2013-04-27 14:33:25 +0000
85@@ -219,6 +219,8 @@
86
87 expr* get_expr() const { return theExpr; }
88
89+ void set_expr(expr* e);
90+
91 void compute_scripting_kind();
92
93 void accept(expr_visitor&);
94
95=== modified file 'src/compiler/translator/prolog_graph.cpp'
96--- src/compiler/translator/prolog_graph.cpp 2013-02-07 17:24:36 +0000
97+++ src/compiler/translator/prolog_graph.cpp 2013-04-27 14:33:25 +0000
98@@ -41,7 +41,14 @@
99 if ( v )
100 varName = BUILD_STRING('$', v->getVarExpr()->get_name()->getStringValue());
101
102- RAISE_ERROR(err::XQST0054, loc, ERROR_PARAMS(varName));
103+ if (theModuleSctx->xquery_version() == StaticContextConsts::xquery_version_1_0)
104+ {
105+ RAISE_ERROR(err::XQST0054, loc, ERROR_PARAMS(varName));
106+ }
107+ else
108+ {
109+ RAISE_ERROR(err::XQDY0054, loc, ERROR_PARAMS(varName));
110+ }
111 }
112
113
114@@ -96,7 +103,7 @@
115
116 In this query, the following cycle exists : var2 --> func2 --> func3 --> var2
117 ********************************************************************************/
118-void PrologGraph::reorder_globals(std::list<GlobalBinding>& prologVarBindings)
119+void PrologGraph::reorder_globals(std::vector<GlobalBinding>& prologVarBindings)
120 {
121 GraphImpl::const_iterator g_ite;
122 GraphImpl::const_iterator g_end = theGraph.end();
123@@ -151,7 +158,7 @@
124 // guarantee that if there is a path P from variable v1 to variable v2 in the
125 // original graph, then in the augmented graph there is a path P' from v1 to
126 // v2 such that P' does not contain any udfs. Therefore, the augmented graph
127- // contains a subgraph VG that consists of edges among variables only and which
128+ // contains a subgraph VG that consists of edges among variables only and
129 // which reflects the same (direct and transitive) dependencies among vars as
130 // the original graph.
131
132@@ -351,7 +358,7 @@
133
134 // STEP 5: reorder thePrologVars according to topological order
135 std::map<const var_expr*, GlobalBinding> gvmap;
136- std::list<GlobalBinding>::iterator bindIte = prologVarBindings.begin();
137+ std::vector<GlobalBinding>::iterator bindIte = prologVarBindings.begin();
138 for (; bindIte != prologVarBindings.end(); ++bindIte)
139 {
140 gvmap[(*bindIte).theVar] = *bindIte;
141
142=== modified file 'src/compiler/translator/prolog_graph.h'
143--- src/compiler/translator/prolog_graph.h 2013-02-07 17:24:36 +0000
144+++ src/compiler/translator/prolog_graph.h 2013-04-27 14:33:25 +0000
145@@ -172,7 +172,7 @@
146
147 void addEdge(const PrologGraphVertex& v1, const PrologGraphVertex& v2);
148
149- void reorder_globals(std::list<GlobalBinding>& prologVarBindings);
150+ void reorder_globals(std::vector<GlobalBinding>& prologVarBindings);
151
152 private:
153 void reportCycle(const QueryLoc& loc, const PrologGraphVertex* v);
154
155=== modified file 'src/compiler/translator/translator.cpp'
156--- src/compiler/translator/translator.cpp 2013-04-24 03:54:58 +0000
157+++ src/compiler/translator/translator.cpp 2013-04-27 14:33:25 +0000
158@@ -193,32 +193,7 @@
159
160 #define CTX_TM theSctx->get_typemanager()
161
162-
163-/*******************************************************************************
164- Internal names for certain implicit vars
165-********************************************************************************/
166-#define DOT_VARNAME getDotVarName()
167-#define DOT_POS_VARNAME getDotPosVarName()
168-#define LAST_IDX_VARNAME getLastIdxVarName()
169-
170-#define DOT_REF \
171- theExprManager->create_wrapper_expr(theRootSctx, \
172- theUDF, \
173- loc, \
174- lookup_ctx_var(DOT_VARNAME, loc))
175-
176-#define DOT_POS_REF \
177- theExprManager->create_wrapper_expr(theRootSctx, \
178- theUDF, \
179- loc, \
180- lookup_ctx_var(DOT_POS_VARNAME, loc))
181-
182-#define DOT_SIZE_REF \
183- theExprManager->create_wrapper_expr(theRootSctx, \
184- theUDF, \
185- loc, \
186- lookup_ctx_var(LAST_IDX_VARNAME, loc))
187-
188+
189 namespace translator_ns
190 {
191
192@@ -266,45 +241,125 @@
193 There is only one ModulesInfo instance per compilation. It is created on the
194 stack by the translate() method.
195
196- theCCB : The control block for the whole query.
197- (see compiler/api/compilercb.h).
198-
199- mod_ns_map : Maps resolved module location uris to target namespaces.
200- Used to skip compilation of a module that has been compiled
201- already (for example this is the case when 2 imported modules
202- both import a common module). It is also used to make sure
203- that a location uri does not appear in two module import
204- statements with different target namespaces.
205-
206- mod_sctx_map : Maps resolved module location uris to sctx objs containing
207- the var and udf declarations that are exported by the
208- modules corresponding to the location uris.
209-
210- theInitExprs : Contains the initializing expr for each prolog var in each
211- module participating in the compilation (see method
212- wrap_in_globalvar_assigh())
213-
214- globalSctx : A single static_context which contains ALL function and
215- variable declarations from ALL imported modules. This is
216- used to catch conflicting definitions.
217+ theCCB:
218+ -------
219+ The control block for the whole query. (see compiler/api/compilercb.h).
220+
221+ mod_ns_map:
222+ -----------
223+ Maps resolved module location uris to target namespaces. Used to skip
224+ compilation of a module that has been compiled already (for example this is
225+ the case when 2 imported modules both import a common module). It is also
226+ used to make sure that a location uri does not appear in two module import
227+ statements with different target namespaces.
228+
229+ mod_sctx_map:
230+ -------------
231+ Maps resolved module location uris to sctx objs containing the var and udf
232+ declarations that are exported by the modules corresponding to the location
233+ uris.
234+
235+ theInitExprs:
236+ -------------
237+ Contains the exprs for declaring and initializing (if an initializer expr was
238+ provided) each prolog var in each module participating in the compilation.
239+ Expressions are appended into this vector at the end of the translation of each
240+ module. Then, at the end of the translation of the main module, all these
241+ exprs are placed inside a top-level block expr, together with the body expr
242+ of the main module.
243+
244+ theDotItemVar:
245+ --------------
246+
247+ theDotPosVar:
248+ -------------
249+
250+ theDotSizeVar:
251+ --------------
252+
253+ theDotItemTypes:
254+ ----------------
255+
256+ theHaveDotItemDecl:
257+ -----------------------
258+ Initially false. It is set to true if any of the participating modules has
259+ an explicit context item declaration. In that case, initializer exprs must
260+ be added in theInitExprs to initialize the context position and size vars
261+ to 1.
262+
263+ theDotItemInitExpr:
264+ -------------------
265+ The position, within theInitExprs of the intilizer expr (if any) for the
266+ context item.
267+
268+ theGlobalSctx:
269+ --------------
270+ A single static_context which contains ALL function and variable declarations
271+ from ALL imported modules. This is used to catch conflicting definitions.
272
273 ********************************************************************************/
274 class ModulesInfo
275 {
276 public:
277 CompilerCB * theCCB;
278+
279 hashmap<zstring, static_context_t> mod_sctx_map;
280+
281 hashmap<zstring, zstring> mod_ns_map;
282- checked_vector<expr*> theInitExprs;
283- std::auto_ptr<static_context> globalSctx;
284+
285+ std::vector<expr*> theInitExprs;
286+
287+ var_expr * theDotItemVar;
288+ var_expr * theDotPosVar;
289+ var_expr * theDotSizeVar;
290+
291+ std::vector<xqtref_t> theDotItemTypes;
292+
293+ bool theHaveDotItemDecl;
294+
295+ csize theDotItemInitExpr;
296+
297+ static_context_t theGlobalSctx;
298
299 public:
300 ModulesInfo(CompilerCB* topCompilerCB)
301 :
302 theCCB(topCompilerCB),
303- globalSctx(static_cast<static_context *>
304- (topCompilerCB->theRootSctx->get_parent())->create_child_context())
305- {
306+ theHaveDotItemDecl(false),
307+ theDotItemInitExpr(0)
308+ {
309+ theGlobalSctx = topCompilerCB->theRootSctx->get_parent()->create_child_context();
310+ }
311+
312+ var_decl_expr* getDotPosDecl() const
313+ {
314+ ZORBA_ASSERT(theInitExprs[1]->get_expr_kind() == var_decl_expr_kind);
315+
316+ var_decl_expr* e = static_cast<var_decl_expr*>(theInitExprs[1]);
317+
318+ assert(e->get_var_expr()->get_name()->getLocalName() ==
319+ static_context::DOT_POS_VAR_NAME);
320+
321+ return e;
322+ }
323+
324+
325+ var_decl_expr* getDotSizeDecl() const
326+ {
327+ ZORBA_ASSERT(theInitExprs[2]->get_expr_kind() == var_decl_expr_kind);
328+
329+ var_decl_expr* e = static_cast<var_decl_expr*>(theInitExprs[2]);
330+
331+ assert(e->get_var_expr()->get_name()->getLocalName() ==
332+ static_context::DOT_SIZE_VAR_NAME);
333+
334+ return e;
335+ }
336+
337+
338+ void addDotItemType(const xqtref_t& type)
339+ {
340+ theDotItemTypes.push_back(type);
341 }
342 };
343
344@@ -431,10 +486,10 @@
345 thePrologVars vector contains one entry for each var V declared in the prolog
346 of this module. The entry maps the var_expr for V to the expr E that initializes
347 V (E is NULL for vars without init expr). At the end of each module translation,
348- the method wrap_in_globalvar_assign() creates appropriate initialization exprs
349- for each var in thePrologVars and registers them in theModulesInfo->theInitExprs,
350- so that they will be incorporated in the whole query plan at the end of the
351- translation of the root module.
352+ the method declare_var() creates appropriate initialization exprs for each var
353+ in thePrologVars and registers them in theModulesInfo->theInitExprs, so that
354+ they will be incorporated in the whole query plan at the end of the translation
355+ of the main module.
356
357 thePrologGraph :
358 ----------------
359@@ -480,7 +535,6 @@
360
361 theAssignedVars :
362 -------------------
363-
364 Local or global variables which are currently in-scope and for which (a)
365 an assignment statement has been encountered, and (b) the block expr that
366 declares the var has not been exited yet. This is used to determine the
367@@ -603,7 +657,7 @@
368
369 user_function * theUDF;
370
371- std::list<GlobalBinding> thePrologVars;
372+ std::vector<GlobalBinding> thePrologVars;
373
374 PrologGraph thePrologGraph;
375 PrologGraphVertex theCurrentPrologVFDecl;
376@@ -653,15 +707,15 @@
377 std::stack<bool> theIsWSBoundaryStack;
378 std::stack<const DirElemContent*> thePossibleWSContentStack;
379
380- function * op_concatenate;
381-
382- rchandle<QName> theDotVarName;
383- rchandle<QName> theDotPosVarName;
384- rchandle<QName> theLastIdxVarName;
385-
386- std::vector<pragma*> theScopedPragmas;
387-
388- StaticContextConsts::xquery_version_t theMaxLibModuleVersion;
389+ function * op_concatenate;
390+
391+ store::Item_t theDotItemVarName;
392+ store::Item_t theDotPosVarName;
393+ store::Item_t theDotSizeVarName;
394+
395+ std::vector<pragma*> theScopedPragmas;
396+
397+ StaticContextConsts::xquery_version_t theMaxLibModuleVersion;
398
399 public:
400
401@@ -711,10 +765,14 @@
402
403 if (rootTranslator == NULL)
404 {
405- QueryLoc loc;
406- theDotVarName = new QName(loc, static_context::DOT_VAR_NAME);
407- theDotPosVarName = new QName(loc, static_context::DOT_POS_VAR_NAME);
408- theLastIdxVarName = new QName(loc, static_context::DOT_SIZE_VAR_NAME);
409+ GENV_ITEMFACTORY->
410+ createQName(theDotItemVarName, "", "", static_context::DOT_VAR_NAME);
411+
412+ GENV_ITEMFACTORY->
413+ createQName(theDotPosVarName, "", "", static_context::DOT_POS_VAR_NAME);
414+
415+ GENV_ITEMFACTORY->
416+ createQName(theDotSizeVarName, "", "", static_context::DOT_SIZE_VAR_NAME);
417
418 theRootTranslator = this;
419 }
420@@ -730,20 +788,20 @@
421 }
422
423
424-const QName* getDotVarName() const
425+const store::Item_t& getDotItemVarName() const
426 {
427- return theRootTranslator->theDotVarName;
428+ return theRootTranslator->theDotItemVarName;
429 }
430
431
432-const QName* getDotPosVarName() const
433+const store::Item_t& getDotPosVarName() const
434 {
435 return theRootTranslator->theDotPosVarName;
436 }
437
438-const QName* getLastIdxVarName() const
439+const store::Item_t& getDotSizeVarName() const
440 {
441- return theRootTranslator->theLastIdxVarName;
442+ return theRootTranslator->theDotSizeVarName;
443 }
444
445
446@@ -1119,12 +1177,11 @@
447 ********************************************************************************/
448 var_expr* create_var(
449 const QueryLoc& loc,
450- store::Item* qname,
451+ const store::Item_t& qname,
452 var_expr::var_kind kind,
453 xqtref_t type = NULL)
454 {
455- var_expr* e = theExprManager->
456- create_var_expr(theRootSctx, theUDF, loc, kind, qname);
457+ var_expr* e = CREATE(var)(theRootSctx, theUDF, loc, kind, qname.getp());
458
459 if (kind == var_expr::pos_var ||
460 kind == var_expr::count_var ||
461@@ -1192,7 +1249,7 @@
462 ********************************************************************************/
463 var_expr* bind_var(
464 const QueryLoc& loc,
465- store::Item* qname,
466+ const store::Item_t& qname,
467 var_expr::var_kind kind,
468 xqtref_t type = NULL)
469 {
470@@ -1223,19 +1280,16 @@
471 /*******************************************************************************
472 Lookup a context variable, i.e., the var (if any) representing the context
473 item, or the context position, or the context size. The variable is identified
474- by its lexical qname (DOT_VARNAME, or DOT_POS_VARNAME, or LAST_IDX_VARNAME).
475+ by its qname.
476
477 Search starts from the "current" sctx and moves upwards the ancestor path
478 until the first instance (if any) of the variable is found.
479
480 If var is not found, the method raises appropriate error.
481 ********************************************************************************/
482-var_expr* lookup_ctx_var(const QName* qname, const QueryLoc& loc)
483+var_expr* lookup_ctx_var(const store::Item_t& qname, const QueryLoc& loc)
484 {
485- store::Item_t qnameItem;
486- expand_no_default_qname(qnameItem, qname, loc);
487-
488- VarInfo* var = theSctx->lookup_var(qnameItem.getp());
489+ VarInfo* var = theSctx->lookup_var(qname.getp());
490
491 if (var == NULL)
492 {
493@@ -1246,7 +1300,7 @@
494 }
495 else
496 {
497- zstring varName = static_context::var_name(qnameItem);
498+ zstring varName = static_context::var_name(qname);
499 RAISE_ERROR(err::XPDY0002, loc,
500 ERROR_PARAMS(ZED(XPDY0002_ContextUndeclared_2), varName));
501 }
502@@ -1333,7 +1387,7 @@
503 {
504 theSctx->bind_fn(f, nargs, loc);
505
506- theModulesInfo->globalSctx->bind_fn(f, nargs, loc);
507+ theModulesInfo->theGlobalSctx->bind_fn(f, nargs, loc);
508
509 if (export_sctx != NULL)
510 {
511@@ -1777,20 +1831,6 @@
512
513
514 /*******************************************************************************
515- Create a var_expr for a LET var with the given qname and add that var to the
516- local sctx obj. Then, create a LET clause for this new var_expr, with the given
517- expr "e" as its defining expression.
518-********************************************************************************/
519-forlet_clause* wrap_in_letclause(
520- expr* e,
521- const QueryLoc& loc,
522- const QName* qname)
523-{
524- return wrap_in_letclause(e, bind_var(loc, qname, var_expr::let_var));
525-}
526-
527-
528-/*******************************************************************************
529 Create a var_expr for a new internal LET var and then create a LET clause for
530 this new var_expr, with the given expr "e" as its defining expression. NOTE:
531 the internal var is not registered in the sctx.
532@@ -1818,24 +1858,6 @@
533
534
535 /*******************************************************************************
536- Create var_exprs for a FOR var with the given qname and its associated POS
537- var, whose qname is also given. Then add those vars to the local sctx obj.
538- Then, create a FOR clause for these new var_exprs, with the given expr as the
539- defining expression of the FOR var.
540-********************************************************************************/
541-forlet_clause* wrap_in_forclause(
542- expr* expr,
543- const QueryLoc& loc,
544- const QName* fv_qname,
545- const QName* pv_qname)
546-{
547- return wrap_in_forclause(expr,
548- bind_var(loc, fv_qname, var_expr::for_var),
549- bind_var(loc, pv_qname, var_expr::pos_var));
550-}
551-
552-
553-/*******************************************************************************
554 Create a var_expr for a new internal FOR var and then create a FOR clause for
555 this new var_expr, with the given expr as its defining expression. NOTE:
556 the internal var is not registered in the sctx.
557@@ -1918,15 +1940,16 @@
558
559 normalize_fo(countExpr);
560
561- forlet_clause* lcLast = wrap_in_letclause(countExpr, loc, LAST_IDX_VARNAME);
562+ var_expr* dotItemVar = bind_var(loc, getDotItemVarName(), var_expr::for_var);
563+ var_expr* dotPosVar = bind_var(loc, getDotPosVarName(), var_expr::pos_var);
564+ var_expr* dotSizeVar = bind_var(loc, getDotSizeVarName(), var_expr::let_var);
565+
566+ forlet_clause* lcLast = wrap_in_letclause(countExpr, dotSizeVar);
567
568 // Iterate over the input seq
569 varWrapper = CREATE(wrapper)(theRootSctx, theUDF, loc, lcInputVar);
570
571- for_clause* fcDot = wrap_in_forclause(varWrapper,
572- loc,
573- DOT_VARNAME,
574- DOT_POS_VARNAME);
575+ for_clause* fcDot = wrap_in_forclause(varWrapper, dotItemVar, dotPosVar);
576 flworExpr->add_clause(lcInputSeq);
577 flworExpr->add_clause(lcLast);
578 flworExpr->add_clause(fcDot);
579@@ -1934,10 +1957,12 @@
580 else
581 {
582 // Iterate over the input seq
583- for_clause* fcDot = wrap_in_forclause(inputExpr,
584- loc,
585- DOT_VARNAME,
586- DOT_POS_VARNAME);
587+
588+ var_expr* dotItemVar = bind_var(loc, getDotItemVarName(), var_expr::for_var);
589+ var_expr* dotPosVar = bind_var(loc, getDotPosVarName(), var_expr::pos_var);
590+
591+ for_clause* fcDot = wrap_in_forclause(inputExpr, dotItemVar, dotPosVar);
592+
593 flworExpr->add_clause(fcDot);
594 }
595
596@@ -2143,156 +2168,6 @@
597
598
599 /*******************************************************************************
600- Create declaration/initialization exprs for a prolog or block-local variable.
601-
602- The following 4 cases are considered:
603- 1. non-extrernal var with init expr,
604- 2. external var with init expr,
605- 3. non-extrernal var without init expr,
606- 4. external var without init expr,
607-
608- The corresponding expr created here (and added to stmts) are:
609-
610- 1. var_decl_expr(varExpr, initExpr)
611-
612- 2. var_decl_expr(varExpr, initExpr)
613-
614- In this case, the var_decl_expr will be a NOOP if a value has been assigned
615- to the external var via the c++ api. If so, this value overrides the
616- initializing expr in the prolog.
617-
618- 3. var_decl_expr(varExpr)
619-
620- 4. var_decl_expr(varExpr)
621-
622- In this case, the variable must be initialized via the c++ api before the
623- query is executed, and it is this external intialization that will declare
624- the var, ie, add an entry for the var in the dynamic ctx. Nevertheless, we
625- need to generate the var_decl_expr because it is when this expr is
626- encounered during codegen that an id will be assigned to the var (and
627- stored in the var_expr). This id is needed in order to register the var
628- in the dyn ctx.
629-
630- If the var declaration includes a type declaration, then the following expr
631- is also created and added to stmts:
632-
633- treat(ctxvar-get(varName), type)
634-
635-********************************************************************************/
636-void declare_var(const GlobalBinding& b, std::vector<expr*>& stmts)
637-{
638- function* varGet = BUILTIN_FUNC(OP_VAR_GET_1);
639-
640- expr* initExpr = b.theExpr;
641- var_expr* varExpr = b.theVar;
642-
643- const QueryLoc& loc = varExpr->get_loc();
644-
645- xqtref_t varType = varExpr->get_type();
646-
647- if (varType == NULL &&
648- varExpr->get_name()->getLocalName() == static_context::DOT_VAR_NAME)
649- {
650- varType = GENV_TYPESYSTEM.ITEM_TYPE_ONE;
651- }
652-
653- if (initExpr != NULL && varType != NULL && !b.is_extern())
654- {
655- initExpr = theExprManager->
656- create_treat_expr(theRootSctx,
657- theUDF,
658- loc,
659- initExpr,
660- varType,
661- TREAT_TYPE_MATCH);
662- }
663-
664- expr* declExpr = theExprManager->
665- create_var_decl_expr(theRootSctx, theUDF, loc, varExpr, initExpr);
666-
667- stmts.push_back(declExpr);
668-
669- // check type for vars that are external
670- if (varType != NULL && b.is_extern())
671- {
672- expr* getExpr = theExprManager->
673- create_fo_expr(theRootSctx, theUDF, loc, varGet, varExpr);
674-
675- expr* treatExpr = theExprManager->
676- create_treat_expr(theRootSctx,
677- theUDF,
678- loc,
679- getExpr,
680- varType,
681- TREAT_TYPE_MATCH);
682-
683- stmts.push_back(treatExpr);
684- }
685-}
686-
687-
688-/*******************************************************************************
689- Create declaration/initialization exprs for each prolog variable of this
690- module and put these exprs in theModulesInfo->theInitExprs. Then create a
691- sequential expr with its children being all the init exprs in
692- theModulesInfo->theInitExprs plus the given expr "e" as its last child.
693-
694- The method is called at the end of the translation of each module. The returned
695- expr is the result of the module translation. For the root module, the given
696- "program" expr is the result of translating the MainModule Program. For non-root
697- modules, "program" is an empty fn:concatenate() expr.
698-********************************************************************************/
699-expr* wrap_in_globalvar_assign(expr* program)
700-{
701- assert(theAssignedVars.size() == 1);
702-
703- for (std::list<GlobalBinding>::iterator i = thePrologVars.begin();
704- i != thePrologVars.end();
705- ++i)
706- {
707- declare_var(*i, theModulesInfo->theInitExprs);
708- }
709-
710- expr* preloadedInitExpr = static_cast<static_context*>(theSctx->get_parent())->
711- get_query_expr();
712-
713- if (!theModulesInfo->theInitExprs.empty() || preloadedInitExpr != NULL)
714- {
715- std::vector<expr*> args;
716- args.reserve(2 + theModulesInfo->theInitExprs.size());
717-
718- if (preloadedInitExpr)
719- args.push_back(preloadedInitExpr);
720-
721- args.insert(args.end(),
722- theModulesInfo->theInitExprs.begin(),
723- theModulesInfo->theInitExprs.end());
724-
725- if (!inLibraryModule())
726- {
727- args.push_back(program);
728- }
729-
730- block_expr* res = theExprManager->
731- create_block_expr(theRootSctx,
732- theUDF,
733- program->get_loc(),
734- theCCB->theIsEval,
735- args,
736- &theAssignedVars[0]);
737-
738- assert(theAssignedVars[0].empty());
739-
740- return res;
741- }
742- else
743- {
744- return program;
745- }
746-}
747-
748-
749-/*******************************************************************************
750 Imports a given schema
751 ********************************************************************************/
752 void* import_schema(
753@@ -2486,6 +2361,91 @@
754 }
755
756
757+/*******************************************************************************
758+ Create declaration/initialization exprs for a prolog or block-local variable.
759+
760+ The following 4 cases are considered:
761+ 1. non-extrernal var with init expr,
762+ 2. external var with init expr,
763+ 3. non-extrernal var without init expr,
764+ 4. external var without init expr,
765+
766+ The corresponding expr created here (and added to stmts) are:
767+
768+ 1. var_decl_expr(varExpr, initExpr)
769+
770+ 2. var_decl_expr(varExpr, initExpr)
771+
772+ In this case, the var_decl_expr will be a NOOP if a value has been assigned
773+ to the external var via the c++ api. If so, this value overrides the
774+ initializing expr in the prolog.
775+
776+ 3. var_decl_expr(varExpr)
777+
778+ 4. var_decl_expr(varExpr)
779+
780+ In this case, the variable must be initialized via the c++ api before the
781+ query is executed, and it is this external intialization that will declare
782+ the var, ie, add an entry for the var in the dynamic ctx. Nevertheless, we
783+ need to generate the var_decl_expr because it is when this expr is
784+ encounered during codegen that an id will be assigned to the var (and
785+ stored in the var_expr). This id is needed in order to register the var
786+ in the dyn ctx.
787+
788+ If the var declaration includes a type declaration, then the following expr
789+ is also created and added to stmts:
790+
791+ treat(ctxvar-get(varName), type)
792+
793+********************************************************************************/
794+void declare_var(const GlobalBinding& b, std::vector<expr*>& stmts)
795+{
796+ function* varGet = BUILTIN_FUNC(OP_VAR_GET_1);
797+
798+ expr* initExpr = b.theExpr;
799+ var_expr* varExpr = b.theVar;
800+
801+ const QueryLoc& loc = varExpr->get_loc();
802+
803+ if (varExpr == theModulesInfo->theDotItemVar)
804+ {
805+ if (initExpr != NULL)
806+ {
807+ expr* setExpr = CREATE(var_set)(theRootSctx, theUDF, loc, varExpr, initExpr);
808+
809+ stmts.push_back(setExpr);
810+
811+ theModulesInfo->theDotItemInitExpr = stmts.size() - 1;
812+ }
813+
814+ return;
815+ }
816+
817+ xqtref_t varType = varExpr->get_type();
818+
819+ if (initExpr != NULL && varType != NULL && !b.is_extern())
820+ {
821+ initExpr = CREATE(treat)(theRootSctx, theUDF, loc,
822+ initExpr, varType, TREAT_TYPE_MATCH);
823+ }
824+
825+ expr* declExpr = CREATE(var_decl)(theRootSctx, theUDF, loc, varExpr, initExpr);
826+
827+ stmts.push_back(declExpr);
828+
829+ // check type for vars that are external
830+ if (varType != NULL && b.is_extern())
831+ {
832+ expr* getExpr = CREATE(fo)(theRootSctx, theUDF, loc, varGet, varExpr);
833+
834+ expr* treatExpr = CREATE(treat)(theRootSctx, theUDF, loc,
835+ getExpr, varType, TREAT_TYPE_MATCH);
836+
837+ stmts.push_back(treatExpr);
838+ }
839+}
840+
841+
842 /////////////////////////////////////////////////////////////////////////////////
843 // //
844 // Module, VersionDecl, MainModule, LibraryModule, ModuleDecl //
845@@ -2510,10 +2470,12 @@
846 {
847 theSctx->set_language_kind(StaticContextConsts::language_kind_jsoniq);
848 std::string versionStr = v.get_version().str();
849+
850 if (versionStr == "1.0")
851 theSctx->set_jsoniq_version(StaticContextConsts::jsoniq_version_1_0);
852 else
853 theSctx->set_jsoniq_version(StaticContextConsts::jsoniq_version_unknown);
854+
855 return no_state;
856 }
857
858@@ -2539,8 +2501,7 @@
859 version = StaticContextConsts::xquery_version_unknown;
860 }
861
862- if (theMaxLibModuleVersion != StaticContextConsts::xquery_version_unknown
863- &&
864+ if (theMaxLibModuleVersion != StaticContextConsts::xquery_version_unknown &&
865 version > theMaxLibModuleVersion)
866 {
867 zstring maxversion;
868@@ -2581,20 +2542,19 @@
869
870 theAssignedVars.resize(theAssignedVars.size() + 1);
871
872- // Make sure that the context item is always in-scope inside the main module.
873- // However, do not create a ver_decl expr for it, because this will create a
874- // treat_as expr as well, so the ctx item will always appear as being used,
875- // and as a result it will always have to be set.
876+ // Make sure that the focus vars are always in-scope inside the main module.
877+ // Also create ver_decl exprs for them (but without any initializers and
878+ // type checks yet) and place them at the begininning of theModulesInfo->theInitExprs.
879 var_expr* var1 = bind_var(loc,
880- DOT_VARNAME,
881+ getDotItemVarName(),
882 var_expr::prolog_var,
883 theSctx->get_context_item_type());
884 var_expr* var2 = bind_var(loc,
885- DOT_POS_VARNAME,
886+ getDotPosVarName(),
887 var_expr::prolog_var,
888 theRTM.INTEGER_TYPE_ONE);
889 var_expr* var3 = bind_var(loc,
890- LAST_IDX_VARNAME,
891+ getDotSizeVarName(),
892 var_expr::prolog_var,
893 theRTM.INTEGER_TYPE_ONE);
894
895@@ -2606,12 +2566,26 @@
896 var2->set_unique_id(dynamic_context::IDVAR_CONTEXT_ITEM_POSITION);
897 var3->set_unique_id(dynamic_context::IDVAR_CONTEXT_ITEM_SIZE);
898
899- //GlobalBinding b(var, NULL, true);
900- //declare_var(b, theModulesInfo->theInitExprs);
901+ ZORBA_ASSERT(theModulesInfo->theInitExprs.empty());
902+
903+ expr* decl1Expr = CREATE(var_decl)(theRootSctx, theUDF, loc, var1, NULL);
904+ expr* decl2Expr = CREATE(var_decl)(theRootSctx, theUDF, loc, var2, NULL);
905+ expr* decl3Expr = CREATE(var_decl)(theRootSctx, theUDF, loc, var3, NULL);
906+
907+ theModulesInfo->theInitExprs.push_back(decl1Expr);
908+ theModulesInfo->theInitExprs.push_back(decl2Expr);
909+ theModulesInfo->theInitExprs.push_back(decl3Expr);
910+
911+ // Store the focus vars in theModulesInfo, so that lib modules can find them
912+ // and bind them in their own root static context as well.
913+ theModulesInfo->theDotItemVar = var1;
914+ theModulesInfo->theDotPosVar = var2;
915+ theModulesInfo->theDotSizeVar = var3;
916
917 return no_state;
918 }
919
920+
921 void end_visit(const MainModule& v, void* /*visit_state*/)
922 {
923 TRACE_VISIT_OUT();
924@@ -2620,33 +2594,116 @@
925
926 assert(theCCB->theIsEval || !program->is_updating());
927
928- // If an appliaction set a type for the context item via the c++ api, then
929- // create a full declaration for it in order to enforce that type.
930- if (!theHaveContextItemDecl &&
931- theRTM.ITEM_TYPE_ONE != theSctx->get_context_item_type())
932- {
933- var_expr* var = lookup_ctx_var(DOT_VARNAME, loc);
934- var->set_external(true);
935- GlobalBinding b(var, NULL, true);
936- declare_var(b, theModulesInfo->theInitExprs);
937- }
938-
939- // the main module debug iterator has no location otherwise
940- // this would take precedence over a child debug iterator
941- // starting in the same line
942+ // the main module debug iterator has no location otherwise this would take
943+ // precedence over a child debug iterator starting in the same line
944 wrap_in_debugger_expr(program, program->get_loc(), true);
945
946- program = wrap_in_globalvar_assign(program);
947+ assert(theAssignedVars.size() == 1);
948+
949+ // Handle declarations (or their absence) of the focus vars
950+ bool keepFocusDecls = true;
951+
952+ if (theModulesInfo->theHaveDotItemDecl)
953+ {
954+ expr* initExpr = CREATE(const)(theRootSctx, theUDF, loc, xs_integer(1));
955+
956+ var_decl_expr* dotPosDecl = theModulesInfo->getDotPosDecl();
957+ var_decl_expr* dotSizeDecl = theModulesInfo->getDotSizeDecl();
958+
959+ dotPosDecl->set_expr(initExpr);
960+ dotSizeDecl->set_expr(initExpr);
961+ }
962+ else if (theRTM.ITEM_TYPE_ONE != theSctx->get_context_item_type())
963+ {
964+ // An appliaction has set a type for the context item via the c++ api.
965+ theModulesInfo->addDotItemType(theSctx->get_context_item_type());
966+ }
967+ else
968+ {
969+ keepFocusDecls = false;
970+
971+ theModulesInfo->theInitExprs.erase(theModulesInfo->theInitExprs.begin());
972+ theModulesInfo->theInitExprs.erase(theModulesInfo->theInitExprs.begin());
973+ theModulesInfo->theInitExprs.erase(theModulesInfo->theInitExprs.begin());
974+ }
975+
976+ // Create exprs for the prolog vars and add them to theModulesInfo->theInitExprs
977+ std::vector<GlobalBinding>::iterator ite = thePrologVars.begin();
978+ std::vector<GlobalBinding>::iterator end = thePrologVars.end();
979+ for (; ite != end; ++ite)
980+ {
981+ declare_var(*ite, theModulesInfo->theInitExprs);
982+ }
983+
984+ if (keepFocusDecls)
985+ enforceDotItemTypes(loc);
986+
987+ // Put everything together under a single root expr.
988+ expr* preloadedInitExpr = static_cast<static_context*>(theSctx->get_parent())->
989+ get_query_expr();
990+
991+ if (!theModulesInfo->theInitExprs.empty() || preloadedInitExpr != NULL)
992+ {
993+ std::vector<expr*> args;
994+ args.reserve(2 + theModulesInfo->theInitExprs.size());
995+
996+ if (preloadedInitExpr)
997+ args.push_back(preloadedInitExpr);
998+
999+ args.insert(args.end(),
1000+ theModulesInfo->theInitExprs.begin(),
1001+ theModulesInfo->theInitExprs.end());
1002+
1003+ args.push_back(program);
1004+
1005+ program = CREATE(block)(theRootSctx, theUDF, program->get_loc(),
1006+ theCCB->theIsEval,
1007+ args,
1008+ &theAssignedVars[0]);
1009+
1010+ assert(theAssignedVars[0].empty());
1011+ }
1012
1013 push_nodestack(program);
1014
1015 theAssignedVars.pop_back();
1016
1017+ // "export" the program, if this is a load-prolog query.
1018 if (theModulesInfo->theCCB->isLoadPrologQuery())
1019 theSctx->set_query_expr(program);
1020 }
1021
1022
1023+void enforceDotItemTypes(const QueryLoc& loc)
1024+{
1025+ std::vector<expr*>::iterator ite;
1026+
1027+ if (theModulesInfo->theDotItemInitExpr > 0)
1028+ ite = theModulesInfo->theInitExprs.begin() + theModulesInfo->theDotItemInitExpr;
1029+ else
1030+ ite = theModulesInfo->theInitExprs.begin();
1031+
1032+ ++ite;
1033+
1034+ csize numTypes = theModulesInfo->theDotItemTypes.size();
1035+
1036+ for (csize i = 0; i < numTypes; ++ i)
1037+ {
1038+ function* varGet = BUILTIN_FUNC(OP_VAR_GET_1);
1039+
1040+ expr* getExpr = CREATE(fo)(theRootSctx, theUDF, loc,
1041+ varGet, theModulesInfo->theDotItemVar);
1042+
1043+ expr* treatExpr = CREATE(treat)(theRootSctx, theUDF, loc,
1044+ getExpr,
1045+ theModulesInfo->theDotItemTypes[i],
1046+ TREAT_TYPE_MATCH);
1047+
1048+ ite = theModulesInfo->theInitExprs.insert(ite, treatExpr);
1049+ }
1050+}
1051+
1052+
1053 /*******************************************************************************
1054 LibraryModule ::= ModuleDecl Prolog
1055 ********************************************************************************/
1056@@ -2656,6 +2713,10 @@
1057
1058 theAssignedVars.resize(theAssignedVars.size() + 1);
1059
1060+ bind_var(theModulesInfo->theDotItemVar, theRootSctx);
1061+ bind_var(theModulesInfo->theDotPosVar, theRootSctx);
1062+ bind_var(theModulesInfo->theDotSizeVar, theRootSctx);
1063+
1064 return no_state;
1065 }
1066
1067@@ -2663,15 +2724,20 @@
1068 {
1069 TRACE_VISIT_OUT();
1070
1071- expr* program = wrap_in_globalvar_assign(create_empty_seq(loc));
1072+ assert(theAssignedVars.size() == 1);
1073+
1074+ // Create exprs for the prolog vars and add them to theModulesInfo->theInitExprs
1075+ std::vector<GlobalBinding>::iterator ite = thePrologVars.begin();
1076+ std::vector<GlobalBinding>::iterator end = thePrologVars.end();
1077+ for (; ite != end; ++ite)
1078+ {
1079+ declare_var(*ite, theModulesInfo->theInitExprs);
1080+ }
1081
1082 theAssignedVars.pop_back();
1083
1084- // Note: There is no real reason to put the expr returned by
1085- // wrap_in_globalvar_assign() in theNodeStack. The only reason is for the
1086- // translate_aux() function to be able to pick that expr from the stack in
1087- // order to print it.
1088- push_nodestack(program);
1089+ // Note: Push a NULL to the node stack so that translate_aux() will work properly
1090+ push_nodestack(NULL);
1091 }
1092
1093
1094@@ -2696,19 +2762,15 @@
1095
1096 if (static_context::is_reserved_module(theModuleNamespace))
1097 {
1098- throw XQUERY_EXCEPTION(
1099- zerr::ZXQP0016_RESERVED_MODULE_TARGET_NAMESPACE,
1100- ERROR_PARAMS( theModuleNamespace ),
1101- ERROR_LOC( loc )
1102- );
1103+ RAISE_ERROR(zerr::ZXQP0016_RESERVED_MODULE_TARGET_NAMESPACE, loc,
1104+ ERROR_PARAMS(theModuleNamespace));
1105 }
1106
1107 if (theModulePrefix == "xml" || theModulePrefix == "xmlns")
1108- throw XQUERY_EXCEPTION(
1109- err::XQST0070,
1110- ERROR_PARAMS( theModulePrefix, ZED( NoRebindPrefix ) ),
1111- ERROR_LOC( loc )
1112- );
1113+ {
1114+ RAISE_ERROR(err::XQST0070, loc,
1115+ ERROR_PARAMS(theModulePrefix, ZED(NoRebindPrefix)));
1116+ }
1117
1118 theSctx->bind_ns(theModulePrefix, theModuleNamespace, loc);
1119
1120@@ -3223,7 +3285,7 @@
1121 }
1122 else
1123 {
1124- for (ulong i = 0; i < atlist->size(); ++i)
1125+ for (csize i = 0; i < atlist->size(); ++i)
1126 {
1127 compURIs.push_back(theSctx->resolve_relative_uri((*atlist)[i]).str());
1128 }
1129@@ -3294,18 +3356,16 @@
1130 // rather than using compURI directly, because we want the version
1131 // fragment to be passed to the mappers.
1132 zstring lErrorMessage;
1133- std::auto_ptr<internal::Resource> lResource;
1134- internal::StreamResource* lStreamResource = NULL;
1135+ std::auto_ptr<internal::Resource> resource;
1136+ internal::StreamResource* streamResource = NULL;
1137
1138 try
1139 {
1140- lResource =
1141- theSctx->resolve_uri(compModVer.versioned_uri(),
1142- internal::EntityData::MODULE,
1143- lErrorMessage);
1144+ resource = theSctx->resolve_uri(compModVer.versioned_uri(),
1145+ internal::EntityData::MODULE,
1146+ lErrorMessage);
1147
1148- lStreamResource =
1149- dynamic_cast<internal::StreamResource*> (lResource.get());
1150+ streamResource = dynamic_cast<internal::StreamResource*>(resource.get());
1151 }
1152 catch (ZorbaException& e)
1153 {
1154@@ -3313,21 +3373,16 @@
1155 throw;
1156 }
1157
1158- if (lStreamResource != NULL)
1159+ if (streamResource != NULL)
1160 {
1161- modfile = lStreamResource->getStream();
1162- compURL = lStreamResource->getStreamUrl();
1163+ modfile = streamResource->getStream();
1164+ compURL = streamResource->getStreamUrl();
1165 }
1166 else
1167 {
1168- throw XQUERY_EXCEPTION(
1169- err::XQST0059,
1170- ERROR_PARAMS(
1171- ZED( XQST0059_SpecificationMessage ),
1172- targetNS, compURI, lErrorMessage
1173- ),
1174- ERROR_LOC( loc )
1175- );
1176+ RAISE_ERROR(err::XQST0059, loc,
1177+ ERROR_PARAMS(ZED(XQST0059_SpecificationMessage),
1178+ targetNS, compURI, lErrorMessage));
1179 }
1180
1181 // Get the parent of the query root sctx. This is the user-specified sctx
1182@@ -3469,7 +3524,7 @@
1183
1184 // Merge the exported sctx of the imported module into the sctx of the
1185 // current module. Note: We catch duplicate functions / vars in
1186- // theModulesInfo->globalSctx. We can safely ignore the return value.
1187+ // theModulesInfo->theGlobalSctx. We can safely ignore the return value.
1188 // We might even be able to assert() here (not sure though).
1189 theSctx->import_module(importedSctx, loc);
1190
1191@@ -3566,7 +3621,6 @@
1192 continue;
1193 }
1194
1195-#if 1
1196 const GlobalVarDecl* var_decl = it->dyn_cast<GlobalVarDecl>().getp();
1197
1198 if (var_decl != NULL &&
1199@@ -3645,7 +3699,7 @@
1200
1201 // Make sure that there is no other prolog var with the same name in any of
1202 // modules translated so far.
1203- bind_var(ve, theModulesInfo->globalSctx.get());
1204+ bind_var(ve, theModulesInfo->theGlobalSctx);
1205
1206 // If this is a library module, register the var in the exported sctx as well.
1207 if (export_sctx != NULL)
1208@@ -3653,7 +3707,6 @@
1209
1210 continue;
1211 }
1212-#endif
1213
1214 const FunctionDecl* func_decl = it->dyn_cast<FunctionDecl>().getp();
1215
1216@@ -3867,30 +3920,84 @@
1217 return no_state;
1218 }
1219
1220-store::Item_t parse_and_expand_qname(
1221- const zstring& value,
1222- const char* default_ns,
1223- const QueryLoc& loc) const
1224-{
1225- zstring lPrefix;
1226- zstring lLocalName;
1227-
1228- zstring::size_type n = value.rfind(':');
1229-
1230- if ( n == zstring::npos )
1231- {
1232- lLocalName = value;
1233- }
1234- else
1235- {
1236- lPrefix = value.substr( 0, n );
1237- lLocalName = value.substr( n+1 );
1238- }
1239- store::Item_t lQName;
1240- theSctx->expand_qname( lQName, default_ns, lPrefix, lLocalName, loc );
1241-
1242- return lQName;
1243-}
1244+
1245+void end_visit(const VFO_DeclList& v, void* /*visit_state*/)
1246+{
1247+ TRACE_VISIT_OUT();
1248+
1249+ thePrologGraph.reorder_globals(thePrologVars);
1250+}
1251+
1252+
1253+void check_xquery_feature_options(const QueryLoc& loc)
1254+{
1255+ // Constructing feature vectors.
1256+ std::map<zstring, bool> lFeatures;
1257+ parse_feature_list("require-feature", &lFeatures, true, loc);
1258+ parse_feature_list("prohibit-feature", &lFeatures, false, loc);
1259+
1260+ std::vector<zstring> lSupportedFeatures;
1261+ lSupportedFeatures.push_back("module");
1262+ lSupportedFeatures.push_back("higher-order-function");
1263+ lSupportedFeatures.push_back("schema-aware");
1264+ std::vector<zstring> lNonSupportedFeatures;
1265+ lNonSupportedFeatures.push_back("static-typing");
1266+
1267+ // Non supported features cannot be required.
1268+ for (std::vector<zstring>::iterator lIt = lNonSupportedFeatures.begin();
1269+ lIt != lNonSupportedFeatures.end();
1270+ ++lIt)
1271+ {
1272+ if (is_required_feature(lFeatures, *lIt))
1273+ {
1274+ RAISE_ERROR(err::XQST0120, loc, ERROR_PARAMS(*lIt));
1275+ }
1276+ }
1277+ // It is not possible to require all extensions.
1278+ if (is_required_feature(lFeatures, "all-extensions"))
1279+ {
1280+ RAISE_ERROR(err::XQST0126, loc, ERROR_PARAMS("all-extensions"));
1281+ }
1282+ // All optional features can only be required if all unsupported features are
1283+ // prohibited.
1284+ if (is_required_feature(lFeatures, "all-optional-features"))
1285+ {
1286+ for (std::vector<zstring>::iterator lIt = lNonSupportedFeatures.begin();
1287+ lIt != lNonSupportedFeatures.end();
1288+ ++lIt)
1289+ {
1290+ if (!is_prohibited_feature(lFeatures, *lIt))
1291+ {
1292+ RAISE_ERROR(err::XQST0120, loc, ERROR_PARAMS(*lIt));
1293+ }
1294+ }
1295+ }
1296+ // Supported features cannot be prohibited.
1297+ for (std::vector<zstring>::iterator lIt = lSupportedFeatures.begin();
1298+ lIt != lSupportedFeatures.end();
1299+ ++lIt)
1300+ {
1301+ if (is_prohibited_feature(lFeatures, *lIt))
1302+ {
1303+ RAISE_ERROR(err::XQST0128, loc, ERROR_PARAMS(*lIt));
1304+ }
1305+ }
1306+ // All optional features can only be prohibited if all supported features
1307+ // are required.
1308+ if (is_prohibited_feature(lFeatures, "all-optional-features"))
1309+ {
1310+ for (std::vector<zstring>::iterator lIt = lSupportedFeatures.begin();
1311+ lIt != lSupportedFeatures.end();
1312+ ++lIt)
1313+ {
1314+ if (!is_required_feature(lFeatures, *lIt))
1315+ {
1316+ RAISE_ERROR(err::XQST0128, loc, ERROR_PARAMS(*lIt));
1317+ }
1318+ }
1319+ }
1320+}
1321+
1322
1323 void parse_feature_list(
1324 const zstring& anOptionName,
1325@@ -3957,6 +4064,33 @@
1326 }
1327 }
1328
1329+
1330+store::Item_t parse_and_expand_qname(
1331+ const zstring& value,
1332+ const char* default_ns,
1333+ const QueryLoc& loc) const
1334+{
1335+ zstring lPrefix;
1336+ zstring lLocalName;
1337+
1338+ zstring::size_type n = value.rfind(':');
1339+
1340+ if ( n == zstring::npos )
1341+ {
1342+ lLocalName = value;
1343+ }
1344+ else
1345+ {
1346+ lPrefix = value.substr( 0, n );
1347+ lLocalName = value.substr( n+1 );
1348+ }
1349+ store::Item_t lQName;
1350+ theSctx->expand_qname( lQName, default_ns, lPrefix, lLocalName, loc );
1351+
1352+ return lQName;
1353+}
1354+
1355+
1356 bool is_recognized_feature(const zstring& aFeatureName)
1357 {
1358 return aFeatureName == "static-typing" ||
1359@@ -3967,10 +4101,10 @@
1360 aFeatureName == "all-optional-features";
1361 }
1362
1363+
1364 bool is_required_feature(
1365 const std::map<zstring, bool>& aFeatureMatrix,
1366- const zstring& aFeatureName
1367-)
1368+ const zstring& aFeatureName)
1369 {
1370 std::map<zstring, bool>::const_iterator lIt =
1371 aFeatureMatrix.find(aFeatureName);
1372@@ -3981,10 +4115,10 @@
1373 return lIt->second;
1374 }
1375
1376+
1377 bool is_prohibited_feature(
1378 const std::map<zstring, bool>& aFeatureMatrix,
1379- const zstring& aFeatureName
1380-)
1381+ const zstring& aFeatureName)
1382 {
1383 std::map<zstring, bool>::const_iterator lIt =
1384 aFeatureMatrix.find(aFeatureName);
1385@@ -3995,83 +4129,6 @@
1386 return !lIt->second;
1387 }
1388
1389-void check_xquery_feature_options(const QueryLoc& loc)
1390-{
1391- // Constructing feature vectors.
1392- std::map<zstring, bool> lFeatures;
1393- parse_feature_list("require-feature", &lFeatures, true, loc);
1394- parse_feature_list("prohibit-feature", &lFeatures, false, loc);
1395-
1396- std::vector<zstring> lSupportedFeatures;
1397- lSupportedFeatures.push_back("module");
1398- lSupportedFeatures.push_back("higher-order-function");
1399- lSupportedFeatures.push_back("schema-aware");
1400- std::vector<zstring> lNonSupportedFeatures;
1401- lNonSupportedFeatures.push_back("static-typing");
1402-
1403- // Non supported features cannot be required.
1404- for (std::vector<zstring>::iterator lIt = lNonSupportedFeatures.begin();
1405- lIt != lNonSupportedFeatures.end();
1406- ++lIt)
1407- {
1408- if (is_required_feature(lFeatures, *lIt))
1409- {
1410- RAISE_ERROR(err::XQST0120, loc, ERROR_PARAMS(*lIt));
1411- }
1412- }
1413- // It is not possible to require all extensions.
1414- if (is_required_feature(lFeatures, "all-extensions"))
1415- {
1416- RAISE_ERROR(err::XQST0126, loc, ERROR_PARAMS("all-extensions"));
1417- }
1418- // All optional features can only be required if all unsupported features are
1419- // prohibited.
1420- if (is_required_feature(lFeatures, "all-optional-features"))
1421- {
1422- for (std::vector<zstring>::iterator lIt = lNonSupportedFeatures.begin();
1423- lIt != lNonSupportedFeatures.end();
1424- ++lIt)
1425- {
1426- if (!is_prohibited_feature(lFeatures, *lIt))
1427- {
1428- RAISE_ERROR(err::XQST0120, loc, ERROR_PARAMS(*lIt));
1429- }
1430- }
1431- }
1432- // Supported features cannot be prohibited.
1433- for (std::vector<zstring>::iterator lIt = lSupportedFeatures.begin();
1434- lIt != lSupportedFeatures.end();
1435- ++lIt)
1436- {
1437- if (is_prohibited_feature(lFeatures, *lIt))
1438- {
1439- RAISE_ERROR(err::XQST0128, loc, ERROR_PARAMS(*lIt));
1440- }
1441- }
1442- // All optional features can only be prohibited if all supported features
1443- // are required.
1444- if (is_prohibited_feature(lFeatures, "all-optional-features"))
1445- {
1446- for (std::vector<zstring>::iterator lIt = lSupportedFeatures.begin();
1447- lIt != lSupportedFeatures.end();
1448- ++lIt)
1449- {
1450- if (!is_required_feature(lFeatures, *lIt))
1451- {
1452- RAISE_ERROR(err::XQST0128, loc, ERROR_PARAMS(*lIt));
1453- }
1454- }
1455- }
1456-}
1457-
1458-
1459-void end_visit(const VFO_DeclList& v, void* /*visit_state*/)
1460-{
1461- TRACE_VISIT_OUT();
1462-
1463- thePrologGraph.reorder_globals(thePrologVars);
1464-}
1465-
1466
1467 /*******************************************************************************
1468
1469@@ -4358,6 +4415,77 @@
1470
1471
1472 /*******************************************************************************
1473+ ContextItemDecl ::= "declare" "context" "item" ("as" ItemType)?
1474+ ((":=" VarValue) |
1475+ ("external" (":=" VarDefaultValue)?))
1476+********************************************************************************/
1477+void* begin_visit(const CtxItemDecl& v)
1478+{
1479+ TRACE_VISIT();
1480+
1481+ if (theSctx->xquery_version() <= StaticContextConsts::xquery_version_1_0)
1482+ RAISE_ERROR(err::XPST0003, loc,
1483+ ERROR_PARAMS(ZED(XPST0003_XQueryVersionAtLeast30_2), theSctx->xquery_version()));
1484+
1485+ if (theHaveContextItemDecl)
1486+ {
1487+ RAISE_ERROR_NO_PARAMS(err::XQST0099, loc);
1488+ }
1489+
1490+ if (v.get_expr() != NULL && inLibraryModule())
1491+ {
1492+ RAISE_ERROR_NO_PARAMS(err::XQST0113, loc);
1493+ }
1494+
1495+ theHaveContextItemDecl = true;
1496+ theModulesInfo->theHaveDotItemDecl = true;
1497+
1498+ if (!inLibraryModule())
1499+ {
1500+ var_expr* var = theModulesInfo->theDotItemVar;
1501+
1502+ thePrologGraph.addVarVertex(var);
1503+ theCurrentPrologVFDecl = PrologGraphVertex(var);
1504+ }
1505+
1506+ return no_state;
1507+}
1508+
1509+void end_visit(const CtxItemDecl& v, void* /*visit_state*/)
1510+{
1511+ TRACE_VISIT_OUT();
1512+
1513+ xqtref_t type;
1514+
1515+ if (v.get_type() != NULL)
1516+ {
1517+ type = pop_tstack();
1518+
1519+ theSctx->set_context_item_type(type, loc);
1520+
1521+ theModulesInfo->addDotItemType(type);
1522+ }
1523+ else
1524+ {
1525+ theModulesInfo->addDotItemType(theSctx->get_context_item_type());
1526+ }
1527+
1528+ if (!inLibraryModule())
1529+ {
1530+ theCurrentPrologVFDecl.setNull();
1531+
1532+ expr* initExpr = (v.get_expr() ? pop_nodestack() : NULL);
1533+
1534+ var_expr* var = theModulesInfo->theDotItemVar;
1535+
1536+ var->set_external(v.is_external());
1537+
1538+ thePrologVars.push_back(GlobalBinding(var, initExpr, true));
1539+ }
1540+}
1541+
1542+
1543+/*******************************************************************************
1544
1545 Global declarations:
1546 --------------------
1547@@ -4439,7 +4567,7 @@
1548
1549 // Make sure that there is no other prolog var with the same name in any of
1550 // modules translated so far.
1551- bind_var(ve, theModulesInfo->globalSctx.get());
1552+ bind_var(ve, theModulesInfo->theGlobalSctx);
1553
1554 // If this is a library module, register the var in the exported sctx as well.
1555 if (export_sctx != NULL)
1556@@ -4481,7 +4609,7 @@
1557 #endif
1558
1559 // The ve and its associated intExpr will be put into var_decl_expr that
1560- // will creaated by the wrap_in_globalvar_assign() method when it is called
1561+ // will creaated by the declare_prolog_var() method when it is called
1562 // at the end of the translation of each module.
1563 thePrologVars.push_back(GlobalBinding(ve, initExpr, v.is_extern()));
1564 }
1565@@ -4580,66 +4708,6 @@
1566 }
1567
1568
1569-
1570-/*******************************************************************************
1571- ContextItemDecl ::= "declare" "context" "item" ("as" ItemType)?
1572- ((":=" VarValue) |
1573- ("external" (":=" VarDefaultValue)?))
1574-********************************************************************************/
1575-void* begin_visit(const CtxItemDecl& v)
1576-{
1577- TRACE_VISIT();
1578-
1579- if (theSctx->xquery_version() <= StaticContextConsts::xquery_version_1_0)
1580- RAISE_ERROR(err::XPST0003, loc,
1581- ERROR_PARAMS(ZED(XPST0003_XQueryVersionAtLeast30_2), theSctx->xquery_version()));
1582-
1583- theHaveContextItemDecl = true;
1584-
1585- return no_state;
1586-}
1587-
1588-void end_visit(const CtxItemDecl& v, void* /*visit_state*/)
1589-{
1590- TRACE_VISIT_OUT();
1591-
1592- expr* initExpr = NULL;
1593- if (v.get_expr() != NULL)
1594- initExpr = pop_nodestack();
1595-
1596- xqtref_t type;
1597-
1598- if (v.get_type() != NULL)
1599- {
1600- type = pop_tstack();
1601- theSctx->set_context_item_type(type, loc);
1602- }
1603- else
1604- {
1605- type = theSctx->get_context_item_type();
1606- assert(type != NULL);
1607- }
1608-
1609- var_expr* var = NULL;
1610-
1611- if (inLibraryModule())
1612- {
1613- var = bind_var(loc, DOT_VARNAME, var_expr::prolog_var, type);
1614- }
1615- else
1616- {
1617- var = lookup_ctx_var(DOT_VARNAME, loc);
1618- assert(var);
1619- }
1620-
1621- var->set_external(v.is_external());
1622- var->set_type(type);
1623-
1624- GlobalBinding b(var, initExpr, true);
1625- declare_var(b, theModulesInfo->theInitExprs);
1626-}
1627-
1628-
1629 /*******************************************************************************
1630 OptionDecl ::= DECLARE_OPTION QNAME STRING_LITERAL
1631 ********************************************************************************/
1632@@ -5035,10 +5103,10 @@
1633
1634 push_scope();
1635
1636- index->setDomainVariable(bind_var(loc, DOT_VARNAME, var_expr::for_var));
1637+ index->setDomainVariable(bind_var(loc, getDotItemVarName(), var_expr::for_var));
1638
1639 index->setDomainPositionVariable(bind_var(loc,
1640- DOT_POS_VARNAME,
1641+ getDotPosVarName(),
1642 var_expr::pos_var));
1643
1644 return no_state;
1645@@ -5431,18 +5499,12 @@
1646
1647 // let $x := dc:collection(xs:QName("org:employees"))
1648 // return
1649- var_expr* varExpr = bind_var(loc,
1650- varItem,
1651- var_expr::let_var,
1652- NULL);
1653+ var_expr* varExpr = bind_var(loc, varItem, var_expr::let_var, NULL);
1654
1655 let_clause* letClause = theExprManager->
1656 create_let_clause(theRootSctx, loc, varExpr, collExpr);
1657
1658- flwor_expr* flworExpr = theExprManager->
1659- create_flwor_expr(theRootSctx, theUDF, loc, false);
1660-
1661-
1662+ flwor_expr* flworExpr = CREATE(flwor)(theRootSctx, theUDF, loc, false);
1663
1664 flworExpr->add_clause(letClause);
1665 // flworExpr->set_return_expr( andExpr ); done in end_visit
1666@@ -5653,8 +5715,7 @@
1667 var_expr* fromVarExpr = bind_var(loc, fromVarQName, var_expr::for_var, NULL);
1668
1669 // for $x in dc:collection(xs:QName("org:transactions"))
1670- evFlworExpr->add_clause(wrap_in_forclause(fromCollExpr,
1671- fromVarExpr, NULL));
1672+ evFlworExpr->add_clause(wrap_in_forclause(fromCollExpr, fromVarExpr, NULL));
1673
1674
1675 push_nodestack(someFlworExpr);
1676@@ -9540,7 +9601,7 @@
1677 // In cases 2, 3, and 4 create a new empty relpath_expr
1678 if (pe_type != ParseConstants::path_leading_lone_slash)
1679 {
1680- pathExpr = theExprManager->create_relpath_expr(theRootSctx, theUDF, loc);
1681+ pathExpr = CREATE(relpath)(theRootSctx, theUDF, loc);
1682 }
1683
1684 // If path expr starts with / or // (cases 1, 2, or 3), create an expr
1685@@ -9554,13 +9615,13 @@
1686
1687 if (pe_type != ParseConstants::path_relative)
1688 {
1689- relpath_expr* ctx_path_expr = theExprManager->create_relpath_expr(theRootSctx, theUDF, loc);
1690+ relpath_expr* ctx_path_expr = CREATE(relpath)(theRootSctx, theUDF, loc);
1691
1692- expr* sourceExpr = theExprManager->create_treat_expr(theRootSctx, theUDF,
1693- loc,
1694- DOT_REF,
1695- GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
1696- TREAT_PATH_DOT);
1697+ expr* sourceExpr = CREATE(treat)(theRootSctx, theUDF,
1698+ loc,
1699+ dotRef(loc),
1700+ GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
1701+ TREAT_PATH_DOT);
1702
1703 ctx_path_expr->add_back(sourceExpr);
1704
1705@@ -9682,11 +9743,10 @@
1706 // then the input expr to the this path expr is "treat . as node()"
1707 if (axisStep != NULL)
1708 {
1709- expr* sourceExpr = theExprManager->create_treat_expr(theRootSctx, theUDF,
1710- loc,
1711- DOT_REF,
1712- GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
1713- TREAT_PATH_DOT);
1714+ expr* sourceExpr = CREATE(treat)(theRootSctx, theUDF, loc,
1715+ dotRef(loc),
1716+ GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
1717+ TREAT_PATH_DOT);
1718 pathExpr->add_back(sourceExpr);
1719
1720 if (axisStep->get_predicate_list() == NULL)
1721@@ -9763,7 +9823,7 @@
1722
1723 if (stepExpr->get_expr_kind() == wrapper_expr_kind)
1724 {
1725- var_expr* dotVar = lookup_var(DOT_VARNAME, loc, false);
1726+ var_expr* dotVar = lookup_var(getDotItemVarName(), loc, false);
1727 if (static_cast<wrapper_expr*>(stepExpr)->get_input() == dotVar)
1728 errKind = TREAT_PATH_DOT;
1729 }
1730@@ -10533,13 +10593,13 @@
1731 theUDF,
1732 loc,
1733 BUILTIN_FUNC(OP_VALUE_EQUAL_2),
1734- lookup_ctx_var(DOT_POS_VARNAME, loc),
1735+ lookup_ctx_var(getDotPosVarName(), loc),
1736 predvar);
1737
1738 normalize_fo(eqExpr);
1739
1740- expr* retExpr = theExprManager->
1741- create_if_expr(theRootSctx, theUDF, loc, eqExpr, DOT_REF, create_empty_seq(loc));
1742+ expr* retExpr =
1743+ CREATE(if)(theRootSctx, theUDF, loc, eqExpr, dotRef(loc), create_empty_seq(loc));
1744
1745 flworExpr->set_return_expr(retExpr);
1746
1747@@ -10590,18 +10650,18 @@
1748 theUDF,
1749 loc,
1750 BUILTIN_FUNC(OP_VALUE_EQUAL_2),
1751- lookup_ctx_var(DOT_POS_VARNAME, loc),
1752+ lookup_ctx_var(getDotPosVarName(), loc),
1753 predvar);
1754
1755 normalize_fo(eqExpr);
1756
1757- expr* thenExpr = theExprManager->
1758- create_if_expr(theRootSctx, theUDF, loc, eqExpr, DOT_REF, create_empty_seq(loc));
1759+ expr* thenExpr =
1760+ CREATE(if)(theRootSctx, theUDF, loc, eqExpr, dotRef(loc), create_empty_seq(loc));
1761
1762 // Else, return $dot if the the value of the pred expr is true, otherwise
1763 // return the empty seq.
1764- expr* elseExpr = theExprManager->
1765- create_if_expr(theRootSctx, theUDF, loc, predvar, DOT_REF, create_empty_seq(loc));
1766+ expr* elseExpr =
1767+ CREATE(if)(theRootSctx, theUDF, loc, predvar, dotRef(loc), create_empty_seq(loc));
1768
1769 // The outer if
1770 expr* ifExpr = theExprManager->
1771@@ -10741,7 +10801,9 @@
1772 theRootSctx, theUDF, loc, v.get_boolval()));
1773 }
1774
1775+
1776 /*******************************************************************************
1777+
1778 ********************************************************************************/
1779 void* begin_visit(const NullLiteral& v)
1780 {
1781@@ -10760,6 +10822,7 @@
1782 theRootSctx, theUDF, loc, lNull));
1783 }
1784
1785+
1786 /*******************************************************************************
1787 StringConcatExpr ::= RangeExpr ( "||" RangeExpr )*
1788 *******************************************************************************/
1789@@ -10808,6 +10871,7 @@
1790 push_nodestack(concat);
1791 }
1792
1793+
1794 /*******************************************************************************
1795 VarRef ::= "$" VarName
1796 VarName ::= QName
1797@@ -10910,9 +10974,92 @@
1798 }
1799 }
1800
1801- push_nodestack(theExprManager->create_wrapper_expr(theRootSctx, theUDF,
1802- loc,
1803- ve));
1804+ push_nodestack(CREATE(wrapper)(theRootSctx, theUDF, loc, ve));
1805+}
1806+
1807+
1808+/*******************************************************************************
1809+
1810+********************************************************************************/
1811+expr* dotRef(const QueryLoc& loc)
1812+{
1813+ var_expr* dotVar = lookup_ctx_var(getDotItemVarName(), loc);
1814+
1815+ if (dotVar->get_kind() == var_expr::prolog_var)
1816+ {
1817+ if (!theCurrentPrologVFDecl.isNull())
1818+ {
1819+ thePrologGraph.addEdge(theCurrentPrologVFDecl, dotVar);
1820+ }
1821+ }
1822+
1823+ return CREATE(wrapper)(theRootSctx, theUDF, loc, dotVar);
1824+}
1825+
1826+
1827+/*******************************************************************************
1828+
1829+********************************************************************************/
1830+expr* dotPosRef(const QueryLoc& loc)
1831+{
1832+ var_expr* posVar = lookup_ctx_var(getDotPosVarName(), loc);
1833+
1834+ if (posVar->get_kind() == var_expr::prolog_var)
1835+ {
1836+ if (!theCurrentPrologVFDecl.isNull())
1837+ {
1838+ thePrologGraph.addEdge(theCurrentPrologVFDecl, posVar);
1839+ }
1840+ }
1841+
1842+ return CREATE(wrapper)(theRootSctx, theUDF, loc, posVar);
1843+}
1844+
1845+
1846+/*******************************************************************************
1847+
1848+********************************************************************************/
1849+expr* dotSizeRef(const QueryLoc& loc)
1850+{
1851+ var_expr* sizeVar = lookup_ctx_var(getDotSizeVarName(), loc);
1852+
1853+ if (sizeVar->get_kind() == var_expr::prolog_var)
1854+ {
1855+ if (!theCurrentPrologVFDecl.isNull())
1856+ {
1857+ thePrologGraph.addEdge(theCurrentPrologVFDecl, sizeVar);
1858+ }
1859+ }
1860+
1861+ return CREATE(wrapper)(theRootSctx, theUDF, loc, sizeVar);
1862+}
1863+
1864+
1865+
1866+/*******************************************************************************
1867+ ContextItemExpr ::= "."
1868+********************************************************************************/
1869+void* begin_visit(const ContextItemExpr& v)
1870+{
1871+ TRACE_VISIT ();
1872+ return no_state;
1873+}
1874+
1875+void end_visit (const ContextItemExpr& v, void* /*visit_state*/)
1876+{
1877+ TRACE_VISIT_OUT();
1878+
1879+ var_expr* ve = lookup_ctx_var(getDotItemVarName(), loc);
1880+
1881+ if (ve->get_kind() == var_expr::prolog_var)
1882+ {
1883+ if (!theCurrentPrologVFDecl.isNull())
1884+ {
1885+ thePrologGraph.addEdge(theCurrentPrologVFDecl, ve);
1886+ }
1887+ }
1888+
1889+ push_nodestack(CREATE(wrapper)(theRootSctx, theUDF, loc, ve));
1890 }
1891
1892
1893@@ -10947,23 +11094,6 @@
1894
1895
1896 /*******************************************************************************
1897- ContextItemExpr ::= "."
1898-********************************************************************************/
1899-void* begin_visit(const ContextItemExpr& v)
1900-{
1901- TRACE_VISIT ();
1902- return no_state;
1903-}
1904-
1905-void end_visit (const ContextItemExpr& v, void* /*visit_state*/)
1906-{
1907- TRACE_VISIT_OUT();
1908-
1909- push_nodestack(DOT_REF);
1910-}
1911-
1912-
1913-/*******************************************************************************
1914 OrderedExpr ::= "ordered" "{" Expr "}"
1915 ********************************************************************************/
1916 void* begin_visit(const OrderedExpr& v)
1917@@ -11447,20 +11577,20 @@
1918 {
1919 case FunctionConsts::FN_POSITION_0:
1920 {
1921- resultExpr = lookup_ctx_var(DOT_POS_VARNAME, loc);
1922+ resultExpr = lookup_ctx_var(getDotPosVarName(), loc);
1923 break;
1924 }
1925 case FunctionConsts::FN_LAST_0:
1926 {
1927- resultExpr = lookup_ctx_var(LAST_IDX_VARNAME, loc);
1928+ resultExpr = lookup_ctx_var(getDotSizeVarName(), loc);
1929 break;
1930 }
1931 case FunctionConsts::FN_FUNCTION_LOOKUP_2:
1932 {
1933 // hof ???? What if focus is not defined ?
1934- arguments.push_back(DOT_REF);
1935- arguments.push_back(DOT_POS_REF);
1936- arguments.push_back(DOT_SIZE_REF);
1937+ arguments.push_back(dotRef(loc));
1938+ arguments.push_back(dotPosRef(loc));
1939+ arguments.push_back(dotSizeRef(loc));
1940 f = BUILTIN_FUNC(OP_ZORBA_FUNCTION_LOOKUP_5);
1941 break;
1942 }
1943@@ -11480,39 +11610,39 @@
1944 case FunctionConsts::FN_HAS_CHILDREN_0:
1945 case FunctionConsts::FN_PATH_0:
1946 {
1947- arguments.push_back(DOT_REF);
1948+ arguments.push_back(dotRef(loc));
1949 f = theSctx->lookup_fn(f->getName(), 1, loc);
1950 break;
1951 }
1952 case FunctionConsts::FN_NUMBER_0:
1953 {
1954- arguments.push_back(DOT_REF);
1955+ arguments.push_back(dotRef(loc));
1956 f = theSctx->lookup_fn(f->getName(), 1, loc);
1957 return generate_fn_body(f, arguments, loc);
1958 break;
1959 }
1960 case FunctionConsts::FN_LANG_1:
1961 {
1962- arguments.push_back(DOT_REF);
1963+ arguments.push_back(dotRef(loc));
1964 f = BUILTIN_FUNC(FN_LANG_2);
1965 break;
1966 }
1967 case FunctionConsts::FN_IDREF_1:
1968 {
1969- arguments.push_back(DOT_REF);
1970+ arguments.push_back(dotRef(loc));
1971 f = BUILTIN_FUNC(FN_IDREF_2);
1972 break;
1973 }
1974 case FunctionConsts::FN_ID_1:
1975 {
1976- arguments.push_back(DOT_REF);
1977+ arguments.push_back(dotRef(loc));
1978 f = BUILTIN_FUNC(FN_ID_2);
1979 resultExpr = generate_fn_body(f, arguments, loc);
1980 break;
1981 }
1982 case FunctionConsts::FN_ELEMENT_WITH_ID_1:
1983 {
1984- arguments.push_back(DOT_REF);
1985+ arguments.push_back(dotRef(loc));
1986 f = BUILTIN_FUNC(FN_ELEMENT_WITH_ID_2);
1987 resultExpr = generate_fn_body(f, arguments, loc);
1988 break;
1989@@ -12112,7 +12242,7 @@
1990
1991 if (posVar && posVar->get_kind() != var_expr::prolog_var)
1992 {
1993- expr* posVarRef = DOT_POS_REF;
1994+ expr* posVarRef = dotPosRef(loc);
1995
1996 push_scope();
1997
1998@@ -12137,15 +12267,15 @@
1999 }
2000 case FunctionConsts::FN_LAST_0:
2001 {
2002- var_expr* sizeVar = lookup_var(getLastIdxVarName(), loc, false);
2003+ var_expr* sizeVar = lookup_var(getDotSizeVarName(), loc, false);
2004
2005 if (sizeVar && sizeVar->get_kind() != var_expr::prolog_var)
2006 {
2007- expr* sizeVarRef = DOT_SIZE_REF;
2008+ expr* sizeVarRef = dotSizeRef(loc);
2009
2010 push_scope();
2011
2012- var_expr* substVar = bind_var(loc, getLastIdxVarName(), var_expr::local_var);
2013+ var_expr* substVar = bind_var(loc, getDotSizeVarName(), var_expr::local_var);
2014
2015 // Must set the id of the substVar if we are coming here from a
2016 // FunctionLookupIterator.
2017@@ -12185,15 +12315,15 @@
2018 case FunctionConsts::FN_ID_1:
2019 case FunctionConsts::FN_ELEMENT_WITH_ID_1:
2020 {
2021- var_expr* dotVar = lookup_var(getDotVarName(), loc, false);
2022+ var_expr* dotVar = lookup_var(getDotItemVarName(), loc, false);
2023
2024 if (dotVar && dotVar->get_kind() != var_expr::prolog_var)
2025 {
2026- expr* dotVarRef = DOT_REF;
2027+ expr* dotVarRef = dotRef(loc);
2028
2029 push_scope();
2030
2031- var_expr* substVar = bind_var(loc, getDotVarName(), var_expr::local_var);
2032+ var_expr* substVar = bind_var(loc, getDotItemVarName(), var_expr::local_var);
2033
2034 // Must set the id of the substVar if we are coming here from a
2035 // FunctionLookupIterator.
2036@@ -12216,18 +12346,18 @@
2037 {
2038 bool varAdded = false;
2039
2040- var_expr* ctxItemVar = lookup_var(getDotVarName(), loc, false);
2041+ var_expr* ctxItemVar = lookup_var(getDotItemVarName(), loc, false);
2042 var_expr* ctxPosVar = lookup_var(getDotPosVarName(), loc, false);
2043- var_expr* ctxSizeVar = lookup_var(getLastIdxVarName(), loc, false);
2044+ var_expr* ctxSizeVar = lookup_var(getDotSizeVarName(), loc, false);
2045
2046 if (ctxItemVar && ctxItemVar->get_kind() != var_expr::prolog_var)
2047 {
2048- expr* ctxVRef = DOT_REF;
2049+ expr* ctxVRef = dotRef(loc);
2050
2051 push_scope();
2052 varAdded = true;
2053
2054- var_expr* substVar = bind_var(loc, getDotVarName(), var_expr::local_var);
2055+ var_expr* substVar = bind_var(loc, getDotItemVarName(), var_expr::local_var);
2056
2057 substVar->set_unique_id(ctxItemVar->get_unique_id());
2058
2059@@ -12236,7 +12366,7 @@
2060
2061 if (ctxPosVar && ctxPosVar->get_kind() != var_expr::prolog_var)
2062 {
2063- expr* ctxVRef = DOT_POS_REF;
2064+ expr* ctxVRef = dotPosRef(loc);
2065
2066 if (!varAdded)
2067 {
2068@@ -12253,7 +12383,7 @@
2069
2070 if (ctxSizeVar && ctxSizeVar->get_kind() != var_expr::prolog_var)
2071 {
2072- expr* ctxVRef = DOT_SIZE_REF;
2073+ expr* ctxVRef = dotSizeRef(loc);
2074
2075 if (!varAdded)
2076 {
2077@@ -12261,7 +12391,7 @@
2078 varAdded = true;
2079 }
2080
2081- var_expr* substVar = bind_var(loc, getLastIdxVarName(), var_expr::local_var);
2082+ var_expr* substVar = bind_var(loc, getDotSizeVarName(), var_expr::local_var);
2083
2084 substVar->set_unique_id(ctxSizeVar->get_unique_id());
2085
2086@@ -15827,7 +15957,7 @@
2087 expr* result = t->result();
2088
2089 CompilerCB* ccb = minfo->theCCB;
2090- if (ccb->theConfig.translate_cb != NULL)
2091+ if (result && ccb->theConfig.translate_cb != NULL)
2092 ccb->theConfig.translate_cb(&*result, "XQuery program");
2093
2094 return result;
2095
2096=== modified file 'src/context/static_context.h'
2097--- src/context/static_context.h 2013-04-23 13:15:14 +0000
2098+++ src/context/static_context.h 2013-04-27 14:33:25 +0000
2099@@ -576,7 +576,7 @@
2100
2101 std::ostream * theTraceStream;
2102
2103- expr* theQueryExpr;
2104+ expr * theQueryExpr;
2105
2106 std::string theModuleNamespace;
2107
2108
2109=== modified file 'src/diagnostics/diagnostic_en.xml'
2110--- src/diagnostics/diagnostic_en.xml 2013-04-23 13:12:58 +0000
2111+++ src/diagnostics/diagnostic_en.xml 2013-04-27 14:33:25 +0000
2112@@ -823,6 +823,14 @@
2113 <value>$1</value>
2114 </diagnostic>
2115
2116+ <diagnostic code="XQST0113">
2117+ <comment>
2118+ Specifying a VarValue or VarDefaultValue for a context item declaration
2119+ in a library module is a static error.
2120+ </comment>
2121+ <value>context item declaration with initializing expression not allowed in library module</value>
2122+ </diagnostic>
2123+
2124 <diagnostic code="XQST0114">
2125 <comment>
2126 It is a static error for a decimal format declaration to define the
2127@@ -964,6 +972,15 @@
2128 <value>"$1": invalid attibute node-name</value>
2129 </diagnostic>
2130
2131+ <diagnostic code="XQDY0054">
2132+ <comment>
2133+ It is a dynamic error if a cycle is encountered in the definition of a
2134+ module's dynamic context components, for example because of a cycle in
2135+ variable declarations.
2136+ </comment>
2137+ <value>${"1": }variable must not depend on itself</value>
2138+ </diagnostic>
2139+
2140 <diagnostic code="XQDY0061">
2141 <comment>
2142 It is a dynamic error if the operand of a validate expression is a
2143
2144=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
2145--- src/diagnostics/pregenerated/diagnostic_list.cpp 2013-04-23 13:12:58 +0000
2146+++ src/diagnostics/pregenerated/diagnostic_list.cpp 2013-04-27 14:33:25 +0000
2147@@ -223,6 +223,9 @@
2148 XQueryErrorCode XQST0111( "XQST0111" );
2149
2150
2151+XQueryErrorCode XQST0113( "XQST0113" );
2152+
2153+
2154 XQueryErrorCode XQST0114( "XQST0114" );
2155
2156
2157@@ -262,6 +265,9 @@
2158 XQueryErrorCode XQDY0044( "XQDY0044" );
2159
2160
2161+XQueryErrorCode XQDY0054( "XQDY0054" );
2162+
2163+
2164 XQueryErrorCode XQDY0061( "XQDY0061" );
2165
2166
2167
2168=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
2169--- src/diagnostics/pregenerated/dict_en.cpp 2013-04-23 13:12:58 +0000
2170+++ src/diagnostics/pregenerated/dict_en.cpp 2013-04-27 14:33:25 +0000
2171@@ -204,6 +204,7 @@
2172 { "XQDY0027", "\"$1\": unexpected validity property${: 2}" },
2173 { "XQDY0041", "can not cast to xs:NCName" },
2174 { "XQDY0044", "\"$1\": invalid attibute node-name" },
2175+ { "XQDY0054", "${\"1\": }variable must not depend on itself" },
2176 { "XQDY0061", "invalid validate expression operand${: 1}" },
2177 { "XQDY0064", "\"XML\": invalid name expression" },
2178 { "XQDY0072", "comment must not contain \"--\" or end with \"-\"" },
2179@@ -261,6 +262,7 @@
2180 { "XQST0103", "$1: non-distinct variable in window clause" },
2181 { "XQST0106", "$1: multiple annotations with $2 names" },
2182 { "XQST0111", "$1" },
2183+ { "XQST0113", "context item declaration with initializing expression not allowed in library module" },
2184 { "XQST0114", "\"$1\": duplicate decimal format property" },
2185 { "XQST0120", "\"$1\": feature not supported" },
2186 { "XQST0123", "$1" },
2187
2188=== modified file 'test/fots/CMakeLists.txt'
2189--- test/fots/CMakeLists.txt 2013-04-25 22:49:49 +0000
2190+++ test/fots/CMakeLists.txt 2013-04-27 14:33:25 +0000
2191@@ -293,10 +293,7 @@
2192 EXPECTED_FOTS_FAILURE (prod-CastExpr.schema CastAs-ListType-31 0)
2193 EXPECTED_FOTS_FAILURE (prod-CastableExpr K-SeqExprCastable-5a 0)
2194 EXPECTED_FOTS_FAILURE (prod-CompDocConstructor K2-ConDocNode-2 0)
2195-EXPECTED_FOTS_FAILURE (prod-ContextItemDecl contextDecl-016 0)
2196-EXPECTED_FOTS_FAILURE (prod-ContextItemDecl contextDecl-017 0)
2197 EXPECTED_FOTS_FAILURE (prod-ContextItemDecl contextDecl-047 0)
2198-EXPECTED_FOTS_FAILURE (prod-ContextItemDecl contextDecl-049 0)
2199 EXPECTED_FOTS_FAILURE (prod-CountClause count-007 0)
2200 EXPECTED_FOTS_FAILURE (prod-CountClause count-008 0)
2201 EXPECTED_FOTS_FAILURE (prod-DefaultNamespaceDecl defaultnamespacedeclerr-6 0)
2202@@ -354,7 +351,6 @@
2203 EXPECTED_FOTS_FAILURE (prod-ModuleImport errata8-002a 0)
2204 EXPECTED_FOTS_FAILURE (prod-ModuleImport modules-pub-priv-30 0)
2205 EXPECTED_FOTS_FAILURE (prod-ModuleImport modules-pub-priv-34 0)
2206-EXPECTED_FOTS_FAILURE (prod-ModuleImport cbcl-module-004 0)
2207 EXPECTED_FOTS_FAILURE (prod-OptionDecl.serialization Serialization-003 0)
2208 EXPECTED_FOTS_FAILURE (prod-OptionDecl.serialization Serialization-004 0)
2209 EXPECTED_FOTS_FAILURE (prod-OptionDecl.serialization Serialization-005 0)
2210@@ -412,8 +408,6 @@
2211 EXPECTED_FOTS_FAILURE (prod-ValidateExpr validate-as-106 0)
2212 EXPECTED_FOTS_FAILURE (prod-VarDecl.external K2-ExternalVariablesWithout-18 0)
2213 EXPECTED_FOTS_FAILURE (prod-VarDecl.external K2-ExternalVariablesWith-22 0)
2214-EXPECTED_FOTS_FAILURE (prod-VarDefaultValue extvardef-016a 0)
2215-EXPECTED_FOTS_FAILURE (prod-VarDefaultValue extvardef-016b 0)
2216 EXPECTED_FOTS_FAILURE (prod-VersionDecl VersionDecl-v1-processor-and-v3-query 0)
2217 EXPECTED_FOTS_FAILURE (prod-VersionDecl version_declaration-023-v3 0)
2218 EXPECTED_FOTS_FAILURE (xs-anyURI cbcl-anyURI-002 0)
2219
2220=== modified file 'test/rbkt/Queries/CMakeLists.txt'
2221--- test/rbkt/Queries/CMakeLists.txt 2013-04-19 23:19:10 +0000
2222+++ test/rbkt/Queries/CMakeLists.txt 2013-04-27 14:33:25 +0000
2223@@ -582,7 +582,6 @@
2224
2225 # external variable default expected failures
2226 EXPECTED_FAILURE(test/rbkt/zorba/ext_var/w3c/extvardef-014 923672) # not possible to set context item for rbkt tests
2227-EXPECTED_FAILURE(test/rbkt/zorba/ext_var/w3c/extvardef-015 923686)
2228 EXPECTED_FAILURE(test/rbkt/zorba/ext_var/w3c/extvardef-016 923686)
2229
2230
2231
2232=== modified file 'test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011.spec'
2233--- test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011.spec 2011-12-06 15:13:50 +0000
2234+++ test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011.spec 2013-04-27 14:33:25 +0000
2235@@ -1,1 +1,1 @@
2236-Error: http://www.w3.org/2005/xqt-errors:XQST0054
2237+Error: http://www.w3.org/2005/xqt-errors:XQDY0054
2238
2239=== modified file 'test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011a.spec'
2240--- test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011a.spec 2011-12-06 15:13:50 +0000
2241+++ test/rbkt/Queries/zorba/ext_var/w3c/extvardef-011a.spec 2013-04-27 14:33:25 +0000
2242@@ -1,1 +1,1 @@
2243-Error: http://www.w3.org/2005/xqt-errors:XQST0054
2244+Error: http://www.w3.org/2005/xqt-errors:XQDY0054

Subscribers

People subscribed via source and target branches