diff options
author | unknown <pem@mysql.comhem.se> | 2004-08-17 20:20:58 +0200 |
---|---|---|
committer | unknown <pem@mysql.comhem.se> | 2004-08-17 20:20:58 +0200 |
commit | 9b5a6f7228850479abe0e4e2439dcf6b27a87136 (patch) | |
tree | 0a14fd07bbceeceb892fb762e8f9af5e74153b89 /sql/sp_pcontext.h | |
parent | f43fe31e571bb5e127d5e0ca4ad6680a15104aa7 (diff) | |
download | mariadb-git-9b5a6f7228850479abe0e4e2439dcf6b27a87136.tar.gz |
WL#2002: Implement stored procedure GOTO.
Mostly done, it works, but the temporary LABEL syntax still to be fixed.
mysql-test/r/sp-error.result:
New test case for WL#2002 (GOTO).
mysql-test/r/sp.result:
New test case for WL#2002 (GOTO).
(Also corrected another test)
mysql-test/t/sp-error.test:
New test case for WL#2002 (GOTO).
mysql-test/t/sp.test:
New test case for WL#2002 (GOTO).
(Also corrected another test)
sql/lex.h:
New symbol GOTO.
Also a temporary symbol LABEL, which hopefully will go away soon.
sql/sp_head.cc:
Fixed backpatching to cope with free GOTO labels an hpop and cpop instructions.
Also optimized away pointless jump instructions.
sql/sp_head.h:
Fixed backpatching to cope with free GOTO labels an hpop and cpop instructions.
We now sometimes generate hpop/cpop 0 instructions but the optimizer removes them.
sql/sp_pcontext.cc:
Added free GOTO labels, and support for coping with jumps out of blocks
with handlers or cursors.
sql/sp_pcontext.h:
Added free GOTO labels, and support for coping with jumps out of blocks
with handlers or cursors.
sql/sql_yacc.yy:
Added GOTO and LABEL, and adjusted backpatching accordingly. Also fixed LEAVE
out of blocks. The LABEL syntax will go away soon, hopefully.
Diffstat (limited to 'sql/sp_pcontext.h')
-rw-r--r-- | sql/sp_pcontext.h | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h index a82cefa2e42..e3bdc41779a 100644 --- a/sql/sp_pcontext.h +++ b/sql/sp_pcontext.h @@ -39,11 +39,18 @@ typedef struct sp_pvar Item *dflt; } sp_pvar_t; + +#define SP_LAB_REF 0 // Unresolved reference (for goto) +#define SP_LAB_GOTO 1 // Free goto label +#define SP_LAB_BEGIN 2 // Label at BEGIN +#define SP_LAB_ITER 3 // Label at iteration control + typedef struct sp_label { char *name; uint ip; // Instruction index - my_bool isbegin; // For ITERATE error checking + int type; // begin/iter or ref/free + uint scopes; // No. of scopes at label } sp_label_t; typedef struct sp_cond_type @@ -61,7 +68,7 @@ typedef struct sp_cond typedef struct sp_scope { - uint vars, conds, curs; + uint vars, conds, hndlrs, curs, glab; } sp_scope_t; class sp_pcontext : public Sql_alloc @@ -82,7 +89,18 @@ class sp_pcontext : public Sql_alloc push_scope(); void - pop_scope(); + pop_scope(sp_scope_t *sp = 0); + + uint + scopes() + { + return m_scopes.elements; + } + + // Sets '*diffs' to the differences between current scope index snew and sold + void + diff_scopes(uint sold, sp_scope_t *diffs); + // // Parameters and variables @@ -223,6 +241,18 @@ class sp_pcontext : public Sql_alloc return m_handlers; } + inline void + push_handlers(uint count) + { + m_hndlrlev+= count; + } + + inline void + pop_handlers(uint count) + { + m_hndlrlev-= count; + } + // // Cursors // @@ -246,17 +276,32 @@ class sp_pcontext : public Sql_alloc return m_cursmax; } + // + // GOTO labels + // + + sp_label_t * + push_glabel(char *name, uint ip); + + sp_label_t * + find_glabel(char *name); + + void + pop_glabel(uint count); + private: uint m_params; // The number of parameters uint m_framesize; // The maximum framesize uint m_handlers; // The total number of handlers uint m_cursmax; // The maximum number of cursors + uint m_hndlrlev; // Current number of active handlers DYNAMIC_ARRAY m_pvar; // Parameters/variables DYNAMIC_ARRAY m_cond; // Conditions DYNAMIC_ARRAY m_cursor; // Cursors DYNAMIC_ARRAY m_scopes; // For error checking + DYNAMIC_ARRAY m_glabel; // Goto labels List<sp_label_t> m_label; // The label list |