Skip to content

Commit 09c1af9

Browse files
committed
cleanup sql_yacc.yy: reduce code duplication in rules for BEGIN...END with and without label
1 parent d49e118 commit 09c1af9

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

sql/sql_yacc.yy

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,8 @@ static bool sp_create_assignment_instr(THD *thd, bool no_lookahead)
953953
chooser_compare_func_creator boolfunc2creator;
954954
class sp_condition_value *spcondvalue;
955955
struct { int vars, conds, hndlrs, curs; } spblock;
956-
sp_name *spname;
956+
class sp_name *spname;
957+
class sp_label *splabel;
957958
LEX *lex;
958959
class my_var *myvar;
959960
sp_head *sphead;
@@ -1911,6 +1912,7 @@ END_OF_INPUT
19111912
%type <spblock> sp_decls sp_decl
19121913
%type <lex> sp_cursor_stmt
19131914
%type <spname> sp_name
1915+
%type <splabel> sp_block_content
19141916
%type <index_hint> index_hint_type
19151917
%type <num> index_hint_clause normal_join inner_join
19161918
%type <filetype> data_or_xml
@@ -3743,7 +3745,7 @@ sp_proc_stmt_return:
37433745
;
37443746

37453747
sp_unlabeled_control:
3746-
{ /* Unlabeled controls get a secret label. */
3748+
{ /* Unlabeled controls get an empty label. */
37473749
LEX *lex= Lex;
37483750

37493751
lex->spcont->push_label(thd, empty_lex_str,
@@ -4170,7 +4172,7 @@ sp_opt_label:
41704172
;
41714173

41724174
sp_labeled_block:
4173-
label_ident ':'
4175+
label_ident ':' BEGIN_SYM
41744176
{
41754177
LEX *lex= Lex;
41764178
sp_pcontext *ctx= lex->spcont;
@@ -4181,46 +4183,39 @@ sp_labeled_block:
41814183
my_error(ER_SP_LABEL_REDEFINE, MYF(0), $1.str);
41824184
MYSQL_YYABORT;
41834185
}
4184-
4185-
lab= lex->spcont->push_label(thd, $1, lex->sphead->instructions());
4186-
lab->type= sp_label::BEGIN;
4186+
lex->name= $1;
41874187
}
41884188
sp_block_content sp_opt_label
41894189
{
4190-
LEX *lex= Lex;
4191-
sp_label *lab= lex->spcont->pop_label();
4192-
4193-
if ($5.str)
4190+
if ($6.str)
41944191
{
4195-
if (my_strcasecmp(system_charset_info, $5.str, lab->name.str) != 0)
4192+
if (my_strcasecmp(system_charset_info, $6.str, $5->name.str) != 0)
41964193
{
4197-
my_error(ER_SP_LABEL_MISMATCH, MYF(0), $5.str);
4194+
my_error(ER_SP_LABEL_MISMATCH, MYF(0), $6.str);
41984195
MYSQL_YYABORT;
41994196
}
42004197
}
42014198
}
42024199
;
42034200

4201+
/* QQ This is just a dummy for grouping declarations and statements
4202+
together. No [[NOT] ATOMIC] yet, and we need to figure out how
4203+
make it coexist with the existing BEGIN COMMIT/ROLLBACK. */
42044204
sp_unlabeled_block:
4205-
{ /* Unlabeled blocks get a secret label. */
4206-
LEX *lex= Lex;
4207-
uint ip= lex->sphead->instructions();
4208-
sp_label *lab= lex->spcont->push_label(thd, empty_lex_str, ip);
4209-
lab->type= sp_label::BEGIN;
4210-
}
4211-
sp_block_content
4205+
BEGIN_SYM
42124206
{
4213-
LEX *lex= Lex;
4214-
lex->spcont->pop_label();
4207+
Lex->name= empty_lex_str; // Unlabeled blocks get an empty label
42154208
}
4209+
sp_block_content
4210+
{ }
42164211
;
42174212

42184213
sp_block_content:
4219-
BEGIN_SYM
4220-
{ /* QQ This is just a dummy for grouping declarations and statements
4221-
together. No [[NOT] ATOMIC] yet, and we need to figure out how
4222-
make it coexist with the existing BEGIN COMMIT/ROLLBACK. */
4214+
{
42234215
LEX *lex= Lex;
4216+
sp_label *lab= lex->spcont->push_label(thd, lex->name,
4217+
lex->sphead->instructions());
4218+
lab->type= sp_label::BEGIN;
42244219
lex->spcont= lex->spcont->push_context(thd,
42254220
sp_pcontext::REGULAR_SCOPE);
42264221
}
@@ -4234,21 +4229,22 @@ sp_block_content:
42344229
sp_instr *i;
42354230

42364231
sp->backpatch(ctx->last_label()); /* We always have a label */
4237-
if ($3.hndlrs)
4232+
if ($2.hndlrs)
42384233
{
4239-
i= new sp_instr_hpop(sp->instructions(), ctx, $3.hndlrs);
4234+
i= new sp_instr_hpop(sp->instructions(), ctx, $2.hndlrs);
42404235
if (i == NULL ||
42414236
sp->add_instr(i))
42424237
MYSQL_YYABORT;
42434238
}
4244-
if ($3.curs)
4239+
if ($2.curs)
42454240
{
4246-
i= new sp_instr_cpop(sp->instructions(), ctx, $3.curs);
4241+
i= new sp_instr_cpop(sp->instructions(), ctx, $2.curs);
42474242
if (i == NULL ||
42484243
sp->add_instr(i))
42494244
MYSQL_YYABORT;
42504245
}
42514246
lex->spcont= ctx->pop_context();
4247+
$$ = lex->spcont->pop_label();
42524248
}
42534249
;
42544250

0 commit comments

Comments
 (0)