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

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 10975
Merged at revision: 11110
Proposed branch: lp:~zorba-coders/zorba/markos-scratch
Merge into: lp:zorba
Diff against target: 4951 lines (+1239/-1080)
51 files modified
ChangeLog (+1/-0)
src/compiler/api/compilercb.cpp (+1/-0)
src/compiler/api/compilercb.h (+5/-5)
src/compiler/codegen/plan_visitor.cpp (+37/-29)
src/compiler/expression/expr.cpp (+43/-28)
src/compiler/expression/expr.h (+42/-65)
src/compiler/expression/expr_base.cpp (+28/-11)
src/compiler/expression/expr_base.h (+0/-1)
src/compiler/expression/expr_clone.cpp (+6/-5)
src/compiler/expression/expr_consts.h (+59/-0)
src/compiler/expression/expr_iter.cpp (+307/-145)
src/compiler/expression/expr_manager.cpp (+14/-9)
src/compiler/expression/expr_manager.h (+37/-17)
src/compiler/expression/expr_put.cpp (+15/-15)
src/compiler/expression/expr_type.cpp (+12/-16)
src/compiler/expression/expr_utils.h (+8/-0)
src/compiler/expression/flwor_expr.cpp (+13/-10)
src/compiler/expression/flwor_expr.h (+32/-31)
src/compiler/expression/fo_expr.cpp (+1/-0)
src/compiler/expression/fo_expr.h (+0/-24)
src/compiler/expression/ftnode.h (+4/-0)
src/compiler/expression/script_exprs.cpp (+2/-2)
src/compiler/expression/script_exprs.h (+3/-6)
src/compiler/expression/update_exprs.cpp (+1/-0)
src/compiler/rewriter/framework/rewriter.h (+1/-3)
src/compiler/rewriter/rewriters/default_optimizer.cpp (+0/-3)
src/compiler/rewriter/rules/flwor_rules.cpp (+42/-34)
src/compiler/rewriter/rules/fold_rules.cpp (+125/-184)
src/compiler/rewriter/rules/hoist_rules.cpp (+1/-1)
src/compiler/rewriter/rules/index_join_rule.cpp (+2/-2)
src/compiler/rewriter/rules/nodeid_rules.cpp (+8/-8)
src/compiler/rewriter/rules/path_rules.cpp (+11/-11)
src/compiler/rewriter/rules/ruleset.h (+18/-2)
src/compiler/rewriter/rules/type_rules.cpp (+3/-3)
src/compiler/rewriter/tools/dataflow_annotations.cpp (+22/-62)
src/compiler/rewriter/tools/dataflow_annotations.h (+0/-3)
src/compiler/rewriter/tools/expr_tools.cpp (+1/-1)
src/compiler/translator/translator.cpp (+137/-131)
src/compiler/xqddf/value_index.cpp (+1/-0)
src/functions/func_booleans_impl.cpp (+1/-2)
src/functions/func_collections_impl.cpp (+3/-0)
src/functions/func_sequences_impl.cpp (+143/-111)
src/functions/func_sequences_impl.h (+9/-37)
src/functions/function.h (+2/-2)
src/functions/function_consts.h (+2/-1)
src/functions/udf.h (+3/-1)
src/runtime/core/sequencetypes.cpp (+24/-24)
src/runtime/core/sequencetypes.h (+6/-35)
src/runtime/eval/eval.cpp (+1/-0)
src/runtime/function_item/function_item.cpp (+1/-0)
src/runtime/json/jsoniq_functions_impl.cpp (+1/-0)
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+131166@code.launchpad.net

Commit message

reduced include dependencies on the compiler + various optimizer optimizations

Description of the change

reduced include dependencies on the compiler + various optimizer optimizations

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 :

