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:
Markus Mäkelä
2019-02-18 18:03:08 +02:00
parent 684ddfd12d
commit 3fef15e892
3 changed files with 11 additions and 12 deletions

View File

@ -24,6 +24,8 @@
* Code for parsing SQL comments and processing them into MaxScale hints
*/
using InputIter = mxs::Buffer::iterator;
/* Parser tokens for the hint parser */
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
*/
template<class InputIter>
InputIter skip_until(InputIter it, InputIter end, char c)
{
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
* 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)
{
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
*/
template<class InputIter>
std::vector<std::pair<InputIter, InputIter>> get_all_comments(InputIter start, InputIter end)
{
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
template<class InputIter>
struct Token
{
InputIter begin;
@ -212,8 +210,7 @@ static const std::unordered_map<std::string, TOKEN_VALUE> tokens
*
* @return The next token
*/
template<class InputIter>
Token<InputIter> next_token(InputIter* iter, InputIter end)
Token next_token(InputIter* iter, InputIter end)
{
InputIter& it = *iter;
@ -265,7 +262,6 @@ Token<InputIter> next_token(InputIter* iter, InputIter end)
*
* @return The processed hint or NULL on invalid input
*/
template<class InputIter>
HINT* process_definition(InputIter it, InputIter end)
{
HINT* rval = nullptr;
@ -324,7 +320,6 @@ HINT* process_definition(InputIter it, InputIter end)
return rval;
}
template<class InputIter>
HINT* HINT_SESSION::process_comment(InputIter it, InputIter end)
{
HINT* rval = nullptr;

View File

@ -39,7 +39,7 @@ private:
std::vector<HINT*> stack;
std::unordered_map<std::string, HINT*> named_hints;
template<class InputIter>
using InputIter = mxs::Buffer::iterator;
HINT* process_comment(InputIter it, InputIter end);
void process_hints(GWBUF* buffer);

View File

@ -27,8 +27,9 @@ void test(const std::string& input, std::initializer_list<std::string> expected)
{
bool rval = true;
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())
{
@ -76,7 +77,9 @@ static HINT_SESSION session(nullptr);
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);
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)
{
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))
{