summaryrefslogtreecommitdiff
path: root/sql/sp_pcontext.h
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2004-08-26 12:54:30 +0200
committerunknown <pem@mysql.comhem.se>2004-08-26 12:54:30 +0200
commit071651efbd5d910047f458121ca1222428d7aa58 (patch)
treee80e61a8c32e018499a7a29eacd653c2d0fd2fbd /sql/sp_pcontext.h
parentac06195caa5176a0245e635bb7678413c26cb7ab (diff)
downloadmariadb-git-071651efbd5d910047f458121ca1222428d7aa58.tar.gz
Major rehacking and cleanup of sp_pcontext.
This finishes (almost) WL#2002: Implement stored procedure GOTO. Only the syntax issue for free labels remains ("label L;" vs "L:"). include/mysqld_error.h: New error code for GOTO in SP handler. mysql-test/r/sp-error.result: New error test cases for GOTO. mysql-test/r/sp.result: New test cases for GOTO. Also removed some things that made it impossible to run the test in an external (debugged) mysqld. mysql-test/t/sp-error.test: New error test cases for GOTO. mysql-test/t/sp.test: New test cases for GOTO. Also removed some things that made it impossible to run the test in an external (debugged) mysqld. sql/share/czech/errmsg.txt: New error message for GOTO in SP handler. sql/share/danish/errmsg.txt: New error message for GOTO in SP handler. sql/share/dutch/errmsg.txt: New error message for GOTO in SP handler. sql/share/english/errmsg.txt: New error message for GOTO in SP handler. sql/share/estonian/errmsg.txt: New error message for GOTO in SP handler. sql/share/french/errmsg.txt: New error message for GOTO in SP handler. sql/share/german/errmsg.txt: New error message for GOTO in SP handler. sql/share/greek/errmsg.txt: New error message for GOTO in SP handler. sql/share/hungarian/errmsg.txt: New error message for GOTO in SP handler. sql/share/italian/errmsg.txt: New error message for GOTO in SP handler. sql/share/japanese/errmsg.txt: New error message for GOTO in SP handler. sql/share/korean/errmsg.txt: New error message for GOTO in SP handler. sql/share/norwegian-ny/errmsg.txt: New error message for GOTO in SP handler. sql/share/norwegian/errmsg.txt: New error message for GOTO in SP handler. sql/share/polish/errmsg.txt: New error message for GOTO in SP handler. sql/share/portuguese/errmsg.txt: New error message for GOTO in SP handler. sql/share/romanian/errmsg.txt: New error message for GOTO in SP handler. sql/share/russian/errmsg.txt: New error message for GOTO in SP handler. sql/share/serbian/errmsg.txt: New error message for GOTO in SP handler. sql/share/slovak/errmsg.txt: New error message for GOTO in SP handler. sql/share/spanish/errmsg.txt: New error message for GOTO in SP handler. sql/share/swedish/errmsg.txt: New error message for GOTO in SP handler. sql/share/ukrainian/errmsg.txt: New error message for GOTO in SP handler. sql/sp_head.cc: Code cleanup (renaming of pcontext methods), support goto, and fixed bug in jump shortcutting in the optimizer (detect infinite loops). sql/sp_head.h: Code cleanup (renaming of pcontext methods), support goto, and fixed bug in jump shortcutting in the optimizer (detect infinite loops). sql/sp_pcontext.cc: Major rehack and cleanup: - We now push and pop a chain of contexts during parsing (instead of having a single one). - Makes error detection for GOTO easier and enables some optmizations and debugger support. - Makes it a little trickier to keep track on variable and cursor indexes instead. - Renamed things to get a more consistent naming scheme too. sql/sp_pcontext.h: Major rehack and cleanup: - We now push and pop a chain of contexts during parsing (instead of having a single one). - Makes error detection for GOTO easier and enables some optmizations and debugger support. - Makes it a little trickier to keep track on variable and cursor indexes instead. - Renamed things to get a more consistent naming scheme too. sql/sql_yacc.yy: Changes to reflect the rework and renamings in sp_pcontext, and fixed some GOTO error checking.
Diffstat (limited to 'sql/sp_pcontext.h')
-rw-r--r--sql/sp_pcontext.h113
1 files changed, 50 insertions, 63 deletions
diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h
index e3bdc41779a..6db62614aa5 100644
--- a/sql/sp_pcontext.h
+++ b/sql/sp_pcontext.h
@@ -50,7 +50,7 @@ typedef struct sp_label
char *name;
uint ip; // Instruction index
int type; // begin/iter or ref/free
- uint scopes; // No. of scopes at label
+ struct sp_pcontext *ctx; // The label's context
} sp_label_t;
typedef struct sp_cond_type
@@ -66,11 +66,6 @@ typedef struct sp_cond
sp_cond_type_t *val;
} sp_cond_t;
-typedef struct sp_scope
-{
- uint vars, conds, hndlrs, curs, glab;
-} sp_scope_t;
-
class sp_pcontext : public Sql_alloc
{
sp_pcontext(const sp_pcontext &); /* Prevent use of these */
@@ -78,28 +73,30 @@ class sp_pcontext : public Sql_alloc
public:
- sp_pcontext();
+ sp_pcontext(sp_pcontext *prev);
// Free memory
void
destroy();
- // For error checking of duplicate things
- void
- push_scope();
+ sp_pcontext *
+ push_context();
- void
- pop_scope(sp_scope_t *sp = 0);
+ // Returns the previous context, not the one we pop
+ sp_pcontext *
+ pop_context();
- uint
- scopes()
+ sp_pcontext *
+ parent_context()
{
- return m_scopes.elements;
+ return m_parent;
}
- // Sets '*diffs' to the differences between current scope index snew and sold
- void
- diff_scopes(uint sold, sp_scope_t *diffs);
+ uint
+ diff_handlers(sp_pcontext *ctx);
+
+ uint
+ diff_cursors(sp_pcontext *ctx);
//
@@ -107,28 +104,27 @@ class sp_pcontext : public Sql_alloc
//
inline uint
- max_framesize()
+ max_pvars()
{
- return m_framesize;
+ return m_psubsize + m_pvar.elements;
}
inline uint
- current_framesize()
+ current_pvars()
{
- return m_pvar.elements;
+ return m_poffset + m_pvar.elements;
}
inline uint
- params()
+ context_pvars()
{
- return m_params;
+ return m_pvar.elements;
}
- // Set the number of parameters to the current esize
- inline void
- set_params()
+ inline uint
+ pvar_context2index(uint i)
{
- m_params= m_pvar.elements;
+ return m_poffset + i;
}
inline void
@@ -199,7 +195,11 @@ class sp_pcontext : public Sql_alloc
inline sp_label_t *
last_label()
{
- return m_label.head();
+ sp_label_t *lab= m_label.head();
+
+ if (!lab && m_parent)
+ lab= m_parent->last_label();
+ return lab;
}
inline sp_label_t *
@@ -236,23 +236,17 @@ class sp_pcontext : public Sql_alloc
}
inline uint
- handlers()
+ max_handlers()
{
- return m_handlers;
+ return m_hsubsize + m_handlers;
}
inline void
- push_handlers(uint count)
+ push_handlers(uint n)
{
- m_hndlrlev+= count;
+ m_handlers+= n;
}
- inline void
- pop_handlers(uint count)
- {
- m_hndlrlev-= count;
- }
-
//
// Cursors
//
@@ -263,48 +257,41 @@ class sp_pcontext : public Sql_alloc
my_bool
find_cursor(LEX_STRING *name, uint *poff, my_bool scoped=0);
- inline void
- pop_cursor(uint num)
+ inline uint
+ max_cursors()
{
- while (num--)
- pop_dynamic(&m_cursor);
+ return m_csubsize + m_cursor.elements;
}
inline uint
- cursors()
+ current_cursors()
{
- return m_cursmax;
+ return m_coffset + m_cursor.elements;
}
- //
- // GOTO labels
- //
-
- sp_label_t *
- push_glabel(char *name, uint ip);
+protected:
- sp_label_t *
- find_glabel(char *name);
-
- void
- pop_glabel(uint count);
+ // The maximum sub context's framesizes
+ uint m_psubsize;
+ uint m_csubsize;
+ uint m_hsubsize;
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
+ sp_pcontext *m_parent; // Parent context
+
+ uint m_poffset; // Variable offset for this context
+ uint m_coffset; // Cursor offset for this context
+ uint m_handlers; // No. of handlers in this context
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
+ List<sp_pcontext> m_children; // Children contexts, used for destruction
+
}; // class sp_pcontext : public Sql_alloc