-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathparse_tree_items.h
613 lines (465 loc) · 17.3 KB
/
parse_tree_items.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/* Copyright (c) 2013, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef PARSE_TREE_ITEMS_INCLUDED
#define PARSE_TREE_ITEMS_INCLUDED
#include "field_types.h" // enum_field_types
#include "lex_string.h"
#include "my_inttypes.h" // TODO: replace with cstdint
#include "mysql/strings/m_ctype.h"
#include "sql/comp_creator.h"
#include "sql/field.h"
#include "sql/item.h"
#include "sql/item_func.h"
#include "sql/item_sum.h" // Item_sum_count
#include "sql/item_timefunc.h" // Item_func_now_local
#include "sql/parse_location.h"
#include "sql/parse_tree_helpers.h" // Parse_tree_item
#include "sql/parse_tree_node_base.h"
#include "sql/set_var.h"
class PT_subquery;
class PT_window;
struct udf_func;
class PTI_truth_transform : public Parse_tree_item {
typedef Parse_tree_item super;
Item *expr;
Bool_test truth_test;
public:
PTI_truth_transform(const POS &pos, Item *expr_arg, Bool_test truth_test)
: super(pos), expr(expr_arg), truth_test(truth_test) {}
bool do_itemize(Parse_context *pc, Item **res) override;
protected:
void add_json_info(Json_object *obj) override;
};
class PTI_comp_op : public Parse_tree_item {
typedef Parse_tree_item super;
Item *left;
chooser_compare_func_creator boolfunc2creator;
Item *right;
public:
PTI_comp_op(const POS &pos, Item *left_arg,
chooser_compare_func_creator boolfunc2creator_arg,
Item *right_arg)
: super(pos),
left(left_arg),
boolfunc2creator(boolfunc2creator_arg),
right(right_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
protected:
void add_json_info(Json_object *obj) override {
obj->add_alias("operator", create_dom_ptr<Json_string>(
(*boolfunc2creator)(false)->symbol(false)));
}
};
class PTI_comp_op_all : public Parse_tree_item {
typedef Parse_tree_item super;
Item *left;
chooser_compare_func_creator comp_op;
bool is_all;
PT_subquery *subselect;
protected:
void add_json_info(Json_object *obj) override {
obj->add_alias("is_all", create_dom_ptr<Json_boolean>(is_all));
obj->add_alias("operator", create_dom_ptr<Json_string>(
(*comp_op)(false)->symbol(false)));
}
public:
PTI_comp_op_all(const POS &pos, Item *left_arg,
chooser_compare_func_creator comp_op_arg, bool is_all_arg,
PT_subquery *subselect_arg)
: super(pos),
left(left_arg),
comp_op(comp_op_arg),
is_all(is_all_arg),
subselect(subselect_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_simple_ident_ident : public Parse_tree_item {
typedef Parse_tree_item super;
LEX_CSTRING ident;
Symbol_location raw;
public:
PTI_simple_ident_ident(const POS &pos, const LEX_CSTRING &ident_arg)
: super(pos), ident(ident_arg), raw(pos.raw) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
/**
Parse tree Item wrapper for 3-dimentional simple_ident-s
*/
class PTI_simple_ident_q_3d : public Parse_tree_item {
typedef Parse_tree_item super;
protected:
const char *db;
const char *table;
const char *field;
public:
PTI_simple_ident_q_3d(const POS &pos, const char *db_arg,
const char *table_arg, const char *field_arg)
: super(pos), db(db_arg), table(table_arg), field(field_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
/**
Parse tree Item wrapper for 3-dimentional simple_ident-s
*/
class PTI_simple_ident_q_2d : public PTI_simple_ident_q_3d {
typedef PTI_simple_ident_q_3d super;
public:
PTI_simple_ident_q_2d(const POS &pos, const char *table_arg,
const char *field_arg)
: super(pos, nullptr, table_arg, field_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_simple_ident_nospvar_ident : public Parse_tree_item {
typedef Parse_tree_item super;
LEX_STRING ident;
public:
PTI_simple_ident_nospvar_ident(const POS &pos, const LEX_STRING &ident_arg)
: super(pos), ident(ident_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_function_call_nonkeyword_now final : public Item_func_now_local {
typedef Item_func_now_local super;
public:
PTI_function_call_nonkeyword_now(const POS &pos, uint8 dec_arg)
: super(pos, dec_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_function_call_nonkeyword_sysdate : public Parse_tree_item {
typedef Parse_tree_item super;
uint8 dec;
public:
explicit PTI_function_call_nonkeyword_sysdate(const POS &pos, uint8 dec_arg)
: super(pos), dec(dec_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_udf_expr : public Parse_tree_item {
typedef Parse_tree_item super;
Item *expr;
LEX_STRING select_alias;
Symbol_location expr_loc;
public:
PTI_udf_expr(const POS &pos, Item *expr_arg,
const LEX_STRING &select_alias_arg,
const Symbol_location &expr_loc_arg)
: super(pos),
expr(expr_arg),
select_alias(select_alias_arg),
expr_loc(expr_loc_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_function_call_generic_ident_sys : public Parse_tree_item {
typedef Parse_tree_item super;
LEX_STRING ident;
PT_item_list *opt_udf_expr_list;
udf_func *udf;
public:
PTI_function_call_generic_ident_sys(const POS &pos,
const LEX_STRING &ident_arg,
PT_item_list *opt_udf_expr_list_arg)
: super(pos),
ident(ident_arg),
opt_udf_expr_list(opt_udf_expr_list_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
protected:
void add_json_info(Json_object *obj) override {
obj->add_alias("func_name",
create_dom_ptr<Json_string>(ident.str, ident.length));
}
};
/**
Parse tree Item wrapper for 2-dimentional functional names (ex.: db.func_name)
*/
class PTI_function_call_generic_2d : public Parse_tree_item {
typedef Parse_tree_item super;
LEX_STRING db;
LEX_STRING func;
PT_item_list *opt_expr_list;
public:
PTI_function_call_generic_2d(const POS &pos, const LEX_STRING &db_arg,
const LEX_STRING &func_arg,
PT_item_list *opt_expr_list_arg)
: super(pos),
db(db_arg),
func(func_arg),
opt_expr_list(opt_expr_list_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
protected:
void add_json_info(Json_object *obj) override;
};
class PTI_text_literal : public Item_string {
typedef Item_string super;
protected:
bool is_7bit;
LEX_STRING literal;
PTI_text_literal(const POS &pos, bool is_7bit_arg,
const LEX_STRING &literal_arg)
: super(pos), is_7bit(is_7bit_arg), literal(literal_arg) {}
};
class PTI_text_literal_text_string : public PTI_text_literal {
typedef PTI_text_literal super;
public:
PTI_text_literal_text_string(const POS &pos, bool is_7bit_arg,
const LEX_STRING &literal_arg)
: super(pos, is_7bit_arg, literal_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_text_literal_nchar_string : public PTI_text_literal {
typedef PTI_text_literal super;
public:
PTI_text_literal_nchar_string(const POS &pos, bool is_7bit_arg,
const LEX_STRING &literal_arg)
: super(pos, is_7bit_arg, literal_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_text_literal_underscore_charset : public PTI_text_literal {
typedef PTI_text_literal super;
const CHARSET_INFO *cs;
public:
PTI_text_literal_underscore_charset(const POS &pos, bool is_7bit_arg,
const CHARSET_INFO *cs_arg,
const LEX_STRING &literal_arg)
: super(pos, is_7bit_arg, literal_arg), cs(cs_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override {
if (super::do_itemize(pc, res)) return true;
init(literal.str, literal.length, cs, DERIVATION_COERCIBLE,
MY_REPERTOIRE_UNICODE30);
set_repertoire_from_value();
set_cs_specified(true);
return false;
}
};
class PTI_text_literal_concat : public PTI_text_literal {
typedef PTI_text_literal super;
PTI_text_literal *head;
public:
PTI_text_literal_concat(const POS &pos, bool is_7bit_arg,
PTI_text_literal *head_arg, const LEX_STRING &tail)
: super(pos, is_7bit_arg, tail), head(head_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_temporal_literal : public Parse_tree_item {
typedef Parse_tree_item super;
LEX_STRING literal;
enum_field_types field_type;
const CHARSET_INFO *cs;
public:
PTI_temporal_literal(const POS &pos, const LEX_STRING &literal_arg,
enum_field_types field_type_arg,
const CHARSET_INFO *cs_arg)
: super(pos),
literal(literal_arg),
field_type(field_type_arg),
cs(cs_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_literal_underscore_charset_hex_num : public Item_string {
typedef Item_string super;
public:
PTI_literal_underscore_charset_hex_num(const POS &pos,
const CHARSET_INFO *charset,
const LEX_STRING &literal)
: super(pos, null_name_string,
Item_hex_string::make_hex_str(literal.str, literal.length),
charset) {}
bool do_itemize(Parse_context *pc, Item **res) override {
if (super::do_itemize(pc, res)) return true;
set_repertoire_from_value();
set_cs_specified(true);
return check_well_formed_result(&str_value, true, true) == nullptr;
}
};
class PTI_literal_underscore_charset_bin_num : public Item_string {
typedef Item_string super;
public:
PTI_literal_underscore_charset_bin_num(const POS &pos,
const CHARSET_INFO *charset,
const LEX_STRING &literal)
: super(pos, null_name_string,
Item_bin_string::make_bin_str(literal.str, literal.length),
charset) {}
bool do_itemize(Parse_context *pc, Item **res) override {
if (super::do_itemize(pc, res)) return true;
set_cs_specified(true);
return check_well_formed_result(&str_value, true, true) == nullptr;
}
};
class PTI_variable_aux_set_var final : public Item_func_set_user_var {
typedef Item_func_set_user_var super;
public:
PTI_variable_aux_set_var(const POS &pos, const LEX_STRING &var, Item *expr)
: super(pos, var, expr) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_user_variable final : public Item_func_get_user_var {
typedef Item_func_get_user_var super;
public:
PTI_user_variable(const POS &pos, const LEX_STRING &var) : super(pos, var) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
/**
Parse tree Item wrapper for 3-dimentional variable names
Example: \@global.default.x
*/
class PTI_get_system_variable : public Parse_tree_item {
typedef Parse_tree_item super;
public:
PTI_get_system_variable(const POS &pos, enum_var_type scope,
const POS &name_pos, const LEX_CSTRING &opt_prefix,
const LEX_CSTRING &name)
: super{pos},
m_scope{scope},
m_name_pos{name_pos},
m_opt_prefix{opt_prefix},
m_name{name} {}
bool do_itemize(Parse_context *pc, Item **res) override;
private:
const enum_var_type m_scope;
const POS m_name_pos;
const LEX_CSTRING m_opt_prefix;
const LEX_CSTRING m_name;
};
class PTI_count_sym : public Item_sum_count {
typedef Item_sum_count super;
public:
PTI_count_sym(const POS &pos, PT_window *w)
: super(pos, (Item *)nullptr, w) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_in_sum_expr : public Parse_tree_item {
typedef Parse_tree_item super;
Item *expr;
public:
PTI_in_sum_expr(const POS &pos, Item *expr_arg)
: super(pos), expr(expr_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_singlerow_subselect : public Parse_tree_item {
typedef Parse_tree_item super;
PT_subquery *subselect;
public:
PTI_singlerow_subselect(const POS &pos, PT_subquery *subselect_arg)
: super(pos), subselect(subselect_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_exists_subselect : public Parse_tree_item {
typedef Parse_tree_item super;
PT_subquery *subselect;
public:
PTI_exists_subselect(const POS &pos, PT_subquery *subselect_arg)
: super(pos), subselect(subselect_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_odbc_date : public Parse_tree_item {
typedef Parse_tree_item super;
LEX_STRING ident;
Item *expr;
protected:
void add_json_info(Json_object *obj) override {
obj->add_alias("date_type",
create_dom_ptr<Json_string>(ident.str, ident.length));
}
public:
PTI_odbc_date(const POS &pos, const LEX_STRING &ident_arg, Item *expr_arg)
: super(pos), ident(ident_arg), expr(expr_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_handle_sql2003_note184_exception : public Parse_tree_item {
typedef Parse_tree_item super;
Item *left;
bool is_negation;
Item *right;
public:
PTI_handle_sql2003_note184_exception(const POS &pos, Item *left_arg,
bool is_negation_arg, Item *right_arg)
: super(pos),
left(left_arg),
is_negation(is_negation_arg),
right(right_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
void add_json_info(Json_object *obj) override {
obj->add_alias("negated", create_dom_ptr<Json_boolean>(is_negation));
}
};
class PTI_expr_with_alias : public Parse_tree_item {
typedef Parse_tree_item super;
Item *expr;
Symbol_location expr_loc;
LEX_CSTRING alias;
public:
PTI_expr_with_alias(const POS &pos, Item *expr_arg,
const Symbol_location &expr_loc_arg,
const LEX_CSTRING &alias_arg)
: super(pos), expr(expr_arg), expr_loc(expr_loc_arg), alias(alias_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
protected:
void add_json_info(Json_object *obj) override;
};
class PTI_int_splocal : public Parse_tree_item {
using super = Parse_tree_item;
public:
PTI_int_splocal(const POS &pos, const LEX_CSTRING &name)
: super(pos), m_location{pos}, m_name{name} {}
bool do_itemize(Parse_context *pc, Item **res) override;
private:
/// Location of the variable name.
const POS m_location;
/// Same data as in PTI_in_sum_expr#m_location but 0-terminated "for free".
const LEX_CSTRING m_name;
};
class PTI_limit_option_ident : public PTI_int_splocal {
using super = PTI_int_splocal;
public:
PTI_limit_option_ident(const POS &pos, const LEX_CSTRING &name)
: super{pos, name} {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_limit_option_param_marker : public Parse_tree_item {
typedef Parse_tree_item super;
Item_param *param_marker;
public:
explicit PTI_limit_option_param_marker(const POS &pos,
Item_param *param_marker_arg)
: super(pos), param_marker(param_marker_arg) {}
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_context : public Parse_tree_item {
typedef Parse_tree_item super;
Item *expr;
const enum_parsing_context m_parsing_place;
protected:
PTI_context(const POS &pos, Item *expr_arg, enum_parsing_context place)
: super(pos), expr(expr_arg), m_parsing_place(place) {}
public:
bool do_itemize(Parse_context *pc, Item **res) override;
};
class PTI_where final : public PTI_context {
public:
PTI_where(const POS &pos, Item *expr_arg)
: PTI_context(pos, expr_arg, CTX_WHERE) {}
};
class PTI_having final : public PTI_context {
public:
PTI_having(const POS &pos, Item *expr_arg)
: PTI_context(pos, expr_arg, CTX_HAVING) {}
};
class PTI_qualify final : public PTI_context {
public:
PTI_qualify(const POS &pos, Item *expr_arg)
: PTI_context(pos, expr_arg, CTX_QUALIFY) {}
};
#endif /* PARSE_TREE_ITEMS_INCLUDED */