Validation queue job markos-scratch-2012-10-24T12-23-01.282Z 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
=== modified file 'ChangeLog'
--- ChangeLog 2012-10-23 21:07:15 +0000
+++ ChangeLog 2012-10-24 11:34:21 +0000
@@ -8,6 +8,7 @@
88
9Optimizations:9Optimizations:
10 * Optimized the MarkExpr and EliminateFlworVariables rules of the optimizer10 * Optimized the MarkExpr and EliminateFlworVariables rules of the optimizer
11 * Optimized the MarkFreeVars optimizer rule
1112
12Bug Fixes/Other Changes:13Bug Fixes/Other Changes:
13 * Fixed mustCopyInputNodes() method of no-copy, and jsoniq functions.14 * Fixed mustCopyInputNodes() method of no-copy, and jsoniq functions.
1415
=== modified file 'src/compiler/api/compilercb.cpp'
--- src/compiler/api/compilercb.cpp 2012-10-12 09:05:54 +0000
+++ src/compiler/api/compilercb.cpp 2012-10-24 11:34:21 +0000
@@ -17,6 +17,7 @@
1717
18#include "compiler/api/compilercb.h"18#include "compiler/api/compilercb.h"
19#include "compiler/expression/expr_base.h"19#include "compiler/expression/expr_base.h"
20#include "compiler/expression/expr_manager.h"
2021
21#ifdef ZORBA_WITH_DEBUGGER22#ifdef ZORBA_WITH_DEBUGGER
22#include "debugger/debugger_commons.h"23#include "debugger/debugger_commons.h"
2324
=== modified file 'src/compiler/api/compilercb.h'
--- src/compiler/api/compilercb.h 2012-10-12 09:05:54 +0000
+++ src/compiler/api/compilercb.h 2012-10-24 11:34:21 +0000
@@ -29,19 +29,21 @@
29// without having the definition of static_context availble.29// without having the definition of static_context availble.
30# include "context/static_context.h"30# include "context/static_context.h"
31#endif31#endif
32
32#include "compiler/expression/pragma.h"33#include "compiler/expression/pragma.h"
3334
34#include "zorbaserialization/class_serializer.h"35#include "zorbaserialization/class_serializer.h"
3536
36#include "compiler/expression/mem_manager.h"
37#include "compiler/expression/expr_manager.h"
3837
39namespace zorba {38namespace zorba
39{
4040
41#ifdef ZORBA_WITH_DEBUGGER41#ifdef ZORBA_WITH_DEBUGGER
42class DebuggerCommons;42class DebuggerCommons;
43#endif43#endif
44class static_context;44class static_context;
45class ExprManager;
46
4547
46/*******************************************************************************48/*******************************************************************************
47 There is one CompilerCB per query plus one CompilerCB per invocation of an49 There is one CompilerCB per query plus one CompilerCB per invocation of an
@@ -233,8 +235,6 @@
233235
234 ExprManager* getExprManager() const { return theEM; }236 ExprManager* getExprManager() const { return theEM; }
235237
236 MemoryManager& getMemoryManager() const { return theEM->getMemory(); }
237
238 //238 //
239 // Pragmas239 // Pragmas
240 //240 //
241241
=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp 2012-10-08 12:09:36 +0000
+++ src/compiler/codegen/plan_visitor.cpp 2012-10-24 11:34:21 +0000
@@ -31,6 +31,7 @@
31#include "system/globalenv.h"31#include "system/globalenv.h"
32#include "system/properties.h"32#include "system/properties.h"
3333
34#include "compiler/expression/expr_manager.h"
34#include "compiler/api/compilercb.h"35#include "compiler/api/compilercb.h"
35#include "compiler/codegen/plan_visitor.h"36#include "compiler/codegen/plan_visitor.h"
36#include "compiler/expression/expr.h"37#include "compiler/expression/expr.h"
@@ -896,7 +897,9 @@
896 {897 {
897 ++numForClauses;898 ++numForClauses;
898899
899 if (c->get_expr()->is_sequential())900 const for_clause* fc = static_cast<const for_clause*>(c);
901
902 if (fc->get_expr()->is_sequential())
900 {903 {
901 // TODO: do not convert to general flwor if the whole flwor consists904 // TODO: do not convert to general flwor if the whole flwor consists
902 // of a single FOR followed by RETURN.905 // of a single FOR followed by RETURN.
@@ -907,7 +910,9 @@
907 }910 }
908 else if (c->get_kind() == flwor_clause::let_clause)911 else if (c->get_kind() == flwor_clause::let_clause)
909 {912 {
910 if (c->get_expr()->is_sequential())913 const let_clause* lc = static_cast<const let_clause*>(c);
914
915 if (lc->get_expr()->is_sequential())
911 {916 {
912 if (numForClauses > 0)917 if (numForClauses > 0)
913 {918 {
@@ -933,7 +938,7 @@
933 {938 {
934 materialize_clause* mat =939 materialize_clause* mat =
935 theCCB->theEM->create_materialize_clause(v.get_sctx(),940 theCCB->theEM->create_materialize_clause(v.get_sctx(),
936 v.get_return_expr()->get_loc());941 v.get_return_expr()->get_loc());
937942
938 v.add_clause(mat);943 v.add_clause(mat);
939 ++numClauses;944 ++numClauses;
@@ -960,14 +965,17 @@
960 case flwor_clause::let_clause:965 case flwor_clause::let_clause:
961 case flwor_clause::window_clause:966 case flwor_clause::window_clause:
962 {967 {
968 expr* domExpr = static_cast<const forletwin_clause*>(c)->get_expr();
969
963 if (k == flwor_clause::for_clause || k == flwor_clause::window_clause)970 if (k == flwor_clause::for_clause || k == flwor_clause::window_clause)
964 {971 {
965 xqtref_t domainType = c->get_expr()->get_return_type();972 xqtref_t domainType = domExpr->get_return_type();
973
966 if (domainType->get_quantifier() != TypeConstants::QUANT_ONE)974 if (domainType->get_quantifier() != TypeConstants::QUANT_ONE)
967 ++numForClauses;975 ++numForClauses;
968 }976 }
969977
970 if (c->get_expr()->is_sequential())978 if (domExpr->is_sequential())
971 {979 {
972 if (k == flwor_clause::for_clause ||980 if (k == flwor_clause::for_clause ||
973 k == flwor_clause::window_clause ||981 k == flwor_clause::window_clause ||
@@ -981,12 +989,12 @@
981 v.get_clause(i-1)->get_kind() != flwor_clause::order_clause &&989 v.get_clause(i-1)->get_kind() != flwor_clause::order_clause &&
982 v.get_clause(i-1)->get_kind() != flwor_clause::group_clause)990 v.get_clause(i-1)->get_kind() != flwor_clause::group_clause)
983 {991 {
984 orderby_clause* mat =992 orderby_clause* mat = theCCB->theEM->
985 theCCB->theEM->create_orderby_clause(v.get_sctx(),993 create_orderby_clause(v.get_sctx(),
986 c->get_loc(),994 c->get_loc(),
987 true,995 true,
988 modifiers,996 modifiers,
989 orderingExprs);997 orderingExprs);
990998
991 v.add_clause(i, mat);999 v.add_clause(i, mat);
992 ++i;1000 ++i;
@@ -997,12 +1005,12 @@
997 (i < numClauses - 1 &&1005 (i < numClauses - 1 &&
998 v.get_clause(i+1)->get_kind() != flwor_clause::group_clause))1006 v.get_clause(i+1)->get_kind() != flwor_clause::group_clause))
999 {1007 {
1000 orderby_clause* mat =1008 orderby_clause* mat = theCCB->theEM->
1001 theCCB->theEM->create_orderby_clause(v.get_sctx(),1009 create_orderby_clause(v.get_sctx(),
1002 c->get_loc(),1010 c->get_loc(),
1003 true,1011 true,
1004 modifiers,1012 modifiers,
1005 orderingExprs);1013 orderingExprs);
10061014
1007 v.add_clause(i+1, mat);1015 v.add_clause(i+1, mat);
1008 ++numClauses;1016 ++numClauses;
@@ -1032,12 +1040,12 @@
1032 lastClause->get_kind() != flwor_clause::order_clause &&1040 lastClause->get_kind() != flwor_clause::order_clause &&
1033 lastClause->get_kind() != flwor_clause::group_clause)1041 lastClause->get_kind() != flwor_clause::group_clause)
1034 {1042 {
1035 orderby_clause* mat =1043 orderby_clause* mat = theCCB->theEM->
1036 theCCB->theEM->create_orderby_clause(v.get_sctx(),1044 create_orderby_clause(v.get_sctx(),
1037 v.get_return_expr()->get_loc(),1045 v.get_return_expr()->get_loc(),
1038 true,1046 true,
1039 modifiers,1047 modifiers,
1040 orderingExprs);1048 orderingExprs);
10411049
1042 v.add_clause(mat);1050 v.add_clause(mat);
1043 ++numClauses;1051 ++numClauses;
@@ -1566,7 +1574,7 @@
15661574
1567 return new flwor::WindowIterator(sctx,1575 return new flwor::WindowIterator(sctx,
1568 var->get_loc(),1576 var->get_loc(),
1569 wc->get_winkind() == window_clause::tumbling_window ? flwor::WindowIterator::TUMBLING : flwor::WindowIterator::SLIDING,1577 wc->get_winkind() == tumbling_window ? flwor::WindowIterator::TUMBLING : flwor::WindowIterator::SLIDING,
1570 PREV_ITER,1578 PREV_ITER,
1571 domainIter,1579 domainIter,
1572 var->get_name(),1580 var->get_name(),
@@ -2272,10 +2280,10 @@
2272 enum FlowCtlException::action a;2280 enum FlowCtlException::action a;
2273 switch (v.get_action())2281 switch (v.get_action())
2274 {2282 {
2275 case flowctl_expr::BREAK:2283 case FLOW_BREAK:
2276 a = FlowCtlException::BREAK;2284 a = FlowCtlException::BREAK;
2277 break;2285 break;
2278 case flowctl_expr::CONTINUE:2286 case FLOW_CONTINUE:
2279 a = FlowCtlException::CONTINUE;2287 a = FlowCtlException::CONTINUE;
2280 break;2288 break;
2281 default:2289 default:
@@ -3022,7 +3030,7 @@
30223030
3023 theConstructorsStack.push(&v);3031 theConstructorsStack.push(&v);
30243032
3025 if (v.get_type() == text_expr::text_constructor)3033 if (v.get_type() == text_constructor)
3026 theEnclosedContextStack.push(TEXT_CONTENT);3034 theEnclosedContextStack.push(TEXT_CONTENT);
3027 else3035 else
3028 theEnclosedContextStack.push(ATTRIBUTE_CONTENT);3036 theEnclosedContextStack.push(ATTRIBUTE_CONTENT);
@@ -3049,11 +3057,11 @@
30493057
3050 switch (v.get_type())3058 switch (v.get_type())
3051 {3059 {
3052 case text_expr::text_constructor:3060 case text_constructor:
3053 push_itstack(new TextIterator(sctx, qloc, content, isRoot));3061 push_itstack(new TextIterator(sctx, qloc, content, isRoot));
3054 break;3062 break;
30553063
3056 case text_expr::comment_constructor:3064 case comment_constructor:
3057 push_itstack(new CommentIterator(sctx, qloc, content, isRoot));3065 push_itstack(new CommentIterator(sctx, qloc, content, isRoot));
3058 break;3066 break;
30593067
30603068
=== modified file 'src/compiler/expression/expr.cpp'
--- src/compiler/expression/expr.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/expression/expr.cpp 2012-10-24 11:34:21 +0000
@@ -174,12 +174,12 @@
174 static_context* sctx,174 static_context* sctx,
175 user_function* udf,175 user_function* udf,
176 const QueryLoc& loc,176 const QueryLoc& loc,
177 order_type_t type,177 DocOrderMode type,
178 expr* inExpr)178 expr* input)
179 :179 :
180 expr(ccb, sctx, udf, loc, order_expr_kind),180 expr(ccb, sctx, udf, loc, order_expr_kind),
181 theType(type),181 theInput(input),
182 theExpr(inExpr)182 theType(type)
183{183{
184 compute_scripting_kind();184 compute_scripting_kind();
185}185}
@@ -187,7 +187,7 @@
187187
188void order_expr::compute_scripting_kind()188void order_expr::compute_scripting_kind()
189{189{
190 theScriptingKind = theExpr->get_scripting_detail();190 theScriptingKind = theInput->get_scripting_detail();
191191
192 if (is_vacuous())192 if (is_vacuous())
193 theScriptingKind = SIMPLE_EXPR;193 theScriptingKind = SIMPLE_EXPR;
@@ -204,14 +204,14 @@
204 const QueryLoc& loc,204 const QueryLoc& loc,
205 enum ParseConstants::validation_mode_t mode,205 enum ParseConstants::validation_mode_t mode,
206 const store::Item_t& typeName,206 const store::Item_t& typeName,
207 expr* inExpr,207 expr* input,
208 rchandle<TypeManager> typemgr)208 rchandle<TypeManager> typemgr)
209 :209 :
210 expr(ccb, sctx, udf, loc, validate_expr_kind),210 expr(ccb, sctx, udf, loc, validate_expr_kind),
211 theInput(input),
211 theMode(mode),212 theMode(mode),
212 theTypeName(typeName),213 theTypeName(typeName),
213 theTypeMgr(typemgr),214 theTypeMgr(typemgr)
214 theExpr(inExpr)
215{215{
216 compute_scripting_kind();216 compute_scripting_kind();
217}217}
@@ -219,9 +219,9 @@
219219
220void validate_expr::compute_scripting_kind()220void validate_expr::compute_scripting_kind()
221{221{
222 checkNonUpdating(theExpr);222 checkNonUpdating(theInput);
223223
224 theScriptingKind = theExpr->get_scripting_detail();224 theScriptingKind = theInput->get_scripting_detail();
225225
226 if (is_vacuous())226 if (is_vacuous())
227 theScriptingKind = SIMPLE_EXPR;227 theScriptingKind = SIMPLE_EXPR;
@@ -266,7 +266,7 @@
266 const xqtref_t& type)266 const xqtref_t& type)
267 :267 :
268 expr(ccb, sctx, udf, loc, kind),268 expr(ccb, sctx, udf, loc, kind),
269 theInputExpr(input),269 theInput(input),
270 theTargetType(type)270 theTargetType(type)
271{271{
272 assert(type != NULL);272 assert(type != NULL);
@@ -290,9 +290,9 @@
290290
291void cast_or_castable_base_expr::compute_scripting_kind()291void cast_or_castable_base_expr::compute_scripting_kind()
292{292{
293 checkNonUpdating(theInputExpr);293 checkNonUpdating(theInput);
294294
295 theScriptingKind = theInputExpr->get_scripting_detail();295 theScriptingKind = theInput->get_scripting_detail();
296296
297 if (is_vacuous())297 if (is_vacuous())
298 theScriptingKind = SIMPLE_EXPR;298 theScriptingKind = SIMPLE_EXPR;
@@ -355,7 +355,7 @@
355 const QueryLoc& loc,355 const QueryLoc& loc,
356 expr* inputExpr,356 expr* inputExpr,
357 const xqtref_t& type,357 const xqtref_t& type,
358 TreatIterator::ErrorKind err,358 TreatErrorKind err,
359 bool check_prime,359 bool check_prime,
360 store::Item* qname)360 store::Item* qname)
361 :361 :
@@ -378,7 +378,7 @@
378 const QueryLoc& loc,378 const QueryLoc& loc,
379 expr* input,379 expr* input,
380 const xqtref_t& type,380 const xqtref_t& type,
381 PromoteIterator::ErrorKind err,381 PromoteErrorKind err,
382 store::Item* qname)382 store::Item* qname)
383 :383 :
384 cast_base_expr(ccb, sctx, udf, loc, promote_expr_kind, input, type),384 cast_base_expr(ccb, sctx, udf, loc, promote_expr_kind, input, type),
@@ -663,7 +663,7 @@
663 static_context* sctx,663 static_context* sctx,
664 user_function* udf,664 user_function* udf,
665 const QueryLoc& loc,665 const QueryLoc& loc,
666 text_constructor_type type_arg,666 TextConstructorType type_arg,
667 expr* content)667 expr* content)
668 :668 :
669 expr(ccb, sctx, udf, loc, text_expr_kind),669 expr(ccb, sctx, udf, loc, text_expr_kind),
@@ -743,10 +743,10 @@
743 static_context* sctx,743 static_context* sctx,
744 user_function* udf,744 user_function* udf,
745 const QueryLoc& loc,745 const QueryLoc& loc,
746 expr* wrapped)746 expr* input)
747 :747 :
748 expr(ccb, sctx, udf, loc, wrapper_expr_kind),748 expr(ccb, sctx, udf, loc, wrapper_expr_kind),
749 theWrappedExpr(wrapped)749 theInput(input)
750{750{
751 compute_scripting_kind();751 compute_scripting_kind();
752}752}
@@ -754,7 +754,7 @@
754754
755void wrapper_expr::compute_scripting_kind()755void wrapper_expr::compute_scripting_kind()
756{756{
757 theScriptingKind = theWrappedExpr->get_scripting_detail();757 theScriptingKind = theInput->get_scripting_detail();
758}758}
759759
760760
@@ -1105,6 +1105,14 @@
1105}1105}
11061106
11071107
1108void eval_expr::add_var(var_expr* var)
1109{
1110 theOuterVarNames.push_back(var->get_name());
1111 theOuterVarTypes.push_back(var->get_return_type());
1112 theArgs.push_back(var);
1113}
1114
1115
1108#ifdef ZORBA_WITH_DEBUGGER1116#ifdef ZORBA_WITH_DEBUGGER
1109/*******************************************************************************1117/*******************************************************************************
11101118
@@ -1131,6 +1139,13 @@
1131 theScriptingKind = theExpr->get_scripting_detail();1139 theScriptingKind = theExpr->get_scripting_detail();
1132}1140}
11331141
1142
1143void debugger_expr::add_var(var_expr* var, expr* arg)
1144{
1145 theVars.push_back(var);
1146 theArgs.push_back(arg);
1147}
1148
1134#endif1149#endif
11351150
11361151
@@ -1142,10 +1157,10 @@
1142 static_context* sctx,1157 static_context* sctx,
1143 user_function* udf,1158 user_function* udf,
1144 const QueryLoc& loc,1159 const QueryLoc& loc,
1145 expr* aChild)1160 expr* input)
1146 :1161 :
1147 expr(ccb, sctx, udf, loc, aChild->get_expr_kind()),1162 expr(ccb, sctx, udf, loc, function_trace_expr_kind),
1148 theExpr(aChild),1163 theInput(input),
1149 theFunctionArity(0)1164 theFunctionArity(0)
1150{1165{
1151 bool modified;1166 bool modified;
@@ -1154,14 +1169,14 @@
1154}1169}
11551170
11561171
1157function_trace_expr::function_trace_expr(user_function* udf, expr* aExpr)1172function_trace_expr::function_trace_expr(user_function* udf, expr* input)
1158 :1173 :
1159 expr(aExpr->get_ccb(),1174 expr(input->get_ccb(),
1160 aExpr->get_sctx(),1175 input->get_sctx(),
1161 udf,1176 udf,
1162 aExpr->get_loc(),1177 input->get_loc(),
1163 function_trace_expr_kind),1178 function_trace_expr_kind),
1164 theExpr(aExpr),1179 theInput(input),
1165 theFunctionArity(0)1180 theFunctionArity(0)
1166{1181{
1167 bool modified;1182 bool modified;
@@ -1177,7 +1192,7 @@
11771192
1178void function_trace_expr::compute_scripting_kind()1193void function_trace_expr::compute_scripting_kind()
1179{1194{
1180 theScriptingKind = theExpr->get_scripting_detail();1195 theScriptingKind = theInput->get_scripting_detail();
1181}1196}
11821197
11831198
11841199
=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/expr.h 2012-10-24 11:34:21 +0000
@@ -28,7 +28,7 @@
2828
29#include "functions/signature.h"29#include "functions/signature.h"
3030
31#include "compiler/expression/var_expr.h"31#include "compiler/expression/expr_base.h"
3232
33#include "context/static_context.h"33#include "context/static_context.h"
34#include "context/namespace_context.h"34#include "context/namespace_context.h"
@@ -37,7 +37,6 @@
3737
38#include "store/api/item.h"38#include "store/api/item.h"
3939
40#include "runtime/core/sequencetypes.h"
4140
42namespace zorba41namespace zorba
43{42{
@@ -48,6 +47,7 @@
48class signature;47class signature;
49class pragma;48class pragma;
5049
50
51/*******************************************************************************51/*******************************************************************************
52 [68] IfExpr ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle52 [68] IfExpr ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
53********************************************************************************/53********************************************************************************/
@@ -96,16 +96,9 @@
96 friend class ExprIterator;96 friend class ExprIterator;
97 friend class expr;97 friend class expr;
9898
99public:
100 enum order_type_t
101 {
102 ordered,
103 unordered
104 };
105
106protected:99protected:
107 order_type_t theType;100 expr * theInput;
108 expr * theExpr;101 DocOrderMode theType;
109102
110protected:103protected:
111 order_expr(104 order_expr(
@@ -113,13 +106,13 @@
113 static_context* sctx,106 static_context* sctx,
114 user_function* udf,107 user_function* udf,
115 const QueryLoc&,108 const QueryLoc&,
116 order_type_t,109 DocOrderMode,
117 expr*);110 expr*);
118111
119public:112public:
120 order_type_t get_type() const { return theType; }113 expr* get_input() const { return theInput; }
121114
122 expr* get_expr() const { return theExpr; }115 DocOrderMode get_type() const { return theType; }
123116
124 void compute_scripting_kind();117 void compute_scripting_kind();
125118
@@ -139,10 +132,10 @@
139 friend class expr;132 friend class expr;
140133
141protected:134protected:
142 ParseConstants::validation_mode_t theMode;135 expr * theInput;
143 store::Item_t theTypeName;136 ParseConstants::validation_mode_t theMode;
144 rchandle<TypeManager> theTypeMgr;137 store::Item_t theTypeName;
145 expr * theExpr;138 rchandle<TypeManager> theTypeMgr;
146139
147protected:140protected:
148 validate_expr(141 validate_expr(
@@ -156,7 +149,7 @@
156 rchandle<TypeManager>);149 rchandle<TypeManager>);
157150
158public:151public:
159 expr* get_expr() const { return theExpr; }152 expr* get_input() const { return theInput; }
160153
161 const store::Item* get_type_name() const { return theTypeName; }154 const store::Item* get_type_name() const { return theTypeName; }
162155
@@ -205,7 +198,7 @@
205 friend class expr;198 friend class expr;
206199
207protected:200protected:
208 expr * theInputExpr;201 expr * theInput;
209 xqtref_t theTargetType;202 xqtref_t theTargetType;
210203
211protected:204protected:
@@ -219,7 +212,7 @@
219 const xqtref_t& type);212 const xqtref_t& type);
220213
221public:214public:
222 expr* get_input() const { return theInputExpr; }215 expr* get_input() const { return theInput; }
223216
224 xqtref_t get_target_type() const;217 xqtref_t get_target_type() const;
225218
@@ -297,9 +290,9 @@
297 friend class expr;290 friend class expr;
298291
299protected:292protected:
300 TreatIterator::ErrorKind theErrorKind;293 TreatErrorKind theErrorKind;
301 bool theCheckPrime;294 bool theCheckPrime;
302 store::Item_t theQName;295 store::Item_t theQName;
303296
304protected:297protected:
305 treat_expr(298 treat_expr(
@@ -309,12 +302,12 @@
309 const QueryLoc&,302 const QueryLoc&,
310 expr*,303 expr*,
311 const xqtref_t&,304 const xqtref_t&,
312 TreatIterator::ErrorKind err,305 TreatErrorKind err,
313 bool check_prime = true,306 bool check_prime = true,
314 store::Item* qname = NULL);307 store::Item* qname = NULL);
315308
316public:309public:
317 TreatIterator::ErrorKind get_err() const { return theErrorKind; }310 TreatErrorKind get_err() const { return theErrorKind; }
318311
319 bool get_check_prime() const { return theCheckPrime; }312 bool get_check_prime() const { return theCheckPrime; }
320313
@@ -375,8 +368,8 @@
375 friend class expr;368 friend class expr;
376369
377protected:370protected:
378 PromoteIterator::ErrorKind theErrorKind;371 PromoteErrorKind theErrorKind;
379 store::Item_t theQName;372 store::Item_t theQName;
380373
381protected:374protected:
382 promote_expr(375 promote_expr(
@@ -386,11 +379,11 @@
386 const QueryLoc& loc,379 const QueryLoc& loc,
387 expr* input,380 expr* input,
388 const xqtref_t& type,381 const xqtref_t& type,
389 PromoteIterator::ErrorKind err,382 PromoteErrorKind err,
390 store::Item* qname);383 store::Item* qname);
391384
392public:385public:
393 PromoteIterator::ErrorKind get_err() const { return theErrorKind; }386 PromoteErrorKind get_err() const { return theErrorKind; }
394387
395 void set_qname(const store::Item_t& qname) { theQName = qname; }388 void set_qname(const store::Item_t& qname) { theQName = qname; }
396389
@@ -504,8 +497,8 @@
504 friend class expr;497 friend class expr;
505498
506private:499private:
507 expr* theInputExpr;500 expr * theInputExpr;
508 bool theIsAttrName;501 bool theIsAttrName;
509502
510protected:503protected:
511 name_cast_expr(504 name_cast_expr(
@@ -541,7 +534,7 @@
541534
542protected:535protected:
543 expr * theContent;536 expr * theContent;
544 bool theCopyInputNodes;537 bool theCopyInputNodes;
545538
546protected:539protected:
547 doc_expr(540 doc_expr(
@@ -713,16 +706,9 @@
713 friend class ExprIterator;706 friend class ExprIterator;
714 friend class expr;707 friend class expr;
715708
716public:
717 typedef enum
718 {
719 text_constructor,
720 comment_constructor
721 } text_constructor_type;
722
723protected:709protected:
724 text_constructor_type type;710 TextConstructorType type;
725 expr * theContentExpr;711 expr * theContentExpr;
726712
727protected:713protected:
728 text_expr(714 text_expr(
@@ -730,13 +716,13 @@
730 static_context* sctx,716 static_context* sctx,
731 user_function* udf,717 user_function* udf,
732 const QueryLoc&,718 const QueryLoc&,
733 text_constructor_type,719 TextConstructorType,
734 expr*);720 expr*);
735721
736public:722public:
737 expr* get_text() const { return theContentExpr; }723 expr* get_text() const { return theContentExpr; }
738724
739 text_constructor_type get_type() const { return type; }725 TextConstructorType get_type() const { return type; }
740726
741 void compute_scripting_kind();727 void compute_scripting_kind();
742728
@@ -1040,7 +1026,7 @@
1040 friend class ExprManager;1026 friend class ExprManager;
10411027
1042protected:1028protected:
1043 expr * theWrappedExpr;1029 expr * theInput;
10441030
1045protected:1031protected:
1046 wrapper_expr(1032 wrapper_expr(
@@ -1051,9 +1037,9 @@
1051 expr* wrapped);1037 expr* wrapped);
10521038
1053public:1039public:
1054 expr* get_expr() const { return theWrappedExpr; }1040 expr* get_input() const { return theInput; }
10551041
1056 void set_expr(expr* e) { theWrappedExpr = e;}1042 void set_expr(expr* e) { theInput = e;}
10571043
1058 void compute_scripting_kind();1044 void compute_scripting_kind();
10591045
@@ -1073,11 +1059,11 @@
1073 friend class ExprManager;1059 friend class ExprManager;
10741060
1075protected:1061protected:
1076 expr* theExpr;1062 expr * theInput;
1077 store::Item_t theFunctionName;1063 store::Item_t theFunctionName;
1078 QueryLoc theFunctionLocation;1064 QueryLoc theFunctionLocation;
1079 QueryLoc theFunctionCallLocation;1065 QueryLoc theFunctionCallLocation;
1080 unsigned int theFunctionArity;1066 unsigned int theFunctionArity;
10811067
1082protected:1068protected:
1083 function_trace_expr(1069 function_trace_expr(
@@ -1094,14 +1080,14 @@
1094public:1080public:
1095 virtual ~function_trace_expr();1081 virtual ~function_trace_expr();
10961082
1083 expr* get_input() const { return theInput; }
1084
1097 void compute_scripting_kind();1085 void compute_scripting_kind();
10981086
1099 void accept(expr_visitor&);1087 void accept(expr_visitor&);
11001088
1101 std::ostream& put(std::ostream&) const;1089 std::ostream& put(std::ostream&) const;
11021090
1103 expr* get_expr() const { return theExpr; }
1104
1105 void setFunctionName(store::Item_t aFunctionName)1091 void setFunctionName(store::Item_t aFunctionName)
1106 {1092 {
1107 theFunctionName = aFunctionName;1093 theFunctionName = aFunctionName;
@@ -1215,12 +1201,7 @@
12151201
1216 const std::vector<xqtref_t>& get_var_types() const { return theOuterVarTypes; }1202 const std::vector<xqtref_t>& get_var_types() const { return theOuterVarTypes; }
12171203
1218 void add_var(var_expr* var)1204 void add_var(var_expr* var);
1219 {
1220 theOuterVarNames.push_back(var->get_name());
1221 theOuterVarTypes.push_back(var->get_return_type());
1222 theArgs.push_back(var);
1223 }
12241205
1225 expr_script_kind_t get_inner_scripting_kind() const;1206 expr_script_kind_t get_inner_scripting_kind() const;
12261207
@@ -1288,11 +1269,7 @@
12881269
1289 const var_expr* get_var(csize i) const { return theVars[i]; }1270 const var_expr* get_var(csize i) const { return theVars[i]; }
12901271
1291 void add_var(var_expr* var, expr* arg)1272 void add_var(var_expr* var, expr* arg);
1292 {
1293 theVars.push_back(var);
1294 theArgs.push_back(arg);
1295 }
12961273
1297 void compute_scripting_kind();1274 void compute_scripting_kind();
1298};1275};
12991276
=== modified file 'src/compiler/expression/expr_base.cpp'
--- src/compiler/expression/expr_base.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/expression/expr_base.cpp 2012-10-24 11:34:21 +0000
@@ -20,6 +20,7 @@
20#include "compiler/expression/fo_expr.h"20#include "compiler/expression/fo_expr.h"
21#include "compiler/expression/flwor_expr.h"21#include "compiler/expression/flwor_expr.h"
22#include "compiler/expression/path_expr.h"22#include "compiler/expression/path_expr.h"
23#include "compiler/expression/script_exprs.h"
23#include "compiler/expression/expr_iter.h"24#include "compiler/expression/expr_iter.h"
24#include "compiler/expression/expr_visitor.h"25#include "compiler/expression/expr_visitor.h"
25#include "compiler/expression/expr_manager.h"26#include "compiler/expression/expr_manager.h"
@@ -155,6 +156,7 @@
155 // This is the default. The constructors for certain exprs set different values.156 // This is the default. The constructors for certain exprs set different values.
156 setNonDiscardable(ANNOTATION_FALSE);157 setNonDiscardable(ANNOTATION_FALSE);
157 setUnfoldable(ANNOTATION_FALSE);158 setUnfoldable(ANNOTATION_FALSE);
159 setContainsRecursiveCall(ANNOTATION_FALSE);
158 setConstructsNodes(ANNOTATION_FALSE);160 setConstructsNodes(ANNOTATION_FALSE);
159 setDereferencesNodes(ANNOTATION_FALSE);161 setDereferencesNodes(ANNOTATION_FALSE);
160}162}
@@ -766,8 +768,7 @@
766768
767 while (kind == wrapper_expr_kind)769 while (kind == wrapper_expr_kind)
768 {770 {
769 const wrapper_expr* wrapperExpr = static_cast<const wrapper_expr*>(currExpr);771 currExpr = static_cast<const wrapper_expr*>(currExpr)->get_input();
770 currExpr = wrapperExpr->get_expr();
771 kind = currExpr->get_expr_kind();772 kind = currExpr->get_expr_kind();
772 }773 }
773774
@@ -834,14 +835,14 @@
834835
835 case order_expr_kind:836 case order_expr_kind:
836 {837 {
837 const order_expr* orderExpr = static_cast<const order_expr *>(this);838 return static_cast<const order_expr*>(this)->get_input()->
838 return orderExpr->get_expr()->is_map_internal(e, found);839 is_map_internal(e, found);
839 }840 }
840841
841 case wrapper_expr_kind:842 case wrapper_expr_kind:
842 {843 {
843 const wrapper_expr* wrapperExpr = static_cast<const wrapper_expr *>(this);844 return static_cast<const wrapper_expr*>(this)->get_input()->
844 return wrapperExpr->get_expr()->is_map_internal(e, found);845 is_map_internal(e, found);
845 }846 }
846847
847 case const_expr_kind:848 case const_expr_kind:
@@ -896,7 +897,9 @@
896 if (found)897 if (found)
897 break;898 break;
898899
899 if (clause->get_expr()->is_map_internal(e, found) && found)900 const for_clause* fc = static_cast<const for_clause*>(clause);
901
902 if (fc->get_expr()->is_map_internal(e, found) && found)
900 {903 {
901 break;904 break;
902 }905 }
@@ -908,12 +911,25 @@
908 break;911 break;
909 }912 }
910 case flwor_clause::let_clause:913 case flwor_clause::let_clause:
914 {
915 if (found)
916 break;
917
918 const let_clause* lc = static_cast<const let_clause*>(clause);
919
920 if (lc->get_expr()->contains_expr(e))
921 return false;
922
923 break;
924 }
911 case flwor_clause::where_clause:925 case flwor_clause::where_clause:
912 {926 {
913 if (found)927 if (found)
914 break;928 break;
915929
916 if (clause->get_expr()->contains_expr(e))930 const where_clause* wc = static_cast<const where_clause*>(clause);
931
932 if (wc->get_expr()->contains_expr(e))
917 return false;933 return false;
918934
919 break;935 break;
@@ -923,10 +939,11 @@
923 if (found)939 if (found)
924 break;940 break;
925941
926 if (clause->get_expr()->contains_expr(e))
927 return false;
928
929 const window_clause* wc = static_cast<const window_clause*>(clause);942 const window_clause* wc = static_cast<const window_clause*>(clause);
943
944 if (wc->get_expr()->contains_expr(e))
945 return false;
946
930 flwor_wincond* startCond = wc->get_win_start();947 flwor_wincond* startCond = wc->get_win_start();
931 flwor_wincond* stopCond = wc->get_win_stop();948 flwor_wincond* stopCond = wc->get_win_stop();
932949
933950
=== modified file 'src/compiler/expression/expr_base.h'
--- src/compiler/expression/expr_base.h 2012-10-22 15:10:23 +0000
+++ src/compiler/expression/expr_base.h 2012-10-24 11:34:21 +0000
@@ -124,7 +124,6 @@
124********************************************************************************/124********************************************************************************/
125class expr125class expr
126{126{
127 friend class expr_iterator_data;
128 friend class ExprIterator;127 friend class ExprIterator;
129 friend class forletwin_clause;128 friend class forletwin_clause;
130 friend class for_clause;129 friend class for_clause;
131130
=== modified file 'src/compiler/expression/expr_clone.cpp'
--- src/compiler/expression/expr_clone.cpp 2012-10-09 12:56:08 +0000
+++ src/compiler/expression/expr_clone.cpp 2012-10-24 11:34:21 +0000
@@ -24,6 +24,7 @@
24#include "compiler/expression/json_exprs.h"24#include "compiler/expression/json_exprs.h"
25#include "compiler/expression/function_item_expr.h"25#include "compiler/expression/function_item_expr.h"
26#include "compiler/expression/ft_expr.h"26#include "compiler/expression/ft_expr.h"
27#include "compiler/expression/ftnode.h"
27#include "compiler/expression/expr_manager.h"28#include "compiler/expression/expr_manager.h"
2829
29#include "compiler/api/compilercb.h"30#include "compiler/api/compilercb.h"
@@ -462,7 +463,7 @@
462 theLoc,463 theLoc,
463 e->get_valmode(),464 e->get_valmode(),
464 const_cast<store::Item*>(e->get_type_name()),465 const_cast<store::Item*>(e->get_type_name()),
465 e->get_expr()->clone(udf, subst),466 e->get_input()->clone(udf, subst),
466 e->get_typemgr());467 e->get_typemgr());
467468
468 break;469 break;
@@ -502,7 +503,7 @@
502 udf,503 udf,
503 theLoc,504 theLoc,
504 e->get_type(),505 e->get_type(),
505 e->get_expr()->clone(udf, subst));506 e->get_input()->clone(udf, subst));
506 break;507 break;
507 }508 }
508#ifndef ZORBA_NO_FULL_TEXT509#ifndef ZORBA_NO_FULL_TEXT
@@ -734,9 +735,9 @@
734 {735 {
735 const wrapper_expr* e = static_cast<const wrapper_expr*>(this);736 const wrapper_expr* e = static_cast<const wrapper_expr*>(this);
736737
737 expr* wrappedClone = e->theWrappedExpr->clone(udf, subst);738 expr* wrappedClone = e->theInput->clone(udf, subst);
738739
739 if (e->theWrappedExpr->get_expr_kind() == var_expr_kind &&740 if (e->theInput->get_expr_kind() == var_expr_kind &&
740 wrappedClone->get_expr_kind() != var_expr_kind)741 wrappedClone->get_expr_kind() != var_expr_kind)
741 {742 {
742 newExpr = wrappedClone;743 newExpr = wrappedClone;
@@ -753,7 +754,7 @@
753 const function_trace_expr* e = static_cast<const function_trace_expr*>(this);754 const function_trace_expr* e = static_cast<const function_trace_expr*>(this);
754755
755 function_trace_expr* cloneExpr = theCCB->theEM->756 function_trace_expr* cloneExpr = theCCB->theEM->
756 create_function_trace_expr(udf, e->theExpr->clone(udf, subst));757 create_function_trace_expr(udf, e->theInput->clone(udf, subst));
757758
758 cloneExpr->theFunctionName = e->theFunctionName;759 cloneExpr->theFunctionName = e->theFunctionName;
759 cloneExpr->theFunctionLocation = e->theFunctionLocation;760 cloneExpr->theFunctionLocation = e->theFunctionLocation;
760761
=== modified file 'src/compiler/expression/expr_consts.h'
--- src/compiler/expression/expr_consts.h 2012-09-19 21:16:15 +0000
+++ src/compiler/expression/expr_consts.h 2012-10-24 11:34:21 +0000
@@ -21,6 +21,65 @@
21{21{
2222
2323
24enum PromoteErrorKind
25{
26 PROMOTE_FUNC_RETURN,
27 PROMOTE_FUNC_PARAM,
28 PROMOTE_TYPE_PROMOTION,
29 PROMOTE_JSONIQ_ARRAY_SELECTOR,
30 PROMOTE_JSONIQ_OBJECT_SELECTOR,
31 PROMOTE_JSONIQ_SELECTOR
32};
33
34
35enum TreatErrorKind
36{
37 TREAT_FUNC_RETURN,
38 TREAT_FUNC_PARAM,
39 TREAT_TYPE_MATCH,
40 TREAT_EXPR,
41 TREAT_INDEX_DOMAIN,
42 TREAT_INDEX_KEY,
43 TREAT_PATH_STEP,
44 TREAT_PATH_DOT,
45 TREAT_MULTI_VALUED_GROUPING_KEY,
46 TREAT_JSONIQ_VALUE,
47 TREAT_JSONIQ_UPDATE_TARGET,
48 TREAT_JSONIQ_OBJECT_UPDATE_TARGET,
49 TREAT_JSONIQ_OBJECT_UPDATE_CONTENT,
50 TREAT_JSONIQ_ARRAY_UPDATE_TARGET,
51 TREAT_JSONIQ_OBJECT_UPDATE_VALUE
52};
53
54
55enum WindowKind
56{
57 tumbling_window,
58 sliding_window
59};
60
61
62enum TextConstructorType
63{
64 text_constructor,
65 comment_constructor
66};
67
68
69enum FlowCtlAction
70{
71 FLOW_BREAK,
72 FLOW_CONTINUE
73};
74
75
76enum DocOrderMode
77{
78 doc_ordered,
79 doc_unordered
80};
81
82
24enum axis_kind_t83enum axis_kind_t
25{84{
26 axis_kind_self = 0,85 axis_kind_self = 0,
2786
=== modified file 'src/compiler/expression/expr_iter.cpp'
--- src/compiler/expression/expr_iter.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/expression/expr_iter.cpp 2012-10-24 11:34:21 +0000
@@ -94,12 +94,6 @@
9494
95void ExprIterator::next()95void ExprIterator::next()
96{96{
97 flwor_clause* c = NULL;
98 window_clause* wc = NULL;
99 orderby_clause* oc = NULL;
100 group_clause* gc = NULL;
101 flwor_wincond* wincond = NULL;
102
103 switch (theExpr->get_expr_kind())97 switch (theExpr->get_expr_kind())
104 {98 {
105 case flwor_expr_kind:99 case flwor_expr_kind:
@@ -107,6 +101,223 @@
107 {101 {
108 flwor_expr* flworExpr = static_cast<flwor_expr*>(theExpr);102 flwor_expr* flworExpr = static_cast<flwor_expr*>(theExpr);
109103
104#if 0
105 switch (theState)
106 {
107 case 0:
108 {
109 theClausesIter = flworExpr->theClauses.begin();
110 theClausesEnd = flworExpr->theClauses.end();
111
112 if (theClausesIter == theClausesEnd)
113 {
114 theIsDone = true;
115 theState = 10;
116 return;
117 }
118
119 flwor_clause* c = *theClausesIter;
120
121 switch (c->get_kind())
122 {
123 case flwor_clause::for_clause:
124 case flwor_clause::let_clause:
125 {
126 theCurrentChild = &(static_cast<forletwin_clause *>(c)->theDomainExpr);
127
128 ++theClausesIter;
129 theState = 1;
130 return;
131 }
132 case flwor_clause::window_clause:
133 {
134 theCurrentChild = &(static_cast<forletwin_clause *>(c)->theDomainExpr);
135
136 theWincondIter = 0;
137 theState = 2;
138 return;
139 }
140 case flwor_clause::where_clause:
141 {
142 theCurrentChild = &(static_cast<where_clause *>(c)->theWhereExpr);
143
144 ++theClausesIter;
145 theState = 1;
146 return;
147 }
148 case flwor_clause::count_clause:
149 {
150 ++theClausesIter;
151 break;
152 }
153 default:
154 ZORBA_ASSERT(false);
155 }
156 }
157 case 1:
158 {
159nextclause:
160
161 while(theClausesIter != theClausesEnd)
162 {
163 flwor_clause* c = *theClausesIter;
164
165 switch (c->get_kind())
166 {
167 case flwor_clause::for_clause:
168 case flwor_clause::let_clause:
169 {
170 theCurrentChild = &(static_cast<forletwin_clause *>(c)->theDomainExpr);
171 ++theClausesIter;
172 return;
173 }
174 case flwor_clause::window_clause:
175 {
176 window_clause* wc = static_cast<window_clause *>(*theClausesIter);
177
178 theCurrentChild = &(wc->theDomainExpr);
179
180 theState = 2;
181 theWincondIter = 0;
182 return;
183 }
184
185 case flwor_clause::where_clause:
186 {
187 theCurrentChild = &(static_cast<where_clause *>(c)->theWhereExpr);
188 ++theClausesIter;
189 return;
190 }
191
192 case flwor_clause::order_clause:
193 {
194 orderby_clause* oc = static_cast<orderby_clause *>(c);
195
196 theArgsIter = oc->theOrderingExprs.begin();
197 theArgsEnd = oc->theOrderingExprs.end();
198
199 theCurrentChild = &(*theArgsIter);
200
201 ++theArgsIter;
202 theState = 3;
203 return;
204 }
205
206 case flwor_clause::group_clause:
207 {
208 group_clause* gc = static_cast<group_clause *>(c);
209
210 theGroupVarsIter = gc->theGroupVars.begin();
211 theGroupVarsEnd = gc->theGroupVars.end();
212 theNonGroupVarsIter = gc->theNonGroupVars.begin();
213 theNonGroupVarsEnd = gc->theNonGroupVars.end();
214
215 theCurrentChild = &((*theGroupVarsIter).first);
216
217 ++theGroupVarsIter;
218 theState = 4;
219 return;
220 }
221
222 case flwor_clause::count_clause:
223 {
224 ++theClausesIter;
225 break;
226 }
227
228 default:
229 {
230 ZORBA_ASSERT(false);
231 }
232 }
233 } // while
234
235 theCurrentChild = &(flworExpr->theReturnExpr);
236 theState = 10;
237 return;
238 }
239
240 case 2:
241 {
242 while (theWincondIter < 2)
243 {
244 window_clause* wc = static_cast<window_clause *>(*theClausesIter);
245
246 flwor_wincond* wincond = (theWincondIter == 0 ?
247 wc->theWinStartCond :
248 wc->theWinStopCond );
249 if (wincond != 0)
250 {
251 theCurrentChild = &(wincond->theCondExpr);
252 ++theWincondIter;
253 return;
254 }
255
256 ++theWincondIter;
257 }
258
259 theState = 1;
260 ++theClausesIter;
261 goto nextclause;
262 }
263
264 case 3:
265 {
266 while (theArgsIter != theArgsEnd)
267 {
268 theCurrentChild = &(*theArgsIter);
269 ++theArgsIter;
270 return;
271 }
272
273 theState = 1;
274 ++theClausesIter;
275 goto nextclause;
276 }
277
278 case 4:
279 {
280 while (theGroupVarsIter != theGroupVarsEnd)
281 {
282 theCurrentChild = &((*theGroupVarsIter).first);
283
284 ++theGroupVarsIter;
285 return;
286 }
287
288 theState = 5;
289 }
290
291 case 5:
292 {
293 while (theNonGroupVarsIter != theNonGroupVarsEnd)
294 {
295 theCurrentChild = &((*theNonGroupVarsIter).first);
296
297 ++theNonGroupVarsIter;
298 return;
299 }
300
301 theState = 1;
302 ++theClausesIter;
303 goto nextclause;
304 }
305
306 default:
307 {
308 theIsDone = true;
309 return;
310 }
311 }
312
313#else
314
315 flwor_clause* c = NULL;
316 window_clause* wc = NULL;
317 orderby_clause* oc = NULL;
318 group_clause* gc = NULL;
319 flwor_wincond* wincond = NULL;
320
110 EXPR_ITER_BEGIN();321 EXPR_ITER_BEGIN();
111322
112 theClausesBegin = flworExpr->theClauses.begin();323 theClausesBegin = flworExpr->theClauses.begin();
@@ -127,6 +338,11 @@
127 EXPR_ITER_NEXT(static_cast<let_clause *>(c)->theDomainExpr);338 EXPR_ITER_NEXT(static_cast<let_clause *>(c)->theDomainExpr);
128 }339 }
129340
341 else if (c->get_kind() == flwor_clause::where_clause)
342 {
343 EXPR_ITER_NEXT(static_cast<where_clause *>(c)->theWhereExpr);
344 }
345
130 else if (c->get_kind() == flwor_clause::window_clause)346 else if (c->get_kind() == flwor_clause::window_clause)
131 {347 {
132 for (theWincondIter = 0; theWincondIter < 2; ++theWincondIter)348 for (theWincondIter = 0; theWincondIter < 2; ++theWincondIter)
@@ -146,11 +362,6 @@
146 EXPR_ITER_NEXT(wc->theDomainExpr);362 EXPR_ITER_NEXT(wc->theDomainExpr);
147 }363 }
148364
149 else if (c->get_kind() == flwor_clause::where_clause)
150 {
151 EXPR_ITER_NEXT(static_cast<where_clause *>(c)->theWhereExpr);
152 }
153
154 else if (c->get_kind() == flwor_clause::group_clause)365 else if (c->get_kind() == flwor_clause::group_clause)
155 {366 {
156 gc = static_cast<group_clause *>(c);367 gc = static_cast<group_clause *>(c);
@@ -188,7 +399,8 @@
188399
189 if (theClausesEnd != flworExpr->theClauses.end())400 if (theClausesEnd != flworExpr->theClauses.end())
190 {401 {
191 ulong pos = (ulong)(theClausesIter - theClausesBegin);402 ZORBA_ASSERT(0);
403 csize pos = (theClausesIter - theClausesBegin);
192 if (pos >= flworExpr->num_clauses())404 if (pos >= flworExpr->num_clauses())
193 break;405 break;
194406
@@ -200,86 +412,55 @@
200 EXPR_ITER_NEXT(flworExpr->theReturnExpr);412 EXPR_ITER_NEXT(flworExpr->theReturnExpr);
201413
202 EXPR_ITER_END();414 EXPR_ITER_END();
203 break;415#endif
416 return;
204 }417 }
205418
206 case relpath_expr_kind:419 case relpath_expr_kind:
207 {420 {
208 EXPR_ITER_BEGIN();421 EXPR_ITER_BEGIN();
209422
210 {423 theArgsIter = static_cast<relpath_expr*>(theExpr)->theSteps.begin();
211 relpath_expr* pathExpr = static_cast<relpath_expr*>(theExpr);424 theArgsEnd = static_cast<relpath_expr*>(theExpr)->theSteps.end();
212 theArgsIter = pathExpr->theSteps.begin();
213 theArgsEnd = pathExpr->theSteps.end();
214 }
215
216 for (; theArgsIter != theArgsEnd; ++theArgsIter)425 for (; theArgsIter != theArgsEnd; ++theArgsIter)
217 {426 {
218 EXPR_ITER_NEXT(*theArgsIter);427 EXPR_ITER_NEXT(*theArgsIter);
219 }428 }
220429
221 EXPR_ITER_END();430 EXPR_ITER_END();
222 break;431 return;
223 }432 }
224433
225 case axis_step_expr_kind:434 case axis_step_expr_kind:
226 {435 {
227 axis_step_expr* axisExpr = static_cast<axis_step_expr*>(theExpr);
228
229 EXPR_ITER_BEGIN();436 EXPR_ITER_BEGIN();
230437 EXPR_ITER_NEXT(static_cast<axis_step_expr*>(theExpr)->theNodeTest);
231 EXPR_ITER_NEXT(axisExpr->theNodeTest);
232
233 EXPR_ITER_END();438 EXPR_ITER_END();
234 break;439 return;
235 }440 }
236441
237 case match_expr_kind:442 case match_expr_kind:
238 {
239 theIsDone = true;
240 break;
241 }
242
243 case var_expr_kind:443 case var_expr_kind:
244 {
245 theIsDone = true;
246 break;
247 }
248
249 case wrapper_expr_kind:
250 {
251 wrapper_expr* wrapperExpr = static_cast<wrapper_expr*>(theExpr);
252
253 EXPR_ITER_BEGIN();
254
255 EXPR_ITER_NEXT(wrapperExpr->theWrappedExpr);
256
257 EXPR_ITER_END();
258 break;
259 }
260
261 case const_expr_kind:444 case const_expr_kind:
445 case flowctl_expr_kind:
262 {446 {
263 theIsDone = true;447 theIsDone = true;
264 break;448 return;
265 }449 }
266450
267
268 case fo_expr_kind:451 case fo_expr_kind:
269 {452 {
270 fo_expr* foExpr = static_cast<fo_expr*>(theExpr);
271
272 EXPR_ITER_BEGIN();453 EXPR_ITER_BEGIN();
273454
274 theArgsIter = foExpr->theArgs.begin();455 theArgsIter = static_cast<fo_expr*>(theExpr)->theArgs.begin();
275 theArgsEnd = foExpr->theArgs.end();456 theArgsEnd = static_cast<fo_expr*>(theExpr)->theArgs.end();
276 for (; theArgsIter != theArgsEnd; ++theArgsIter)457 for (; theArgsIter != theArgsEnd; ++theArgsIter)
277 {458 {
278 EXPR_ITER_NEXT(*theArgsIter);459 EXPR_ITER_NEXT(*theArgsIter);
279 }460 }
280461
281 EXPR_ITER_END();462 EXPR_ITER_END();
282 break;463 return;
283 }464 }
284465
285 case cast_expr_kind:466 case cast_expr_kind:
@@ -288,27 +469,55 @@
288 case instanceof_expr_kind:469 case instanceof_expr_kind:
289 case castable_expr_kind:470 case castable_expr_kind:
290 {471 {
291 cast_or_castable_base_expr* castExpr =472 EXPR_ITER_BEGIN();
292 static_cast<cast_or_castable_base_expr*>(theExpr);473 EXPR_ITER_NEXT(static_cast<cast_or_castable_base_expr*>(theExpr)->theInput);
293474 EXPR_ITER_END();
294 EXPR_ITER_BEGIN();475 return;
295476 }
296 EXPR_ITER_NEXT(castExpr->theInputExpr);477
297478 case wrapper_expr_kind:
298 EXPR_ITER_END();479 {
299 break;480 EXPR_ITER_BEGIN();
481 EXPR_ITER_NEXT(static_cast<wrapper_expr*>(theExpr)->theInput);
482 EXPR_ITER_END();
483 return;
484 }
485
486 case function_trace_expr_kind:
487 {
488 EXPR_ITER_BEGIN();
489 EXPR_ITER_NEXT(static_cast<function_trace_expr*>(theExpr)->theInput);
490 EXPR_ITER_END();
491 return;
492 }
493
494 case order_expr_kind:
495 {
496 if (theState == 0)
497 {
498 theCurrentChild = &(static_cast<order_expr*>(theExpr)->theInput);
499 theState = 1;
500 return;
501 }
502
503 theIsDone = true;
504 return;
505 }
506
507 case validate_expr_kind:
508 {
509 EXPR_ITER_BEGIN();
510 EXPR_ITER_NEXT(static_cast<validate_expr*>(theExpr)->theInput);
511 EXPR_ITER_END();
512 return;
300 }513 }
301514
302 case name_cast_expr_kind:515 case name_cast_expr_kind:
303 {516 {
304 name_cast_expr* nameCastExpr = static_cast<name_cast_expr*>(theExpr);
305
306 EXPR_ITER_BEGIN();517 EXPR_ITER_BEGIN();
307518 EXPR_ITER_NEXT(static_cast<name_cast_expr*>(theExpr)->theInputExpr);
308 EXPR_ITER_NEXT(nameCastExpr->theInputExpr);
309
310 EXPR_ITER_END();519 EXPR_ITER_END();
311 break;520 return;
312 }521 }
313522
314 case doc_expr_kind:523 case doc_expr_kind:
@@ -321,7 +530,7 @@
321 EXPR_ITER_NEXT(docExpr->theContent);530 EXPR_ITER_NEXT(docExpr->theContent);
322531
323 EXPR_ITER_END();532 EXPR_ITER_END();
324 break;533 return;
325 }534 }
326535
327 case elem_expr_kind:536 case elem_expr_kind:
@@ -339,7 +548,7 @@
339 EXPR_ITER_NEXT(elemExpr->theContent);548 EXPR_ITER_NEXT(elemExpr->theContent);
340549
341 EXPR_ITER_END();550 EXPR_ITER_END();
342 break;551 return;
343 }552 }
344553
345 case attr_expr_kind:554 case attr_expr_kind:
@@ -354,7 +563,7 @@
354 EXPR_ITER_NEXT(attrExpr->theValueExpr);563 EXPR_ITER_NEXT(attrExpr->theValueExpr);
355564
356 EXPR_ITER_END();565 EXPR_ITER_END();
357 break;566 return;
358 }567 }
359568
360 case text_expr_kind:569 case text_expr_kind:
@@ -366,7 +575,7 @@
366 EXPR_ITER_NEXT(textExpr->theContentExpr);575 EXPR_ITER_NEXT(textExpr->theContentExpr);
367576
368 EXPR_ITER_END();577 EXPR_ITER_END();
369 break;578 return;
370 }579 }
371580
372 case pi_expr_kind:581 case pi_expr_kind:
@@ -374,12 +583,10 @@
374 pi_expr* piExpr = static_cast<pi_expr*>(theExpr);583 pi_expr* piExpr = static_cast<pi_expr*>(theExpr);
375584
376 EXPR_ITER_BEGIN();585 EXPR_ITER_BEGIN();
377
378 EXPR_ITER_NEXT(piExpr->theTargetExpr);586 EXPR_ITER_NEXT(piExpr->theTargetExpr);
379 EXPR_ITER_NEXT(piExpr->theContentExpr);587 EXPR_ITER_NEXT(piExpr->theContentExpr);
380
381 EXPR_ITER_END();588 EXPR_ITER_END();
382 break;589 return;
383 }590 }
384591
385#ifdef ZORBA_WITH_JSON592#ifdef ZORBA_WITH_JSON
@@ -393,7 +600,7 @@
393 EXPR_ITER_NEXT(e->theContentExpr);600 EXPR_ITER_NEXT(e->theContentExpr);
394601
395 EXPR_ITER_END();602 EXPR_ITER_END();
396 break;603 return;
397 }604 }
398605
399 case json_object_expr_kind:606 case json_object_expr_kind:
@@ -406,7 +613,7 @@
406 EXPR_ITER_NEXT(e->theContentExpr);613 EXPR_ITER_NEXT(e->theContentExpr);
407614
408 EXPR_ITER_END();615 EXPR_ITER_END();
409 break;616 return;
410 }617 }
411618
412 case json_direct_object_expr_kind:619 case json_direct_object_expr_kind:
@@ -430,7 +637,7 @@
430 }637 }
431638
432 EXPR_ITER_END();639 EXPR_ITER_END();
433 break;640 return;
434 }641 }
435642
436#endif643#endif
@@ -446,31 +653,7 @@
446 EXPR_ITER_NEXT(ifExpr->theElseExpr);653 EXPR_ITER_NEXT(ifExpr->theElseExpr);
447654
448 EXPR_ITER_END();655 EXPR_ITER_END();
449 break;656 return;
450 }
451
452 case order_expr_kind:
453 {
454 order_expr* ordExpr = static_cast<order_expr*>(theExpr);
455
456 EXPR_ITER_BEGIN();
457
458 EXPR_ITER_NEXT(ordExpr->theExpr);
459
460 EXPR_ITER_END();
461 break;
462 }
463
464 case validate_expr_kind:
465 {
466 validate_expr* valExpr = static_cast<validate_expr*>(theExpr);
467
468 EXPR_ITER_BEGIN();
469
470 EXPR_ITER_NEXT(valExpr->theExpr);
471
472 EXPR_ITER_END();
473 break;
474 }657 }
475658
476 case extension_expr_kind:659 case extension_expr_kind:
@@ -478,11 +661,9 @@
478 extension_expr* extExpr = static_cast<extension_expr*>(theExpr);661 extension_expr* extExpr = static_cast<extension_expr*>(theExpr);
479662
480 EXPR_ITER_BEGIN();663 EXPR_ITER_BEGIN();
481
482 EXPR_ITER_NEXT(extExpr->theExpr);664 EXPR_ITER_NEXT(extExpr->theExpr);
483
484 EXPR_ITER_END();665 EXPR_ITER_END();
485 break;666 return;
486 }667 }
487668
488 case trycatch_expr_kind:669 case trycatch_expr_kind:
@@ -501,7 +682,7 @@
501 }682 }
502683
503 EXPR_ITER_END();684 EXPR_ITER_END();
504 break;685 return;
505 }686 }
506687
507 case function_item_expr_kind:688 case function_item_expr_kind:
@@ -518,7 +699,7 @@
518 }699 }
519700
520 EXPR_ITER_END();701 EXPR_ITER_END();
521 break;702 return;
522 }703 }
523704
524 case dynamic_function_invocation_expr_kind:705 case dynamic_function_invocation_expr_kind:
@@ -538,7 +719,7 @@
538 }719 }
539720
540 EXPR_ITER_END();721 EXPR_ITER_END();
541 break;722 return;
542 }723 }
543724
544 case insert_expr_kind:725 case insert_expr_kind:
@@ -551,7 +732,7 @@
551 EXPR_ITER_NEXT(insExpr->theTargetExpr);732 EXPR_ITER_NEXT(insExpr->theTargetExpr);
552733
553 EXPR_ITER_END();734 EXPR_ITER_END();
554 break;735 return;
555 }736 }
556737
557 case delete_expr_kind:738 case delete_expr_kind:
@@ -563,7 +744,7 @@
563 EXPR_ITER_NEXT(delExpr->theTargetExpr);744 EXPR_ITER_NEXT(delExpr->theTargetExpr);
564745
565 EXPR_ITER_END();746 EXPR_ITER_END();
566 break;747 return;
567 }748 }
568749
569 case replace_expr_kind:750 case replace_expr_kind:
@@ -576,7 +757,7 @@
576 EXPR_ITER_NEXT(repExpr->theSourceExpr);757 EXPR_ITER_NEXT(repExpr->theSourceExpr);
577758
578 EXPR_ITER_END();759 EXPR_ITER_END();
579 break;760 return;
580 }761 }
581762
582 case rename_expr_kind:763 case rename_expr_kind:
@@ -589,7 +770,7 @@
589 EXPR_ITER_NEXT(renExpr->theSourceExpr);770 EXPR_ITER_NEXT(renExpr->theSourceExpr);
590771
591 EXPR_ITER_END();772 EXPR_ITER_END();
592 break;773 return;
593 }774 }
594775
595 case transform_expr_kind:776 case transform_expr_kind:
@@ -609,7 +790,7 @@
609 EXPR_ITER_NEXT(trfExpr->theReturnExpr);790 EXPR_ITER_NEXT(trfExpr->theReturnExpr);
610791
611 EXPR_ITER_END();792 EXPR_ITER_END();
612 break;793 return;
613 }794 }
614795
615 case block_expr_kind:796 case block_expr_kind:
@@ -626,7 +807,7 @@
626 }807 }
627808
628 EXPR_ITER_END();809 EXPR_ITER_END();
629 break;810 return;
630 }811 }
631812
632 case apply_expr_kind:813 case apply_expr_kind:
@@ -635,7 +816,7 @@
635 EXPR_ITER_BEGIN();816 EXPR_ITER_BEGIN();
636 EXPR_ITER_NEXT(applyExpr->theExpr);817 EXPR_ITER_NEXT(applyExpr->theExpr);
637 EXPR_ITER_END();818 EXPR_ITER_END();
638 break;819 return;
639 }820 }
640821
641 case var_decl_expr_kind:822 case var_decl_expr_kind:
@@ -648,7 +829,7 @@
648 EXPR_ITER_NEXT(varDeclExpr->theInitExpr);829 EXPR_ITER_NEXT(varDeclExpr->theInitExpr);
649830
650 EXPR_ITER_END();831 EXPR_ITER_END();
651 break;832 return;
652 }833 }
653834
654 case var_set_expr_kind:835 case var_set_expr_kind:
@@ -657,13 +838,7 @@
657 EXPR_ITER_BEGIN();838 EXPR_ITER_BEGIN();
658 EXPR_ITER_NEXT(varSetExpr->theExpr);839 EXPR_ITER_NEXT(varSetExpr->theExpr);
659 EXPR_ITER_END();840 EXPR_ITER_END();
660 break;841 return;
661 }
662
663 case flowctl_expr_kind:
664 {
665 theIsDone = true;
666 break;
667 }842 }
668843
669 case while_expr_kind:844 case while_expr_kind:
@@ -671,11 +846,9 @@
671 while_expr* whileExpr = static_cast<while_expr*>(theExpr);846 while_expr* whileExpr = static_cast<while_expr*>(theExpr);
672847
673 EXPR_ITER_BEGIN();848 EXPR_ITER_BEGIN();
674
675 EXPR_ITER_NEXT(whileExpr->theBody);849 EXPR_ITER_NEXT(whileExpr->theBody);
676
677 EXPR_ITER_END();850 EXPR_ITER_END();
678 break;851 return;
679 }852 }
680853
681 case exit_expr_kind:854 case exit_expr_kind:
@@ -683,11 +856,9 @@
683 exit_expr* exitExpr = static_cast<exit_expr*>(theExpr);856 exit_expr* exitExpr = static_cast<exit_expr*>(theExpr);
684857
685 EXPR_ITER_BEGIN();858 EXPR_ITER_BEGIN();
686
687 EXPR_ITER_NEXT(exitExpr->theExpr);859 EXPR_ITER_NEXT(exitExpr->theExpr);
688
689 EXPR_ITER_END();860 EXPR_ITER_END();
690 break;861 return;
691 }862 }
692863
693 case exit_catcher_expr_kind:864 case exit_catcher_expr_kind:
@@ -699,7 +870,7 @@
699 EXPR_ITER_NEXT(catcherExpr->theExpr);870 EXPR_ITER_NEXT(catcherExpr->theExpr);
700871
701 EXPR_ITER_END();872 EXPR_ITER_END();
702 break;873 return;
703 }874 }
704875
705#ifndef ZORBA_NO_FULL_TEXT876#ifndef ZORBA_NO_FULL_TEXT
@@ -723,7 +894,7 @@
723 EXPR_ITER_NEXT(ftExpr->ftignore_);894 EXPR_ITER_NEXT(ftExpr->ftignore_);
724895
725 EXPR_ITER_END();896 EXPR_ITER_END();
726 break;897 return;
727 }898 }
728#endif /* ZORBA_NO_FULL_TEXT */899#endif /* ZORBA_NO_FULL_TEXT */
729900
@@ -743,7 +914,7 @@
743 }914 }
744915
745 EXPR_ITER_END();916 EXPR_ITER_END();
746 break;917 return;
747 }918 }
748919
749#ifdef ZORBA_WITH_DEBUGGER920#ifdef ZORBA_WITH_DEBUGGER
@@ -763,19 +934,10 @@
763 }934 }
764935
765 EXPR_ITER_END();936 EXPR_ITER_END();
766 break;937 return;
767 }938 }
768#endif939#endif
769940
770 case function_trace_expr_kind:
771 {
772 function_trace_expr* dummyExpr = static_cast<function_trace_expr*>(theExpr);
773 EXPR_ITER_BEGIN();
774 EXPR_ITER_NEXT(dummyExpr->theExpr);
775 EXPR_ITER_END();
776 break;
777 }
778
779 default:941 default:
780 {942 {
781 ZORBA_ASSERT(false);943 ZORBA_ASSERT(false);
782944
=== modified file 'src/compiler/expression/expr_manager.cpp'
--- src/compiler/expression/expr_manager.cpp 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/expr_manager.cpp 2012-10-24 11:34:21 +0000
@@ -179,7 +179,7 @@
179 static_context* sctx,179 static_context* sctx,
180 user_function* udf,180 user_function* udf,
181 const QueryLoc& loc,181 const QueryLoc& loc,
182 order_expr::order_type_t order,182 DocOrderMode order,
183 expr* exp)183 expr* exp)
184{184{
185 CREATE_AND_RETURN_EXPR(order_expr, sctx, udf, loc, order, exp);185 CREATE_AND_RETURN_EXPR(order_expr, sctx, udf, loc, order, exp);
@@ -216,7 +216,7 @@
216 const QueryLoc& loc,216 const QueryLoc& loc,
217 expr* treated,217 expr* treated,
218 const xqtref_t& type,218 const xqtref_t& type,
219 TreatIterator::ErrorKind err,219 TreatErrorKind err,
220 bool check_prime,220 bool check_prime,
221 store::Item* qname)221 store::Item* qname)
222{222{
@@ -231,7 +231,7 @@
231 const QueryLoc& loc,231 const QueryLoc& loc,
232 expr* promoted,232 expr* promoted,
233 const xqtref_t& type,233 const xqtref_t& type,
234 PromoteIterator::ErrorKind err,234 PromoteErrorKind err,
235 store::Item* qname)235 store::Item* qname)
236{236{
237 CREATE_AND_RETURN_EXPR(promote_expr, sctx, udf, loc, promoted, type, err, qname);237 CREATE_AND_RETURN_EXPR(promote_expr, sctx, udf, loc, promoted, type, err, qname);
@@ -329,7 +329,7 @@
329 static_context* sctx,329 static_context* sctx,
330 user_function* udf,330 user_function* udf,
331 const QueryLoc& loc,331 const QueryLoc& loc,
332 text_expr::text_constructor_type textType,332 TextConstructorType textType,
333 expr* text)333 expr* text)
334{334{
335 CREATE_AND_RETURN_EXPR(text_expr, sctx, udf, loc, textType, text);335 CREATE_AND_RETURN_EXPR(text_expr, sctx, udf, loc, textType, text);
@@ -538,10 +538,15 @@
538 static_context* sctx,538 static_context* sctx,
539 user_function* udf,539 user_function* udf,
540 const QueryLoc& loc,540 const QueryLoc& loc,
541 var_expr::var_kind k,541 ulong varKind,
542 store::Item* name)542 store::Item* name)
543{543{
544 CREATE_AND_RETURN_EXPR(var_expr, sctx, udf, loc, k, name);544 CREATE_AND_RETURN_EXPR(var_expr,
545 sctx,
546 udf,
547 loc,
548 static_cast<var_expr::var_kind>(varKind),
549 name);
545}550}
546551
547552
@@ -729,7 +734,7 @@
729 static_context* sctx,734 static_context* sctx,
730 user_function* udf,735 user_function* udf,
731 const QueryLoc& loc,736 const QueryLoc& loc,
732 flowctl_expr::action action)737 FlowCtlAction action)
733{738{
734 CREATE_AND_RETURN_EXPR(flowctl_expr, sctx, udf, loc, action);739 CREATE_AND_RETURN_EXPR(flowctl_expr, sctx, udf, loc, action);
735}740}
@@ -908,7 +913,7 @@
908window_clause* ExprManager::create_window_clause(913window_clause* ExprManager::create_window_clause(
909 static_context* sctx,914 static_context* sctx,
910 const QueryLoc& loc,915 const QueryLoc& loc,
911 window_clause::window_t winKind,916 WindowKind winKind,
912 var_expr* varExpr,917 var_expr* varExpr,
913 expr* domainExpr,918 expr* domainExpr,
914 flwor_wincond* winStart,919 flwor_wincond* winStart,
@@ -935,7 +940,7 @@
935 static_context* sctx,940 static_context* sctx,
936 const QueryLoc& loc,941 const QueryLoc& loc,
937 const flwor_clause::rebind_list_t& gvars,942 const flwor_clause::rebind_list_t& gvars,
938 flwor_clause::rebind_list_t ngvars,943 const flwor_clause::rebind_list_t& ngvars,
939 const std::vector<std::string>& collations)944 const std::vector<std::string>& collations)
940{945{
941 CREATE_AND_RETURN(group_clause, sctx, theCCB, loc, gvars, ngvars, collations);946 CREATE_AND_RETURN(group_clause, sctx, theCCB, loc, gvars, ngvars, collations);
942947
=== modified file 'src/compiler/expression/expr_manager.h'
--- src/compiler/expression/expr_manager.h 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/expr_manager.h 2012-10-24 11:34:21 +0000
@@ -19,17 +19,37 @@
19#define ZORBA_COMPILER_EXPRMANAGER_H19#define ZORBA_COMPILER_EXPRMANAGER_H
2020
21#include "expr_classes.h"21#include "expr_classes.h"
22#include "expr.h"22#include "expr_consts.h"
23#include "script_exprs.h"23#include "expr_utils.h"
24#include "flwor_expr.h"
25#include "ftnode.h"
26
27#include "mem_manager.h"24#include "mem_manager.h"
2825
26#include "compiler/parser/parse_constants.h"
27
28#include "zorbatypes/schema_types.h"
29
30#include "store/api/update_consts.h"
31
32
29namespace zorba33namespace zorba
30{34{
3135
32class CompilerCB;36class CompilerCB;
37class expr;
38class var_expr;
39class catch_clause;
40class pragma;
41class flwor_clause;
42class flwor_wincond;
43class copy_clause;
44class window_clause;
45class group_clause;
46class where_clause;
47class count_clause;
48class orderby_clause;
49class materialize_clause;
50struct flwor_wincond_vars;
51class ftnode;
52
3353
3454
35class ExprManager55class ExprManager
@@ -86,7 +106,7 @@
86 static_context* sctx,106 static_context* sctx,
87 user_function* udf,107 user_function* udf,
88 const QueryLoc& loc,108 const QueryLoc& loc,
89 order_expr::order_type_t,109 DocOrderMode,
90 expr*);110 expr*);
91111
92 validate_expr* create_validate_expr(112 validate_expr* create_validate_expr(
@@ -111,7 +131,7 @@
111 const QueryLoc& loc,131 const QueryLoc& loc,
112 expr* input,132 expr* input,
113 const xqtref_t& type,133 const xqtref_t& type,
114 TreatIterator::ErrorKind err,134 TreatErrorKind err,
115 bool check_prime = true,135 bool check_prime = true,
116 store::Item* qnname = NULL);136 store::Item* qnname = NULL);
117137
@@ -122,7 +142,7 @@
122 const QueryLoc& loc,142 const QueryLoc& loc,
123 expr* input,143 expr* input,
124 const xqtref_t& type,144 const xqtref_t& type,
125 PromoteIterator::ErrorKind err,145 PromoteErrorKind err,
126 store::Item* qname);146 store::Item* qname);
127147
128 castable_expr* create_castable_expr(148 castable_expr* create_castable_expr(
@@ -185,7 +205,7 @@
185 static_context* sctx,205 static_context* sctx,
186 user_function* udf,206 user_function* udf,
187 const QueryLoc&,207 const QueryLoc&,
188 text_expr::text_constructor_type,208 TextConstructorType,
189 expr*);209 expr*);
190210
191 pi_expr* create_pi_expr(211 pi_expr* create_pi_expr(
@@ -312,7 +332,7 @@
312 static_context* sctx,332 static_context* sctx,
313 user_function* udf,333 user_function* udf,
314 const QueryLoc& loc,334 const QueryLoc& loc,
315 var_expr::var_kind k,335 ulong varKind,
316 store::Item* name);336 store::Item* name);
317337
318 var_expr* create_var_expr(user_function* udf, const var_expr& source);338 var_expr* create_var_expr(user_function* udf, const var_expr& source);
@@ -427,7 +447,7 @@
427 static_context* sctx,447 static_context* sctx,
428 user_function* udf,448 user_function* udf,
429 const QueryLoc& loc,449 const QueryLoc& loc,
430 flowctl_expr::action action);450 FlowCtlAction action);
431451
432 while_expr* create_while_expr(452 while_expr* create_while_expr(
433 static_context* sctx,453 static_context* sctx,
@@ -479,7 +499,7 @@
479 user_function* udf,499 user_function* udf,
480 QueryLoc const&,500 QueryLoc const&,
481 expr* range,501 expr* range,
482 ftnode *ftselection,502 ftnode* ftselection,
483 expr* ftignore);503 expr* ftignore);
484504
485////////////////////////////////////////////////////////////////////////////////505////////////////////////////////////////////////////////////////////////////////
@@ -539,7 +559,7 @@
539 window_clause* create_window_clause(559 window_clause* create_window_clause(
540 static_context* sctx,560 static_context* sctx,
541 const QueryLoc& loc,561 const QueryLoc& loc,
542 window_clause::window_t winKind,562 WindowKind winKind,
543 var_expr* varExpr,563 var_expr* varExpr,
544 expr* domainExpr,564 expr* domainExpr,
545 flwor_wincond* winStart,565 flwor_wincond* winStart,
@@ -549,15 +569,15 @@
549 flwor_wincond* create_flwor_wincond(569 flwor_wincond* create_flwor_wincond(
550 static_context* sctx,570 static_context* sctx,
551 bool isOnly,571 bool isOnly,
552 const flwor_wincond::vars& in_vars,572 const flwor_wincond_vars& in_vars,
553 const flwor_wincond::vars& out_vars,573 const flwor_wincond_vars& out_vars,
554 expr* cond);574 expr* cond);
555575
556 group_clause* create_group_clause(576 group_clause* create_group_clause(
557 static_context* sctx,577 static_context* sctx,
558 const QueryLoc& loc,578 const QueryLoc& loc,
559 const flwor_clause::rebind_list_t& gvars,579 const var_rebind_list_t& gvars,
560 flwor_clause::rebind_list_t ngvars,580 const var_rebind_list_t& ngvars,
561 const std::vector<std::string>& collations);581 const std::vector<std::string>& collations);
562582
563 orderby_clause * create_orderby_clause (583 orderby_clause * create_orderby_clause (
564584
=== modified file 'src/compiler/expression/expr_put.cpp'
--- src/compiler/expression/expr_put.cpp 2012-10-08 12:09:36 +0000
+++ src/compiler/expression/expr_put.cpp 2012-10-24 11:34:21 +0000
@@ -154,9 +154,9 @@
154 get_expr()->put(os);154 get_expr()->put(os);
155 return os;155 return os;
156#else156#else
157 if (get_expr()->get_expr_kind() == var_expr_kind)157 if (get_input()->get_expr_kind() == var_expr_kind)
158 {158 {
159 const var_expr* varExpr = static_cast<const var_expr*>(get_expr());159 const var_expr* varExpr = static_cast<const var_expr*>(get_input());
160160
161 BEGIN_PUT_NO_EOL(var_ref) ;161 BEGIN_PUT_NO_EOL(var_ref) ;
162 put_qname(varExpr->get_name(), os);162 put_qname(varExpr->get_name(), os);
@@ -165,8 +165,8 @@
165 }165 }
166 else166 else
167 {167 {
168 BEGIN_PUT( wrapper_expr );168 BEGIN_PUT(wrapper_expr);
169 get_expr()->put(os);169 get_input()->put(os);
170 END_PUT();170 END_PUT();
171 }171 }
172#endif172#endif
@@ -440,7 +440,7 @@
440{440{
441 os << indent << "promote_expr " << theTargetType->toString()441 os << indent << "promote_expr " << theTargetType->toString()
442 << expr_addr (this) << " [\n" << inc_indent;442 << expr_addr (this) << " [\n" << inc_indent;
443 theInputExpr->put(os);443 theInput->put(os);
444 END_PUT();444 END_PUT();
445}445}
446446
@@ -491,7 +491,7 @@
491ostream& function_trace_expr::put(ostream& os) const491ostream& function_trace_expr::put(ostream& os) const
492{492{
493 BEGIN_PUT(function_trace_expr);493 BEGIN_PUT(function_trace_expr);
494 theExpr->put(os);494 theInput->put(os);
495 END_PUT();495 END_PUT();
496}496}
497497
@@ -599,28 +599,28 @@
599ostream& instanceof_expr::put( ostream& os) const599ostream& instanceof_expr::put( ostream& os) const
600{600{
601 BEGIN_PUT1( instanceof_expr, theTargetType->toString() );601 BEGIN_PUT1( instanceof_expr, theTargetType->toString() );
602 theInputExpr->put(os);602 theInput->put(os);
603 END_PUT();603 END_PUT();
604}604}
605605
606ostream& treat_expr::put( ostream& os) const606ostream& treat_expr::put( ostream& os) const
607{607{
608 BEGIN_PUT1( treat_expr, theTargetType->toString() );608 BEGIN_PUT1( treat_expr, theTargetType->toString() );
609 theInputExpr->put(os);609 theInput->put(os);
610 END_PUT();610 END_PUT();
611}611}
612612
613ostream& castable_expr::put( ostream& os) const613ostream& castable_expr::put( ostream& os) const
614{614{
615 BEGIN_PUT1( castable_expr, theTargetType->toString() );615 BEGIN_PUT1( castable_expr, theTargetType->toString() );
616 theInputExpr->put(os);616 theInput->put(os);
617 END_PUT();617 END_PUT();
618}618}
619619
620ostream& cast_expr::put( ostream& os) const620ostream& cast_expr::put( ostream& os) const
621{621{
622 BEGIN_PUT1( cast_expr, theTargetType->toString() );622 BEGIN_PUT1( cast_expr, theTargetType->toString() );
623 theInputExpr->put(os);623 theInput->put(os);
624 END_PUT();624 END_PUT();
625}625}
626626
@@ -643,7 +643,7 @@
643 case ParseConstants::val_typename: os << "typename\n"; break;643 case ParseConstants::val_typename: os << "typename\n"; break;
644 default: os << "??\n";644 default: os << "??\n";
645 }645 }
646 theExpr->put(os) << endl;646 theInput->put(os) << endl;
647 END_PUT();647 END_PUT();
648}648}
649649
@@ -796,16 +796,16 @@
796796
797ostream& order_expr::put(ostream& os) const797ostream& order_expr::put(ostream& os) const
798{798{
799 os << indent << "order_expr" << expr_addr (this) << "\n" << inc_indent799 os << indent << "order_expr" << expr_addr(this) << "\n" << inc_indent
800 << indent << "[ ";800 << indent << "[ ";
801801
802 switch (theType)802 switch (theType)
803 {803 {
804 case ordered: os << "ordered\n"; break;804 case doc_ordered: os << "ordered\n"; break;
805 case unordered: os << "unordered\n"; break;805 case doc_unordered: os << "unordered\n"; break;
806 default: os << "??\n";806 default: os << "??\n";
807 }807 }
808 theExpr->put(os) << endl;808 theInput->put(os) << endl;
809 END_PUT();809 END_PUT();
810}810}
811811
812812
=== modified file 'src/compiler/expression/expr_type.cpp'
--- src/compiler/expression/expr_type.cpp 2012-10-16 13:08:12 +0000
+++ src/compiler/expression/expr_type.cpp 2012-10-24 11:34:21 +0000
@@ -105,14 +105,6 @@
105 break;105 break;
106 }106 }
107107
108 case order_expr_kind:
109 {
110 order_expr* e = static_cast<order_expr*>(this);
111
112 newType = e->theExpr->get_return_type();
113 break;
114 }
115
116 case validate_expr_kind:108 case validate_expr_kind:
117 {109 {
118 theType = rtm.ANY_NODE_TYPE_ONE;110 theType = rtm.ANY_NODE_TYPE_ONE;
@@ -332,7 +324,7 @@
332 {324 {
333 cast_expr* e = static_cast<cast_expr*>(this);325 cast_expr* e = static_cast<cast_expr*>(this);
334326
335 xqtref_t argType = e->theInputExpr->get_return_type();327 xqtref_t argType = e->theInput->get_return_type();
336 TypeConstants::quantifier_t argQuant = argType->get_quantifier();328 TypeConstants::quantifier_t argQuant = argType->get_quantifier();
337 TypeConstants::quantifier_t targetQuant = e->theTargetType->get_quantifier();329 TypeConstants::quantifier_t targetQuant = e->theTargetType->get_quantifier();
338330
@@ -378,7 +370,7 @@
378 {370 {
379 promote_expr* e = static_cast<promote_expr*>(this);371 promote_expr* e = static_cast<promote_expr*>(this);
380372
381 xqtref_t in_type = e->theInputExpr->get_return_type();373 xqtref_t in_type = e->theInput->get_return_type();
382 xqtref_t in_ptype = TypeOps::prime_type(tm, *in_type);374 xqtref_t in_ptype = TypeOps::prime_type(tm, *in_type);
383 xqtref_t target_ptype = TypeOps::prime_type(tm, *e->theTargetType);375 xqtref_t target_ptype = TypeOps::prime_type(tm, *e->theTargetType);
384376
@@ -490,7 +482,7 @@
490482
491 switch (e->type)483 switch (e->type)
492 {484 {
493 case text_expr::text_constructor:485 case text_constructor:
494 {486 {
495 xqtref_t t = e->get_text()->get_return_type();487 xqtref_t t = e->get_text()->get_return_type();
496488
@@ -504,7 +496,7 @@
504 break;496 break;
505 }497 }
506498
507 case text_expr::comment_constructor:499 case comment_constructor:
508 nodeKind = store::StoreConsts::commentNode;500 nodeKind = store::StoreConsts::commentNode;
509 break;501 break;
510502
@@ -702,15 +694,19 @@
702694
703 case function_trace_expr_kind:695 case function_trace_expr_kind:
704 {696 {
705 function_trace_expr* e = static_cast<function_trace_expr*>(this);697 newType = static_cast<function_trace_expr*>(this)->theInput->get_return_type();
706 newType = e->theExpr->get_return_type();698 break;
699 }
700
701 case order_expr_kind:
702 {
703 newType = static_cast<order_expr*>(this)->theInput->get_return_type();
707 break;704 break;
708 }705 }
709706
710 case wrapper_expr_kind:707 case wrapper_expr_kind:
711 {708 {
712 wrapper_expr* e = static_cast<wrapper_expr*>(this);709 newType = static_cast<wrapper_expr*>(this)->theInput->get_return_type();
713 newType = e->theWrappedExpr->get_return_type();
714 break;710 break;
715 }711 }
716712
717713
=== modified file 'src/compiler/expression/expr_utils.h'
--- src/compiler/expression/expr_utils.h 2012-09-19 21:16:15 +0000
+++ src/compiler/expression/expr_utils.h 2012-10-24 11:34:21 +0000
@@ -22,6 +22,9 @@
22namespace zorba 22namespace zorba
23{23{
2424
25class expr;
26class var_expr;
27
25/******************************************************************************28/******************************************************************************
26 Used by the orderspecs of an order by clause, and by the keyspecs of an29 Used by the orderspecs of an order by clause, and by the keyspecs of an
27 index declaration.30 index declaration.
@@ -47,6 +50,11 @@
47};50};
4851
4952
53/******************************************************************************
54
55********************************************************************************/
56typedef std::vector<std::pair<expr*, var_expr*> > var_rebind_list_t;
57
50}58}
51#endif59#endif
5260
5361
=== modified file 'src/compiler/expression/flwor_expr.cpp'
--- src/compiler/expression/flwor_expr.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/expression/flwor_expr.cpp 2012-10-24 11:34:21 +0000
@@ -25,6 +25,7 @@
25#include "compiler/expression/fo_expr.h"25#include "compiler/expression/fo_expr.h"
26#include "compiler/expression/expr.h"26#include "compiler/expression/expr.h"
27#include "compiler/expression/expr_visitor.h"27#include "compiler/expression/expr_visitor.h"
28#include "compiler/expression/expr_manager.h"
2829
29#include "compiler/api/compilercb.h"30#include "compiler/api/compilercb.h"
3031
@@ -111,7 +112,7 @@
111 theDomainExpr->get_loc(),112 theDomainExpr->get_loc(),
112 theDomainExpr,113 theDomainExpr,
113 varType,114 varType,
114 TreatIterator::TYPE_MATCH);115 TREAT_TYPE_MATCH);
115 }116 }
116 }117 }
117 }118 }
@@ -180,7 +181,7 @@
180 loc,181 loc,
181 domainExpr,182 domainExpr,
182 declaredType,183 declaredType,
183 TreatIterator::TYPE_MATCH);184 TREAT_TYPE_MATCH);
184185
185 set_expr(domainExpr);186 set_expr(domainExpr);
186 }187 }
@@ -307,7 +308,7 @@
307 loc,308 loc,
308 domainExpr,309 domainExpr,
309 declaredType,310 declaredType,
310 TreatIterator::TYPE_MATCH);311 TREAT_TYPE_MATCH);
311312
312 set_expr(domainExpr);313 set_expr(domainExpr);
313 }314 }
@@ -370,7 +371,7 @@
370 static_context* sctx,371 static_context* sctx,
371 CompilerCB* ccb,372 CompilerCB* ccb,
372 const QueryLoc& loc,373 const QueryLoc& loc,
373 window_t winKind,374 WindowKind winKind,
374 var_expr* varExpr,375 var_expr* varExpr,
375 expr* domainExpr,376 expr* domainExpr,
376 flwor_wincond* winStart,377 flwor_wincond* winStart,
@@ -412,7 +413,7 @@
412 loc,413 loc,
413 domainExpr,414 domainExpr,
414 varType,415 varType,
415 TreatIterator::TYPE_MATCH);416 TREAT_TYPE_MATCH);
416417
417 set_expr(domainExpr);418 set_expr(domainExpr);
418 }419 }
@@ -523,7 +524,7 @@
523}524}
524525
525526
526flwor_wincond::vars::vars()527flwor_wincond_vars::flwor_wincond_vars()
527 :528 :
528 posvar(NULL),529 posvar(NULL),
529 curr(NULL),530 curr(NULL),
@@ -533,13 +534,13 @@
533}534}
534535
535536
536flwor_wincond::vars::~vars()537flwor_wincond_vars::~flwor_wincond_vars()
537{538{
538// set_flwor_clause(NULL);539// set_flwor_clause(NULL);
539}540}
540541
541542
542void flwor_wincond::vars::set_flwor_clause(flwor_clause* c)543void flwor_wincond_vars::set_flwor_clause(flwor_clause* c)
543{544{
544 if (posvar != NULL) posvar->set_flwor_clause(c);545 if (posvar != NULL) posvar->set_flwor_clause(c);
545 if (curr != NULL) curr->set_flwor_clause(c);546 if (curr != NULL) curr->set_flwor_clause(c);
@@ -548,7 +549,7 @@
548}549}
549550
550551
551void flwor_wincond::vars::clone(552void flwor_wincond_vars::clone(
552 ExprManager* mgr,553 ExprManager* mgr,
553 user_function* udf,554 user_function* udf,
554 flwor_wincond::vars& cloneVars,555 flwor_wincond::vars& cloneVars,
@@ -619,7 +620,7 @@
619 CompilerCB* ccb,620 CompilerCB* ccb,
620 const QueryLoc& loc,621 const QueryLoc& loc,
621 const rebind_list_t& gvars,622 const rebind_list_t& gvars,
622 rebind_list_t ngvars,623 const rebind_list_t& ngvars,
623 const std::vector<std::string>& collations)624 const std::vector<std::string>& collations)
624 :625 :
625 flwor_clause(sctx, ccb, loc, flwor_clause::group_clause),626 flwor_clause(sctx, ccb, loc, flwor_clause::group_clause),
@@ -808,6 +809,8 @@
808 flwor_clause(sctx, ccb, loc, flwor_clause::count_clause),809 flwor_clause(sctx, ccb, loc, flwor_clause::count_clause),
809 theVarExpr(var)810 theVarExpr(var)
810{811{
812 if (theVarExpr != NULL)
813 theVarExpr->set_flwor_clause(this);
811}814}
812815
813816
814817
=== modified file 'src/compiler/expression/flwor_expr.h'
--- src/compiler/expression/flwor_expr.h 2012-10-22 15:10:23 +0000
+++ src/compiler/expression/flwor_expr.h 2012-10-24 11:34:21 +0000
@@ -51,7 +51,7 @@
51 friend class ExprManager;51 friend class ExprManager;
5252
53public:53public:
54 typedef std::vector<std::pair<expr*, var_expr*> > rebind_list_t;54 typedef var_rebind_list_t rebind_list_t;
5555
56 typedef enum56 typedef enum
57 {57 {
@@ -98,8 +98,6 @@
9898
99 flwor_expr* get_flwor_expr() const { return theFlworExpr; }99 flwor_expr* get_flwor_expr() const { return theFlworExpr; }
100100
101 virtual expr* get_expr() const { return NULL; }
102
103 virtual void set_expr(expr* v) { }101 virtual void set_expr(expr* v) { }
104102
105 virtual var_expr* get_pos_var() const { return NULL; }103 virtual var_expr* get_pos_var() const { return NULL; }
@@ -271,11 +269,8 @@
271 friend class ExprManager;269 friend class ExprManager;
272 friend class ExprIterator;270 friend class ExprIterator;
273271
274public:
275 typedef enum { tumbling_window, sliding_window } window_t;
276
277protected:272protected:
278 window_t theWindowKind;273 WindowKind theWindowKind;
279 flwor_wincond * theWinStartCond;274 flwor_wincond * theWinStartCond;
280 flwor_wincond * theWinStopCond;275 flwor_wincond * theWinStopCond;
281 bool theLazyEval;276 bool theLazyEval;
@@ -285,7 +280,7 @@
285 static_context* sctx,280 static_context* sctx,
286 CompilerCB* ccb,281 CompilerCB* ccb,
287 const QueryLoc& loc,282 const QueryLoc& loc,
288 window_t winKind,283 WindowKind winKind,
289 var_expr* varExpr,284 var_expr* varExpr,
290 expr* domainExpr,285 expr* domainExpr,
291 flwor_wincond* winStart,286 flwor_wincond* winStart,
@@ -295,7 +290,7 @@
295public:290public:
296 ~window_clause();291 ~window_clause();
297292
298 window_t get_winkind() const { return theWindowKind; }293 WindowKind get_winkind() const { return theWindowKind; }
299294
300 flwor_wincond* get_win_start() const { return theWinStartCond; }295 flwor_wincond* get_win_start() const { return theWinStartCond; }
301296
@@ -317,6 +312,32 @@
317312
318/***************************************************************************//**313/***************************************************************************//**
319314
315********************************************************************************/
316struct flwor_wincond_vars
317{
318 var_expr* posvar;
319 var_expr* curr;
320 var_expr* prev;
321 var_expr* next;
322
323 flwor_wincond_vars();
324
325 ~flwor_wincond_vars();
326
327 void set_flwor_clause(flwor_clause* c);
328
329 void clone(
330 ExprManager* mgr,
331 user_function* udf,
332 flwor_wincond_vars& cloneVars,
333 expr::substitution_t& subst) const;
334
335 std::ostream& put(std::ostream&) const;
336};
337
338
339/***************************************************************************//**
340
320 Class flwor_wincond represents a start/stop condition of a window clause.341 Class flwor_wincond represents a start/stop condition of a window clause.
321342
322 - Syntax:343 - Syntax:
@@ -353,27 +374,7 @@
353 friend class ExprIterator;374 friend class ExprIterator;
354375
355public:376public:
356 struct vars377 typedef flwor_wincond_vars vars;
357 {
358 var_expr* posvar;
359 var_expr* curr;
360 var_expr* prev;
361 var_expr* next;
362
363 vars();
364
365 ~vars();
366
367 void set_flwor_clause(flwor_clause* c);
368
369 void clone(
370 ExprManager* mgr,
371 user_function* udf,
372 vars& cloneVars,
373 expr::substitution_t& subst) const;
374
375 std::ostream& put(std::ostream&) const;
376 };
377378
378protected:379protected:
379 bool theIsOnly;380 bool theIsOnly;
@@ -456,7 +457,7 @@
456 CompilerCB* ccb,457 CompilerCB* ccb,
457 const QueryLoc& loc,458 const QueryLoc& loc,
458 const rebind_list_t& gvars,459 const rebind_list_t& gvars,
459 rebind_list_t ngvars,460 const rebind_list_t& ngvars,
460 const std::vector<std::string>& collations);461 const std::vector<std::string>& collations);
461462
462public:463public:
463464
=== modified file 'src/compiler/expression/fo_expr.cpp'
--- src/compiler/expression/fo_expr.cpp 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/fo_expr.cpp 2012-10-24 11:34:21 +0000
@@ -19,6 +19,7 @@
1919
20#include "compiler/expression/fo_expr.h"20#include "compiler/expression/fo_expr.h"
21#include "compiler/expression/expr_visitor.h"21#include "compiler/expression/expr_visitor.h"
22#include "compiler/expression/expr_manager.h"
2223
23#include "compiler/api/compilercb.h"24#include "compiler/api/compilercb.h"
2425
2526
=== modified file 'src/compiler/expression/fo_expr.h'
--- src/compiler/expression/fo_expr.h 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/fo_expr.h 2012-10-24 11:34:21 +0000
@@ -118,30 +118,6 @@
118};118};
119119
120120
121////////// The following expressions in the AST "decay" into an fo_expr ///////
122
123typedef fo_expr additive_expr;
124
125typedef fo_expr and_expr;
126
127typedef fo_expr comparison_expr;
128
129typedef fo_expr enclosed_expr;
130
131typedef fo_expr intersect_except_expr;
132
133typedef fo_expr multiplicative_expr;
134
135typedef fo_expr or_expr;
136
137typedef fo_expr quantified_expr;
138
139typedef fo_expr range_expr;
140
141typedef fo_expr unary_expr;
142
143typedef fo_expr union_expr;
144
145} // namespace zorba121} // namespace zorba
146122
147#endif123#endif
148124
=== modified file 'src/compiler/expression/ftnode.h'
--- src/compiler/expression/ftnode.h 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/ftnode.h 2012-10-24 11:34:21 +0000
@@ -20,13 +20,17 @@
20#include <zorba/locale.h>20#include <zorba/locale.h>
2121
22#include "common/shared_types.h"22#include "common/shared_types.h"
23
23#include "compiler/expression/expr_base.h"24#include "compiler/expression/expr_base.h"
24#include "compiler/expression/ftnode_classes.h"25#include "compiler/expression/ftnode_classes.h"
25#include "compiler/parser/ft_types.h"26#include "compiler/parser/ft_types.h"
26#include "compiler/parser/parse_constants.h"27#include "compiler/parser/parse_constants.h"
27#include "compiler/parsetree/parsenodes.h"28#include "compiler/parsetree/parsenodes.h"
29
28#include "runtime/base/plan_iterator.h"30#include "runtime/base/plan_iterator.h"
31
29#include "util/cxx_util.h"32#include "util/cxx_util.h"
33
30#include "zorbatypes/rchandle.h"34#include "zorbatypes/rchandle.h"
31#include "zorbatypes/zstring.h"35#include "zorbatypes/zstring.h"
3236
3337
=== modified file 'src/compiler/expression/script_exprs.cpp'
--- src/compiler/expression/script_exprs.cpp 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/script_exprs.cpp 2012-10-24 11:34:21 +0000
@@ -26,7 +26,7 @@
26#include "functions/function.h"26#include "functions/function.h"
2727
28#include "diagnostics/assert.h"28#include "diagnostics/assert.h"
2929#include "diagnostics/xquery_diagnostics.h"
3030
31namespace zorba31namespace zorba
32{32{
@@ -401,7 +401,7 @@
401 static_context* sctx,401 static_context* sctx,
402 user_function* udf,402 user_function* udf,
403 const QueryLoc& loc,403 const QueryLoc& loc,
404 enum action action)404 FlowCtlAction action)
405 :405 :
406 expr(ccb, sctx, udf, loc, flowctl_expr_kind),406 expr(ccb, sctx, udf, loc, flowctl_expr_kind),
407 theAction(action)407 theAction(action)
408408
=== modified file 'src/compiler/expression/script_exprs.h'
--- src/compiler/expression/script_exprs.h 2012-10-09 14:06:08 +0000
+++ src/compiler/expression/script_exprs.h 2012-10-24 11:34:21 +0000
@@ -390,11 +390,8 @@
390 friend class ExprIterator;390 friend class ExprIterator;
391 friend class expr;391 friend class expr;
392392
393public:
394 enum action { BREAK, CONTINUE };
395
396protected:393protected:
397 enum action theAction;394 FlowCtlAction theAction;
398395
399protected:396protected:
400 flowctl_expr(397 flowctl_expr(
@@ -402,10 +399,10 @@
402 static_context* sctx,399 static_context* sctx,
403 user_function* udf,400 user_function* udf,
404 const QueryLoc& loc,401 const QueryLoc& loc,
405 enum action action);402 FlowCtlAction action);
406403
407public:404public:
408 enum action get_action() const { return theAction; }405 FlowCtlAction get_action() const { return theAction; }
409406
410 void compute_scripting_kind();407 void compute_scripting_kind();
411408
412409
=== modified file 'src/compiler/expression/update_exprs.cpp'
--- src/compiler/expression/update_exprs.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/expression/update_exprs.cpp 2012-10-24 11:34:21 +0000
@@ -18,6 +18,7 @@
18#include "compiler/expression/update_exprs.h"18#include "compiler/expression/update_exprs.h"
19#include "compiler/expression/var_expr.h"19#include "compiler/expression/var_expr.h"
20#include "compiler/expression/expr_visitor.h"20#include "compiler/expression/expr_visitor.h"
21#include "compiler/expression/expr_manager.h"
2122
22#include "compiler/api/compilercb.h"23#include "compiler/api/compilercb.h"
2324
2425
=== modified file 'src/compiler/rewriter/framework/rewriter.h'
--- src/compiler/rewriter/framework/rewriter.h 2012-09-19 21:16:15 +0000
+++ src/compiler/rewriter/framework/rewriter.h 2012-10-24 11:34:21 +0000
@@ -29,12 +29,10 @@
29{29{
30public:30public:
31 Rewriter() {}31 Rewriter() {}
32
32 virtual ~Rewriter() { }33 virtual ~Rewriter() { }
3334
34 virtual bool rewrite(RewriterContext& rCtx) = 0;35 virtual bool rewrite(RewriterContext& rCtx) = 0;
35
36protected:
37 CompilerCB::config::opt_level_t theOptLevel;
38};36};
3937
40}38}
4139
=== modified file 'src/compiler/rewriter/rewriters/default_optimizer.cpp'
--- src/compiler/rewriter/rewriters/default_optimizer.cpp 2012-10-19 20:42:38 +0000
+++ src/compiler/rewriter/rewriters/default_optimizer.cpp 2012-10-24 11:34:21 +0000
@@ -36,8 +36,6 @@
36public:36public:
37 FoldRules()37 FoldRules()
38 {38 {
39 //ADD_RULE(MarkExpensiveOps);
40 // Most rules try to update the freevars annotations, but for now let's stay on the safe side
41 ADD_RULE(MarkExprs);39 ADD_RULE(MarkExprs);
42 ADD_RULE(MarkFreeVars);40 ADD_RULE(MarkFreeVars);
43 ADD_RULE(FoldConst(false));41 ADD_RULE(FoldConst(false));
@@ -65,7 +63,6 @@
6563
66 SingletonRuleMajorDriver<EliminateTypeEnforcingOperations> driverTypeRules;64 SingletonRuleMajorDriver<EliminateTypeEnforcingOperations> driverTypeRules;
67 SingletonRuleMajorDriver<EliminateExtraneousPathSteps> driverPathSimplify;65 SingletonRuleMajorDriver<EliminateExtraneousPathSteps> driverPathSimplify;
68 //SingletonRuleMajorDriver<ReplaceExprWithConstantOneWhenPossible> driverExprSimplify;
69 RuleOnceDriver<EliminateUnusedLetVars> driverEliminateVars;66 RuleOnceDriver<EliminateUnusedLetVars> driverEliminateVars;
70 RuleOnceDriver<MarkProducerNodeProps> driverMarkProducerNodeProps;67 RuleOnceDriver<MarkProducerNodeProps> driverMarkProducerNodeProps;
71 RuleOnceDriver<MarkConsumerNodeProps> driverMarkConsumerNodeProps;68 RuleOnceDriver<MarkConsumerNodeProps> driverMarkConsumerNodeProps;
7269
=== modified file 'src/compiler/rewriter/rules/flwor_rules.cpp'
--- src/compiler/rewriter/rules/flwor_rules.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/rewriter/rules/flwor_rules.cpp 2012-10-24 11:34:21 +0000
@@ -23,6 +23,7 @@
23#include "compiler/rewriter/tools/expr_tools.h"23#include "compiler/rewriter/tools/expr_tools.h"
2424
25#include "compiler/expression/flwor_expr.h"25#include "compiler/expression/flwor_expr.h"
26#include "compiler/expression/script_exprs.h"
26#include "compiler/expression/expr_iter.h"27#include "compiler/expression/expr_iter.h"
27#include "compiler/expression/expr.h"28#include "compiler/expression/expr.h"
2829
@@ -239,19 +240,22 @@
239240
240 if (clause->get_kind() == flwor_clause::where_clause)241 if (clause->get_kind() == flwor_clause::where_clause)
241 {242 {
242 whereExpr = clause->get_expr();243 whereExpr = static_cast<where_clause*>(clause)->get_expr();
243 const expr::FreeVars& whereVars = whereExpr->getFreeVars();244 const expr::FreeVars& whereVars = whereExpr->getFreeVars();
244245
245 if (myVars.empty())246 csize k = 0;
246 flwor.get_vars(myVars);247 expr::FreeVars::const_iterator ite = whereVars.begin();
247248 expr::FreeVars::const_iterator end = whereVars.end();
248 expr::FreeVars diff;249 for (; ite != end; ++ite)
249 std::set_intersection(myVars.begin(),250 {
250 myVars.end(),251 flwor_clause* vc = (*ite)->get_flwor_clause();
251 whereVars.begin(),252 if (vc != NULL && vc->get_flwor_expr() == flworp)
252 whereVars.end(),253 break;
253 std::inserter(diff, diff.begin()));254
254 if (diff.empty())255 ++k;
256 }
257
258 if (k == whereVars.size())
255 {259 {
256 flwor.remove_clause(i);260 flwor.remove_clause(i);
257261
@@ -522,7 +526,7 @@
522 }526 }
523 else if (clause->get_kind() == flwor_clause::where_clause)527 else if (clause->get_kind() == flwor_clause::where_clause)
524 {528 {
525 expr* whereExpr = clause->get_expr();529 expr* whereExpr = static_cast<where_clause*>(clause)->get_expr();
526530
527 //TODO: Consider case where both whereExpr and whereCond ar AND ops531 //TODO: Consider case where both whereExpr and whereCond ar AND ops
528 if (whereCond == NULL)532 if (whereCond == NULL)
@@ -638,7 +642,7 @@
638 }642 }
639 case wrapper_expr_kind:643 case wrapper_expr_kind:
640 {644 {
641 return is_trivial_expr(static_cast<const wrapper_expr*>(e)->get_expr());645 return is_trivial_expr(static_cast<const wrapper_expr*>(e)->get_input());
642 }646 }
643 default:647 default:
644 return false;648 return false;
@@ -709,10 +713,6 @@
709 domExpr->get_return_type()->max_card() >= 2)713 domExpr->get_return_type()->max_card() >= 2)
710 return false;714 return false;
711715
712 // test rbkt/zorba/extern/5890.xq illustrates why this check is needed
713 //if (hasNodeConstr && fc.get_expr()->contains_node_construction())
714 // return false;
715
716 break;716 break;
717 }717 }
718 case flwor_clause::where_clause:718 case flwor_clause::where_clause:
@@ -722,9 +722,11 @@
722722
723 assert(varQuant == TypeConstants::QUANT_ONE);723 assert(varQuant == TypeConstants::QUANT_ONE);
724724
725 if (std::find(refpath.begin(), refpath.end(), clause->get_expr()) != refpath.end())725 expr* whereExpr = static_cast<const where_clause*>(clause)->get_expr();
726
727 if (std::find(refpath.begin(), refpath.end(), whereExpr) != refpath.end())
726 {728 {
727 referencingExpr = clause->get_expr();729 referencingExpr = whereExpr;
728 break;730 break;
729 }731 }
730732
@@ -1324,7 +1326,7 @@
1324 if (clause->get_kind() != flwor_clause::where_clause)1326 if (clause->get_kind() != flwor_clause::where_clause)
1325 continue;1327 continue;
13261328
1327 expr* whereExpr = clause->get_expr();1329 expr* whereExpr = static_cast<where_clause*>(clause)->get_expr();
13281330
1329 expr* posExpr = NULL;1331 expr* posExpr = NULL;
1330 var_expr* posVar = NULL;1332 var_expr* posVar = NULL;
@@ -1807,24 +1809,22 @@
1807 {1809 {
1808 bool merge = false;1810 bool merge = false;
1809 flwor_expr* nestedFlwor = NULL;1811 flwor_expr* nestedFlwor = NULL;
1810 ulong numNestedClauses;1812 csize numNestedClauses;
18111813
1812 flwor_clause* c = flwor->get_clause(i);1814 flwor_clause* c = flwor->get_clause(i);
18131815
1814 expr* domainExpr = c->get_expr();1816 if (c->get_kind() == flwor_clause::let_clause)
1815
1816 if (domainExpr != NULL &&
1817 domainExpr->get_expr_kind() == flwor_expr_kind &&
1818 !domainExpr->is_sequential())
1819 {1817 {
1820 nestedFlwor = static_cast<flwor_expr*>(c->get_expr());1818 expr* domainExpr = static_cast<let_clause*>(c)->get_expr();
1821 numNestedClauses = nestedFlwor->num_clauses();
18221819
1823 if (c->get_kind() == flwor_clause::let_clause)1820 if (domainExpr->get_expr_kind() == flwor_expr_kind &&
1821 !domainExpr->is_sequential())
1824 {1822 {
1823 nestedFlwor = static_cast<flwor_expr*>(domainExpr);
1824 numNestedClauses = nestedFlwor->num_clauses();
1825 merge = true;1825 merge = true;
18261826
1827 for (ulong j = 0; j < numNestedClauses; ++j)1827 for (csize j = 0; j < numNestedClauses; ++j)
1828 {1828 {
1829 flwor_clause* nestedClause = nestedFlwor->get_clause(j);1829 flwor_clause* nestedClause = nestedFlwor->get_clause(j);
1830 flwor_clause::ClauseKind nestedClauseKind = nestedClause->get_kind();1830 flwor_clause::ClauseKind nestedClauseKind = nestedClause->get_kind();
@@ -1832,7 +1832,7 @@
1832 if (nestedClauseKind == flwor_clause::for_clause)1832 if (nestedClauseKind == flwor_clause::for_clause)
1833 {1833 {
1834 xqtref_t nestedDomainType =1834 xqtref_t nestedDomainType =
1835 nestedClause->get_expr()->get_return_type();1835 static_cast<for_clause*>(nestedClause)->get_expr()->get_return_type();
18361836
1837 if (nestedDomainType->get_quantifier() != TypeConstants::QUANT_ONE)1837 if (nestedDomainType->get_quantifier() != TypeConstants::QUANT_ONE)
1838 {1838 {
@@ -1847,12 +1847,20 @@
1847 }1847 }
1848 }1848 }
1849 }1849 }
1850 else if (c->get_kind() == flwor_clause::for_clause &&1850 }
1851 c->get_pos_var() == NULL)1851 else if (c->get_kind() == flwor_clause::for_clause &&
1852 static_cast<for_clause*>(c)->get_pos_var() == NULL)
1853 {
1854 expr* domainExpr = static_cast<for_clause*>(c)->get_expr();
1855
1856 if (domainExpr->get_expr_kind() == flwor_expr_kind &&
1857 !domainExpr->is_sequential())
1852 {1858 {
1859 nestedFlwor = static_cast<flwor_expr*>(domainExpr);
1860 numNestedClauses = nestedFlwor->num_clauses();
1853 merge = true;1861 merge = true;
18541862
1855 for (ulong j = 0; j < numNestedClauses; ++j)1863 for (csize j = 0; j < numNestedClauses; ++j)
1856 {1864 {
1857 flwor_clause* nestedClause = nestedFlwor->get_clause(j);1865 flwor_clause* nestedClause = nestedFlwor->get_clause(j);
1858 flwor_clause::ClauseKind nestedClauseKind = nestedClause->get_kind();1866 flwor_clause::ClauseKind nestedClauseKind = nestedClause->get_kind();
18591867
=== modified file 'src/compiler/rewriter/rules/fold_rules.cpp'
--- src/compiler/rewriter/rules/fold_rules.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/rewriter/rules/fold_rules.cpp 2012-10-24 11:34:21 +0000
@@ -51,8 +51,6 @@
5151
52namespace zorba {52namespace zorba {
5353
54static void remove_wincond_vars(const flwor_wincond*, expr::FreeVars&);
55
56static bool standalone_expr(expr*);54static bool standalone_expr(expr*);
5755
58static bool already_folded(expr*, RewriterContext&);56static bool already_folded(expr*, RewriterContext&);
@@ -236,84 +234,82 @@
236 iter.next();234 iter.next();
237 }235 }
238236
237 switch (node->get_expr_kind())
238 {
239 case fo_expr_kind:
240 {
241 fo_expr* fo = static_cast<fo_expr *>(node);
242 function* f = fo->get_func();
243
244 if (!f->isUdf())
245 {
246 if (FunctionConsts::FN_ERROR_0 <= f->getKind() &&
247 f->getKind() <= FunctionConsts::FN_TRACE_2)
248 {
249 curNonDiscardable = ANNOTATION_TRUE_FIXED;
250 curUnfoldable = ANNOTATION_TRUE_FIXED;
251 }
252 else if (f->getKind() == FunctionConsts::FN_ZORBA_REF_NODE_BY_REFERENCE_1)
253 {
254 curDereferencesNodes = ANNOTATION_TRUE;
255 }
256
257 // Do not fold functions that always require access to the dynamic context,
258 // or may need to access the implicit timezone (which is also in the dynamic
259 // constext).
260 if (saveUnfoldable != ANNOTATION_TRUE_FIXED &&
261 (f->accessesDynCtx() ||
262 maybe_needs_implicit_timezone(fo) ||
263 !f->isDeterministic()))
264 {
265 curUnfoldable = ANNOTATION_TRUE_FIXED;
266 }
267 }
268 else if (theIsLocal)
269 {
270 curUnfoldable = saveUnfoldable;
271 curDereferencesNodes = saveDereferencesNodes;
272 curConstructsNodes = saveConstructsNodes;
273 }
274 else
275 {
276 if (saveUnfoldable != ANNOTATION_TRUE_FIXED &&
277 (f->accessesDynCtx() || !f->isDeterministic()))
278 {
279 curUnfoldable = ANNOTATION_TRUE_FIXED;
280 }
281
282 if (static_cast<user_function*>(f)->dereferencesNodes())
283 curDereferencesNodes = ANNOTATION_TRUE;
284
285 if (static_cast<user_function*>(f)->constructsNodes())
286 curConstructsNodes = ANNOTATION_TRUE;
287 }
288
289 break;
290 }
291
292 case var_expr_kind:
293 {
294 var_expr::var_kind varKind = static_cast<var_expr *>(node)->get_kind();
295
296 if (varKind == var_expr::prolog_var || varKind == var_expr::local_var)
297 curUnfoldable = ANNOTATION_TRUE_FIXED;
298
299 break;
300 }
301
302 default:
303 {
304 break;
305 }
306 }
307
239 if (node->is_sequential())308 if (node->is_sequential())
240 {309 {
241 curNonDiscardable = ANNOTATION_TRUE_FIXED;310 curNonDiscardable = ANNOTATION_TRUE_FIXED;
242 curUnfoldable = ANNOTATION_TRUE_FIXED;311 curUnfoldable = ANNOTATION_TRUE_FIXED;
243 }312 }
244 else
245 {
246 switch (node->get_expr_kind())
247 {
248 case fo_expr_kind:
249 {
250 fo_expr* fo = static_cast<fo_expr *>(node);
251 function* f = fo->get_func();
252
253 if (!f->isUdf())
254 {
255 if (FunctionConsts::FN_ERROR_0 <= f->getKind() &&
256 f->getKind() <= FunctionConsts::FN_TRACE_2)
257 {
258 curNonDiscardable = ANNOTATION_TRUE_FIXED;
259 curUnfoldable = ANNOTATION_TRUE_FIXED;
260 }
261 else if (f->getKind() == FunctionConsts::FN_ZORBA_REF_NODE_BY_REFERENCE_1)
262 {
263 curDereferencesNodes = ANNOTATION_TRUE;
264 }
265
266 // Do not fold functions that always require access to the dynamic context,
267 // or may need to access the implicit timezone (which is also in the dynamic
268 // constext).
269 if (saveUnfoldable != ANNOTATION_TRUE_FIXED &&
270 (f->accessesDynCtx() ||
271 maybe_needs_implicit_timezone(fo) ||
272 !f->isDeterministic()))
273 {
274 curUnfoldable = ANNOTATION_TRUE_FIXED;
275 }
276 }
277 else if (theIsLocal)
278 {
279 curUnfoldable = saveUnfoldable;
280 curDereferencesNodes = saveDereferencesNodes;
281 curConstructsNodes = saveConstructsNodes;
282 }
283 else
284 {
285 if (saveUnfoldable != ANNOTATION_TRUE_FIXED &&
286 (f->accessesDynCtx() || !f->isDeterministic()))
287 {
288 curUnfoldable = ANNOTATION_TRUE_FIXED;
289 }
290
291 if (static_cast<user_function*>(f)->dereferencesNodes())
292 curDereferencesNodes = ANNOTATION_TRUE;
293
294 if (static_cast<user_function*>(f)->constructsNodes())
295 curConstructsNodes = ANNOTATION_TRUE;
296 }
297
298 break;
299 }
300
301 case var_expr_kind:
302 {
303 var_expr::var_kind varKind = static_cast<var_expr *>(node)->get_kind();
304
305 if (varKind == var_expr::prolog_var || varKind == var_expr::local_var)
306 curUnfoldable = ANNOTATION_TRUE_FIXED;
307
308 break;
309 }
310
311 default:
312 {
313 break;
314 }
315 }
316 }
317313
318 if (saveNonDiscardable != curNonDiscardable &&314 if (saveNonDiscardable != curNonDiscardable &&
319 saveNonDiscardable != ANNOTATION_TRUE_FIXED)315 saveNonDiscardable != ANNOTATION_TRUE_FIXED)
@@ -382,134 +378,79 @@
382 For each expr E, collect all the variables that are referenced directly by E378 For each expr E, collect all the variables that are referenced directly by E
383 and its subexpressions.379 and its subexpressions.
384********************************************************************************/380********************************************************************************/
385381expr* MarkFreeVars::apply(RewriterContext& rCtx, expr* node, bool& modified)
386RULE_REWRITE_PRE(MarkFreeVars)
387{
388 return NULL;
389}
390
391RULE_REWRITE_POST(MarkFreeVars)
392{382{
393 expr::FreeVars& freevars = node->getFreeVars();383 expr::FreeVars& freevars = node->getFreeVars();
394384
395 freevars.clear();385 freevars.clear();
396386
397 if (node->get_expr_kind() == var_expr_kind)387 switch (node->get_expr_kind())
388 {
389 case var_expr_kind:
398 {390 {
399 var_expr* v = static_cast<var_expr *>(node);391 var_expr* v = static_cast<var_expr *>(node);
400 freevars.insert(v);392 freevars.insert(v);
401 }393
402 else394 break;
403 {395 }
404 // Get the free vars of each child expr and add them to the free vars of the396 // Get the free vars of each child expr and add them to the free vars of the
405 // parent.397 // parent. But in case of a flwor expr, do not add any variables defined by
406 ExprIterator iter(node);398 // the flwor expr itself
407 while (!iter.done())399
408 {400 case flwor_expr_kind:
409 expr* e = **iter;401 case gflwor_expr_kind:
410402 {
403 flwor_expr* flwor = static_cast<flwor_expr *> (node);
404
405 ExprIterator iter(node);
406 while (!iter.done())
407 {
408 expr* e = **iter;
409
410 apply(rCtx, e, modified);
411
412 const expr::FreeVars& kfv = e->getFreeVars();
413
414 expr::FreeVars::const_iterator ite = kfv.begin();
415 expr::FreeVars::const_iterator end = kfv.end();
416 for (; ite != end; ++ite)
417 {
418 flwor_clause* c = (*ite)->get_flwor_clause();
419 if (c != NULL && c->get_flwor_expr() == flwor)
420 continue;
421
422 freevars.insert(*ite);
423 }
424
425 iter.next();
426 }
427
428 break;
429 }
430 default:
431 {
432 ExprIterator iter(node);
433
434 while (!iter.done())
435 {
436 expr* e = **iter;
437
438 apply(rCtx, e, modified);
439
411 const expr::FreeVars& kfv = e->getFreeVars();440 const expr::FreeVars& kfv = e->getFreeVars();
412 std::copy(kfv.begin(),441 std::copy(kfv.begin(),
413 kfv.end(),442 kfv.end(),
414 inserter(freevars, freevars.begin()));443 inserter(freevars, freevars.begin()));
415444
416 iter.next();445 iter.next();
417 }446 }
418447 }
419 // For a flwor expr, remove the vars defined by the flwor expr itself from
420 // the flwor free vars .
421 if (node->get_expr_kind() == flwor_expr_kind ||
422 node->get_expr_kind() == gflwor_expr_kind)
423 {
424 flwor_expr* flwor = dynamic_cast<flwor_expr *> (node);
425 for (flwor_expr::clause_list_t::const_iterator i = flwor->clause_begin();
426 i != flwor->clause_end();
427 ++i)
428 {
429 const flwor_clause* c = *i;
430
431 if (c->get_kind() == flwor_clause::for_clause)
432 {
433 const for_clause* fc = static_cast<const for_clause *>(c);
434
435 freevars.erase(fc->get_var());
436 if (fc->get_pos_var() != NULL)
437 freevars.erase(fc->get_pos_var());
438 }
439 else if (c->get_kind() == flwor_clause::let_clause)
440 {
441 const let_clause* lc = static_cast<const let_clause *>(c);
442
443 freevars.erase(lc->get_var());
444 }
445 else if (c->get_kind() == flwor_clause::window_clause)
446 {
447 const window_clause* wc = static_cast<const window_clause *>(c);
448
449 freevars.erase(wc->get_var());
450
451 flwor_wincond* startCond = wc->get_win_start();
452 flwor_wincond* stopCond = wc->get_win_stop();
453
454 if (startCond != NULL)
455 remove_wincond_vars(startCond, freevars);
456
457 if (stopCond != NULL)
458 remove_wincond_vars(stopCond, freevars);
459 }
460 else if (c->get_kind() == flwor_clause::group_clause)
461 {
462 const group_clause* gc = static_cast<const group_clause *>(c);
463
464 const flwor_clause::rebind_list_t& gvars = gc->get_grouping_vars();
465 csize numGroupVars = gvars.size();
466
467 for (csize i = 0; i < numGroupVars; ++i)
468 {
469 freevars.erase(gvars[i].second);
470 }
471
472 const flwor_clause::rebind_list_t& ngvars = gc->get_nongrouping_vars();
473 csize numNonGroupVars = ngvars.size();
474
475 for (csize i = 0; i < numNonGroupVars; ++i)
476 {
477 freevars.erase(ngvars[i].second);
478 }
479 }
480 else if (c->get_kind() == flwor_clause::count_clause)
481 {
482 const count_clause* cc = static_cast<const count_clause *>(c);
483
484 freevars.erase(cc->get_var());
485 }
486 }
487 }
488 }448 }
489449
490 return NULL;450 return NULL;
491}451}
492452
493453
494static void remove_wincond_vars(
495 const flwor_wincond* cond,
496 expr::FreeVars& freevars)
497{
498 const flwor_wincond::vars& inVars = cond->get_in_vars();
499 const flwor_wincond::vars& outVars = cond->get_out_vars();
500
501 freevars.erase(inVars.posvar);
502 freevars.erase(inVars.curr);
503 freevars.erase(inVars.prev);
504 freevars.erase(inVars.next);
505
506 freevars.erase(outVars.posvar);
507 freevars.erase(outVars.curr);
508 freevars.erase(outVars.prev);
509 freevars.erase(outVars.next);
510}
511
512
513/*******************************************************************************454/*******************************************************************************
514 Execute const exprs that return at most one item as a result. Replace such455 Execute const exprs that return at most one item as a result. Replace such
515 exprs by either a const_expr whose value is the returned item, or an empty456 exprs by either a const_expr whose value is the returned item, or an empty
@@ -1014,7 +955,7 @@
1014955
1015 if (c->get_kind() == flwor_clause::for_clause)956 if (c->get_kind() == flwor_clause::for_clause)
1016 {957 {
1017 return c->get_expr();958 return static_cast<for_clause*>(c)->get_expr();
1018 }959 }
1019 else960 else
1020 {961 {
1021962
=== modified file 'src/compiler/rewriter/rules/hoist_rules.cpp'
--- src/compiler/rewriter/rules/hoist_rules.cpp 2012-10-20 21:29:37 +0000
+++ src/compiler/rewriter/rules/hoist_rules.cpp 2012-10-24 11:34:21 +0000
@@ -564,7 +564,7 @@
564 k == axis_step_expr_kind ||564 k == axis_step_expr_kind ||
565 k == match_expr_kind ||565 k == match_expr_kind ||
566 (k == wrapper_expr_kind &&566 (k == wrapper_expr_kind &&
567 non_hoistable(static_cast<const wrapper_expr*>(e)->get_expr())) ||567 non_hoistable(static_cast<const wrapper_expr*>(e)->get_input())) ||
568 is_already_hoisted(e) ||568 is_already_hoisted(e) ||
569 is_enclosed_expr(e) ||569 is_enclosed_expr(e) ||
570 e->containsRecursiveCall() ||570 e->containsRecursiveCall() ||
571571
=== modified file 'src/compiler/rewriter/rules/index_join_rule.cpp'
--- src/compiler/rewriter/rules/index_join_rule.cpp 2012-10-10 13:05:50 +0000
+++ src/compiler/rewriter/rules/index_join_rule.cpp 2012-10-24 11:34:21 +0000
@@ -736,9 +736,9 @@
736 {736 {
737 wrapper_expr* wrapper = reinterpret_cast<wrapper_expr*>(subExpr);737 wrapper_expr* wrapper = reinterpret_cast<wrapper_expr*>(subExpr);
738738
739 if (wrapper->get_expr()->get_expr_kind() == var_expr_kind)739 if (wrapper->get_input()->get_expr_kind() == var_expr_kind)
740 {740 {
741 var_expr* var = reinterpret_cast<var_expr*>(wrapper->get_expr());741 var_expr* var = reinterpret_cast<var_expr*>(wrapper->get_input());
742 long varid = -1;742 long varid = -1;
743743
744 if (rCtx.theVarIdMap->find(var) != rCtx.theVarIdMap->end())744 if (rCtx.theVarIdMap->find(var) != rCtx.theVarIdMap->end())
745745
=== modified file 'src/compiler/rewriter/rules/nodeid_rules.cpp'
--- src/compiler/rewriter/rules/nodeid_rules.cpp 2012-10-16 13:24:49 +0000
+++ src/compiler/rewriter/rules/nodeid_rules.cpp 2012-10-24 11:34:21 +0000
@@ -122,7 +122,7 @@
122122
123 order_expr* orderExpr = static_cast<order_expr *>(node);123 order_expr* orderExpr = static_cast<order_expr *>(node);
124124
125 rCtx.theIsInOrderedMode = (orderExpr->get_type() == order_expr::ordered ?125 rCtx.theIsInOrderedMode = (orderExpr->get_type() == doc_ordered ?
126 true : false);126 true : false);
127 break;127 break;
128 }128 }
@@ -278,17 +278,17 @@
278278
279 case wrapper_expr_kind :279 case wrapper_expr_kind :
280 {280 {
281 wrapper_expr* we = static_cast<wrapper_expr *>(node);281 wrapper_expr* e = static_cast<wrapper_expr *>(node);
282 pushdown_ignores_sorted_nodes(node, we->get_expr());282 pushdown_ignores_sorted_nodes(node, e->get_input());
283 pushdown_ignores_duplicate_nodes(node, we->get_expr());283 pushdown_ignores_duplicate_nodes(node, e->get_input());
284 break;284 break;
285 }285 }
286286
287 case function_trace_expr_kind :287 case function_trace_expr_kind :
288 {288 {
289 function_trace_expr* fte = static_cast<function_trace_expr*>(node);289 function_trace_expr* e = static_cast<function_trace_expr *>(node);
290 pushdown_ignores_sorted_nodes(node, fte->get_expr());290 pushdown_ignores_sorted_nodes(node, e->get_input());
291 pushdown_ignores_duplicate_nodes(node, fte->get_expr());291 pushdown_ignores_duplicate_nodes(node, e->get_input());
292 break;292 break;
293 }293 }
294294
@@ -892,7 +892,7 @@
892 {892 {
893 validate_expr* e = static_cast<validate_expr *>(node);893 validate_expr* e = static_cast<validate_expr *>(node);
894 std::vector<expr*> sources;894 std::vector<expr*> sources;
895 theSourceFinder->findNodeSources(e->get_expr(), sources);895 theSourceFinder->findNodeSources(e->get_input(), sources);
896 markSources(sources);896 markSources(sources);
897 break;897 break;
898 }898 }
899899
=== modified file 'src/compiler/rewriter/rules/path_rules.cpp'
--- src/compiler/rewriter/rules/path_rules.cpp 2012-09-19 21:16:15 +0000
+++ src/compiler/rewriter/rules/path_rules.cpp 2012-10-24 11:34:21 +0000
@@ -26,22 +26,22 @@
2626
27RULE_REWRITE_PRE(EliminateExtraneousPathSteps)27RULE_REWRITE_PRE(EliminateExtraneousPathSteps)
28{28{
29 relpath_expr* re = dynamic_cast<relpath_expr *>(node);29 if (node->get_expr_kind() == relpath_expr_kind)
30 if (re != NULL)
31 {30 {
31 relpath_expr* re = static_cast<relpath_expr *>(node);
32 csize numSteps = re->size();32 csize numSteps = re->size();
3333
34 for (csize i = 0; i < numSteps - 1; i++)34 for (csize i = 1; i < numSteps - 1; ++i)
35 {35 {
36 axis_step_expr* axisStep = dynamic_cast<axis_step_expr*>((*re)[i]);36 assert((*re)[i]->get_expr_kind() == axis_step_expr_kind);
3737
38 if (axisStep != NULL &&38 axis_step_expr* axisStep = static_cast<axis_step_expr*>((*re)[i]);
39 axisStep->getAxis() == axis_kind_descendant_or_self &&39
40 if (axisStep->getAxis() == axis_kind_descendant_or_self &&
40 axisStep->getTest()->getTestKind() == match_anykind_test)41 axisStep->getTest()->getTestKind() == match_anykind_test)
41 {42 {
42 axis_step_expr* nextStep = dynamic_cast<axis_step_expr*>((*re)[i+1]);43 axis_step_expr* nextStep = static_cast<axis_step_expr*>((*re)[i+1]);
43 if (nextStep != NULL &&44 if (nextStep->getAxis() == axis_kind_child)
44 nextStep->getAxis() == axis_kind_child)
45 {45 {
46 nextStep->setAxis(axis_kind_descendant);46 nextStep->setAxis(axis_kind_descendant);
47 (*re).erase(i);47 (*re).erase(i);
@@ -53,7 +53,7 @@
5353
54 if (numSteps == 1)54 if (numSteps == 1)
55 {55 {
56 return (*re) [0];56 return (*re)[0];
57 }57 }
58 }58 }
5959
6060
=== modified file 'src/compiler/rewriter/rules/ruleset.h'
--- src/compiler/rewriter/rules/ruleset.h 2012-10-19 20:42:38 +0000
+++ src/compiler/rewriter/rules/ruleset.h 2012-10-24 11:34:21 +0000
@@ -47,10 +47,10 @@
4747
48PREPOST_RULE(MergeFLWOR);48PREPOST_RULE(MergeFLWOR);
4949
50 //PREPOST_RULE(MarkFreeVars);
51
50PREPOST_RULE(EliminateExtraneousPathSteps);52PREPOST_RULE(EliminateExtraneousPathSteps);
5153
52PREPOST_RULE(MarkFreeVars);
53
54PREPOST_RULE(InlineFunctions);54PREPOST_RULE(InlineFunctions);
5555
56PREPOST_RULE(PartialEval);56PREPOST_RULE(PartialEval);
@@ -100,6 +100,22 @@
100 expr* apply(RewriterContext& rCtx, expr* node, bool& modified);100 expr* apply(RewriterContext& rCtx, expr* node, bool& modified);
101};101};
102102
103#if 1
104/*******************************************************************************
105
106********************************************************************************/
107class MarkFreeVars : public RewriteRule
108{
109public:
110 MarkFreeVars()
111 :
112 RewriteRule(RewriteRule::MarkFreeVars, "MarkFreeVars")
113 {
114 }
115
116 expr* apply(RewriterContext& rCtx, expr* node, bool& modified);
117};
118#endif
103119
104/*******************************************************************************120/*******************************************************************************
105121
106122
=== modified file 'src/compiler/rewriter/rules/type_rules.cpp'
--- src/compiler/rewriter/rules/type_rules.cpp 2012-10-10 13:05:50 +0000
+++ src/compiler/rewriter/rules/type_rules.cpp 2012-10-24 11:34:21 +0000
@@ -188,7 +188,7 @@
188 node->get_loc(),188 node->get_loc(),
189 arg,189 arg,
190 target_type,190 target_type,
191 TreatIterator::TYPE_MATCH,191 TREAT_TYPE_MATCH,
192 false); // do not check the prime types192 false); // do not check the prime types
193 }193 }
194194
@@ -268,7 +268,7 @@
268 argExpr->get_loc(),268 argExpr->get_loc(),
269 argExpr,269 argExpr,
270 rtm.DOUBLE_TYPE_STAR,270 rtm.DOUBLE_TYPE_STAR,
271 PromoteIterator::FUNC_PARAM,271 PROMOTE_FUNC_PARAM,
272 replacement->getName());272 replacement->getName());
273273
274 fo->set_arg(0, promoteExpr);274 fo->set_arg(0, promoteExpr);
@@ -570,7 +570,7 @@
570 arg->get_loc(),570 arg->get_loc(),
571 arg,571 arg,
572 t,572 t,
573 PromoteIterator::FUNC_PARAM,573 PROMOTE_FUNC_PARAM,
574 fn->getName());574 fn->getName());
575}575}
576576
577577
=== modified file 'src/compiler/rewriter/tools/dataflow_annotations.cpp'
--- src/compiler/rewriter/tools/dataflow_annotations.cpp 2012-10-12 09:05:54 +0000
+++ src/compiler/rewriter/tools/dataflow_annotations.cpp 2012-10-24 11:34:21 +0000
@@ -110,16 +110,32 @@
110 case while_expr_kind: // TODO110 case while_expr_kind: // TODO
111 break;111 break;
112112
113 case promote_expr_kind:
114 case castable_expr_kind:
115 case instanceof_expr_kind:
116 {
117 default_walk(e);
118 cast_or_castable_base_expr* ue = static_cast<cast_or_castable_base_expr*>(e);
119 PROPOGATE_SORTED_NODES(ue->get_input(), e);
120 PROPOGATE_DISTINCT_NODES(ue->get_input(), e);
121 break;
122 }
123
113 case wrapper_expr_kind:124 case wrapper_expr_kind:
114 compute_wrapper_expr(static_cast<wrapper_expr *>(e));125 {
126 default_walk(e);
127 wrapper_expr* ue = static_cast<wrapper_expr*>(e);
128 PROPOGATE_SORTED_NODES(ue->get_input(), e);
129 PROPOGATE_DISTINCT_NODES(ue->get_input(), e);
115 break;130 break;
131 }
116132
117 case function_trace_expr_kind:133 case function_trace_expr_kind:
118 {134 {
119 default_walk(e);135 default_walk(e);
120 function_trace_expr* fte = static_cast<function_trace_expr*>(e);136 function_trace_expr* ue = static_cast<function_trace_expr*>(e);
121 PROPOGATE_SORTED_NODES(fte->get_expr(), e);137 PROPOGATE_SORTED_NODES(ue->get_input(), e);
122 PROPOGATE_DISTINCT_NODES(fte->get_expr(), e);138 PROPOGATE_DISTINCT_NODES(ue->get_input(), e);
123 break;139 break;
124 }140 }
125141
@@ -136,10 +152,6 @@
136 compute_trycatch_expr(static_cast<trycatch_expr *>(e));152 compute_trycatch_expr(static_cast<trycatch_expr *>(e));
137 break;153 break;
138154
139 case promote_expr_kind:
140 compute_promote_expr(static_cast<promote_expr *>(e));
141 break;
142
143 case if_expr_kind:155 case if_expr_kind:
144 compute_if_expr(static_cast<if_expr *>(e));156 compute_if_expr(static_cast<if_expr *>(e));
145 break;157 break;
@@ -148,18 +160,10 @@
148 compute_fo_expr(static_cast<fo_expr *>(e));160 compute_fo_expr(static_cast<fo_expr *>(e));
149 break;161 break;
150162
151 case instanceof_expr_kind:
152 compute_instanceof_expr(static_cast<instanceof_expr *>(e));
153 break;
154
155 case treat_expr_kind:163 case treat_expr_kind:
156 compute_treat_expr(static_cast<treat_expr *>(e));164 compute_treat_expr(static_cast<treat_expr *>(e));
157 break;165 break;
158166
159 case castable_expr_kind:
160 compute_castable_expr(static_cast<castable_expr *>(e));
161 break;
162
163 case cast_expr_kind:167 case cast_expr_kind:
164 compute_cast_expr(static_cast<cast_expr *>(e));168 compute_cast_expr(static_cast<cast_expr *>(e));
165 break;169 break;
@@ -336,17 +340,6 @@
336/*******************************************************************************340/*******************************************************************************
337341
338********************************************************************************/342********************************************************************************/
339void DataflowAnnotationsComputer::compute_wrapper_expr(wrapper_expr* e)
340{
341 default_walk(e);
342 PROPOGATE_SORTED_NODES(e->get_expr(), e);
343 PROPOGATE_DISTINCT_NODES(e->get_expr(), e);
344}
345
346
347/*******************************************************************************
348
349********************************************************************************/
350void DataflowAnnotationsComputer::compute_var_expr(var_expr* e)343void DataflowAnnotationsComputer::compute_var_expr(var_expr* e)
351{344{
352 if (!generic_compute(e))345 if (!generic_compute(e))
@@ -451,17 +444,6 @@
451/*******************************************************************************444/*******************************************************************************
452445
453********************************************************************************/446********************************************************************************/
454void DataflowAnnotationsComputer::compute_promote_expr(promote_expr* e)
455{
456 default_walk(e);
457 PROPOGATE_SORTED_NODES(e->get_input(), e);
458 PROPOGATE_DISTINCT_NODES(e->get_input(), e);
459}
460
461
462/*******************************************************************************
463
464********************************************************************************/
465void DataflowAnnotationsComputer::compute_if_expr(if_expr* e)447void DataflowAnnotationsComputer::compute_if_expr(if_expr* e)
466{448{
467 default_walk(e);449 default_walk(e);
@@ -540,17 +522,6 @@
540/*******************************************************************************522/*******************************************************************************
541523
542********************************************************************************/524********************************************************************************/
543void DataflowAnnotationsComputer::compute_instanceof_expr(instanceof_expr *e)
544{
545 default_walk(e);
546 PROPOGATE_SORTED_NODES(e->get_input(), e);
547 PROPOGATE_DISTINCT_NODES(e->get_input(), e);
548}
549
550
551/*******************************************************************************
552
553********************************************************************************/
554void DataflowAnnotationsComputer::compute_treat_expr(treat_expr *e)525void DataflowAnnotationsComputer::compute_treat_expr(treat_expr *e)
555{526{
556 default_walk(e);527 default_walk(e);
@@ -565,17 +536,6 @@
565/*******************************************************************************536/*******************************************************************************
566537
567********************************************************************************/538********************************************************************************/
568void DataflowAnnotationsComputer::compute_castable_expr(castable_expr *e)
569{
570 default_walk(e);
571 PROPOGATE_SORTED_NODES(e->get_input(), e);
572 PROPOGATE_DISTINCT_NODES(e->get_input(), e);
573}
574
575
576/*******************************************************************************
577
578********************************************************************************/
579void DataflowAnnotationsComputer::compute_cast_expr(cast_expr* e)539void DataflowAnnotationsComputer::compute_cast_expr(cast_expr* e)
580{540{
581 default_walk(e);541 default_walk(e);
@@ -601,8 +561,8 @@
601 default_walk(e);561 default_walk(e);
602 if (!generic_compute(e))562 if (!generic_compute(e))
603 {563 {
604 PROPOGATE_SORTED_NODES(e->get_expr(), e);564 PROPOGATE_SORTED_NODES(e->get_input(), e);
605 PROPOGATE_DISTINCT_NODES(e->get_expr(), e);565 PROPOGATE_DISTINCT_NODES(e->get_input(), e);
606 }566 }
607}567}
608568
609569
=== modified file 'src/compiler/rewriter/tools/dataflow_annotations.h'
--- src/compiler/rewriter/tools/dataflow_annotations.h 2012-10-12 09:05:54 +0000
+++ src/compiler/rewriter/tools/dataflow_annotations.h 2012-10-24 11:34:21 +0000
@@ -38,15 +38,12 @@
38private:38private:
39 void compute_var_decl_expr(var_decl_expr* e);39 void compute_var_decl_expr(var_decl_expr* e);
40 void compute_block_expr(block_expr* e);40 void compute_block_expr(block_expr* e);
41 void compute_wrapper_expr(wrapper_expr* e);
42 void compute_var_expr(var_expr* e);41 void compute_var_expr(var_expr* e);
43 void compute_var_set_expr(var_set_expr* e);42 void compute_var_set_expr(var_set_expr* e);
44 void compute_flwor_expr(flwor_expr* e);43 void compute_flwor_expr(flwor_expr* e);
45 void compute_trycatch_expr(trycatch_expr* e);44 void compute_trycatch_expr(trycatch_expr* e);
46 void compute_promote_expr(promote_expr* e);
47 void compute_if_expr(if_expr* e);45 void compute_if_expr(if_expr* e);
48 void compute_fo_expr(fo_expr* e);46 void compute_fo_expr(fo_expr* e);
49 void compute_instanceof_expr(instanceof_expr* e);
50 void compute_treat_expr(treat_expr* e);47 void compute_treat_expr(treat_expr* e);
51 void compute_castable_expr(castable_expr* e);48 void compute_castable_expr(castable_expr* e);
52 void compute_cast_expr(cast_expr* e);49 void compute_cast_expr(cast_expr* e);
5350
=== modified file 'src/compiler/rewriter/tools/expr_tools.cpp'
--- src/compiler/rewriter/tools/expr_tools.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/rewriter/tools/expr_tools.cpp 2012-10-24 11:34:21 +0000
@@ -188,7 +188,7 @@
188 {188 {
189 wrapper_expr* wrapper = reinterpret_cast<wrapper_expr*>(e);189 wrapper_expr* wrapper = reinterpret_cast<wrapper_expr*>(e);
190190
191 if (wrapper->get_expr() == oldVar)191 if (wrapper->get_input() == oldVar)
192 {192 {
193 wrapper->set_expr(newVar);193 wrapper->set_expr(newVar);
194 return;194 return;
195195
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2012-10-23 19:08:52 +0000
+++ src/compiler/translator/translator.cpp 2012-10-24 11:34:21 +0000
@@ -1463,7 +1463,7 @@
1463 {1463 {
1464 argExpr = wrap_in_type_promotion(argExpr,1464 argExpr = wrap_in_type_promotion(argExpr,
1465 paramType,1465 paramType,
1466 PromoteIterator::FUNC_PARAM,1466 PROMOTE_FUNC_PARAM,
1467 func->getName());1467 func->getName());
1468 }1468 }
1469 else1469 else
@@ -1471,7 +1471,7 @@
1471 argExpr = wrap_in_type_match(argExpr,1471 argExpr = wrap_in_type_match(argExpr,
1472 paramType,1472 paramType,
1473 loc,1473 loc,
1474 TreatIterator::FUNC_PARAM,1474 TREAT_FUNC_PARAM,
1475 func->getName());1475 func->getName());
1476 }1476 }
1477 }1477 }
@@ -1500,7 +1500,7 @@
1500expr* wrap_in_type_promotion(1500expr* wrap_in_type_promotion(
1501 expr* e,1501 expr* e,
1502 const xqtref_t& type,1502 const xqtref_t& type,
1503 PromoteIterator::ErrorKind errorKind,1503 PromoteErrorKind errorKind,
1504 store::Item* qname = NULL)1504 store::Item* qname = NULL)
1505{1505{
1506 e = wrap_in_atomization(e);1506 e = wrap_in_atomization(e);
@@ -1522,7 +1522,7 @@
1522 expr* e,1522 expr* e,
1523 const xqtref_t& type,1523 const xqtref_t& type,
1524 const QueryLoc& loc,1524 const QueryLoc& loc,
1525 TreatIterator::ErrorKind errorKind,1525 TreatErrorKind errorKind,
1526 store::Item_t qname = NULL)1526 store::Item_t qname = NULL)
1527{1527{
1528 TypeManager* tm = e->get_type_manager();1528 TypeManager* tm = e->get_type_manager();
@@ -2053,7 +2053,7 @@
2053 loc,2053 loc,
2054 initExpr,2054 initExpr,
2055 varType,2055 varType,
2056 TreatIterator::TYPE_MATCH);2056 TREAT_TYPE_MATCH);
2057 }2057 }
20582058
2059 expr* declExpr = theExprManager->2059 expr* declExpr = theExprManager->
@@ -2073,7 +2073,7 @@
2073 loc,2073 loc,
2074 getExpr,2074 getExpr,
2075 varType,2075 varType,
2076 TreatIterator::TYPE_MATCH);2076 TREAT_TYPE_MATCH);
20772077
2078 stmts.push_back(treatExpr);2078 stmts.push_back(treatExpr);
2079 }2079 }
@@ -3823,7 +3823,7 @@
3823 {3823 {
3824 body = wrap_in_type_promotion(body,3824 body = wrap_in_type_promotion(body,
3825 returnType,3825 returnType,
3826 PromoteIterator::FUNC_RETURN,3826 PROMOTE_FUNC_RETURN,
3827 udf->getName());3827 udf->getName());
38283828
3829 body->set_loc(v.get_return_type()->get_location());3829 body->set_loc(v.get_return_type()->get_location());
@@ -3833,7 +3833,7 @@
3833 body = wrap_in_type_match(body,3833 body = wrap_in_type_match(body,
3834 returnType,3834 returnType,
3835 loc,3835 loc,
3836 TreatIterator::FUNC_RETURN,3836 TREAT_FUNC_RETURN,
3837 udf->getName());3837 udf->getName());
3838 }3838 }
38393839
@@ -4540,13 +4540,13 @@
4540 domainExpr = wrap_in_type_match(domainExpr,4540 domainExpr = wrap_in_type_match(domainExpr,
4541 theRTM.STRUCTURED_ITEM_TYPE_STAR,4541 theRTM.STRUCTURED_ITEM_TYPE_STAR,
4542 loc,4542 loc,
4543 TreatIterator::INDEX_DOMAIN,4543 TREAT_INDEX_DOMAIN,
4544 index->getName());4544 index->getName());
4545#else4545#else
4546 domainExpr = wrap_in_type_match(domainExpr,4546 domainExpr = wrap_in_type_match(domainExpr,
4547 theRTM.ANY_NODE_TYPE_STAR,4547 theRTM.ANY_NODE_TYPE_STAR,
4548 loc,4548 loc,
4549 TreatIterator::INDEX_DOMAIN,4549 TREAT_INDEX_DOMAIN,
4550 index->getName());4550 index->getName());
4551#endif4551#endif
45524552
@@ -4718,7 +4718,7 @@
4718 keyExpr = wrap_in_type_match(keyExpr,4718 keyExpr = wrap_in_type_match(keyExpr,
4719 type,4719 type,
4720 loc,4720 loc,
4721 TreatIterator::INDEX_KEY,4721 TREAT_INDEX_KEY,
4722 index->getName());4722 index->getName());
47234723
4724 keyTypes[i] = ptype->getBaseBuiltinType();4724 keyTypes[i] = ptype->getBaseBuiltinType();
@@ -5941,7 +5941,7 @@
5941 loc,5941 loc,
5942 valueExpr,5942 valueExpr,
5943 varType,5943 varType,
5944 TreatIterator::TYPE_MATCH);5944 TREAT_TYPE_MATCH);
59455945
5946 push_nodestack(theExprManager->create_var_set_expr(theRootSctx,5946 push_nodestack(theExprManager->create_var_set_expr(theRootSctx,
5947 theUDF,5947 theUDF,
@@ -6047,7 +6047,7 @@
6047 expr* condExpr = pop_nodestack();6047 expr* condExpr = pop_nodestack();
60486048
6049 expr* breakExpr = theExprManager->6049 expr* breakExpr = theExprManager->
6050 create_flowctl_expr(theRootSctx, theUDF, loc, flowctl_expr::BREAK);6050 create_flowctl_expr(theRootSctx, theUDF, loc, FLOW_BREAK);
60516051
6052 condExpr = theExprManager->6052 condExpr = theExprManager->
6053 create_if_expr(theRootSctx, theUDF, loc, condExpr, create_empty_seq(loc), breakExpr);6053 create_if_expr(theRootSctx, theUDF, loc, condExpr, create_empty_seq(loc), breakExpr);
@@ -6082,7 +6082,7 @@
6082{6082{
6083 TRACE_VISIT_OUT();6083 TRACE_VISIT_OUT();
60846084
6085 enum flowctl_expr::action a;6085 FlowCtlAction a;
60866086
6087 switch (v.get_action())6087 switch (v.get_action())
6088 {6088 {
@@ -6092,7 +6092,7 @@
6092 {6092 {
6093 RAISE_ERROR_NO_PARAMS(zerr::XSST0009, loc);6093 RAISE_ERROR_NO_PARAMS(zerr::XSST0009, loc);
6094 }6094 }
6095 a = flowctl_expr::BREAK;6095 a = FLOW_BREAK;
6096 break;6096 break;
6097 }6097 }
6098 case FlowCtlStatement::CONTINUE:6098 case FlowCtlStatement::CONTINUE:
@@ -6101,7 +6101,7 @@
6101 {6101 {
6102 RAISE_ERROR_NO_PARAMS(zerr::XSST0010, loc);6102 RAISE_ERROR_NO_PARAMS(zerr::XSST0010, loc);
6103 }6103 }
6104 a = flowctl_expr::CONTINUE;6104 a = FLOW_CONTINUE;
6105 break;6105 break;
6106 }6106 }
6107 default:6107 default:
@@ -6557,9 +6557,9 @@
6557 // Pop the window the domain expr.6557 // Pop the window the domain expr.
6558 expr* windowDomainExpr = pop_nodestack();6558 expr* windowDomainExpr = pop_nodestack();
65596559
6560 window_clause::window_t winKind = (v.get_wintype() == WindowClause::tumbling_window ?6560 WindowKind winKind = (v.get_wintype() == WindowClause::tumbling_window ?
6561 window_clause::tumbling_window :6561 tumbling_window :
6562 window_clause::sliding_window);6562 sliding_window);
65636563
6564 window_clause* clause = theExprManager->create_window_clause(theRootSctx,6564 window_clause* clause = theExprManager->create_window_clause(theRootSctx,
6565 v.get_location(),6565 v.get_location(),
@@ -6943,7 +6943,7 @@
6943 inputExpr = wrap_in_type_match(inputExpr,6943 inputExpr = wrap_in_type_match(inputExpr,
6944 theRTM.ANY_ATOMIC_TYPE_QUESTION,6944 theRTM.ANY_ATOMIC_TYPE_QUESTION,
6945 specLoc,6945 specLoc,
6946 TreatIterator::MULTI_VALUED_GROUPING_KEY);6946 TREAT_MULTI_VALUED_GROUPING_KEY);
69476947
6948 // We need to do this to handle grouping vars with same names but6948 // We need to do this to handle grouping vars with same names but
6949 // different collations.6949 // different collations.
@@ -7589,7 +7589,7 @@
7589 loc,7589 loc,
7590 sv,7590 sv,
7591 type,7591 type,
7592 TreatIterator::TREAT_EXPR);7592 TREAT_EXPR);
75937593
7594 // clauseExpr = [let $caseVar := treat_as($sv, caseType) return NULL]7594 // clauseExpr = [let $caseVar := treat_as($sv, caseType) return NULL]
7595 clauseExpr = wrap_in_let_flwor(treatExpr, caseVar, NULL);7595 clauseExpr = wrap_in_let_flwor(treatExpr, caseVar, NULL);
@@ -8421,10 +8421,10 @@
8421{8421{
8422 TRACE_VISIT_OUT();8422 TRACE_VISIT_OUT();
84238423
8424 push_nodestack(theExprManager->create_instanceof_expr(theRootSctx, theUDF,8424 push_nodestack(CREATE(instanceof)(theRootSctx, theUDF,
8425 loc,8425 loc,
8426 pop_nodestack(),8426 pop_nodestack(),
8427 pop_tstack()));8427 pop_tstack()));
8428}8428}
84298429
84308430
@@ -8441,11 +8441,11 @@
8441{8441{
8442 TRACE_VISIT_OUT();8442 TRACE_VISIT_OUT();
84438443
8444 push_nodestack(theExprManager->create_treat_expr(theRootSctx, theUDF,8444 push_nodestack(CREATE(treat)(theRootSctx, theUDF,
8445 loc,8445 loc,
8446 pop_nodestack(),8446 pop_nodestack(),
8447 pop_tstack(),8447 pop_tstack(),
8448 TreatIterator::TREAT_EXPR));8448 TREAT_EXPR));
8449}8449}
84508450
84518451
@@ -9003,22 +9003,23 @@
9003 loc,9003 loc,
9004 DOT_REF,9004 DOT_REF,
9005 GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,9005 GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
9006 TreatIterator::PATH_DOT);9006 TREAT_PATH_DOT);
90079007
9008 ctx_path_expr->add_back(sourceExpr);9008 ctx_path_expr->add_back(sourceExpr);
90099009
9010 match_expr* me = theExprManager->create_match_expr(theRootSctx, theUDF, loc);9010 match_expr* me = CREATE(match)(theRootSctx, theUDF, loc);
9011 me->setTestKind(match_anykind_test);9011 me->setTestKind(match_anykind_test);
9012 axis_step_expr* ase = theExprManager->create_axis_step_expr(theRootSctx, theUDF, loc);9012 axis_step_expr* ase = CREATE(axis_step)(theRootSctx, theUDF, loc);
9013 ase->setAxis(axis_kind_self);9013 ase->setAxis(axis_kind_self);
9014 ase->setTest(me);9014 ase->setTest(me);
90159015
9016 ctx_path_expr->add_back(&*ase);9016 ctx_path_expr->add_back(&*ase);
90179017
9018 fo_expr* fnroot = theExprManager->create_fo_expr(theRootSctx, theUDF,9018 fo_expr* fnroot = CREATE(fo)(theRootSctx,
9019 loc,9019 theUDF,
9020 BUILTIN_FUNC(FN_ROOT_1),9020 loc,
9021 ctx_path_expr);9021 BUILTIN_FUNC(FN_ROOT_1),
9022 ctx_path_expr);
9022 normalize_fo(fnroot);9023 normalize_fo(fnroot);
90239024
9024 if (pathExpr != NULL)9025 if (pathExpr != NULL)
@@ -9032,11 +9033,12 @@
9032 else9033 else
9033 {9034 {
9034 // case 19035 // case 1
9035 expr* result = theExprManager->create_treat_expr(theRootSctx, theUDF,9036 expr* result = CREATE(treat)(theRootSctx,
9036 loc,9037 theUDF,
9037 fnroot,9038 loc,
9038 GENV_TYPESYSTEM.DOCUMENT_TYPE_ONE,9039 fnroot,
9039 TreatIterator::TREAT_EXPR);9040 GENV_TYPESYSTEM.DOCUMENT_TYPE_ONE,
9041 TREAT_EXPR);
9040 push_nodestack(result);9042 push_nodestack(result);
9041 }9043 }
9042 }9044 }
@@ -9127,7 +9129,7 @@
9127 loc,9129 loc,
9128 DOT_REF,9130 DOT_REF,
9129 GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,9131 GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
9130 TreatIterator::PATH_DOT);9132 TREAT_PATH_DOT);
9131 pathExpr->add_back(sourceExpr);9133 pathExpr->add_back(sourceExpr);
91329134
9133 if (axisStep->get_predicate_list() == NULL)9135 if (axisStep->get_predicate_list() == NULL)
@@ -9200,14 +9202,13 @@
9200#ifdef NODE_SORT_OPT9202#ifdef NODE_SORT_OPT
9201 if (pathExpr->size() == 0)9203 if (pathExpr->size() == 0)
9202 {9204 {
9203 TreatIterator::ErrorKind errKind = TreatIterator::PATH_STEP;9205 TreatErrorKind errKind = TREAT_PATH_STEP;
92049206
9205 if (stepExpr->get_expr_kind() == wrapper_expr_kind)9207 if (stepExpr->get_expr_kind() == wrapper_expr_kind)
9206 {9208 {
9207 wrapper_expr* tmp = static_cast<wrapper_expr*>(stepExpr);
9208 var_expr* dotVar = lookup_var(DOT_VARNAME, loc, zerr::ZXQP0000_NO_ERROR);9209 var_expr* dotVar = lookup_var(DOT_VARNAME, loc, zerr::ZXQP0000_NO_ERROR);
9209 if (tmp->get_expr() == dotVar)9210 if (static_cast<wrapper_expr*>(stepExpr)->get_input() == dotVar)
9210 errKind = TreatIterator::PATH_DOT;9211 errKind = TREAT_PATH_DOT;
9211 }9212 }
92129213
9213 expr* sourceExpr = theExprManager->create_treat_expr(theRootSctx, theUDF,9214 expr* sourceExpr = theExprManager->create_treat_expr(theRootSctx, theUDF,
@@ -10369,7 +10370,7 @@
1036910370
10370 push_nodestack(theExprManager->create_order_expr(theRootSctx, theUDF,10371 push_nodestack(theExprManager->create_order_expr(theRootSctx, theUDF,
10371 loc,10372 loc,
10372 order_expr::ordered,10373 doc_ordered,
10373 pop_nodestack()));10374 pop_nodestack()));
10374}10375}
1037510376
@@ -10390,7 +10391,7 @@
1039010391
10391 push_nodestack(theExprManager->create_order_expr(theRootSctx, theUDF,10392 push_nodestack(theExprManager->create_order_expr(theRootSctx, theUDF,
10392 loc,10393 loc,
10393 order_expr::unordered,10394 doc_unordered,
10394 pop_nodestack()));10395 pop_nodestack()));
10395}10396}
1039610397
@@ -10642,22 +10643,26 @@
1064210643
10643 var_expr* tv = create_temp_var(loc, var_expr::let_var);10644 var_expr* tv = create_temp_var(loc, var_expr::let_var);
1064410645
10645 expr* nanExpr = theExprManager->create_const_expr(theRootSctx, theUDF, loc, xs_double::nan());10646 expr* nanExpr = CREATE(const)(theRootSctx, theUDF, loc, xs_double::nan());
1064610647
10647 expr* condExpr = theExprManager->create_castable_expr(theRootSctx, theUDF, loc, &*tv, theRTM.DOUBLE_TYPE_ONE);10648 expr* condExpr = CREATE(castable)(theRootSctx,
10649 theUDF,
10650 loc,
10651 tv,
10652 theRTM.DOUBLE_TYPE_ONE);
1064810653
10649 expr* castExpr = create_cast_expr(loc, tv, theRTM.DOUBLE_TYPE_ONE, true);10654 expr* castExpr = create_cast_expr(loc, tv, theRTM.DOUBLE_TYPE_ONE, true);
1065010655
10651 expr* ret = theExprManager->create_if_expr(theRootSctx, theUDF, loc, condExpr, castExpr, nanExpr);10656 expr* ret = CREATE(if)(theRootSctx, theUDF, loc, condExpr, castExpr, nanExpr);
1065210657
10653 expr* data_expr = wrap_in_atomization(arguments[0]);10658 expr* data_expr = wrap_in_atomization(arguments[0]);
1065410659
10655 push_nodestack(wrap_in_let_flwor(theExprManager->create_treat_expr(theRootSctx,10660 push_nodestack(wrap_in_let_flwor(CREATE(treat)(theRootSctx,
10656 theUDF,10661 theUDF,
10657 loc,10662 loc,
10658 data_expr,10663 data_expr,
10659 theRTM.ANY_ATOMIC_TYPE_QUESTION,10664 theRTM.ANY_ATOMIC_TYPE_QUESTION,
10660 TreatIterator::TYPE_MATCH),10665 TREAT_TYPE_MATCH),
10661 tv,10666 tv,
10662 ret));10667 ret));
10663 return;10668 return;
@@ -10665,19 +10670,21 @@
10665 case FunctionConsts::FN_STATIC_BASE_URI_0:10670 case FunctionConsts::FN_STATIC_BASE_URI_0:
10666 {10671 {
10667 if (numArgs != 0)10672 if (numArgs != 0)
10673 {
10668 RAISE_ERROR(err::XPST0017, loc,10674 RAISE_ERROR(err::XPST0017, loc,
10669 ERROR_PARAMS("fn:static-base-uri",10675 ERROR_PARAMS("fn:static-base-uri",
10670 ZED(FunctionUndeclared_3),10676 ZED(FunctionUndeclared_3),
10671 numArgs));10677 numArgs));
10678 }
1067210679
10673 zstring baseuri = theSctx->get_base_uri();10680 zstring baseuri = theSctx->get_base_uri();
10674 if (baseuri.empty())10681 if (baseuri.empty())
10675 push_nodestack(create_empty_seq(loc));10682 push_nodestack(create_empty_seq(loc));
10676 else10683 else
10677 push_nodestack(theExprManager->create_cast_expr(theRootSctx, theUDF,10684 push_nodestack(CREATE(cast)(theRootSctx, theUDF,
10678 loc,10685 loc,
10679 theExprManager->create_const_expr(theRootSctx, theUDF, loc, baseuri),10686 CREATE(const)(theRootSctx, theUDF, loc, baseuri),
10680 theRTM.ANY_URI_TYPE_ONE));10687 theRTM.ANY_URI_TYPE_ONE));
10681 return;10688 return;
10682 }10689 }
10683 case FunctionConsts::FN_ID_1:10690 case FunctionConsts::FN_ID_1:
@@ -10890,7 +10897,7 @@
10890 resultExpr = wrap_in_type_match(foExpr,10897 resultExpr = wrap_in_type_match(foExpr,
10891 resultType,10898 resultType,
10892 loc,10899 loc,
10893 TreatIterator::FUNC_RETURN,10900 TREAT_FUNC_RETURN,
10894 f->getName());10901 f->getName());
10895 }10902 }
1089610903
@@ -11024,7 +11031,7 @@
11024 // wrap function's QName11031 // wrap function's QName
11025 expr* qnameExpr = wrap_in_type_promotion(arguments[0],11032 expr* qnameExpr = wrap_in_type_promotion(arguments[0],
11026 theRTM.QNAME_TYPE_ONE,11033 theRTM.QNAME_TYPE_ONE,
11027 PromoteIterator::TYPE_PROMOTION);11034 PROMOTE_TYPE_PROMOTION);
1102811035
11029 for (csize i = 0; i < numArgs ; ++i)11036 for (csize i = 0; i < numArgs ; ++i)
11030 {11037 {
@@ -11487,11 +11494,11 @@
11487 // Wrap the body in appropriate type op.11494 // Wrap the body in appropriate type op.
11488 if (TypeOps::is_builtin_simple(CTX_TM, *returnType))11495 if (TypeOps::is_builtin_simple(CTX_TM, *returnType))
11489 {11496 {
11490 body = wrap_in_type_promotion(body, returnType, PromoteIterator::TYPE_PROMOTION);11497 body = wrap_in_type_promotion(body, returnType, PROMOTE_TYPE_PROMOTION);
11491 }11498 }
11492 else11499 else
11493 {11500 {
11494 body = wrap_in_type_match(body, returnType, loc, TreatIterator::TYPE_MATCH);11501 body = wrap_in_type_match(body, returnType, loc, TREAT_TYPE_MATCH);
11495 }11502 }
1149611503
11497 // Make the body be the return expr of the flwor that binds the function params.11504 // Make the body be the return expr of the flwor that binds the function params.
@@ -11608,19 +11615,21 @@
11608 {11615 {
11609 contentExpr = pop_nodestack();11616 contentExpr = pop_nodestack();
1161011617
11611 contentExpr = theExprManager->11618 contentExpr = CREATE(treat)(theRootSctx,
11612 create_treat_expr(theRootSctx,11619 theUDF,
11613 theUDF,11620 contentExpr->get_loc(),
11614 contentExpr->get_loc(),11621 contentExpr,
11615 contentExpr,11622 GENV_TYPESYSTEM.JSON_OBJECT_TYPE_STAR,
11616 GENV_TYPESYSTEM.JSON_OBJECT_TYPE_STAR,11623 TREAT_TYPE_MATCH,
11617 TreatIterator::TYPE_MATCH,11624 true,
11618 true,11625 NULL);
11619 NULL);
11620 }11626 }
1162111627
11622 expr* jo = theExprManager->11628 expr* jo = CREATE(json_object)(theRootSctx,
11623 create_json_object_expr(theRootSctx, theUDF, loc, contentExpr, v.get_accumulate());11629 theUDF,
11630 loc,
11631 contentExpr,
11632 v.get_accumulate());
1162411633
11625 push_nodestack(jo);11634 push_nodestack(jo);
11626#endif11635#endif
@@ -12114,11 +12123,9 @@
12114 {12123 {
12115 if (!v.isStripped())12124 if (!v.isStripped())
12116 {12125 {
12117 expr* content = theExprManager->create_const_expr(theRootSctx, theUDF, loc, v.get_elem_content().str());12126 expr* content = CREATE(const)(theRootSctx, theUDF, loc, v.get_elem_content().str());
1211812127
12119 push_nodestack(theExprManager->create_text_expr(theRootSctx, theUDF, loc,12128 push_nodestack(CREATE(text)(theRootSctx, theUDF, loc, text_constructor, content));
12120 text_expr::text_constructor,
12121 content));
12122 }12129 }
12123 }12130 }
12124}12131}
@@ -12146,6 +12153,7 @@
12146void check_boundary_whitespace(const DirElemContent& v)12153void check_boundary_whitespace(const DirElemContent& v)
12147{12154{
12148 v.setIsStripped(false);12155 v.setIsStripped(false);
12156
12149 if (theSctx->boundary_space_mode() == StaticContextConsts::strip_space)12157 if (theSctx->boundary_space_mode() == StaticContextConsts::strip_space)
12150 {12158 {
12151 bool lPrevIsBoundary = translator_ns::pop_stack (theIsWSBoundaryStack);12159 bool lPrevIsBoundary = translator_ns::pop_stack (theIsWSBoundaryStack);
@@ -12220,8 +12228,8 @@
12220 // Skip empty CDATA sections12228 // Skip empty CDATA sections
12221 if(!lCDATA_content.empty())12229 if(!lCDATA_content.empty())
12222 {12230 {
12223 expr* content = theExprManager->create_const_expr(theRootSctx, theUDF, loc, lCDATA_content);12231 expr* content = CREATE(const)(theRootSctx, theUDF, loc, lCDATA_content);
12224 push_nodestack(theExprManager->create_text_expr(theRootSctx, theUDF, loc, text_expr::text_constructor, content));12232 push_nodestack(CREATE(text)(theRootSctx, theUDF, loc, text_constructor, content));
12225 }12233 }
12226}12234}
1222712235
@@ -12397,7 +12405,7 @@
12397 // we always create a text node here because if we are in an attribute, we atomice12405 // we always create a text node here because if we are in an attribute, we atomice
12398 // the text node into its string value12406 // the text node into its string value
12399 zstring content("}");12407 zstring content("}");
12400 expr* lConstExpr = theExprManager->create_const_expr(theRootSctx, theUDF, loc, content);12408 expr* lConstExpr = CREATE(const)(theRootSctx, theUDF, loc, content);
12401 push_nodestack ( lConstExpr );12409 push_nodestack ( lConstExpr );
12402 break;12410 break;
12403 }12411 }
@@ -12420,10 +12428,13 @@
12420 TRACE_VISIT_OUT();12428 TRACE_VISIT_OUT();
1242112429
12422 zstring str = v.get_comment().str();12430 zstring str = v.get_comment().str();
12423 expr* content = theExprManager->create_const_expr (theRootSctx, theUDF, loc, str);12431 expr* content = CREATE(const)(theRootSctx, theUDF, loc, str);
12424 push_nodestack (theExprManager->create_text_expr(theRootSctx, theUDF, loc,12432
12425 text_expr::comment_constructor,12433 push_nodestack (CREATE(text)(theRootSctx,
12426 content));12434 theUDF,
12435 loc,
12436 comment_constructor,
12437 content));
12427}12438}
1242812439
1242912440
@@ -12589,8 +12600,8 @@
12589 fo_expr* enclosedExpr = wrap_in_enclosed_expr(inputExpr, loc);12600 fo_expr* enclosedExpr = wrap_in_enclosed_expr(inputExpr, loc);
1259012601
12591 expr* textExpr = theExprManager->create_text_expr(theRootSctx, theUDF, loc,12602 expr* textExpr = theExprManager->create_text_expr(theRootSctx, theUDF, loc,
12592 text_expr::comment_constructor,12603 comment_constructor,
12593 enclosedExpr);12604 enclosedExpr);
1259412605
12595 push_nodestack(textExpr);12606 push_nodestack(textExpr);
12596}12607}
@@ -12653,7 +12664,7 @@
1265312664
12654 expr* textExpr = theExprManager->create_text_expr(theRootSctx, theUDF,12665 expr* textExpr = theExprManager->create_text_expr(theRootSctx, theUDF,
12655 loc,12666 loc,
12656 text_expr::text_constructor,12667 text_constructor,
12657 enclosedExpr);12668 enclosedExpr);
1265812669
12659 push_nodestack(textExpr);12670 push_nodestack(textExpr);
@@ -13454,29 +13465,24 @@
13454 targetExpr = wrap_in_type_match(targetExpr,13465 targetExpr = wrap_in_type_match(targetExpr,
13455 rtm.JSON_OBJECT_TYPE_ONE,13466 rtm.JSON_OBJECT_TYPE_ONE,
13456 loc,13467 loc,
13457 TreatIterator::JSONIQ_OBJECT_UPDATE_TARGET, // JNUP000813468 TREAT_JSONIQ_OBJECT_UPDATE_TARGET, // JNUP0008
13458 NULL);13469 NULL);
1345913470
13460 contentExpr = wrap_in_type_match(contentExpr,13471 contentExpr = wrap_in_type_match(contentExpr,
13461 rtm.JSON_OBJECT_TYPE_STAR,13472 rtm.JSON_OBJECT_TYPE_STAR,
13462 loc,13473 loc,
13463 TreatIterator::JSONIQ_OBJECT_UPDATE_CONTENT, // JNUP001913474 TREAT_JSONIQ_OBJECT_UPDATE_CONTENT, // JNUP0019
13464 NULL);13475 NULL);
1346513476
13466 std::vector<expr*> args(2);13477 std::vector<expr*> args(2);
13467 args[0] = targetExpr;13478 args[0] = targetExpr;
13468 args[1] = theExprManager->create_json_object_expr(13479 args[1] = CREATE(json_object)(theRootSctx, theUDF, loc, contentExpr, false);
13469 theRootSctx,
13470 theUDF,
13471 loc,
13472 contentExpr,
13473 false);
1347413480
13475 expr* updExpr = theExprManager->13481 expr* updExpr = CREATE(fo)(theRootSctx,
13476 create_fo_expr(theRootSctx, theUDF,13482 theUDF,
13477 loc,13483 loc,
13478 BUILTIN_FUNC(OP_ZORBA_JSON_OBJECT_INSERT_2),13484 BUILTIN_FUNC(OP_ZORBA_JSON_OBJECT_INSERT_2),
13479 args);13485 args);
1348013486
13481 push_nodestack(updExpr);13487 push_nodestack(updExpr);
13482#endif13488#endif
@@ -13510,12 +13516,12 @@
1351013516
13511 posExpr = wrap_in_type_promotion(posExpr,13517 posExpr = wrap_in_type_promotion(posExpr,
13512 rtm.INTEGER_TYPE_ONE,13518 rtm.INTEGER_TYPE_ONE,
13513 PromoteIterator::JSONIQ_ARRAY_SELECTOR); // JNUP000713519 PROMOTE_JSONIQ_ARRAY_SELECTOR); // JNUP0007
1351413520
13515 targetExpr = wrap_in_type_match(targetExpr,13521 targetExpr = wrap_in_type_match(targetExpr,
13516 rtm.JSON_ARRAY_TYPE_ONE,13522 rtm.JSON_ARRAY_TYPE_ONE,
13517 loc,13523 loc,
13518 TreatIterator::JSONIQ_ARRAY_UPDATE_TARGET, // JNUP000813524 TREAT_JSONIQ_ARRAY_UPDATE_TARGET, // JNUP0008
13519 NULL);13525 NULL);
1352013526
13521 std::vector<expr*> args(3);13527 std::vector<expr*> args(3);
@@ -13560,15 +13566,15 @@
13560 targetExpr = wrap_in_type_match(targetExpr,13566 targetExpr = wrap_in_type_match(targetExpr,
13561 theRTM.JSON_ARRAY_TYPE_ONE,13567 theRTM.JSON_ARRAY_TYPE_ONE,
13562 loc,13568 loc,
13563 TreatIterator::JSONIQ_ARRAY_UPDATE_TARGET, // JNUP000813569 TREAT_JSONIQ_ARRAY_UPDATE_TARGET, // JNUP0008
13564 NULL);13570 NULL);
1356513571
13566 fo_expr* updExpr = theExprManager->13572 fo_expr* updExpr = CREATE(fo)(theRootSctx,
13567 create_fo_expr(theRootSctx, theUDF,13573 theUDF,
13568 loc,13574 loc,
13569 BUILTIN_FUNC(OP_ZORBA_JSON_ARRAY_APPEND_2),13575 BUILTIN_FUNC(OP_ZORBA_JSON_ARRAY_APPEND_2),
13570 targetExpr,13576 targetExpr,
13571 contentExpr);13577 contentExpr);
1357213578
13573 normalize_fo(updExpr);13579 normalize_fo(updExpr);
1357413580
@@ -13610,13 +13616,13 @@
1361013616
13611 selExpr = wrap_in_type_promotion(selExpr,13617 selExpr = wrap_in_type_promotion(selExpr,
13612 theRTM.ANY_ATOMIC_TYPE_ONE,13618 theRTM.ANY_ATOMIC_TYPE_ONE,
13613 PromoteIterator::JSONIQ_SELECTOR, // JNUP000713619 PROMOTE_JSONIQ_SELECTOR, // JNUP0007
13614 NULL);13620 NULL);
1361513621
13616 targetExpr = wrap_in_type_match(targetExpr,13622 targetExpr = wrap_in_type_match(targetExpr,
13617 theRTM.JSON_ITEM_TYPE_ONE,13623 theRTM.JSON_ITEM_TYPE_ONE,
13618 loc,13624 loc,
13619 TreatIterator::JSONIQ_UPDATE_TARGET, // JNUP000813625 TREAT_JSONIQ_UPDATE_TARGET, // JNUP0008
13620 NULL);13626 NULL);
1362113627
13622 fo_expr* updExpr = theExprManager->13628 fo_expr* updExpr = theExprManager->
@@ -13658,12 +13664,12 @@
13658 args[0] = wrap_in_type_match(targetExpr,13664 args[0] = wrap_in_type_match(targetExpr,
13659 theRTM.JSON_ITEM_TYPE_ONE,13665 theRTM.JSON_ITEM_TYPE_ONE,
13660 loc,13666 loc,
13661 TreatIterator::JSONIQ_UPDATE_TARGET, // JNUP000813667 TREAT_JSONIQ_UPDATE_TARGET, // JNUP0008
13662 NULL);13668 NULL);
1366313669
13664 args[1] = wrap_in_type_promotion(selExpr,13670 args[1] = wrap_in_type_promotion(selExpr,
13665 theRTM.ANY_ATOMIC_TYPE_ONE,13671 theRTM.ANY_ATOMIC_TYPE_ONE,
13666 PromoteIterator::JSONIQ_SELECTOR, // JNUP000713672 PROMOTE_JSONIQ_SELECTOR, // JNUP0007
13667 NULL);13673 NULL);
1366813674
13669 args[2] = theExprManager->create_fo_expr(theRootSctx, theUDF,13675 args[2] = theExprManager->create_fo_expr(theRootSctx, theUDF,
@@ -13709,22 +13715,22 @@
13709 args[0] = wrap_in_type_match(targetExpr,13715 args[0] = wrap_in_type_match(targetExpr,
13710 theRTM.JSON_OBJECT_TYPE_ONE,13716 theRTM.JSON_OBJECT_TYPE_ONE,
13711 loc,13717 loc,
13712 TreatIterator::JSONIQ_OBJECT_UPDATE_TARGET, // JNUP000813718 TREAT_JSONIQ_OBJECT_UPDATE_TARGET, // JNUP0008
13713 NULL);13719 NULL);
1371413720
13715 args[1] = wrap_in_type_promotion(nameExpr,13721 args[1] = wrap_in_type_promotion(nameExpr,
13716 theRTM.STRING_TYPE_ONE,13722 theRTM.STRING_TYPE_ONE,
13717 PromoteIterator::JSONIQ_OBJECT_SELECTOR); // JNUP000713723 PROMOTE_JSONIQ_OBJECT_SELECTOR); // JNUP0007
1371813724
13719 args[2] = wrap_in_type_promotion(newNameExpr,13725 args[2] = wrap_in_type_promotion(newNameExpr,
13720 theRTM.STRING_TYPE_ONE,13726 theRTM.STRING_TYPE_ONE,
13721 PromoteIterator::JSONIQ_OBJECT_SELECTOR); // JNUP000713727 PROMOTE_JSONIQ_OBJECT_SELECTOR); // JNUP0007
1372213728
13723 fo_expr* updExpr = theExprManager->13729 fo_expr* updExpr = CREATE(fo)(theRootSctx,
13724 create_fo_expr(theRootSctx, theUDF,13730 theUDF,
13725 loc,13731 loc,
13726 BUILTIN_FUNC(OP_ZORBA_JSON_RENAME_3),13732 BUILTIN_FUNC(OP_ZORBA_JSON_RENAME_3),
13727 args);13733 args);
1372813734
13729 push_nodestack(updExpr);13735 push_nodestack(updExpr);
13730#endif13736#endif
@@ -14142,7 +14148,7 @@
14142 push_nodestack( wrap_in_type_match(e,14148 push_nodestack( wrap_in_type_match(e,
14143 theRTM.ANY_NODE_TYPE_STAR,14149 theRTM.ANY_NODE_TYPE_STAR,
14144 e->get_loc(),14150 e->get_loc(),
14145 TreatIterator::TYPE_MATCH));14151 TREAT_TYPE_MATCH));
14146#endif /* ZORBA_NO_FULL_TEXT */14152#endif /* ZORBA_NO_FULL_TEXT */
14147}14153}
1414814154
@@ -14319,12 +14325,12 @@
14319 if ( e1 ) {14325 if ( e1 ) {
14320 e1 = wrap_in_type_promotion(e1,14326 e1 = wrap_in_type_promotion(e1,
14321 theRTM.INTEGER_TYPE_ONE,14327 theRTM.INTEGER_TYPE_ONE,
14322 PromoteIterator::TYPE_PROMOTION);14328 PROMOTE_TYPE_PROMOTION);
14323 }14329 }
14324 if ( e2 ) {14330 if ( e2 ) {
14325 e2 = wrap_in_type_promotion(e2,14331 e2 = wrap_in_type_promotion(e2,
14326 theRTM.INTEGER_TYPE_ONE,14332 theRTM.INTEGER_TYPE_ONE,
14327 PromoteIterator::TYPE_PROMOTION);14333 PROMOTE_TYPE_PROMOTION);
14328 }14334 }
1432914335
14330 ftrange *const r = new ftrange( loc, v.get_mode(), e1, e2 );14336 ftrange *const r = new ftrange( loc, v.get_mode(), e1, e2 );
@@ -14584,7 +14590,7 @@
14584 expr* e( pop_nodestack() );14590 expr* e( pop_nodestack() );
14585 e = wrap_in_type_promotion(e,14591 e = wrap_in_type_promotion(e,
14586 theRTM.DOUBLE_TYPE_ONE,14592 theRTM.DOUBLE_TYPE_ONE,
14587 PromoteIterator::TYPE_PROMOTION);14593 PROMOTE_TYPE_PROMOTION);
14588 push_ftstack( new ftweight( loc, e ) );14594 push_ftstack( new ftweight( loc, e ) );
14589#endif /* ZORBA_NO_FULL_TEXT */14595#endif /* ZORBA_NO_FULL_TEXT */
14590}14596}
@@ -14620,7 +14626,7 @@
14620 expr* e( pop_nodestack() );14626 expr* e( pop_nodestack() );
14621 e = wrap_in_type_promotion(e,14627 e = wrap_in_type_promotion(e,
14622 theRTM.INTEGER_TYPE_ONE,14628 theRTM.INTEGER_TYPE_ONE,
14623 PromoteIterator::TYPE_PROMOTION);14629 PROMOTE_TYPE_PROMOTION);
14624 push_ftstack( new ftwindow_filter( loc, e, v.get_unit()->get_unit() ) );14630 push_ftstack( new ftwindow_filter( loc, e, v.get_unit()->get_unit() ) );
14625#endif /* ZORBA_NO_FULL_TEXT */14631#endif /* ZORBA_NO_FULL_TEXT */
14626}14632}
@@ -14637,7 +14643,7 @@
14637 expr* e( pop_nodestack() );14643 expr* e( pop_nodestack() );
14638 e = wrap_in_type_promotion(e,14644 e = wrap_in_type_promotion(e,
14639 theRTM.STRING_TYPE_STAR,14645 theRTM.STRING_TYPE_STAR,
14640 PromoteIterator::TYPE_PROMOTION);14646 PROMOTE_TYPE_PROMOTION);
14641 push_ftstack( new ftwords( loc, e, v.get_any_all_option()->get_option() ) );14647 push_ftstack( new ftwords( loc, e, v.get_any_all_option()->get_option() ) );
14642#endif /* ZORBA_NO_FULL_TEXT */14648#endif /* ZORBA_NO_FULL_TEXT */
14643}14649}
1464414650
=== modified file 'src/compiler/xqddf/value_index.cpp'
--- src/compiler/xqddf/value_index.cpp 2012-10-22 15:10:23 +0000
+++ src/compiler/xqddf/value_index.cpp 2012-10-24 11:34:21 +0000
@@ -29,6 +29,7 @@
29#include "compiler/expression/script_exprs.h"29#include "compiler/expression/script_exprs.h"
30#include "compiler/expression/expr.h"30#include "compiler/expression/expr.h"
31#include "compiler/expression/expr_iter.h"31#include "compiler/expression/expr_iter.h"
32#include "compiler/expression/expr_manager.h"
32#include "compiler/codegen/plan_visitor.h"33#include "compiler/codegen/plan_visitor.h"
3334
34#include "runtime/base/plan_iterator.h"35#include "runtime/base/plan_iterator.h"
3536
=== modified file 'src/functions/func_booleans_impl.cpp'
--- src/functions/func_booleans_impl.cpp 2012-10-10 13:05:50 +0000
+++ src/functions/func_booleans_impl.cpp 2012-10-24 11:34:21 +0000
@@ -47,10 +47,9 @@
47 :47 :
48 function(sig, kind)48 function(sig, kind)
49 {49 {
50 setFlag(FunctionConsts::IsComparison);
50 }51 }
5152
52 bool isComparisonFunction() const { return true; }
53
54 virtual const char* comparison_name() const { return ""; }53 virtual const char* comparison_name() const { return ""; }
5554
56 virtual function* toValueComp(static_context *) const { return NULL; }55 virtual function* toValueComp(static_context *) const { return NULL; }
5756
=== modified file 'src/functions/func_collections_impl.cpp'
--- src/functions/func_collections_impl.cpp 2012-10-16 13:08:47 +0000
+++ src/functions/func_collections_impl.cpp 2012-10-24 11:34:21 +0000
@@ -25,6 +25,9 @@
25#include "compiler/expression/pragma.h"25#include "compiler/expression/pragma.h"
26#include "compiler/api/compilercb.h"26#include "compiler/api/compilercb.h"
2727
28#include "zorbamisc/ns_consts.h"
29
30
28namespace zorba31namespace zorba
29{32{
3033
3134
=== modified file 'src/functions/func_sequences_impl.cpp'
--- src/functions/func_sequences_impl.cpp 2012-10-15 13:35:59 +0000
+++ src/functions/func_sequences_impl.cpp 2012-10-24 11:34:21 +0000
@@ -32,6 +32,7 @@
3232
33#include "compiler/expression/expr.h"33#include "compiler/expression/expr.h"
34#include "compiler/expression/fo_expr.h"34#include "compiler/expression/fo_expr.h"
35#include "compiler/expression/var_expr.h"
35#include "compiler/expression/path_expr.h"36#include "compiler/expression/path_expr.h"
3637
37#include "types/typeops.h"38#include "types/typeops.h"
@@ -43,6 +44,148 @@
43/*******************************************************************************44/*******************************************************************************
4445
45********************************************************************************/46********************************************************************************/
47xqtref_t fn_unordered::getReturnType(const fo_expr* caller) const
48{
49 return caller->get_arg(0)->get_return_type();
50}
51
52
53BoolAnnotationValue fn_unordered::ignoresSortedNodes(expr* fo, csize input) const
54{
55 return ANNOTATION_TRUE;
56}
57
58
59BoolAnnotationValue fn_unordered::ignoresDuplicateNodes(expr* fo, csize input) const
60{
61 return fo->getIgnoresDuplicateNodes();
62}
63
64
65PlanIter_t fn_unordered::codegen(
66 CompilerCB* /*cb*/,
67 static_context* sctx,
68 const QueryLoc& loc,
69 std::vector<PlanIter_t>& argv,
70 expr& ) const
71{
72 return argv[0];
73}
74
75
76/*******************************************************************************
77
78********************************************************************************/
79xqtref_t fn_exactly_one_noraise::getReturnType(const fo_expr* caller) const
80{
81 TypeManager* tm = caller->get_type_manager();
82
83 xqtref_t srcType = caller->get_arg(0)->get_return_type();
84
85 if (theRaiseError)
86 return TypeOps::prime_type(tm, *srcType);
87 else
88 return function::getReturnType(caller);
89}
90
91
92PlanIter_t fn_exactly_one_noraise::codegen(
93 CompilerCB* aCb,
94 static_context* aSctx,
95 const QueryLoc& aLoc,
96 std::vector<PlanIter_t>& aArgs,
97 expr& aAnn) const
98{
99 return new FnExactlyOneIterator(aSctx,
100 aLoc,
101 aArgs,
102 theRaiseError,
103 testFlag(FunctionConsts::DoDistinct));
104}
105
106
107/*******************************************************************************
108
109********************************************************************************/
110PlanIter_t fn_union::codegen(
111 CompilerCB* /*cb*/,
112 static_context* sctx,
113 const QueryLoc& loc,
114 std::vector<PlanIter_t>& argv,
115 expr& ann) const
116{
117 return new FnConcatIterator(sctx, loc, argv);
118}
119
120
121/*******************************************************************************
122
123********************************************************************************/
124BoolAnnotationValue fn_intersect::ignoresSortedNodes(expr* fo, csize input) const
125{
126 if (input == 0)
127 return fo->getIgnoresSortedNodes();
128
129 return ANNOTATION_TRUE;
130}
131
132
133BoolAnnotationValue fn_intersect::ignoresDuplicateNodes(expr* fo, csize input) const
134{
135 if (input == 0)
136 return fo->getIgnoresDuplicateNodes();
137
138 return ANNOTATION_TRUE;
139}
140
141
142PlanIter_t fn_intersect::codegen(
143 CompilerCB* /*cb*/,
144 static_context* sctx,
145 const QueryLoc& loc,
146 std::vector<PlanIter_t>& argv,
147 expr& ann) const
148{
149 return new HashSemiJoinIterator(sctx, loc, argv);
150}
151
152
153/*******************************************************************************
154
155********************************************************************************/
156BoolAnnotationValue fn_except::ignoresSortedNodes(expr* fo, csize input) const
157{
158 if (input == 0)
159 return fo->getIgnoresSortedNodes();
160
161 return ANNOTATION_TRUE;
162}
163
164
165BoolAnnotationValue fn_except::ignoresDuplicateNodes(expr* fo, csize input) const
166{
167 if (input == 0)
168 return fo->getIgnoresDuplicateNodes();
169
170 return ANNOTATION_TRUE;
171}
172
173
174PlanIter_t fn_except::codegen(
175 CompilerCB* /*cb*/,
176 static_context* sctx,
177 const QueryLoc& loc,
178 std::vector<PlanIter_t>& argv,
179 expr& ann) const
180{
181 // TODO: use SortAntiJoinIterator when available (trac ticket 254)
182 return new HashSemiJoinIterator(sctx, loc, argv, true);
183}
184
185
186/*******************************************************************************
187
188********************************************************************************/
46xqtref_t op_concatenate::getReturnType(const fo_expr* caller) const189xqtref_t op_concatenate::getReturnType(const fo_expr* caller) const
47{190{
48 TypeManager* tm = caller->get_type_manager();191 TypeManager* tm = caller->get_type_manager();
@@ -608,32 +751,6 @@
608/*******************************************************************************751/*******************************************************************************
609752
610********************************************************************************/753********************************************************************************/
611BoolAnnotationValue fn_unordered::ignoresSortedNodes(expr* fo, csize input) const
612{
613 return ANNOTATION_TRUE;
614}
615
616
617BoolAnnotationValue fn_unordered::ignoresDuplicateNodes(expr* fo, csize input) const
618{
619 return fo->getIgnoresDuplicateNodes();
620}
621
622
623PlanIter_t fn_unordered::codegen(
624 CompilerCB* /*cb*/,
625 static_context* sctx,
626 const QueryLoc& loc,
627 std::vector<PlanIter_t>& argv,
628 expr& ) const
629{
630 return argv[0];
631}
632
633
634/*******************************************************************************
635
636********************************************************************************/
637xqtref_t fn_zero_or_one::getReturnType(const fo_expr* caller) const754xqtref_t fn_zero_or_one::getReturnType(const fo_expr* caller) const
638{755{
639 TypeManager* tm = caller->get_type_manager();756 TypeManager* tm = caller->get_type_manager();
@@ -693,37 +810,6 @@
693/*******************************************************************************810/*******************************************************************************
694811
695********************************************************************************/812********************************************************************************/
696xqtref_t fn_exactly_one_noraise::getReturnType(const fo_expr* caller) const
697{
698 TypeManager* tm = caller->get_type_manager();
699
700 xqtref_t srcType = caller->get_arg(0)->get_return_type();
701
702 if (theRaiseError)
703 return TypeOps::prime_type(tm, *srcType);
704 else
705 return function::getReturnType(caller);
706}
707
708
709PlanIter_t fn_exactly_one_noraise::codegen(
710 CompilerCB* aCb,
711 static_context* aSctx,
712 const QueryLoc& aLoc,
713 std::vector<PlanIter_t>& aArgs,
714 expr& aAnn) const
715{
716 return new FnExactlyOneIterator(aSctx,
717 aLoc,
718 aArgs,
719 theRaiseError,
720 testFlag(FunctionConsts::DoDistinct));
721}
722
723
724/*******************************************************************************
725
726********************************************************************************/
727bool fn_deep_equal::mustCopyInputNodes(expr* fo, csize producer) const813bool fn_deep_equal::mustCopyInputNodes(expr* fo, csize producer) const
728{814{
729 return (producer < 2 &&815 return (producer < 2 &&
@@ -734,60 +820,6 @@
734/*******************************************************************************820/*******************************************************************************
735821
736********************************************************************************/822********************************************************************************/
737PlanIter_t fn_union::codegen(
738 CompilerCB* /*cb*/,
739 static_context* sctx,
740 const QueryLoc& loc,
741 std::vector<PlanIter_t>& argv,
742 expr& ann) const
743{
744 return new FnConcatIterator(sctx, loc, argv);
745}
746
747
748/*******************************************************************************
749
750********************************************************************************/
751PlanIter_t fn_intersect::codegen(
752 CompilerCB* /*cb*/,
753 static_context* sctx,
754 const QueryLoc& loc,
755 std::vector<PlanIter_t>& argv,
756 expr& ann) const
757{
758#if 0 // we can't access PRODUCES_* from the inputs, must rethink
759 bool distinct = ann.get_annotation (Annotations::IGNORES_DUP_NODES) != TSVAnnotationValue::TRUE_VAL;
760 bool sort = ann.get_annotation (Annotations::IGNORES_SORTED_NODES) != TSVAnnotationValue::TRUE_VAL;
761
762 std::vector<PlanIter_t> inputs;
763 for (std::vector<PlanIter_t>::iterator i = argv.begin ();
764 i != argv.end (); i++)
765 inputs.push_back (new NodeSortIterator (loc, *i, true, distinct, false));
766 return new SortSemiJoinIterator(loc, inputs);
767#endif
768
769 return new HashSemiJoinIterator(sctx, loc, argv);
770}
771
772
773/*******************************************************************************
774
775********************************************************************************/
776PlanIter_t fn_except::codegen(
777 CompilerCB* /*cb*/,
778 static_context* sctx,
779 const QueryLoc& loc,
780 std::vector<PlanIter_t>& argv,
781 expr& ann) const
782{
783 // TODO: use SortAntiJoinIterator when available (trac ticket 254)
784 return new HashSemiJoinIterator(sctx, loc, argv, true);
785}
786
787
788/*******************************************************************************
789
790********************************************************************************/
791BoolAnnotationValue fn_count::ignoresSortedNodes(expr* fo, csize input) const823BoolAnnotationValue fn_count::ignoresSortedNodes(expr* fo, csize input) const
792{824{
793 return ANNOTATION_TRUE;825 return ANNOTATION_TRUE;
794826
=== modified file 'src/functions/func_sequences_impl.h'
--- src/functions/func_sequences_impl.h 2012-09-19 21:16:15 +0000
+++ src/functions/func_sequences_impl.h 2012-10-24 11:34:21 +0000
@@ -21,9 +21,8 @@
2121
22#include "functions/function_impl.h"22#include "functions/function_impl.h"
2323
24#include "compiler/expression/fo_expr.h"24namespace zorba
2525{
26namespace zorba {
2726
28void populate_context_sequences_impl(static_context* sctx);27void populate_context_sequences_impl(static_context* sctx);
2928
@@ -40,10 +39,7 @@
40 {39 {
41 }40 }
4241
43 xqtref_t getReturnType(const fo_expr* caller) const42 xqtref_t getReturnType(const fo_expr* caller) const;
44 {
45 return caller->get_arg(0)->get_return_type();
46 }
4743
48 bool isMap(csize input) const44 bool isMap(csize input) const
49 {45 {
@@ -206,21 +202,9 @@
206 return producer == 0;202 return producer == 0;
207 }203 }
208204
209 BoolAnnotationValue ignoresSortedNodes(expr* fo, csize input) const 205 BoolAnnotationValue ignoresSortedNodes(expr* fo, csize input) const;
210 {206
211 if (input == 0)207 BoolAnnotationValue ignoresDuplicateNodes(expr* fo, csize input) const;
212 return fo->getIgnoresSortedNodes();
213
214 return ANNOTATION_TRUE;
215 }
216
217 BoolAnnotationValue ignoresDuplicateNodes(expr* fo, csize input) const
218 {
219 if (input == 0)
220 return fo->getIgnoresDuplicateNodes();
221
222 return ANNOTATION_TRUE;
223 }
224208
225 bool propagatesInputNodes(expr* fo, csize input) const209 bool propagatesInputNodes(expr* fo, csize input) const
226 {210 {
@@ -258,21 +242,9 @@
258 return producer == 0;242 return producer == 0;
259 }243 }
260244
261 BoolAnnotationValue ignoresSortedNodes(expr* fo, csize input) const 245 BoolAnnotationValue ignoresSortedNodes(expr* fo, csize input) const;
262 {246
263 if (input == 0)247 BoolAnnotationValue ignoresDuplicateNodes(expr* fo, csize input) const;
264 return fo->getIgnoresSortedNodes();
265
266 return ANNOTATION_TRUE;
267 }
268
269 BoolAnnotationValue ignoresDuplicateNodes(expr* fo, csize input) const
270 {
271 if (input == 0)
272 return fo->getIgnoresDuplicateNodes();
273
274 return ANNOTATION_TRUE;
275 }
276248
277 bool propagatesInputNodes(expr* fo, csize input) const249 bool propagatesInputNodes(expr* fo, csize input) const
278 {250 {
279251
=== modified file 'src/functions/function.h'
--- src/functions/function.h 2012-10-08 12:09:36 +0000
+++ src/functions/function.h 2012-10-24 11:34:21 +0000
@@ -145,6 +145,8 @@
145 resetFlag(FunctionConsts::isPrivate);145 resetFlag(FunctionConsts::isPrivate);
146 }146 }
147147
148 bool isComparisonFunction() const { return testFlag(FunctionConsts::IsComparison); }
149
148 bool isDeterministic() const150 bool isDeterministic() const
149 {151 {
150 // Note: For udfs, the flag is set before the udf is optimized (see call152 // Note: For udfs, the flag is set before the udf is optimized (see call
@@ -201,8 +203,6 @@
201 return ArithmeticConsts::UNKNOWN;203 return ArithmeticConsts::UNKNOWN;
202 }204 }
203205
204 virtual bool isComparisonFunction() const { return false; }
205
206 virtual bool isValueComparisonFunction() const { return false; }206 virtual bool isValueComparisonFunction() const { return false; }
207207
208 virtual bool isGeneralComparisonFunction() const { return false; }208 virtual bool isGeneralComparisonFunction() const { return false; }
209209
=== modified file 'src/functions/function_consts.h'
--- src/functions/function_consts.h 2012-10-20 21:29:37 +0000
+++ src/functions/function_consts.h 2012-10-24 11:34:21 +0000
@@ -271,7 +271,8 @@
271 mustCopyInputNodes = 128,271 mustCopyInputNodes = 128,
272 AccessesDynCtx = 256,272 AccessesDynCtx = 256,
273 ConstructsNodes = 512,273 ConstructsNodes = 512,
274 DereferencesNodes = 1024274 DereferencesNodes = 1024,
275 IsComparison = 2048
275} AnnotationFlags;276} AnnotationFlags;
276277
277};278};
278279
=== modified file 'src/functions/udf.h'
--- src/functions/udf.h 2012-10-20 21:29:37 +0000
+++ src/functions/udf.h 2012-10-24 11:34:21 +0000
@@ -19,12 +19,14 @@
1919
20#include "functions/function.h"20#include "functions/function.h"
2121
22#include "compiler/expression/expr_base.h"22//#include "compiler/expression/expr_base.h"
2323
2424
25namespace zorba25namespace zorba
26{26{
2727
28 class expr;
29
28 namespace store30 namespace store
29 {31 {
30 class Index;32 class Index;
3133
=== modified file 'src/runtime/core/sequencetypes.cpp'
--- src/runtime/core/sequencetypes.cpp 2012-10-08 12:09:36 +0000
+++ src/runtime/core/sequencetypes.cpp 2012-10-24 11:34:21 +0000
@@ -355,7 +355,7 @@
355 const QueryLoc& loc,355 const QueryLoc& loc,
356 PlanIter_t& child,356 PlanIter_t& child,
357 const xqtref_t& promoteType,357 const xqtref_t& promoteType,
358 ErrorKind err,358 PromoteErrorKind err,
359 store::Item_t qname)359 store::Item_t qname)
360 :360 :
361 UnaryBaseIterator<PromoteIterator, PlanIteratorState>(sctx, loc, child),361 UnaryBaseIterator<PromoteIterator, PlanIteratorState>(sctx, loc, child),
@@ -379,7 +379,7 @@
379379
380 ar & thePromoteType;380 ar & thePromoteType;
381 SERIALIZE_ENUM(TypeConstants::quantifier_t, theQuantifier);381 SERIALIZE_ENUM(TypeConstants::quantifier_t, theQuantifier);
382 SERIALIZE_ENUM(ErrorKind, theErrorKind);382 SERIALIZE_ENUM(PromoteErrorKind, theErrorKind);
383 ar & theQName;383 ar & theQName;
384}384}
385385
@@ -463,7 +463,7 @@
463463
464 switch (theErrorKind)464 switch (theErrorKind)
465 {465 {
466 case FUNC_RETURN:466 case PROMOTE_FUNC_RETURN:
467 {467 {
468 assert(theQName != NULL);468 assert(theQName != NULL);
469469
@@ -472,7 +472,7 @@
472 valueType, targetType, theQName->getStringValue()));472 valueType, targetType, theQName->getStringValue()));
473 break;473 break;
474 }474 }
475 case FUNC_PARAM:475 case PROMOTE_FUNC_PARAM:
476 {476 {
477 assert(theQName != NULL);477 assert(theQName != NULL);
478478
@@ -481,26 +481,26 @@
481 valueType, targetType, theQName->getStringValue()));481 valueType, targetType, theQName->getStringValue()));
482 break;482 break;
483 }483 }
484 case TYPE_PROMOTION:484 case PROMOTE_TYPE_PROMOTION:
485 {485 {
486 RAISE_ERROR(err::XPTY0004, loc, 486 RAISE_ERROR(err::XPTY0004, loc,
487 ERROR_PARAMS(ZED(XPTY0004_TypePromotion), valueType, targetType));487 ERROR_PARAMS(ZED(XPTY0004_TypePromotion), valueType, targetType));
488 break;488 break;
489 }489 }
490#ifdef ZORBA_WITH_JSON490#ifdef ZORBA_WITH_JSON
491 case JSONIQ_ARRAY_SELECTOR:491 case PROMOTE_JSONIQ_ARRAY_SELECTOR:
492 {492 {
493 RAISE_ERROR(jerr::JNUP0007, loc,493 RAISE_ERROR(jerr::JNUP0007, loc,
494 ERROR_PARAMS(ZED(JNUP0007_Array), valueType));494 ERROR_PARAMS(ZED(JNUP0007_Array), valueType));
495 break;495 break;
496 }496 }
497 case JSONIQ_OBJECT_SELECTOR:497 case PROMOTE_JSONIQ_OBJECT_SELECTOR:
498 {498 {
499 RAISE_ERROR(jerr::JNUP0007, loc,499 RAISE_ERROR(jerr::JNUP0007, loc,
500 ERROR_PARAMS(ZED(JNUP0007_Object), valueType));500 ERROR_PARAMS(ZED(JNUP0007_Object), valueType));
501 break;501 break;
502 }502 }
503 case JSONIQ_SELECTOR:503 case PROMOTE_JSONIQ_SELECTOR:
504 {504 {
505 RAISE_ERROR(jerr::JNUP0007, loc,505 RAISE_ERROR(jerr::JNUP0007, loc,
506 ERROR_PARAMS(ZED(JNUP0007_ObjectArray), valueType));506 ERROR_PARAMS(ZED(JNUP0007_ObjectArray), valueType));
@@ -528,7 +528,7 @@
528 PlanIter_t& child,528 PlanIter_t& child,
529 const xqtref_t& treatType,529 const xqtref_t& treatType,
530 bool checkPrime,530 bool checkPrime,
531 ErrorKind errorKind,531 TreatErrorKind errorKind,
532 store::Item_t qname)532 store::Item_t qname)
533 :533 :
534 UnaryBaseIterator<TreatIterator, PlanIteratorState>(sctx, loc, child),534 UnaryBaseIterator<TreatIterator, PlanIteratorState>(sctx, loc, child),
@@ -549,7 +549,7 @@
549 ar & theTreatType;549 ar & theTreatType;
550 SERIALIZE_ENUM(TypeConstants::quantifier_t, theQuantifier);550 SERIALIZE_ENUM(TypeConstants::quantifier_t, theQuantifier);
551 ar & theCheckPrime;551 ar & theCheckPrime;
552 SERIALIZE_ENUM(ErrorKind, theErrorKind);552 SERIALIZE_ENUM(TreatErrorKind, theErrorKind);
553 ar & theQName;553 ar & theQName;
554}554}
555555
@@ -665,7 +665,7 @@
665665
666 switch (theErrorKind)666 switch (theErrorKind)
667 {667 {
668 case FUNC_RETURN:668 case TREAT_FUNC_RETURN:
669 {669 {
670 assert(theQName != NULL);670 assert(theQName != NULL);
671671
@@ -674,7 +674,7 @@
674 valueType, targetType, theQName->getStringValue()));674 valueType, targetType, theQName->getStringValue()));
675 break;675 break;
676 }676 }
677 case FUNC_PARAM:677 case TREAT_FUNC_PARAM:
678 {678 {
679 assert(theQName != NULL);679 assert(theQName != NULL);
680680
@@ -683,7 +683,7 @@
683 valueType, targetType, theQName->getStringValue()));683 valueType, targetType, theQName->getStringValue()));
684 break;684 break;
685 }685 }
686 case TYPE_MATCH:686 case TREAT_TYPE_MATCH:
687 {687 {
688 RAISE_ERROR(err::XPTY0004, loc, 688 RAISE_ERROR(err::XPTY0004, loc,
689 ERROR_PARAMS(ZED(XPTY0004_TypeMatch), valueType, targetType));689 ERROR_PARAMS(ZED(XPTY0004_TypeMatch), valueType, targetType));
@@ -694,65 +694,65 @@
694 RAISE_ERROR(err::XPDY0050, loc, ERROR_PARAMS(valueType, targetType));694 RAISE_ERROR(err::XPDY0050, loc, ERROR_PARAMS(valueType, targetType));
695 break;695 break;
696 }696 }
697 case INDEX_DOMAIN:697 case TREAT_INDEX_DOMAIN:
698 {698 {
699 RAISE_ERROR(zerr::ZDTY0010_INDEX_DOMAIN_TYPE_ERROR, loc,699 RAISE_ERROR(zerr::ZDTY0010_INDEX_DOMAIN_TYPE_ERROR, loc,
700 ERROR_PARAMS(theQName->getStringValue()));700 ERROR_PARAMS(theQName->getStringValue()));
701 break;701 break;
702 }702 }
703 case INDEX_KEY:703 case TREAT_INDEX_KEY:
704 {704 {
705 RAISE_ERROR(zerr::ZDTY0011_INDEX_KEY_TYPE_ERROR, loc,705 RAISE_ERROR(zerr::ZDTY0011_INDEX_KEY_TYPE_ERROR, loc,
706 ERROR_PARAMS(valueType, targetType, theQName->getStringValue()));706 ERROR_PARAMS(valueType, targetType, theQName->getStringValue()));
707 break;707 break;
708 }708 }
709 case PATH_STEP:709 case TREAT_PATH_STEP:
710 {710 {
711 RAISE_ERROR_NO_PARAMS(err::XPTY0019, loc);711 RAISE_ERROR_NO_PARAMS(err::XPTY0019, loc);
712 break;712 break;
713 }713 }
714 case PATH_DOT:714 case TREAT_PATH_DOT:
715 {715 {
716 RAISE_ERROR_NO_PARAMS(err::XPTY0020, loc);716 RAISE_ERROR_NO_PARAMS(err::XPTY0020, loc);
717 break;717 break;
718 }718 }
719 case MULTI_VALUED_GROUPING_KEY:719 case TREAT_MULTI_VALUED_GROUPING_KEY:
720 {720 {
721 RAISE_ERROR(err::XPTY0004, loc,721 RAISE_ERROR(err::XPTY0004, loc,
722 ERROR_PARAMS(ZED(XPTY0004_MultiValuedGroupingKey)));722 ERROR_PARAMS(ZED(XPTY0004_MultiValuedGroupingKey)));
723 break;723 break;
724 }724 }
725#ifdef ZORBA_WITH_JSON725#ifdef ZORBA_WITH_JSON
726 case JSONIQ_VALUE:726 case TREAT_JSONIQ_VALUE:
727 {727 {
728 RAISE_ERROR_NO_PARAMS(jerr::JNTY0002, loc);728 RAISE_ERROR_NO_PARAMS(jerr::JNTY0002, loc);
729 break;729 break;
730 }730 }
731 case JSONIQ_UPDATE_TARGET:731 case TREAT_JSONIQ_UPDATE_TARGET:
732 {732 {
733 RAISE_ERROR(jerr::JNUP0008, loc,733 RAISE_ERROR(jerr::JNUP0008, loc,
734 ERROR_PARAMS(ZED(JNUP0008_ObjectArray), valueType));734 ERROR_PARAMS(ZED(JNUP0008_ObjectArray), valueType));
735 break;735 break;
736 }736 }
737 case JSONIQ_OBJECT_UPDATE_TARGET:737 case TREAT_JSONIQ_OBJECT_UPDATE_TARGET:
738 {738 {
739 RAISE_ERROR(jerr::JNUP0008, loc,739 RAISE_ERROR(jerr::JNUP0008, loc,
740 ERROR_PARAMS(ZED(JNUP0008_Object), valueType));740 ERROR_PARAMS(ZED(JNUP0008_Object), valueType));
741 break;741 break;
742 }742 }
743 case JSONIQ_OBJECT_UPDATE_CONTENT:743 case TREAT_JSONIQ_OBJECT_UPDATE_CONTENT:
744 {744 {
745 RAISE_ERROR(jerr::JNUP0019, loc,745 RAISE_ERROR(jerr::JNUP0019, loc,
746 ERROR_PARAMS(ZED(JNUP0019), valueType));746 ERROR_PARAMS(ZED(JNUP0019), valueType));
747 break;747 break;
748 }748 }
749 case JSONIQ_ARRAY_UPDATE_TARGET:749 case TREAT_JSONIQ_ARRAY_UPDATE_TARGET:
750 {750 {
751 RAISE_ERROR(jerr::JNUP0008, loc,751 RAISE_ERROR(jerr::JNUP0008, loc,
752 ERROR_PARAMS(ZED(JNUP0008_Array), valueType));752 ERROR_PARAMS(ZED(JNUP0008_Array), valueType));
753 break;753 break;
754 }754 }
755 case JSONIQ_OBJECT_UPDATE_VALUE:755 case TREAT_JSONIQ_OBJECT_UPDATE_VALUE:
756 {756 {
757 RAISE_ERROR_NO_PARAMS(jerr::JNUP0017, loc);757 RAISE_ERROR_NO_PARAMS(jerr::JNUP0017, loc);
758 break;758 break;
759759
=== modified file 'src/runtime/core/sequencetypes.h'
--- src/runtime/core/sequencetypes.h 2012-10-08 12:09:36 +0000
+++ src/runtime/core/sequencetypes.h 2012-10-24 11:34:21 +0000
@@ -24,6 +24,8 @@
2424
25#include "types/typeconstants.h"25#include "types/typeconstants.h"
2626
27#include "compiler/expression/expr_consts.h"
28
27namespace zorba 29namespace zorba
28{30{
2931
@@ -143,21 +145,10 @@
143{145{
144 friend class PrinterVisitor;146 friend class PrinterVisitor;
145147
146public:
147 typedef enum
148 {
149 FUNC_RETURN,
150 FUNC_PARAM,
151 TYPE_PROMOTION,
152 JSONIQ_ARRAY_SELECTOR,
153 JSONIQ_OBJECT_SELECTOR,
154 JSONIQ_SELECTOR
155 } ErrorKind;
156
157private:148private:
158 xqtref_t thePromoteType;149 xqtref_t thePromoteType;
159 TypeConstants::quantifier_t theQuantifier;150 TypeConstants::quantifier_t theQuantifier;
160 ErrorKind theErrorKind;151 PromoteErrorKind theErrorKind;
161 store::Item_t theQName; 152 store::Item_t theQName;
162153
163public:154public:
@@ -173,7 +164,7 @@
173 const QueryLoc& loc,164 const QueryLoc& loc,
174 PlanIter_t& child,165 PlanIter_t& child,
175 const xqtref_t& promoteType,166 const xqtref_t& promoteType,
176 ErrorKind err,167 PromoteErrorKind err,
177 store::Item_t qname = NULL);168 store::Item_t qname = NULL);
178169
179 ~PromoteIterator();170 ~PromoteIterator();
@@ -202,31 +193,11 @@
202{193{
203 friend class PrinterVisitor;194 friend class PrinterVisitor;
204195
205public:
206 typedef enum
207 {
208 FUNC_RETURN,
209 FUNC_PARAM,
210 TYPE_MATCH,
211 TREAT_EXPR,
212 INDEX_DOMAIN,
213 INDEX_KEY,
214 PATH_STEP,
215 PATH_DOT,
216 MULTI_VALUED_GROUPING_KEY,
217 JSONIQ_VALUE,
218 JSONIQ_UPDATE_TARGET,
219 JSONIQ_OBJECT_UPDATE_TARGET,
220 JSONIQ_OBJECT_UPDATE_CONTENT,
221 JSONIQ_ARRAY_UPDATE_TARGET,
222 JSONIQ_OBJECT_UPDATE_VALUE
223 } ErrorKind;
224
225private:196private:
226 xqtref_t theTreatType;197 xqtref_t theTreatType;
227 TypeConstants::quantifier_t theQuantifier;198 TypeConstants::quantifier_t theQuantifier;
228 bool theCheckPrime;199 bool theCheckPrime;
229 ErrorKind theErrorKind;200 TreatErrorKind theErrorKind;
230 store::Item_t theQName;201 store::Item_t theQName;
231202
232public:203public:
@@ -243,7 +214,7 @@
243 PlanIter_t& child,214 PlanIter_t& child,
244 const xqtref_t& treatType,215 const xqtref_t& treatType,
245 bool check_prime,216 bool check_prime,
246 ErrorKind errorKind,217 TreatErrorKind errorKind,
247 store::Item_t qname);218 store::Item_t qname);
248219
249 void accept(PlanIterVisitor& v) const;220 void accept(PlanIterVisitor& v) const;
250221
=== modified file 'src/runtime/eval/eval.cpp'
--- src/runtime/eval/eval.cpp 2012-10-12 09:05:54 +0000
+++ src/runtime/eval/eval.cpp 2012-10-24 11:34:21 +0000
@@ -30,6 +30,7 @@
30#include "compiler/api/compilercb.h"30#include "compiler/api/compilercb.h"
31#include "compiler/api/compiler_api.h"31#include "compiler/api/compiler_api.h"
32#include "compiler/expression/var_expr.h"32#include "compiler/expression/var_expr.h"
33#include "compiler/expression/expr_manager.h"
3334
34#include "context/dynamic_context.h"35#include "context/dynamic_context.h"
35#include "context/static_context.h"36#include "context/static_context.h"
3637
=== modified file 'src/runtime/function_item/function_item.cpp'
--- src/runtime/function_item/function_item.cpp 2012-10-09 14:06:08 +0000
+++ src/runtime/function_item/function_item.cpp 2012-10-24 11:34:21 +0000
@@ -21,6 +21,7 @@
2121
22#include "compiler/api/compilercb.h"22#include "compiler/api/compilercb.h"
23#include "compiler/expression/function_item_expr.h"23#include "compiler/expression/function_item_expr.h"
24#include "compiler/expression/expr_manager.h"
2425
25#include "functions/signature.h"26#include "functions/signature.h"
26#include "functions/udf.h"27#include "functions/udf.h"
2728
=== modified file 'src/runtime/json/jsoniq_functions_impl.cpp'
--- src/runtime/json/jsoniq_functions_impl.cpp 2012-10-16 14:30:02 +0000
+++ src/runtime/json/jsoniq_functions_impl.cpp 2012-10-24 11:34:21 +0000
@@ -40,6 +40,7 @@
40#include "zorba/internal/diagnostic.h"40#include "zorba/internal/diagnostic.h"
4141
42#include "context/static_context.h"42#include "context/static_context.h"
43#include "context/namespace_context.h"
4344
44#include "types/casting.h"45#include "types/casting.h"
45#include "types/typeimpl.h"46#include "types/typeimpl.h"

Subscribers

People subscribed via source and target branches