Skip to content

Commit 237a869

Browse files
author
Amit Khandekar
committed
WL#15426: Implement SHOW PARSE_TREE [2/3, prep]
Preparatory patch: Add position parameter for parse tree node constructors. Position info will be later used for generating the SQL clause to be displayed as a json "text" field in each of the json parse tree nodes. Make the @$ parameter mandatory for all classes derived from Parse_tree_node. This prevents accidental absence of position info when someone adds a new grammar related PT_* class for a new production. For this, replaced the default Parse_tree_node constructor with one taking a single 'pos' parameter of type POS. While at it, fix some existing clang-tidy issues which were showing up for lines changed by this patch. Most of them were cppcoreguidelines-pro-type-member-init. Change-Id: I8277fcdd2209851783eefc4cb7bc286032879a2a
1 parent 3b7d623 commit 237a869

25 files changed

+1415
-1088
lines changed

mysql-test/r/parser.result

+4-4
Original file line numberDiff line numberDiff line change
@@ -2471,22 +2471,22 @@ x VARCHAR(10)
24712471
COLLATE ascii_bin
24722472
COLLATE ascii_bin
24732473
);
2474-
ERROR 42000: Multiple COLLATE clauses near 'ascii_bin
2474+
ERROR 42000: Multiple COLLATE clauses near 'COLLATE ascii_bin
24752475
)' at line 4
24762476
CREATE TABLE t2 (
24772477
x VARCHAR(10)
24782478
COLLATE ascii_bin
24792479
COLLATE ascii_general_ci
24802480
);
2481-
ERROR 42000: Multiple COLLATE clauses near 'ascii_general_ci
2481+
ERROR 42000: Multiple COLLATE clauses near 'COLLATE ascii_general_ci
24822482
)' at line 4
24832483
CREATE TABLE t3 (
24842484
x VARCHAR(10)
24852485
COLLATE ascii_bin
24862486
NOT NULL
24872487
COLLATE ascii_bin
24882488
);
2489-
ERROR 42000: Multiple COLLATE clauses near 'ascii_bin
2489+
ERROR 42000: Multiple COLLATE clauses near 'COLLATE ascii_bin
24902490
)' at line 5
24912491
CREATE TABLE t3 (
24922492
x VARCHAR(10)
@@ -2504,7 +2504,7 @@ GENERATED ALWAYS AS(NULL)
25042504
COLLATE ascii_bin
25052505
COLLATE ascii_bin
25062506
);
2507-
ERROR 42000: Multiple COLLATE clauses near 'ascii_bin
2507+
ERROR 42000: Multiple COLLATE clauses near 'COLLATE ascii_bin
25082508
)' at line 5
25092509
#
25102510
# Bug#28961997: REMOVE PARENTHESES INFORMATION FROM AST

sql/dd/info_schema/show_query_builder.cc

