Skip to content

Commit

Permalink
Refactoring for MDEV-10580 sql_mode=ORACLE: FOR loop statement
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Alexander Barkov committed Apr 5, 2017
1 parent 28f2859 commit 8ec4cf1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 36 deletions.
25 changes: 25 additions & 0 deletions sql/sql_lex.cc
Expand Up @@ -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];

Expand Down
2 changes: 2 additions & 0 deletions sql/sql_lex.h
Expand Up @@ -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)
Expand Down
21 changes: 3 additions & 18 deletions sql/sql_yacc.yy
Expand Up @@ -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();
}
;

Expand Down
21 changes: 3 additions & 18 deletions sql/sql_yacc_ora.yy
Expand Up @@ -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();
}
;

Expand Down

0 comments on commit 8ec4cf1

Please sign in to comment.