summaryrefslogtreecommitdiff
path: root/sql/sql_lex.h
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-05-10 15:55:33 +0400
committerAlexander Barkov <bar@mariadb.com>2018-05-10 15:55:33 +0400
commitfc63c1e17ac040bb295aecf46d53f163efc97688 (patch)
tree6443f6673fab015fa7795a76c7a4f139dfacf2fb /sql/sql_lex.h
parent8b087c63b56408edfae21f3234bae0b5391759b6 (diff)
downloadmariadb-git-fc63c1e17ac040bb295aecf46d53f163efc97688.tar.gz
MDEV-16117 SP with a single FOR statement creates but further fails to load
The code in the "sp_tail" rule in sql_yacc.yy always used YYLIP->get_cpp_tok_start() as the start of the body, and did not check for possible lookahead which happens for keywords "FOR", "VALUES" and "WITH" for LALR(2) resolution in Lex_input_stream::lex_token(). In case of the lookahead token presence, get_tok_start_prev() should have been used instead of get_cpp_tok_start() as the beginning of the SP body. Change summary: This patch hides the implementation of the lookahead token completely inside Lex_input_stream. The users of Lex_input_stream now just get token-by-token transparently and should not care about lookahead any more. Now external users of Lex_input_stream are not aware of the lookahead token at all. Change details: - Moving Lex_input_stream::has_lookahead() into the "private" section. - Removing Lex_input_stream::get_tok_start_prev() and Lex_input_stream::get_cpp_start_prev(). - Fixing the external code to call get_tok_start() and get_cpp_tok_start() in all places where get_tok_start_prev() and get_cpp_start_prev() where used. - Adding a test for has_lookahead() right inside get_tok_start() and get_cpp_tok_start(). If there is a lookahead token, these methods now return the position of the previous token automatically: const char *get_tok_start() { return has_lookahead() ? m_tok_start_prev : m_tok_start; } const char *get_cpp_tok_start() { return has_lookahead() ? m_cpp_tok_start_prev : m_cpp_tok_start; } - Fixing the internal code inside Lex_input_stream methods to use m_tok_start and m_cpp_tok_start directly, instead of calling get_tok_start() and get_cpp_tok_start(), to make sure to access to the *current* token position (independently of a lookahead token presence).
Diffstat (limited to 'sql/sql_lex.h')
-rw-r--r--sql/sql_lex.h20
1 files changed, 4 insertions, 16 deletions
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 43478c60146..9e476f3a5eb 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -2331,8 +2331,6 @@ private:
return (uint) ((m_ptr - m_tok_start) - 1);
}
-public:
-
/**
Test if a lookahead token was already scanned by lex_token(),
for LALR(2) resolution.
@@ -2342,6 +2340,8 @@ public:
return lookahead_token >= 0;
}
+public:
+
/**
End of file indicator for the query text to parse.
@return true if there are no more characters to parse
@@ -2372,7 +2372,7 @@ public:
/** Get the token start position, in the raw buffer. */
const char *get_tok_start()
{
- return m_tok_start;
+ return has_lookahead() ? m_tok_start_prev : m_tok_start;
}
void set_cpp_tok_start(const char *pos)
@@ -2386,28 +2386,16 @@ public:
return m_tok_end;
}
- /** Get the previous token start position, in the raw buffer. */
- const char *get_tok_start_prev()
- {
- return m_tok_start_prev;
- }
-
/** Get the current stream pointer, in the raw buffer. */
const char *get_ptr()
{
return m_ptr;
}
- /** Get the previus token start position, in the pre-processed buffer. */
- const char *get_cpp_start_prev()
- {
- return m_cpp_tok_start_prev;
- }
-
/** Get the token start position, in the pre-processed buffer. */
const char *get_cpp_tok_start()
{
- return m_cpp_tok_start;
+ return has_lookahead() ? m_cpp_tok_start_prev : m_cpp_tok_start;
}
/** Get the token end position, in the pre-processed buffer. */