+16-15
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Select_lex_builder::Select_lex_builder(const POS *pc, THD *thd)
6262
bool Select_lex_builder::add_to_select_item_list(Item *expr) {
6363
// Prepare list if not exist.
6464
if (!m_select_item_list) {
65-
m_select_item_list = new (m_thd->mem_root) PT_select_item_list();
65+
m_select_item_list = new (m_thd->mem_root) PT_select_item_list(*m_pos);
6666

6767
if (m_select_item_list == nullptr) return true;
6868
}
@@ -147,8 +147,9 @@ bool Select_lex_builder::add_from_item(const LEX_CSTRING &schema_name,
147147
if (table_ident == nullptr) return true;
148148

149149
/* ... FROM schame_name.<table_name> ... */
150-
PT_table_factor_table_ident *table_factor = new (m_thd->mem_root)
151-
PT_table_factor_table_ident(table_ident, nullptr, NULL_CSTR, nullptr);
150+
PT_table_factor_table_ident *table_factor =
151+
new (m_thd->mem_root) PT_table_factor_table_ident(
152+
*m_pos, table_ident, nullptr, NULL_CSTR, nullptr);
152153
if (table_factor == nullptr) return true;
153154

154155
if (m_table_reference_list.push_back(table_factor)) return true;
@@ -249,7 +250,7 @@ bool Select_lex_builder::add_condition(Item *a) {
249250
bool Select_lex_builder::add_order_by(const LEX_CSTRING &field_name) {
250251
/* ... ORDER BY <field_name> ASC... */
251252
if (!m_order_by_list) {
252-
m_order_by_list = new (m_thd->mem_root) PT_order_list();
253+
m_order_by_list = new (m_thd->mem_root) PT_order_list(*m_pos);
253254
if (m_order_by_list == nullptr) return true;
254255
}
255256

@@ -259,7 +260,7 @@ bool Select_lex_builder::add_order_by(const LEX_CSTRING &field_name) {
259260
if (ident_field == nullptr) return true;
260261

261262
PT_order_expr *expression =
262-
new (m_thd->mem_root) PT_order_expr(ident_field, ORDER_ASC);
263+
new (m_thd->mem_root) PT_order_expr(*m_pos, ident_field, ORDER_ASC);
263264
m_order_by_list->push_back(expression);
264265

265266
return expression == nullptr;
@@ -271,14 +272,14 @@ bool Select_lex_builder::add_order_by(const LEX_CSTRING &field_name) {
271272
*/
272273
PT_derived_table *Select_lex_builder::prepare_derived_table(
273274
const LEX_CSTRING &table_alias) {
274-
PT_query_primary *query_specification =
275-
new (m_thd->mem_root) PT_query_specification(
276-
options, m_select_item_list, m_table_reference_list, m_where_clause);
275+
PT_query_primary *query_specification = new (m_thd->mem_root)
276+
PT_query_specification(*m_pos, options, m_select_item_list,
277+
m_table_reference_list, m_where_clause);
277278

278279
if (query_specification == nullptr) return nullptr;
279280

280281
PT_query_expression *query_expression =
281-
new (m_thd->mem_root) PT_query_expression(query_specification);
282+
new (m_thd->mem_root) PT_query_expression(*m_pos, query_specification);
282283
if (query_expression == nullptr) return nullptr;
283284

284285
PT_subquery *sub_query =
@@ -288,7 +289,7 @@ PT_derived_table *Select_lex_builder::prepare_derived_table(
288289
Create_col_name_list column_names;
289290
column_names.init(m_thd->mem_root);
290291
PT_derived_table *derived_table = new (m_thd->mem_root)
291-
PT_derived_table(false, sub_query, table_alias, &column_names);
292+
PT_derived_table(*m_pos, false, sub_query, table_alias, &column_names);
292293

293294
return derived_table;
294295
}
@@ -298,19 +299,19 @@ PT_derived_table *Select_lex_builder::prepare_derived_table(
298299
added to this Select_lex_builder.
299300
*/
300301
Query_block *Select_lex_builder::prepare_query_block() {
301-
PT_query_specification *query_specification =
302-
new (m_thd->mem_root) PT_query_specification(
303-
options, m_select_item_list, m_table_reference_list, m_where_clause);
302+
PT_query_specification *query_specification = new (m_thd->mem_root)
303+
PT_query_specification(*m_pos, options, m_select_item_list,
304+
m_table_reference_list, m_where_clause);
304305
if (query_specification == nullptr) return nullptr;
305306

306307
PT_order *pt_order_by = nullptr;
307308
if (m_order_by_list) {
308-
pt_order_by = new (m_thd->mem_root) PT_order(m_order_by_list);
309+
pt_order_by = new (m_thd->mem_root) PT_order(*m_pos, m_order_by_list);
309310
if (pt_order_by == nullptr) return nullptr;
310311
}
311312

312313
PT_query_expression *query_expression = new (m_thd->mem_root)
313-
PT_query_expression(query_specification, pt_order_by, nullptr);
314+
PT_query_expression(*m_pos, query_specification, pt_order_by, nullptr);
314315
if (query_expression == nullptr) return nullptr;
315316

316317
LEX *lex = m_thd->lex;

sql/item.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ void item_init(void) {
137137
}
138138

139139
Item::Item()
140-
: next_free(nullptr),
140+
: super(POS()),
141+
next_free(nullptr),
141142
str_value(),
142143
collation(&my_charset_bin, DERIVATION_COERCIBLE),
143144
item_name(),
@@ -164,7 +165,8 @@ Item::Item()
164165
}
165166

166167
Item::Item(THD *thd, const Item *item)
167-
: next_free(nullptr),
168+
: super(POS()),
169+
next_free(nullptr),
168170
str_value(item->str_value),
169171
collation(item->collation),
170172
item_name(item->item_name),
@@ -191,8 +193,9 @@ Item::Item(THD *thd, const Item *item)
191193
thd->add_item(this);
192194
}
193195

194-
Item::Item(const POS &)
195-
: next_free(nullptr),
196+
Item::Item(const POS &pos)
197+
: super(pos),
198+
next_free(nullptr),
196199
str_value(),
197200
collation(&my_charset_bin, DERIVATION_COERCIBLE),
198201
item_name(),

sql/item_create.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace {
129129
@see Function_factory::create_func()
130130
*/
131131
constexpr auto MAX_ARGLIST_SIZE =
132-
std::numeric_limits<decltype(PT_item_list().elements())>::max();
132+
std::numeric_limits<decltype(PT_item_list(POS()).elements())>::max();
133133

134134
/**
135135
Instantiates a function class with the list of arguments.

sql/item_xmlfunc.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -391,24 +391,24 @@ class Item_xpath_cast_number : public Item_real_func {
391391
class Item_nodeset_context_cache : public Item_nodeset_func {
392392
bool m_is_empty;
393393
uint32 m_num;
394-
uint32 m_pos;
394+
uint32 m_position;
395395
size_t m_size;
396396

397397
public:
398398
Item_nodeset_context_cache(const ParsedXML &pxml_arg, const CHARSET_INFO *cs)
399399
: Item_nodeset_func(pxml_arg, cs),
400400
m_is_empty(true),
401401
m_num(0),
402-
m_pos(0),
402+
m_position(0),
403403
m_size(0) {}
404404
void val_nodeset(XPathFilter *nodeset) const override {
405405
nodeset->clear();
406406
if (!m_is_empty)
407-
nodeset->push_back({m_num, m_pos, static_cast<uint>(m_size)});
407+
nodeset->push_back({m_num, m_position, static_cast<uint>(m_size)});
408408
}
409409
void set_element(uint32 num, uint32 pos, size_t size) {
410410
m_num = num;
411-
m_pos = pos;
411+
m_position = pos;
412412
m_size = size;
413413
m_is_empty = false;
414414
}

sql/parse_location.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
Helper class for the MY_SQL_PARSER_LTYPE
3030
*/
3131
struct Symbol_location {
32-
const char *start; // token start
33-
const char *end; // the 1st byte after the token
32+
const char *start = nullptr; // token start
33+
const char *end = nullptr; // the 1st byte after the token
3434

3535
bool is_empty() const { return length() == 0; }
3636
size_t length() const { return static_cast<size_t>(end - start); }

0 commit comments

Comments
 (0)