MXS-2302: Remove templates from parsing code
The templates were only used to make testing easier and upon review the gain in testing convenience wasn't large enough to warrant its use.
This commit is contained in:
@ -24,6 +24,8 @@
|
|||||||
* Code for parsing SQL comments and processing them into MaxScale hints
|
* Code for parsing SQL comments and processing them into MaxScale hints
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using InputIter = mxs::Buffer::iterator;
|
||||||
|
|
||||||
/* Parser tokens for the hint parser */
|
/* Parser tokens for the hint parser */
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@ -52,7 +54,6 @@ typedef enum
|
|||||||
*
|
*
|
||||||
* @return The iterator pointing at the first occurrence of the character or `end` if one was not found
|
* @return The iterator pointing at the first occurrence of the character or `end` if one was not found
|
||||||
*/
|
*/
|
||||||
template<class InputIter>
|
|
||||||
InputIter skip_until(InputIter it, InputIter end, char c)
|
InputIter skip_until(InputIter it, InputIter end, char c)
|
||||||
{
|
{
|
||||||
while (it != end)
|
while (it != end)
|
||||||
@ -84,7 +85,6 @@ InputIter skip_until(InputIter it, InputIter end, char c)
|
|||||||
* @return A pair of iterators pointing to the range the comment spans. The comment tags themselves are not
|
* @return A pair of iterators pointing to the range the comment spans. The comment tags themselves are not
|
||||||
* included in this range. If no comment is found, a pair of `end` iterators is returned.
|
* included in this range. If no comment is found, a pair of `end` iterators is returned.
|
||||||
*/
|
*/
|
||||||
template<class InputIter>
|
|
||||||
std::pair<InputIter, InputIter> get_comment(InputIter it, InputIter end)
|
std::pair<InputIter, InputIter> get_comment(InputIter it, InputIter end)
|
||||||
{
|
{
|
||||||
while (it != end)
|
while (it != end)
|
||||||
@ -158,7 +158,6 @@ std::pair<InputIter, InputIter> get_comment(InputIter it, InputIter end)
|
|||||||
*
|
*
|
||||||
* @return A list of iterator pairs pointing to all comments in the query
|
* @return A list of iterator pairs pointing to all comments in the query
|
||||||
*/
|
*/
|
||||||
template<class InputIter>
|
|
||||||
std::vector<std::pair<InputIter, InputIter>> get_all_comments(InputIter start, InputIter end)
|
std::vector<std::pair<InputIter, InputIter>> get_all_comments(InputIter start, InputIter end)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<InputIter, InputIter>> rval;
|
std::vector<std::pair<InputIter, InputIter>> rval;
|
||||||
@ -180,7 +179,6 @@ std::vector<std::pair<InputIter, InputIter>> get_all_comments(InputIter start, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Simple container for two iterators and a token type
|
// Simple container for two iterators and a token type
|
||||||
template<class InputIter>
|
|
||||||
struct Token
|
struct Token
|
||||||
{
|
{
|
||||||
InputIter begin;
|
InputIter begin;
|
||||||
@ -212,8 +210,7 @@ static const std::unordered_map<std::string, TOKEN_VALUE> tokens
|
|||||||
*
|
*
|
||||||
* @return The next token
|
* @return The next token
|
||||||
*/
|
*/
|
||||||
template<class InputIter>
|
Token next_token(InputIter* iter, InputIter end)
|
||||||
Token<InputIter> next_token(InputIter* iter, InputIter end)
|
|
||||||
{
|
{
|
||||||
InputIter& it = *iter;
|
InputIter& it = *iter;
|
||||||
|
|
||||||
@ -265,7 +262,6 @@ Token<InputIter> next_token(InputIter* iter, InputIter end)
|
|||||||
*
|
*
|
||||||
* @return The processed hint or NULL on invalid input
|
* @return The processed hint or NULL on invalid input
|
||||||
*/
|
*/
|
||||||
template<class InputIter>
|
|
||||||
HINT* process_definition(InputIter it, InputIter end)
|
HINT* process_definition(InputIter it, InputIter end)
|
||||||
{
|
{
|
||||||
HINT* rval = nullptr;
|
HINT* rval = nullptr;
|
||||||
@ -324,7 +320,6 @@ HINT* process_definition(InputIter it, InputIter end)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class InputIter>
|
|
||||||
HINT* HINT_SESSION::process_comment(InputIter it, InputIter end)
|
HINT* HINT_SESSION::process_comment(InputIter it, InputIter end)
|
||||||
{
|
{
|
||||||
HINT* rval = nullptr;
|
HINT* rval = nullptr;
|
||||||
|
@ -39,7 +39,7 @@ private:
|
|||||||
std::vector<HINT*> stack;
|
std::vector<HINT*> stack;
|
||||||
std::unordered_map<std::string, HINT*> named_hints;
|
std::unordered_map<std::string, HINT*> named_hints;
|
||||||
|
|
||||||
template<class InputIter>
|
using InputIter = mxs::Buffer::iterator;
|
||||||
HINT* process_comment(InputIter it, InputIter end);
|
HINT* process_comment(InputIter it, InputIter end);
|
||||||
void process_hints(GWBUF* buffer);
|
void process_hints(GWBUF* buffer);
|
||||||
|
|
||||||
|
@ -27,8 +27,9 @@ void test(const std::string& input, std::initializer_list<std::string> expected)
|
|||||||
{
|
{
|
||||||
bool rval = true;
|
bool rval = true;
|
||||||
auto it = expected.begin();
|
auto it = expected.begin();
|
||||||
|
mxs::Buffer buffer(input.c_str(), input.size());
|
||||||
|
|
||||||
for (auto output : get_all_comments(input.begin(), input.end()))
|
for (auto output : get_all_comments(buffer.begin(), buffer.end()))
|
||||||
{
|
{
|
||||||
if (it == expected.end())
|
if (it == expected.end())
|
||||||
{
|
{
|
||||||
@ -76,7 +77,9 @@ static HINT_SESSION session(nullptr);
|
|||||||
|
|
||||||
void test_parse(const std::string& input, int expected_type)
|
void test_parse(const std::string& input, int expected_type)
|
||||||
{
|
{
|
||||||
for (auto comment : get_all_comments(input.begin(), input.end()))
|
mxs::Buffer buffer(input.c_str(), input.size());
|
||||||
|
|
||||||
|
for (auto comment : get_all_comments(buffer.begin(), buffer.end()))
|
||||||
{
|
{
|
||||||
std::string comment_str(comment.first, comment.second);
|
std::string comment_str(comment.first, comment.second);
|
||||||
HINT* hint = session.process_comment(comment.first, comment.second);
|
HINT* hint = session.process_comment(comment.first, comment.second);
|
||||||
@ -100,8 +103,9 @@ void test_parse(const std::string& input, int expected_type)
|
|||||||
void count_hints(const std::string& input, int num_expected)
|
void count_hints(const std::string& input, int num_expected)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
mxs::Buffer buffer(input.c_str(), input.size());
|
||||||
|
|
||||||
for (auto comment : get_all_comments(input.begin(), input.end()))
|
for (auto comment : get_all_comments(buffer.begin(), buffer.end()))
|
||||||
{
|
{
|
||||||
if (session.process_comment(comment.first, comment.second))
|
if (session.process_comment(comment.first, comment.second))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user