1 /*
2 * Copyright 2006-2012 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "stdafx.h"
18 #include "expr_manager.h"
19
20 #include "mem_manager.h"
21
22 #include "expr.h"
23 #include "ftnode.h"
24 #include "var_expr.h"
25 #include "flwor_expr.h"
26 #include "fo_expr.h"
27 #include "ft_expr.h"
28 #include "function_item_expr.h"
29 #include "path_expr.h"
30 #include "script_exprs.h"
31 #include "update_exprs.h"
32 #include "json_exprs.h"
33 #include "pragma.h"
34
35 namespace zorba
36 {
37
38 #if 0
39 //A simple expression that can just be deallocated without calling the
40 //destructor.
41 class NullExpr : public expr
42 {
43 public:
44 NullExpr() : expr(NULL, NULL, QueryLoc(), unknown_expr_kind) {}
45
46 void accept(expr_visitor& v) {}
47
48 void compute_scripting_kind() {}
49
50 std::ostream& put(std::ostream& stream) const { return stream; }
51 };
52
53
54 class NullFlworClause : public flwor_clause
55 {
56 public:
57 //it being a let clause is arbitrary, it doesn't matter what type it is.
58 NullFlworClause() :flwor_clause(NULL, NULL, QueryLoc(), flwor_clause::let_clause) {}
59
60 std::ostream& put(std::ostream& stream) const { return stream; }
61
62 flwor_clause* clone(expr::substitution_t &) const { return NULL; }
63 };
64
65
66 class NullWincond : public flwor_wincond
67 {
68 public:
69 NullWincond() : flwor_wincond(NULL, NULL, false, vars(), vars(), NULL) {}
70
71 std::ostream& put(std::ostream& stream) const { return stream; }
72 };
73
74
75 class NullCatchClause : public catch_clause
76 {
77 public:
78 NullCatchClause() : catch_clause(NULL) {}
79
80 std::ostream& put(std::ostream& stream) const{return stream;}
81 };
82
83
84 class NullCopyClause : public copy_clause
85 {
86 public:
87 NullCopyClause() : copy_clause(NULL, NULL, NULL) {}
88 };
89 #endif
90
91
ExprManager(CompilerCB * ccb)92 ExprManager::ExprManager(CompilerCB* ccb)
93 :
94 theCCB(ccb)
95 {
96 theExprs.reserve(1024);
97 theFlworClauses.reserve(1024);
98 }
99
100
101 //calls on the destructors and also keeps tracks of certain numbers
~ExprManager()102 ExprManager::~ExprManager()
103 {
104 for(std::vector<expr*>::iterator iter = theExprs.begin();
105 iter != theExprs.end();
106 ++iter)
107 {
108 //We assume that the exprs being deleted they may be "held"
109 //by a reference or pointer somewhere and will try deleting them again.
110 //To prevent deleting an already deleted expr, we replace them with
111 //a NullExpr
112
113 expr* exp = *iter;
114
115 exp->~expr();
116
117 //constructs a new NULLExpr where the old expr existed
118 //new (exp) NullExpr();
119 }
120
121 for(std::vector<flwor_clause*>::iterator iter = theFlworClauses.begin();
122 iter != theFlworClauses.end();
123 ++iter)
124 {
125 flwor_clause* clause = *iter;
126 clause->~flwor_clause();
127 // new (clause) NullFlworClause();
128 }
129
130 for(std::vector<flwor_wincond*>::iterator iter = theWinconds.begin();
131 iter != theWinconds.end();
132 ++iter)
133 {
134 flwor_wincond* wincond = *iter;
135 wincond->~flwor_wincond();
136 // new (wincond) NullWincond();
137 }
138
139 for(std::vector<catch_clause*>::iterator iter = theCatchClauses.begin();
140 iter != theCatchClauses.end();
141 ++iter)
142 {
143 catch_clause* clause = *iter;
144 clause->~catch_clause();
145 // new (clause) NullCatchClause();
146 }
147
148 for(std::vector<copy_clause*>::iterator iter = theCopyClauses.begin();
149 iter != theCopyClauses.end();
150 ++iter)
151 {
152 copy_clause* clause = *iter;
153 clause->~copy_clause();
154 // new (clause) NullCopyClause();
155 }
156
157 for(std::vector<pragma*>::iterator iter = thePragmas.begin();
158 iter != thePragmas.end();
159 ++iter)
160 {
161 pragma* pragma = *iter;
162 pragma->~pragma();
163 // new (clause) NullCopyClause();
164 }
165 }
166
167
reg(expr * exp)168 void ExprManager::reg(expr* exp)
169 {
170 theExprs.push_back(exp);
171 }
172
173
reg(flwor_clause * clause)174 void ExprManager::reg(flwor_clause* clause)
175 {
176 theFlworClauses.push_back(clause);
177 }
178
179
reg(flwor_wincond * wincond)180 void ExprManager::reg(flwor_wincond* wincond)
181 {
182 theWinconds.push_back(wincond);
183 }
184
185
reg(catch_clause * clause)186 void ExprManager::reg(catch_clause* clause)
187 {
188 theCatchClauses.push_back(clause);
189 }
190
191
reg(copy_clause * clause)192 void ExprManager::reg(copy_clause* clause)
193 {
194 theCopyClauses.push_back(clause);
195 }
196
197
reg(pragma * pragma)198 void ExprManager::reg(pragma* pragma)
199 {
200 thePragmas.push_back(pragma);
201 }
202
203
204 ////////////////////////////////////////////////////////////////////////////////
205
206 #define CREATE_AND_RETURN_EXPR(EXPRTYPE, ...) \
207 EXPRTYPE* EXPPTR = new (theMemoryMgr) EXPRTYPE(theCCB, __VA_ARGS__); \
208 reg(EXPPTR); \
209 return EXPPTR
210
211 #define CREATE_AND_RETURN(TYPE, ...) \
212 TYPE* EXPPTR = new (theMemoryMgr) TYPE(__VA_ARGS__); \
213 reg(EXPPTR); \
214 return EXPPTR
215
216
217 ////////////////////////////////////////////////////////////////////////////////
218
219
create_if_expr(static_context * sctx,const QueryLoc & loc,expr * cond_expr,expr * then_expr,expr * else_expr)220 if_expr* ExprManager::create_if_expr(
221 static_context* sctx,
222 const QueryLoc& loc,
223 expr* cond_expr,
224 expr* then_expr,
225 expr* else_expr)
226 {
227 CREATE_AND_RETURN_EXPR(if_expr, sctx, loc, cond_expr, then_expr, else_expr);
228 }
229
230
create_order_expr(static_context * sctx,const QueryLoc & loc,order_expr::order_type_t order,expr * exp)231 order_expr* ExprManager::create_order_expr(
232 static_context* sctx,
233 const QueryLoc& loc,
234 order_expr::order_type_t order,
235 expr* exp)
236 {
237 CREATE_AND_RETURN_EXPR(order_expr, sctx, loc, order, exp);
238 }
239
240
create_validate_expr(static_context * sctx,const QueryLoc & loc,ParseConstants::validation_mode_t mode,const store::Item_t & aTypeName,expr * validated,rchandle<TypeManager> tm)241 validate_expr* ExprManager::create_validate_expr(
242 static_context* sctx,
243 const QueryLoc& loc,
244 ParseConstants::validation_mode_t mode,
245 const store::Item_t& aTypeName,
246 expr* validated,
247 rchandle<TypeManager> tm)
248 {
249 CREATE_AND_RETURN_EXPR(validate_expr, sctx, loc, mode, aTypeName, validated, tm);
250 }
251
252
create_cast_expr(static_context * sctx,const QueryLoc & loc,expr * casted,xqtref_t type)253 cast_expr* ExprManager::create_cast_expr(
254 static_context* sctx,
255 const QueryLoc& loc,
256 expr* casted,
257 xqtref_t type)
258 {
259 CREATE_AND_RETURN_EXPR(cast_expr, sctx, loc, casted, type);
260 }
261
262
create_treat_expr(static_context * sctx,const QueryLoc & loc,expr * treated,const xqtref_t & type,TreatIterator::ErrorKind err,bool check_prime,store::Item * qname)263 treat_expr* ExprManager::create_treat_expr(
264 static_context* sctx,
265 const QueryLoc& loc,
266 expr* treated,
267 const xqtref_t& type,
268 TreatIterator::ErrorKind err,
269 bool check_prime,
270 store::Item* qname)
271 {
272 CREATE_AND_RETURN_EXPR(treat_expr,
273 sctx, loc, treated, type, err, check_prime, qname);
274 }
275
276
create_promote_expr(static_context * sctx,const QueryLoc & loc,expr * promoted,const xqtref_t & type,PromoteIterator::ErrorKind err,store::Item * qname)277 promote_expr* ExprManager::create_promote_expr(
278 static_context* sctx,
279 const QueryLoc& loc,
280 expr* promoted,
281 const xqtref_t& type,
282 PromoteIterator::ErrorKind err,
283 store::Item* qname)
284 {
285 CREATE_AND_RETURN_EXPR(promote_expr, sctx, loc, promoted, type, err, qname);
286 }
287
288
create_castable_expr(static_context * sctx,const QueryLoc & loc,expr * castable,xqtref_t type)289 castable_expr* ExprManager::create_castable_expr(
290 static_context* sctx,
291 const QueryLoc& loc,
292 expr* castable,
293 xqtref_t type)
294 {
295 CREATE_AND_RETURN_EXPR(castable_expr, sctx, loc, castable, type);
296 }
297
298
create_instanceof_expr(static_context * sctx,const QueryLoc & loc,expr * instanced,xqtref_t type,bool checkPrimeOnly)299 instanceof_expr* ExprManager::create_instanceof_expr(
300 static_context* sctx,
301 const QueryLoc& loc,
302 expr* instanced,
303 xqtref_t type,
304 bool checkPrimeOnly)
305 {
306 CREATE_AND_RETURN_EXPR(instanceof_expr,
307 sctx, loc, instanced, type, checkPrimeOnly);
308 }
309
310
create_name_cast_expr(static_context * sctx,const QueryLoc & loc,expr * casted,const namespace_context * ns,bool isAttr)311 name_cast_expr* ExprManager::create_name_cast_expr(
312 static_context* sctx,
313 const QueryLoc& loc,
314 expr* casted,
315 const namespace_context* ns,
316 bool isAttr)
317 {
318 CREATE_AND_RETURN_EXPR(name_cast_expr, sctx, loc, casted, ns, isAttr);
319 }
320
321
create_doc_expr(static_context * sctx,const QueryLoc & loc,expr * content,bool copyNodes)322 doc_expr* ExprManager::create_doc_expr(
323 static_context* sctx,
324 const QueryLoc& loc,
325 expr* content,
326 bool copyNodes)
327 {
328 CREATE_AND_RETURN_EXPR(doc_expr, sctx, loc, content, copyNodes);
329 }
330
331
create_elem_expr(static_context * sctx,const QueryLoc & loc,expr * qnameExpr,expr * attrs,expr * content,const namespace_context * nsCtx,bool copyNodes)332 elem_expr* ExprManager::create_elem_expr(
333 static_context* sctx,
334 const QueryLoc& loc,
335 expr* qnameExpr,
336 expr* attrs,
337 expr* content,
338 const namespace_context* nsCtx,
339 bool copyNodes)
340 {
341 CREATE_AND_RETURN_EXPR(elem_expr,
342 sctx, loc, qnameExpr, attrs, content, nsCtx, copyNodes);
343 }
344
345
create_elem_expr(static_context * sctx,const QueryLoc & loc,expr * qnameExpr,expr * content,const namespace_context * nsCtx,bool copyNodes)346 elem_expr* ExprManager::create_elem_expr(
347 static_context* sctx,
348 const QueryLoc& loc,
349 expr* qnameExpr,
350 expr* content,
351 const namespace_context* nsCtx,
352 bool copyNodes)
353 {
354 CREATE_AND_RETURN_EXPR(elem_expr,
355 sctx, loc, qnameExpr, content, nsCtx, copyNodes);
356 }
357
358
create_attr_expr(static_context * sctx,const QueryLoc & loc,expr * aQNameExpr,expr * aValueExpr)359 attr_expr* ExprManager::create_attr_expr(
360 static_context* sctx,
361 const QueryLoc& loc,
362 expr* aQNameExpr,
363 expr* aValueExpr)
364 {
365 CREATE_AND_RETURN_EXPR(attr_expr, sctx, loc, aQNameExpr, aValueExpr);
366 }
367
368
create_text_expr(static_context * sctx,const QueryLoc & loc,text_expr::text_constructor_type textType,expr * text)369 text_expr* ExprManager::create_text_expr(
370 static_context* sctx,
371 const QueryLoc& loc,
372 text_expr::text_constructor_type textType,
373 expr* text)
374 {
375 CREATE_AND_RETURN_EXPR(text_expr, sctx, loc, textType, text);
376 }
377
378
create_pi_expr(static_context * sctx,const QueryLoc & loc,expr * targetExpr,expr * contentExpr)379 pi_expr* ExprManager::create_pi_expr(
380 static_context* sctx,
381 const QueryLoc& loc,
382 expr* targetExpr,
383 expr* contentExpr)
384 {
385 CREATE_AND_RETURN_EXPR(pi_expr, sctx, loc, targetExpr, contentExpr);
386 }
387
388
create_const_expr(static_context * sctx,const QueryLoc & loc,zstring & sval)389 const_expr* ExprManager::create_const_expr(
390 static_context* sctx,
391 const QueryLoc& loc,
392 zstring& sval)
393 {
394 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval);
395 }
396
397
create_const_expr(static_context * sctx,const QueryLoc & loc,const std::string & sval)398 const_expr* ExprManager::create_const_expr(
399 static_context* sctx,
400 const QueryLoc& loc,
401 const std::string& sval)
402 {
403 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval);
404 }
405
406
create_const_expr(static_context * sctx,const QueryLoc & loc,const char * sval)407 const_expr* ExprManager::create_const_expr(
408 static_context* sctx,
409 const QueryLoc& loc,
410 const char* sval)
411 {
412 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval);
413 }
414
415
create_const_expr(static_context * sctx,const QueryLoc & loc,xs_integer val)416 const_expr* ExprManager::create_const_expr(
417 static_context* sctx,
418 const QueryLoc& loc,
419 xs_integer val)
420 {
421 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
422 }
423
424
create_const_expr(static_context * sctx,const QueryLoc & loc,xs_decimal val)425 const_expr* ExprManager::create_const_expr(
426 static_context* sctx,
427 const QueryLoc& loc,
428 xs_decimal val)
429 {
430 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
431 }
432
433
create_const_expr(static_context * sctx,const QueryLoc & loc,xs_double val)434 const_expr* ExprManager::create_const_expr(
435 static_context* sctx,
436 const QueryLoc& loc,
437 xs_double val)
438 {
439 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
440 }
441
442
create_const_expr(static_context * sctx,const QueryLoc & loc,xs_boolean val)443 const_expr* ExprManager::create_const_expr(
444 static_context* sctx,
445 const QueryLoc& loc,
446 xs_boolean val)
447 {
448 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
449 }
450
451
create_const_expr(static_context * sctx,const QueryLoc & loc,store::Item_t val)452 const_expr* ExprManager::create_const_expr(
453 static_context* sctx,
454 const QueryLoc& loc,
455 store::Item_t val)
456 {
457 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
458 }
459
460
create_const_expr(static_context * sctx,const QueryLoc & loc,const char * ns,const char * pre,const char * local)461 const_expr* ExprManager::create_const_expr(
462 static_context* sctx,
463 const QueryLoc& loc,
464 const char* ns,
465 const char* pre,
466 const char* local)
467 {
468 CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, ns, pre, local);
469 }
470
471
create_extension_expr(static_context * sctx,const QueryLoc & loc)472 extension_expr* ExprManager::create_extension_expr(
473 static_context* sctx,
474 const QueryLoc& loc)
475 {
476 CREATE_AND_RETURN_EXPR(extension_expr, sctx, loc);
477 }
478
479
create_extension_expr(static_context * sctx,const QueryLoc & loc,expr * extended)480 extension_expr* ExprManager::create_extension_expr(
481 static_context* sctx,
482 const QueryLoc& loc,
483 expr* extended)
484 {
485 CREATE_AND_RETURN_EXPR(extension_expr, sctx, loc, extended);
486 }
487
488
create_catch_clause()489 catch_clause* ExprManager::create_catch_clause()
490 {
491 CREATE_AND_RETURN(catch_clause, theCCB);
492 }
493
494
create_trycatch_expr(static_context * sctx,const QueryLoc & loc,expr * tryExpr)495 trycatch_expr* ExprManager::create_trycatch_expr(
496 static_context* sctx,
497 const QueryLoc& loc,
498 expr* tryExpr)
499 {
500 CREATE_AND_RETURN_EXPR(trycatch_expr, sctx, loc, tryExpr);
501 }
502
503
create_wrapper_expr(static_context * sctx,const QueryLoc & loc,expr * wrapped)504 wrapper_expr* ExprManager::create_wrapper_expr(
505 static_context* sctx,
506 const QueryLoc& loc,
507 expr* wrapped)
508 {
509 CREATE_AND_RETURN_EXPR(wrapper_expr, sctx, loc, wrapped);
510 }
511
512
create_function_trace_expr(static_context * sctx,const QueryLoc & loc,expr * aChild)513 function_trace_expr* ExprManager::create_function_trace_expr(
514 static_context* sctx,
515 const QueryLoc& loc,
516 expr* aChild)
517 {
518 CREATE_AND_RETURN_EXPR(function_trace_expr, sctx, loc, aChild);
519 }
520
521
create_function_trace_expr(expr * aExpr)522 function_trace_expr* ExprManager::create_function_trace_expr(expr* aExpr)
523 {
524 //this function gets the ExprManager from the expression it recieves.
525 function_trace_expr* e = new (theMemoryMgr) function_trace_expr(aExpr);
526 reg(e);
527 return e;
528 }
529
530
create_eval_expr(static_context * sctx,const QueryLoc & loc,expr * e,expr_script_kind_t scriptingKind,namespace_context * nsCtx)531 eval_expr* ExprManager::create_eval_expr(
532 static_context* sctx,
533 const QueryLoc& loc,
534 expr* e,
535 expr_script_kind_t scriptingKind,
536 namespace_context* nsCtx)
537 {
538 CREATE_AND_RETURN_EXPR(eval_expr, sctx, loc, e, scriptingKind, nsCtx);
539 }
540
541 #ifdef ZORBA_WITH_DEBUGGER
542
create_debugger_expr(static_context * sctx,const QueryLoc & loc,expr * aChild,namespace_context * nsCtx,bool aIsVarDeclaration)543 debugger_expr* ExprManager::create_debugger_expr(
544 static_context* sctx,
545 const QueryLoc& loc,
546 expr* aChild,
547 namespace_context* nsCtx,
548 bool aIsVarDeclaration)
549 {
550 CREATE_AND_RETURN_EXPR(debugger_expr,
551 sctx, loc, aChild, nsCtx, aIsVarDeclaration);
552 }
553
554 #endif
555
556 ////////////////////////////////////////////////////////////////////////////////
557
create_var_expr(static_context * sctx,const QueryLoc & loc,var_expr::var_kind k,store::Item * name)558 var_expr* ExprManager::create_var_expr(
559 static_context* sctx,
560 const QueryLoc& loc,
561 var_expr::var_kind k,
562 store::Item* name)
563 {
564 CREATE_AND_RETURN_EXPR(var_expr, sctx, loc, k, name);
565 }
566
567
create_var_expr(const var_expr & source)568 var_expr* ExprManager::create_var_expr(const var_expr& source)
569 {
570 var_expr* e = new (theMemoryMgr) var_expr(source);
571 reg(e);
572 return e;
573 }
574
575
576 ////////////////////////////////////////////////////////////////////////////////
577
578
579 #ifdef ZORBA_WITH_JSON
580
create_json_array_expr(static_context * sctx,const QueryLoc & loc,expr * content)581 json_array_expr* ExprManager::create_json_array_expr(
582 static_context* sctx,
583 const QueryLoc& loc,
584 expr* content)
585 {
586 CREATE_AND_RETURN_EXPR(json_array_expr, sctx, loc, content);
587 }
588
589
create_json_object_expr(static_context * sctx,const QueryLoc & loc,expr * content,bool accumulate)590 json_object_expr* ExprManager::create_json_object_expr(
591 static_context* sctx,
592 const QueryLoc& loc,
593 expr* content,
594 bool accumulate)
595 {
596 CREATE_AND_RETURN_EXPR(json_object_expr, sctx, loc, content, accumulate);
597 }
598
599
create_json_direct_object_expr(static_context * sctx,const QueryLoc & loc,std::vector<expr * > & names,std::vector<expr * > & values)600 json_direct_object_expr* ExprManager::create_json_direct_object_expr(
601 static_context* sctx,
602 const QueryLoc& loc,
603 std::vector<expr*>& names,
604 std::vector<expr*>& values)
605 {
606 CREATE_AND_RETURN_EXPR(json_direct_object_expr, sctx, loc, names, values);
607 }
608
609
610 #endif // ZORBA_WITH_JSON
611
612 ////////////////////////////////////////////////////////////////////////////////
613
614
create_insert_expr(static_context * sctx,const QueryLoc & loc,store::UpdateConsts::InsertType insertType,expr * aSourceExpr,expr * aTargetExpr)615 insert_expr* ExprManager::create_insert_expr(
616 static_context* sctx,
617 const QueryLoc& loc,
618 store::UpdateConsts::InsertType insertType,
619 expr* aSourceExpr,
620 expr* aTargetExpr)
621 {
622 CREATE_AND_RETURN_EXPR(insert_expr,
623 sctx, loc, insertType, aSourceExpr, aTargetExpr);
624 }
625
626
create_delete_expr(static_context * sctx,const QueryLoc & loc,expr * aTargetExpr)627 delete_expr* ExprManager::create_delete_expr(
628 static_context* sctx,
629 const QueryLoc& loc,
630 expr* aTargetExpr)
631 {
632 CREATE_AND_RETURN_EXPR(delete_expr, sctx, loc, aTargetExpr);
633 }
634
635
create_replace_expr(static_context * sctx,const QueryLoc & loc,store::UpdateConsts::ReplaceType aType,expr * aSourceExpr,expr * aTargetExpr)636 replace_expr* ExprManager::create_replace_expr(
637 static_context* sctx,
638 const QueryLoc& loc,
639 store::UpdateConsts::ReplaceType aType,
640 expr* aSourceExpr,
641 expr* aTargetExpr)
642 {
643 CREATE_AND_RETURN_EXPR(replace_expr, sctx, loc, aType, aSourceExpr, aTargetExpr);
644 }
645
646
create_rename_expr(static_context * sctx,const QueryLoc & loc,expr * aSourceExpr,expr * aTargetExpr)647 rename_expr* ExprManager::create_rename_expr(
648 static_context* sctx,
649 const QueryLoc& loc,
650 expr* aSourceExpr,
651 expr* aTargetExpr)
652 {
653 CREATE_AND_RETURN_EXPR(rename_expr, sctx, loc, aSourceExpr, aTargetExpr);
654 }
655
656
create_copy_clause(var_expr * aVar,expr * aExpr)657 copy_clause* ExprManager::create_copy_clause(var_expr* aVar, expr* aExpr)
658 {
659 CREATE_AND_RETURN(copy_clause, theCCB, aVar, aExpr);
660 }
661
662
create_transform_expr(static_context * sctx,const QueryLoc & loc)663 transform_expr* ExprManager::create_transform_expr(
664 static_context* sctx,
665 const QueryLoc& loc)
666 {
667 CREATE_AND_RETURN_EXPR(transform_expr, sctx, loc);
668 }
669
670
create_block_expr(static_context * sctx,const QueryLoc & loc,bool allowLastUpdating,std::vector<expr * > & seq,std::vector<var_expr * > * assignedVars)671 block_expr* ExprManager::create_block_expr(
672 static_context* sctx,
673 const QueryLoc& loc,
674 bool allowLastUpdating,
675 std::vector<expr*>& seq,
676 std::vector<var_expr*>* assignedVars)
677 {
678 CREATE_AND_RETURN_EXPR(block_expr,
679 sctx, loc, allowLastUpdating, seq, assignedVars);
680 }
681
682
create_apply_expr(static_context * sctx,const QueryLoc & loc,expr * inExpr,bool discardXDM)683 apply_expr* ExprManager::create_apply_expr(
684 static_context* sctx,
685 const QueryLoc& loc,
686 expr* inExpr,
687 bool discardXDM)
688 {
689 CREATE_AND_RETURN_EXPR(apply_expr, sctx, loc, inExpr, discardXDM);
690 }
691
692
create_var_decl_expr(static_context * sctx,const QueryLoc & loc,var_expr * varExpr,expr * initExpr)693 var_decl_expr* ExprManager::create_var_decl_expr(
694 static_context* sctx,
695 const QueryLoc& loc,
696 var_expr* varExpr,
697 expr* initExpr)
698 {
699 CREATE_AND_RETURN_EXPR(var_decl_expr, sctx, loc, varExpr, initExpr);
700 }
701
702
create_var_set_expr(static_context * sctx,const QueryLoc & loc,var_expr * varExpr,expr * setExpr)703 var_set_expr* ExprManager::create_var_set_expr(
704 static_context* sctx,
705 const QueryLoc& loc,
706 var_expr* varExpr,
707 expr* setExpr)
708 {
709 CREATE_AND_RETURN_EXPR(var_set_expr, sctx, loc, varExpr, setExpr);
710 }
711
712
create_exit_expr(static_context * sctx,const QueryLoc & loc,expr * inExpr)713 exit_expr* ExprManager::create_exit_expr(
714 static_context* sctx,
715 const QueryLoc& loc,
716 expr* inExpr)
717 {
718 CREATE_AND_RETURN_EXPR(exit_expr, sctx, loc, inExpr);
719 }
720
721
create_exit_catcher_expr(static_context * sctx,const QueryLoc & loc,expr * inExpr,std::vector<expr * > & exitExprs)722 exit_catcher_expr* ExprManager::create_exit_catcher_expr(
723 static_context* sctx,
724 const QueryLoc& loc,
725 expr* inExpr,
726 std::vector<expr*>& exitExprs)
727 {
728 CREATE_AND_RETURN_EXPR(exit_catcher_expr, sctx, loc, inExpr, exitExprs);
729 }
730
731
create_flowctl_expr(static_context * sctx,const QueryLoc & loc,flowctl_expr::action action)732 flowctl_expr* ExprManager::create_flowctl_expr(
733 static_context* sctx,
734 const QueryLoc& loc,
735 flowctl_expr::action action)
736 {
737 CREATE_AND_RETURN_EXPR(flowctl_expr, sctx, loc, action);
738 }
739
740
create_while_expr(static_context * sctx,const QueryLoc & loc,expr * body)741 while_expr* ExprManager::create_while_expr(
742 static_context* sctx, const QueryLoc& loc, expr* body)
743 {
744 CREATE_AND_RETURN_EXPR(while_expr, sctx, loc, body);
745 }
746
747
748 ////////////////////////////////////////////////////////////////////////////////
749
create_relpath_expr(static_context * sctx,const QueryLoc & loc)750 relpath_expr* ExprManager::create_relpath_expr(
751 static_context* sctx,
752 const QueryLoc& loc)
753 {
754 CREATE_AND_RETURN_EXPR(relpath_expr, sctx, loc);
755 }
756
757
create_axis_step_expr(static_context * sctx,const QueryLoc & loc)758 axis_step_expr* ExprManager::create_axis_step_expr(
759 static_context* sctx,
760 const QueryLoc& loc)
761 {
762 CREATE_AND_RETURN_EXPR(axis_step_expr, sctx, loc);
763 }
764
765
create_match_expr(static_context * sctx,const QueryLoc & loc)766 match_expr* ExprManager::create_match_expr(
767 static_context* sctx,
768 const QueryLoc& loc)
769 {
770 CREATE_AND_RETURN_EXPR(match_expr, sctx, loc);
771 }
772
773
774 ////////////////////////////////////////////////////////////////////////////////
775
776 dynamic_function_invocation_expr*
create_dynamic_function_invocation_expr(static_context * sctx,const QueryLoc & loc,expr * anExpr,const std::vector<expr * > & args)777 ExprManager::create_dynamic_function_invocation_expr(
778 static_context* sctx,
779 const QueryLoc& loc,
780 expr* anExpr,
781 const std::vector<expr*>& args)
782 {
783 CREATE_AND_RETURN_EXPR(dynamic_function_invocation_expr, sctx, loc, anExpr, args);
784 }
785
786
create_function_item_expr(static_context * sctx,const QueryLoc & loc,const store::Item * aQName,function * f,uint32_t aArity)787 function_item_expr* ExprManager::create_function_item_expr(
788 static_context* sctx,
789 const QueryLoc& loc,
790 const store::Item* aQName,
791 function* f,
792 uint32_t aArity)
793 {
794 CREATE_AND_RETURN_EXPR(function_item_expr, sctx, loc, aQName, f, aArity);
795 }
796
797
create_function_item_expr(static_context * sctx,const QueryLoc & loc)798 function_item_expr* ExprManager::create_function_item_expr(
799 static_context* sctx,
800 const QueryLoc& loc)
801 {
802 CREATE_AND_RETURN_EXPR(function_item_expr, sctx, loc);
803 }
804
805
create_ftcontains_expr(static_context * sctx,QueryLoc const & loc,expr * range,ftnode * ftselection,expr * ftignore)806 ftcontains_expr* ExprManager::create_ftcontains_expr(
807 static_context* sctx,
808 QueryLoc const& loc,
809 expr* range,
810 ftnode *ftselection,
811 expr* ftignore)
812 {
813 CREATE_AND_RETURN_EXPR(ftcontains_expr, sctx, loc, range, ftselection, ftignore);
814 }
815
816
817 ////////////////////////////////////////////////////////////////////////////////
818
819 //this calls the static create_seq within fo_expr
create_seq(static_context * sctx,const QueryLoc & loc)820 fo_expr* ExprManager::create_seq(static_context* sctx, const QueryLoc& loc)
821 {
822 //TODO make fo_expr use this factory to generate everything
823 return fo_expr::create_seq(theCCB, sctx, loc);
824 }
825
826
create_fo_expr(static_context * sctx,const QueryLoc & loc,const function * f,expr * arg)827 fo_expr* ExprManager::create_fo_expr(
828 static_context* sctx,
829 const QueryLoc& loc,
830 const function* f,
831 expr* arg)
832 {
833 CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, arg);
834 }
835
836
create_fo_expr(static_context * sctx,const QueryLoc & loc,const function * f,expr * arg1,expr * arg2)837 fo_expr* ExprManager::create_fo_expr(
838 static_context* sctx,
839 const QueryLoc& loc,
840 const function* f,
841 expr* arg1,
842 expr* arg2)
843 {
844 CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, arg1, arg2);
845 }
846
847
create_fo_expr(static_context * sctx,const QueryLoc & loc,const function * f,const std::vector<expr * > & args)848 fo_expr* ExprManager::create_fo_expr(
849 static_context* sctx,
850 const QueryLoc& loc,
851 const function* f,
852 const std::vector<expr*>& args)
853 {
854 CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, args);
855 }
856
create_fo_expr(static_context * sctx,const QueryLoc & loc,const function * f)857 fo_expr* ExprManager::create_fo_expr(
858 static_context* sctx,
859 const QueryLoc& loc,
860 const function* f)
861 {
862
863 CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f);
864 }
865 ////////////////////////////////////////////////////////////////////////////////
866
create_for_clause(static_context * sctx,const QueryLoc & loc,var_expr * varExpr,expr * domainExpr,var_expr * posVarExpr,var_expr * scoreVarExpr,bool isOuter)867 for_clause* ExprManager::create_for_clause(
868 static_context* sctx,
869 const QueryLoc& loc,
870 var_expr* varExpr,
871 expr* domainExpr,
872 var_expr* posVarExpr,
873 var_expr* scoreVarExpr,
874 bool isOuter)
875 {
876 CREATE_AND_RETURN(for_clause,
877 sctx, theCCB, loc, varExpr, domainExpr, posVarExpr, scoreVarExpr, isOuter);
878 }
879
create_let_clause(static_context * sctx,const QueryLoc & loc,var_expr * varExpr,expr * domainExpr,bool lazy)880 let_clause* ExprManager::create_let_clause(
881 static_context* sctx,
882 const QueryLoc& loc,
883 var_expr* varExpr,
884 expr* domainExpr,
885 bool lazy)
886 {
887 CREATE_AND_RETURN(let_clause, sctx, theCCB, loc, varExpr, domainExpr, lazy);
888 }
889
create_window_clause(static_context * sctx,const QueryLoc & loc,window_clause::window_t winKind,var_expr * varExpr,expr * domainExpr,flwor_wincond * winStart,flwor_wincond * winStop,bool lazy)890 window_clause* ExprManager::create_window_clause(
891 static_context* sctx,
892 const QueryLoc& loc,
893 window_clause::window_t winKind,
894 var_expr* varExpr,
895 expr* domainExpr,
896 flwor_wincond* winStart,
897 flwor_wincond* winStop,
898 bool lazy)
899 {
900 CREATE_AND_RETURN(window_clause,
901 sctx, theCCB, loc, winKind, varExpr, domainExpr, winStart, winStop, lazy);
902 }
903
create_flwor_wincond(static_context * sctx,bool isOnly,const flwor_wincond::vars & in_vars,const flwor_wincond::vars & out_vars,expr * cond)904 flwor_wincond* ExprManager::create_flwor_wincond(
905 static_context* sctx,
906 bool isOnly,
907 const flwor_wincond::vars& in_vars,
908 const flwor_wincond::vars& out_vars,
909 expr* cond)
910 {
911 CREATE_AND_RETURN(flwor_wincond, theCCB, sctx, isOnly, in_vars, out_vars, cond);
912 }
913
create_group_clause(static_context * sctx,const QueryLoc & loc,const flwor_clause::rebind_list_t & gvars,flwor_clause::rebind_list_t ngvars,const std::vector<std::string> & collations)914 group_clause* ExprManager::create_group_clause(
915 static_context* sctx,
916 const QueryLoc& loc,
917 const flwor_clause::rebind_list_t& gvars,
918 flwor_clause::rebind_list_t ngvars,
919 const std::vector<std::string>& collations)
920 {
921 CREATE_AND_RETURN(group_clause, sctx, theCCB, loc, gvars, ngvars, collations);
922 }
923
create_orderby_clause(static_context * sctx,const QueryLoc & loc,bool stable,const std::vector<OrderModifier> & modifiers,const std::vector<expr * > & orderingExprs)924 orderby_clause* ExprManager::create_orderby_clause(
925 static_context* sctx,
926 const QueryLoc& loc,
927 bool stable,
928 const std::vector<OrderModifier>& modifiers,
929 const std::vector<expr*>& orderingExprs)
930 {
931 CREATE_AND_RETURN(orderby_clause, sctx, theCCB, loc, stable, modifiers, orderingExprs);
932 }
933
create_materialize_clause(static_context * sctx,const QueryLoc & loc)934 materialize_clause* ExprManager::create_materialize_clause(
935 static_context* sctx, const QueryLoc& loc)
936 {
937 CREATE_AND_RETURN(materialize_clause, sctx, theCCB, loc);
938 }
939
create_count_clause(static_context * sctx,const QueryLoc & loc,var_expr * var)940 count_clause* ExprManager::create_count_clause(
941 static_context* sctx, const QueryLoc& loc, var_expr* var)
942 {
943 CREATE_AND_RETURN(count_clause, sctx, theCCB, loc, var);
944 }
945
create_where_clause(static_context * sctx,const QueryLoc & loc,expr * where)946 where_clause* ExprManager::create_where_clause(
947 static_context* sctx, const QueryLoc& loc, expr* where)
948 {
949 CREATE_AND_RETURN(where_clause, sctx, theCCB, loc, where);
950 }
951
create_flwor_expr(static_context * sctx,const QueryLoc & loc,bool general)952 flwor_expr* ExprManager::create_flwor_expr(
953 static_context* sctx, const QueryLoc& loc, bool general)
954 {
955 CREATE_AND_RETURN_EXPR(flwor_expr, sctx, loc, general);
956 }
957
create_pragma(const store::Item_t & name,const zstring & lit)958 pragma* ExprManager::create_pragma(
959 const store::Item_t& name,
960 const zstring& lit)
961 {
962 CREATE_AND_RETURN(pragma, name, lit);
963 }
964
965 ////////////////////////////////////////////////////////////////////////////////
966
967
968 } // namespace zorba
969
970