Skip to content

Commit 3b7d623

Browse files
author
Amit Khandekar
committed
WL#15426: Implement SHOW PARSE_TREE [1/3, prep]
Preparatory patch: Wrapper functions for contextualize() and itemize() The original contextualize() functions of all classes are renamed to do_contextualize(). contextualize() is now just a wrapper around the virtual function do_contextualize(). Besides calling do_contextualize(), the class member function contextualize() is meant to do the work of building json tree node for the corresponding PT_* class. contextualize() is defined only in Parse_tree_node, and is defined with final specifier, so that newly defined classes will be prohibited from overriding this function. They should instead override do_contextualize(). So e.g. when the code calls obj->contextualize(), Parse_tree_node::contextualize() will be called, which in turn calls do_contextualize() of the derived class. Similar thing is done for itemize() and do_itemize() for classes based on Item. Change-Id: If9390a9dde5ca22632ae63c39a53aacb290f79eb
1 parent 29f804b commit 3b7d623

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+766
-715
lines changed

sql/item.cc

+14-14
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,9 @@ bool Item::aggregate_type(const char *name, Item **items, uint count) {
736736
return false;
737737
}
738738

739-
bool Item::itemize(Parse_context *pc, Item **res) {
739+
bool Item::do_itemize(Parse_context *pc, Item **res) {
740740
if (skip_itemize(res)) return false;
741-
if (super::contextualize(pc)) return true;
741+
if (super::do_contextualize(pc)) return true;
742742

743743
// Add item to global list
744744
pc->thd->add_item(this);
@@ -886,9 +886,9 @@ Item *Item::transform(Item_transformer transformer, uchar *arg) {
886886
return (this->*transformer)(arg);
887887
}
888888

889-
bool Item_ident::itemize(Parse_context *pc, Item **res) {
889+
bool Item_ident::do_itemize(Parse_context *pc, Item **res) {
890890
if (skip_itemize(res)) return false;
891-
if (super::itemize(pc, res)) return true;
891+
if (super::do_itemize(pc, res)) return true;
892892
context = pc->thd->lex->current_context();
893893
return false;
894894
}
@@ -2061,9 +2061,9 @@ Item_name_const::Item_name_const(const POS &pos, Item *name_arg, Item *val)
20612061
set_nullable(true);
20622062
}
20632063

2064-
bool Item_name_const::itemize(Parse_context *pc, Item **res) {
2064+
bool Item_name_const::do_itemize(Parse_context *pc, Item **res) {
20652065
if (skip_itemize(res)) return false;
2066-
if (super::itemize(pc, res) || value_item->itemize(pc, &value_item) ||
2066+
if (super::do_itemize(pc, res) || value_item->itemize(pc, &value_item) ||
20672067
name_item->itemize(pc, &name_item))
20682068
return true;
20692069
/*
@@ -2885,9 +2885,9 @@ Item_field::Item_field(const POS &pos, const char *db_arg,
28852885
collation.set(DERIVATION_IMPLICIT);
28862886
}
28872887

2888-
bool Item_field::itemize(Parse_context *pc, Item **res) {
2888+
bool Item_field::do_itemize(Parse_context *pc, Item **res) {
28892889
if (skip_itemize(res)) return false;
2890-
if (super::itemize(pc, res)) return true;
2890+
if (super::do_itemize(pc, res)) return true;
28912891
Query_block *const select = pc->select;
28922892
if (select->parsing_place != CTX_HAVING) select->select_n_where_fields++;
28932893
return false;
@@ -3736,9 +3736,9 @@ Item_param::Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg)
37363736
set_nullable(true); // All parameters are nullable
37373737
}
37383738

3739-
bool Item_param::itemize(Parse_context *pc, Item **res) {
3739+
bool Item_param::do_itemize(Parse_context *pc, Item **res) {
37403740
if (skip_itemize(res)) return false;
3741-
if (super::itemize(pc, res)) return true;
3741+
if (super::do_itemize(pc, res)) return true;
37423742

37433743
/*
37443744
see commentaries in PTI_limit_option_param_marker::itemize()
@@ -8939,9 +8939,9 @@ Item *Item_view_ref::replace_view_refs_with_clone(uchar *arg) {
89398939
current_thd, ref_item());
89408940
}
89418941

8942-
bool Item_default_value::itemize(Parse_context *pc, Item **res) {
8942+
bool Item_default_value::do_itemize(Parse_context *pc, Item **res) {
89438943
if (skip_itemize(res)) return false;
8944-
if (super::itemize(pc, res)) return true;
8944+
if (super::do_itemize(pc, res)) return true;
89458945

89468946
if (arg != nullptr) {
89478947
if (arg->itemize(pc, &arg)) return true;
@@ -10990,13 +10990,13 @@ Item_field *FindEqualField(Item_field *item_field, table_map reachable_tables,
1099010990
return item_field;
1099110991
}
1099210992

10993-
bool Item_asterisk::itemize(Parse_context *pc, Item **res) {
10993+
bool Item_asterisk::do_itemize(Parse_context *pc, Item **res) {
1099410994
assert(pc->select->parsing_place == CTX_SELECT_LIST);
1099510995

1099610996
if (skip_itemize(res)) {
1099710997
return false;
1099810998
}
10999-
if (super::itemize(pc, res)) {
10999+
if (super::do_itemize(pc, res)) {
1100011000
return true;
1100111001
}
1100211002
pc->select->with_wild++;

sql/item.h

+24-10
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ class Item : public Parse_tree_node {
11111111
Hide the contextualize*() functions: call/override the itemize()
11121112
in Item class tree instead.
11131113
*/
1114-
bool contextualize(Parse_context *) override {
1114+
bool do_contextualize(Parse_context *) override {
11151115
assert(0);
11161116
return true;
11171117
}
@@ -1142,6 +1142,12 @@ class Item : public Parse_tree_node {
11421142
*/
11431143
static bool bit_func_returns_binary(const Item *a, const Item *b);
11441144

1145+
/**
1146+
The core function that does the actual itemization. itemize() is just a
1147+
wrapper over this.
1148+
*/
1149+
virtual bool do_itemize(Parse_context *pc, Item **res);
1150+
11451151
public:
11461152
/**
11471153
The same as contextualize() but with additional parameter
@@ -1150,14 +1156,22 @@ class Item : public Parse_tree_node {
11501156
constructor): we can access/change parser contexts from the itemize()
11511157
function.
11521158
1159+
Derived classes should not override this. If needed, they should
1160+
override do_itemize().
1161+
11531162
@param pc current parse context
11541163
@param [out] res pointer to "this" or to a newly allocated
11551164
replacement object to use in the Item tree instead
11561165
11571166
@retval false success
11581167
@retval true syntax/OOM/etc error
11591168
*/
1160-
virtual bool itemize(Parse_context *pc, Item **res);
1169+
virtual bool itemize(Parse_context *pc, Item **res) final {
1170+
// Json parse tree related things to be done pre-do_itemize().
1171+
if (do_itemize(pc, res)) return true;
1172+
// Json parse tree related things to be done post-do_itemize().
1173+
return false;
1174+
}
11611175

11621176
void rename(char *new_name);
11631177
void init_make_field(Send_field *tmp_field, enum enum_field_types type);
@@ -3860,7 +3874,7 @@ class Item_name_const final : public Item {
38603874
public:
38613875
Item_name_const(const POS &pos, Item *name_arg, Item *val);
38623876

3863-
bool itemize(Parse_context *pc, Item **res) override;
3877+
bool do_itemize(Parse_context *pc, Item **res) override;
38643878
bool fix_fields(THD *, Item **) override;
38653879

38663880
enum Type type() const override;
@@ -4065,7 +4079,7 @@ class Item_ident : public Item {
40654079
cached_table(item->cached_table),
40664080
depended_from(item->depended_from) {}
40674081

4068-
bool itemize(Parse_context *pc, Item **res) override;
4082+
bool do_itemize(Parse_context *pc, Item **res) override;
40694083

40704084
const char *full_name() const override;
40714085
void set_orignal_db_name(const char *name_arg) { m_orig_db_name = name_arg; }
@@ -4318,7 +4332,7 @@ class Item_field : public Item_ident {
43184332
Field *field);
43194333
Item_field(Field *field);
43204334

4321-
bool itemize(Parse_context *pc, Item **res) override;
4335+
bool do_itemize(Parse_context *pc, Item **res) override;
43224336

43234337
enum Type type() const override { return FIELD_ITEM; }
43244338
bool eq(const Item *item, bool binary_cmp) const override;
@@ -4528,7 +4542,7 @@ class Item_asterisk : public Item_field {
45284542
const char *opt_table_name)
45294543
: super(pos, opt_schema_name, opt_table_name, "*") {}
45304544

4531-
bool itemize(Parse_context *pc, Item **res) override;
4545+
bool do_itemize(Parse_context *pc, Item **res) override;
45324546
bool fix_fields(THD *, Item **) override {
45334547
assert(false); // should never happen: see setup_wild()
45344548
return true;
@@ -4778,7 +4792,7 @@ class Item_param final : public Item, private Settable_routine_parameter {
47784792

47794793
Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg);
47804794

4781-
bool itemize(Parse_context *pc, Item **item) override;
4795+
bool do_itemize(Parse_context *pc, Item **item) override;
47824796

47834797
Item_result result_type() const override { return m_result_type; }
47844798
enum Type type() const override { return PARAM_ITEM; }
@@ -6457,7 +6471,7 @@ class Item_default_value final : public Item_field {
64576471
public:
64586472
Item_default_value(const POS &pos, Item *a = nullptr)
64596473
: super(pos, nullptr, nullptr, nullptr), arg(a) {}
6460-
bool itemize(Parse_context *pc, Item **res) override;
6474+
bool do_itemize(Parse_context *pc, Item **res) override;
64616475
enum Type type() const override { return DEFAULT_VALUE_ITEM; }
64626476
bool eq(const Item *item, bool binary_cmp) const override;
64636477
bool fix_fields(THD *, Item **) override;
@@ -6533,9 +6547,9 @@ class Item_insert_value final : public Item_field {
65336547
arg(a),
65346548
m_is_values_function(false) {}
65356549

6536-
bool itemize(Parse_context *pc, Item **res) override {
6550+
bool do_itemize(Parse_context *pc, Item **res) override {
65376551
if (skip_itemize(res)) return false;
6538-
return Item_field::itemize(pc, res) || arg->itemize(pc, &arg);
6552+
return Item_field::do_itemize(pc, res) || arg->itemize(pc, &arg);
65396553
}
65406554

65416555
enum Type type() const override { return INSERT_VALUE_ITEM; }

sql/item_cmpfunc.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -2683,10 +2683,10 @@ bool Item_func_opt_neg::eq(const Item *item, bool binary_cmp) const {
26832683
return AllItemsAreEqual(args, item_func->arguments(), arg_count, binary_cmp);
26842684
}
26852685

2686-
bool Item_func_interval::itemize(Parse_context *pc, Item **res) {
2686+
bool Item_func_interval::do_itemize(Parse_context *pc, Item **res) {
26872687
if (skip_itemize(res)) return false;
26882688
if (row == nullptr || // OOM in constructor
2689-
super::itemize(pc, res))
2689+
super::do_itemize(pc, res))
26902690
return true;
26912691
assert(row == args[0]); // row->itemize() is not needed
26922692
return false;
@@ -5423,9 +5423,9 @@ Item *make_condition(Parse_context *pc, Item *item) {
54235423
class: we need to overload this function to run a contextualization
54245424
the Item_cond::list items.
54255425
*/
5426-
bool Item_cond::itemize(Parse_context *pc, Item **res) {
5426+
bool Item_cond::do_itemize(Parse_context *pc, Item **res) {
54275427
if (skip_itemize(res)) return false;
5428-
if (super::itemize(pc, res)) return true;
5428+
if (super::do_itemize(pc, res)) return true;
54295429

54305430
List_iterator<Item> li(list);
54315431
Item *item;
@@ -6425,9 +6425,9 @@ void Item_func_like::print(const THD *thd, String *str,
64256425
str->append(')');
64266426
}
64276427

6428-
bool Item_func_xor::itemize(Parse_context *pc, Item **res) {
6428+
bool Item_func_xor::do_itemize(Parse_context *pc, Item **res) {
64296429
if (skip_itemize(res)) return false;
6430-
if (super::itemize(pc, res)) return true;
6430+
if (super::do_itemize(pc, res)) return true;
64316431

64326432
if (!args[0]->is_bool_func()) {
64336433
args[0] = make_condition(pc, args[0]);

sql/item_cmpfunc.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ class Item_func_xor final : public Item_bool_func2 {
715715

716716
enum Functype functype() const override { return XOR_FUNC; }
717717
const char *func_name() const override { return "xor"; }
718-
bool itemize(Parse_context *pc, Item **res) override;
718+
bool do_itemize(Parse_context *pc, Item **res) override;
719719
longlong val_int() override;
720720
void apply_is_true() override {}
721721
Item *truth_transformer(THD *, Bool_test) override;
@@ -1397,7 +1397,7 @@ class Item_func_interval final : public Item_int_func {
13971397
allowed_arg_cols = 0; // Fetch this value from first argument
13981398
}
13991399

1400-
bool itemize(Parse_context *pc, Item **res) override;
1400+
bool do_itemize(Parse_context *pc, Item **res) override;
14011401
longlong val_int() override;
14021402
bool resolve_type(THD *) override;
14031403
const char *func_name() const override { return "interval"; }
@@ -2454,7 +2454,7 @@ class Item_cond : public Item_bool_func {
24542454
list.prepend(nlist);
24552455
}
24562456

2457-
bool itemize(Parse_context *pc, Item **res) override;
2457+
bool do_itemize(Parse_context *pc, Item **res) override;
24582458

24592459
bool fix_fields(THD *, Item **ref) override;
24602460
void fix_after_pullout(Query_block *parent_query_block,

0 commit comments

Comments
 (0)