From 8ec4cf1f013363c7e5417f2b1862be6552409649 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 22 Aug 2016 13:24:15 +0400 Subject: [PATCH] Refactoring for MDEV-10580 sql_mode=ORACLE: FOR loop statement Adding methods: - LEX::sp_while_loop_expression() - LEX::sp_while_loop_finalize() to reuse code between sql_yacc.yy and sql_yacc_ora.yy. FOR loop will also reuse these methods. --- sql/sql_lex.cc | 25 +++++++++++++++++++++++++ sql/sql_lex.h | 2 ++ sql/sql_yacc.yy | 21 +++------------------ sql/sql_yacc_ora.yy | 21 +++------------------ 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 572db170b77bc..354cf7a7b5523 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -5618,6 +5618,31 @@ void LEX::sp_pop_loop_empty_label(THD *thd) } +bool LEX::sp_while_loop_expression(THD *thd, Item *expr) +{ + sp_instr_jump_if_not *i= new (thd->mem_root) + sp_instr_jump_if_not(sphead->instructions(), spcont, expr, this); + return i == NULL || + /* Jumping forward */ + sphead->push_backpatch(thd, i, spcont->last_label()) || + sphead->new_cont_backpatch(i) || + sphead->add_instr(i); +} + + +bool LEX::sp_while_loop_finalize(THD *thd) +{ + sp_label *lab= spcont->last_label(); /* Jumping back */ + sp_instr_jump *i= new (thd->mem_root) + sp_instr_jump(sphead->instructions(), spcont, lab->ip); + if (i == NULL || + sphead->add_instr(i)) + return true; + sphead->do_cont_backpatch(); + return false; +} + + #ifdef MYSQL_SERVER uint binlog_unsafe_map[256]; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index dc624de8d8045..1cc8cf77b355a 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -3164,6 +3164,8 @@ struct LEX: public Query_tables_list bool sp_push_loop_empty_label(THD *thd); bool sp_pop_loop_label(THD *thd, const LEX_STRING label_name); void sp_pop_loop_empty_label(THD *thd); + bool sp_while_loop_expression(THD *thd, Item *expr); + bool sp_while_loop_finalize(THD *thd); // Check if "KEY IF NOT EXISTS name" used outside of ALTER context bool check_add_key(DDL_options_st ddl) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 35b713c32e7cb..7192df5080fd2 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -3944,30 +3944,15 @@ while_body: expr DO_SYM { LEX *lex= Lex; - sp_head *sp= lex->sphead; - uint ip= sp->instructions(); - sp_instr_jump_if_not *i= new (thd->mem_root) - sp_instr_jump_if_not(ip, lex->spcont, $1, lex); - if (i == NULL || - /* Jumping forward */ - sp->push_backpatch(thd, i, lex->spcont->last_label()) || - sp->new_cont_backpatch(i) || - sp->add_instr(i)) + if (lex->sp_while_loop_expression(thd, $1)) MYSQL_YYABORT; - if (sp->restore_lex(thd)) + if (lex->sphead->restore_lex(thd)) MYSQL_YYABORT; } sp_proc_stmts1 END WHILE_SYM { - LEX *lex= Lex; - uint ip= lex->sphead->instructions(); - sp_label *lab= lex->spcont->last_label(); /* Jumping back */ - sp_instr_jump *i= new (thd->mem_root) - sp_instr_jump(ip, lex->spcont, lab->ip); - if (i == NULL || - lex->sphead->add_instr(i)) + if (Lex->sp_while_loop_finalize(thd)) MYSQL_YYABORT; - lex->sphead->do_cont_backpatch(); } ; diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index a176eaf208da5..adb0323ebf565 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -3488,30 +3488,15 @@ while_body: expr LOOP_SYM { LEX *lex= Lex; - sp_head *sp= lex->sphead; - uint ip= sp->instructions(); - sp_instr_jump_if_not *i= new (thd->mem_root) - sp_instr_jump_if_not(ip, lex->spcont, $1, lex); - if (i == NULL || - /* Jumping forward */ - sp->push_backpatch(thd, i, lex->spcont->last_label()) || - sp->new_cont_backpatch(i) || - sp->add_instr(i)) + if (lex->sp_while_loop_expression(thd, $1)) MYSQL_YYABORT; - if (sp->restore_lex(thd)) + if (lex->sphead->restore_lex(thd)) MYSQL_YYABORT; } sp_proc_stmts1 END LOOP_SYM { - LEX *lex= Lex; - uint ip= lex->sphead->instructions(); - sp_label *lab= lex->spcont->last_label(); /* Jumping back */ - sp_instr_jump *i= new (thd->mem_root) - sp_instr_jump(ip, lex->spcont, lab->ip); - if (i == NULL || - lex->sphead->add_instr(i)) + if (Lex->sp_while_loop_finalize(thd)) MYSQL_YYABORT; - lex->sphead->do_cont_backpatch(); } ;