Commit d49e1183 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup sql_yacc.yy: factor out duplicate code in PROCEDURE/FUNCTION/TRIGGER/EVENT grammar

parent 352723cd
...@@ -224,6 +224,27 @@ static bool is_native_function(THD *thd, const LEX_STRING *name) ...@@ -224,6 +224,27 @@ static bool is_native_function(THD *thd, const LEX_STRING *name)
} }
static sp_head *make_sp_head(THD *thd, sp_name *name,
enum stored_procedure_type type)
{
LEX *lex= thd->lex;
sp_head *sp;
/* Order is important here: new - reset - init */
if ((sp= new sp_head()))
{
sp->reset_thd_mem_root(thd);
sp->init(lex);
sp->m_type= type;
sp->init_sp_name(thd, name);
sp->m_chistics= &lex->sp_chistics;
lex->sphead= sp;
}
bzero(&lex->sp_chistics, sizeof(lex->sp_chistics));
return sp;
}
/** /**
Helper action for a case statement (entering the CASE). Helper action for a case statement (entering the CASE).
This helper is used for both 'simple' and 'searched' cases. This helper is used for both 'simple' and 'searched' cases.
...@@ -2669,18 +2690,10 @@ ev_sql_stmt: ...@@ -2669,18 +2690,10 @@ ev_sql_stmt:
MYSQL_YYABORT; MYSQL_YYABORT;
} }
if (!(lex->sphead= new sp_head())) if (!make_sp_head(thd, lex->event_parse_data->identifier, TYPE_ENUM_PROCEDURE))
MYSQL_YYABORT; MYSQL_YYABORT;
lex->sphead->reset_thd_mem_root(thd); lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
lex->sphead->init(lex);
lex->sphead->init_sp_name(thd, lex->event_parse_data->identifier);
lex->sphead->m_type= TYPE_ENUM_PROCEDURE;
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->set_body_start(thd, lip->get_cpp_ptr()); lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
} }
ev_sql_stmt_inner ev_sql_stmt_inner
...@@ -2691,8 +2704,6 @@ ev_sql_stmt: ...@@ -2691,8 +2704,6 @@ ev_sql_stmt:
lex->sphead->set_stmt_end(thd); lex->sphead->set_stmt_end(thd);
lex->sphead->restore_thd_mem_root(thd); lex->sphead->restore_thd_mem_root(thd);
lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
lex->event_parse_data->body_changed= TRUE; lex->event_parse_data->body_changed= TRUE;
} }
; ;
...@@ -16069,7 +16080,6 @@ trigger_tail: ...@@ -16069,7 +16080,6 @@ trigger_tail:
{ /* $15 */ { /* $15 */
LEX *lex= thd->lex; LEX *lex= thd->lex;
Lex_input_stream *lip= YYLIP; Lex_input_stream *lip= YYLIP;
sp_head *sp;
if (lex->sphead) if (lex->sphead)
{ {
...@@ -16077,21 +16087,14 @@ trigger_tail: ...@@ -16077,21 +16087,14 @@ trigger_tail:
MYSQL_YYABORT; MYSQL_YYABORT;
} }
if (!(sp= new sp_head()))
MYSQL_YYABORT;
sp->reset_thd_mem_root(thd);
sp->init(lex);
sp->m_type= TYPE_ENUM_TRIGGER;
sp->init_sp_name(thd, $3);
lex->stmt_definition_begin= $2; lex->stmt_definition_begin= $2;
lex->ident.str= $7; lex->ident.str= $7;
lex->ident.length= $11 - $7; lex->ident.length= $11 - $7;
lex->sphead= sp;
lex->spname= $3; lex->spname= $3;
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); if (!make_sp_head(thd, $3, TYPE_ENUM_TRIGGER))
lex->sphead->m_chistics= &lex->sp_chistics; MYSQL_YYABORT;
lex->sphead->set_body_start(thd, lip->get_cpp_ptr()); lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
} }
sp_proc_stmt /* $16 */ sp_proc_stmt /* $16 */
...@@ -16169,9 +16172,8 @@ sf_tail: ...@@ -16169,9 +16172,8 @@ sf_tail:
sp_name /* $3 */ sp_name /* $3 */
'(' /* $4 */ '(' /* $4 */
{ /* $5 */ { /* $5 */
LEX *lex= thd->lex; LEX *lex= Lex;
Lex_input_stream *lip= YYLIP; Lex_input_stream *lip= YYLIP;
sp_head *sp;
const char* tmp_param_begin; const char* tmp_param_begin;
lex->stmt_definition_begin= $1; lex->stmt_definition_begin= $1;
...@@ -16182,16 +16184,9 @@ sf_tail: ...@@ -16182,16 +16184,9 @@ sf_tail:
my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "FUNCTION"); my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "FUNCTION");
MYSQL_YYABORT; MYSQL_YYABORT;
} }
/* Order is important here: new - reset - init */
sp= new sp_head();
if (sp == NULL)
MYSQL_YYABORT;
sp->reset_thd_mem_root(thd);
sp->init(lex);
sp->init_sp_name(thd, lex->spname);
sp->m_type= TYPE_ENUM_FUNCTION; if (!make_sp_head(thd, $3, TYPE_ENUM_FUNCTION))
lex->sphead= sp; MYSQL_YYABORT;
tmp_param_begin= lip->get_cpp_tok_start(); tmp_param_begin= lip->get_cpp_tok_start();
tmp_param_begin++; tmp_param_begin++;
...@@ -16231,15 +16226,12 @@ sf_tail: ...@@ -16231,15 +16226,12 @@ sf_tail:
(enum enum_field_types) $11, (enum enum_field_types) $11,
&sp->m_return_field_def)) &sp->m_return_field_def))
MYSQL_YYABORT; MYSQL_YYABORT;
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
} }
sp_c_chistics /* $13 */ sp_c_chistics /* $13 */
{ /* $14 */ { /* $14 */
LEX *lex= thd->lex; LEX *lex= thd->lex;
Lex_input_stream *lip= YYLIP; Lex_input_stream *lip= YYLIP;
lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->set_body_start(thd, lip->get_cpp_tok_start()); lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
} }
sp_proc_stmt /* $15 */ sp_proc_stmt /* $15 */
...@@ -16299,27 +16291,16 @@ sf_tail: ...@@ -16299,27 +16291,16 @@ sf_tail:
sp_tail: sp_tail:
PROCEDURE_SYM remember_name sp_name PROCEDURE_SYM remember_name sp_name
{ {
LEX *lex= Lex; if (Lex->sphead)
sp_head *sp;
if (lex->sphead)
{ {
my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "PROCEDURE"); my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "PROCEDURE");
MYSQL_YYABORT; MYSQL_YYABORT;
} }
lex->stmt_definition_begin= $2; Lex->stmt_definition_begin= $2;
/* Order is important here: new - reset - init */ if (!make_sp_head(thd, $3, TYPE_ENUM_PROCEDURE))
sp= new sp_head();
if (sp == NULL)
MYSQL_YYABORT; MYSQL_YYABORT;
sp->reset_thd_mem_root(thd);
sp->init(lex);
sp->m_type= TYPE_ENUM_PROCEDURE;
sp->init_sp_name(thd, $3);
lex->sphead= sp;
} }
'(' '('
{ {
...@@ -16332,17 +16313,11 @@ sp_tail: ...@@ -16332,17 +16313,11 @@ sp_tail:
sp_pdparam_list sp_pdparam_list
')' ')'
{ {
LEX *lex= thd->lex; Lex->sphead->m_param_end= YYLIP->get_cpp_tok_start();
lex->sphead->m_param_end= YYLIP->get_cpp_tok_start();
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
} }
sp_c_chistics sp_c_chistics
{ {
LEX *lex= thd->lex; Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
} }
sp_proc_stmt sp_proc_stmt
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment