1 /*
2 * Copyright 2006-2008 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 #pragma once
17 #ifndef ZORBA_REWRITER_EXPR_TOOLS_H
18 #define ZORBA_REWRITER_EXPR_TOOLS_H
19
20 #include "common/shared_types.h"
21
22 #include "compiler/expression/expr_base.h"
23 #include "compiler/expression/fo_expr.h"
24 #include "compiler/rewriter/framework/rewriter_context.h"
25
26 #include "functions/function.h"
27
28 #include "store/api/item_factory.h"
29 #include "system/globalenv.h"
30
31 #include <set>
32 #include <algorithm>
33
34 #define LOOKUP_FN( pfx, local, arity ) \
35 (GENV.getRootStaticContext().lookup_fn (pfx, local, arity))
36
37 #define ITEM_FACTORY (GENV.getStore().getItemFactory())
38
39 #define LOC(expr) (expr)->get_loc ()
40
41
42
43 namespace zorba
44 {
45
46 namespace expr_tools
47 {
48
49 int count_variable_uses(const expr* root, const var_expr* var, int limit);
50
51
52 /*******************************************************************************
53
54 ********************************************************************************/
55 expr* fix_annotations(expr* new_expr, const expr* old_expr = NULL);
56
57
58 /*******************************************************************************
59 Util functions used by rules: HoistExprsOutOfLoops and IndexJoin.
60 ********************************************************************************/
61
62 void index_flwor_vars(const expr*, ulong&, VarIdMap&, IdVarMap*);
63
64 void build_expr_to_vars_map(expr*, const VarIdMap&, DynamicBitset&, ExprVarsMap&);
65
66 void replace_var(expr*, const var_expr* oldVar, var_expr* newVar);
67
68
69 /*******************************************************************************
70
71 ********************************************************************************/
is_data(expr * e)72 inline bool is_data(expr* e)
73 {
74 return (e->get_expr_kind() == fo_expr_kind &&
75 static_cast<fo_expr *>(e)->get_func()->getKind() == FunctionConsts::FN_DATA_1);
76 }
77
78
79 }
80 }
81
82 #endif /* ZORBA_EXPR_TOOLS_H */
83 /*
84 * Local variables:
85 * mode: c++
86 * End:
87 */
88 /* vim:set et sw=2 ts=2: */
89