CUBRID Engine  latest
regu_var.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * Regular variable - implementation.
21  */
22 
23 #include "regu_var.hpp"
24 
25 #include "memory_alloc.h"
26 #include "object_primitive.h"
27 #include "xasl_predicate.hpp"
28 
29 using namespace cubxasl; // it should belong to cubxasl namespace
30 
31 void
33 {
34  bool stop = false;
35  map_regu (func, stop);
36 }
37 
38 void
40 {
41  // helper macros to avoid repeating code
42 #define map_regu_and_check_stop(regu) \
43  { (regu)->map_regu (func, stop); if (stop) return; }
44 #define map_regu_not_null_and_check_stop(regu) \
45  if ((regu) != NULL) map_regu_and_check_stop (regu)
46 
47  // apply function to me
48  func (*this, stop);
49  if (stop)
50  {
51  return;
52  }
53  switch (type)
54  {
55  case TYPE_INARITH:
56  case TYPE_OUTARITH:
57  if (value.arithptr == NULL)
58  {
59  assert (false);
60  return;
61  }
62  map_regu_not_null_and_check_stop (value.arithptr->leftptr);
63  map_regu_not_null_and_check_stop (value.arithptr->rightptr);
64  break;
65 
66  case TYPE_FUNC:
67  if (value.funcp == NULL)
68  {
69  assert (false);
70  return;
71  }
72  for (regu_variable_list_node *operand = value.funcp->operand; operand != NULL; operand = operand->next)
73  {
74  map_regu_and_check_stop (&operand->value);
75  }
76  break;
77 
78  case TYPE_REGUVAL_LIST:
79  if (value.reguval_list == NULL)
80  {
81  assert (false);
82  return;
83  }
84  for (regu_value_item *item = value.reguval_list->regu_list; item != NULL; item = item->next)
85  {
87  }
88  break;
89 
90  case TYPE_REGU_VAR_LIST:
91  for (regu_variable_list_node *node = value.regu_var_list; node != NULL; node = node->next)
92  {
93  map_regu_and_check_stop (&node->value);
94  }
95  break;
96 
97  default:
98  // nothing
99  return;
100  }
101 
102 #undef map_regu_not_null_and_check_stop
103 #undef map_regu_and_check_stop
104 }
105 
106 void
108 {
109  bool stop;
110  // wrap regu_func and xasl_func calls into a single map_regu_func_type that can be used by map_regu
111  auto cnv_funcs_to_regu_func = [&] (regu_variable_node &regu, bool &stop)
112  {
113  if (regu.xasl != NULL)
114  {
115  xasl_func (*regu.xasl, stop);
116  if (stop)
117  {
118  return;
119  }
120  }
121  regu_func (regu, stop);
122  };
123  return map_regu (cnv_funcs_to_regu_func, stop);
124 }
125 
126 void
128 {
129  switch (type)
130  {
131  case TYPE_INARITH:
132  case TYPE_OUTARITH:
133  assert (value.arithptr != NULL);
134  if (value.arithptr->rand_seed != NULL)
135  {
136  free_and_init (value.arithptr->rand_seed);
137  }
138  if (value.arithptr->pred != NULL)
139  {
140  value.arithptr->pred->clear_xasl ();
141  }
142  break;
143 
144  case TYPE_FUNC:
145  assert (value.funcp != NULL);
146  pr_clear_value (value.funcp->value);
147 
148  if (value.funcp->tmp_obj != NULL)
149  {
150  switch (value.funcp->ftype)
151  {
152  case F_REGEXP_COUNT:
153  case F_REGEXP_INSTR:
154  case F_REGEXP_LIKE:
155  case F_REGEXP_REPLACE:
156  case F_REGEXP_SUBSTR:
157  {
158  delete value.funcp->tmp_obj->compiled_regex;
159  }
160  break;
161  default:
162  //any of union member may have been erased
163  assert (false);
164  break;
165  }
166 
167  delete value.funcp->tmp_obj;
168  value.funcp->tmp_obj = NULL;
169  }
170 
171  break;
172 
173  case TYPE_DBVAL:
174  pr_clear_value (&value.dbval);
175  break;
176 
177  default:
178  break;
179  }
180 
181  pr_clear_value (vfetch_to);
182 }
183 
184 void
186 {
187  // todo - call map_regu_and_xasl; it requires similar XASL clear_xasl functionality
188  auto map_func = [] (regu_variable_node & regu, bool & stop)
189  {
190  regu.clear_xasl_local ();
191  };
192  map_regu (map_func);
193 }
void map_regu(const map_regu_func_type &func)
Definition: regu_var.cpp:32
#define assert(x)
xasl_node * xasl
Definition: regu_var.hpp:178
#define NULL
Definition: freelistheap.h:34
void clear_xasl_local()
Definition: regu_var.cpp:127
int pr_clear_value(DB_VALUE *value)
#define free_and_init(ptr)
Definition: memory_alloc.h:147
std::function< void(regu_variable_node &regu, bool &stop)> map_regu_func_type
Definition: regu_var.hpp:197
#define map_regu_not_null_and_check_stop(regu)
void map_regu_and_xasl(const map_regu_func_type &regu_func, const map_xasl_func_type &xasl_func)
Definition: regu_var.cpp:107
#define map_regu_and_check_stop(regu)
std::function< void(xasl_node &xasl, bool &stop)> map_xasl_func_type
Definition: regu_var.hpp:198