From 3f535edc133d7d6eb45ebf50627f3ee5deae1155 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 30 Jan 2020 19:19:45 +0800 Subject: make gcc happy. --- src/MoonP/moon_compiler.cpp | 2 +- src/MoonP/moon_parser.cpp | 20 ++++++++++---------- src/MoonP/moon_parser.h | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index e804965..d3e78ed 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -381,7 +381,7 @@ private: node->m_end.m_line = parent->m_begin.m_line; return traversal::Continue; }); - _codeCache.push_back(std::move(res.input)); + _codeCache.push_back(std::move(res.codes)); return ast_ptr(res.node.template to()); } diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 60096af..b2aba20 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp @@ -496,8 +496,8 @@ MoonParser::MoonParser() { ParseInfo MoonParser::parse(const std::string& codes, rule& r) { ParseInfo res; try { - res.input = std::make_unique(); - *(res.input) = _converter.from_bytes(codes); + res.codes = std::make_unique(); + *(res.codes) = _converter.from_bytes(codes); } catch (const std::range_error&) { res.error = "Invalid text encoding."sv; return res; @@ -505,7 +505,7 @@ ParseInfo MoonParser::parse(const std::string& codes, rule& r) { error_list errors; try { State state; - res.node.set(pl::parse(*(res.input), r, errors, &state)); + res.node.set(pl::parse(*(res.codes), r, errors, &state)); } catch (const std::logic_error& err) { res.error = err.what(); return res; @@ -536,12 +536,12 @@ std::string MoonParser::toString(input::iterator begin, input::iterator end) { return _converter.to_bytes(std::wstring(begin, end)); } -input MoonParser::encode(std::string_view input) { - return _converter.from_bytes(std::string(input)); +input MoonParser::encode(std::string_view codes) { + return _converter.from_bytes(std::string(codes)); } -std::string MoonParser::decode(const input& input) { - return _converter.to_bytes(input); +std::string MoonParser::decode(const input& codes) { + return _converter.to_bytes(codes); } namespace Utils { @@ -557,10 +557,10 @@ namespace Utils { std::string ParseInfo::errorMessage(std::string_view msg, const input_range* loc) const { const int ASCII = 255; int length = loc->m_begin.m_line; - auto begin = input->begin(); - auto end = input->end(); + auto begin = codes->begin(); + auto end = codes->end(); int count = 0; - for (auto it = input->begin(); it != input->end(); ++it) { + for (auto it = codes->begin(); it != codes->end(); ++it) { if (*it == '\n') { if (count + 1 == length) { end = it; diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h index 933aa7a..a0ad2fa 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h @@ -24,14 +24,17 @@ namespace MoonP { struct ParseInfo { ast_ptr node; std::string error; - std::unique_ptr input; + std::unique_ptr codes; std::string errorMessage(std::string_view msg, const input_range* loc) const; }; +template +struct identity { typedef T type; }; + #define AST_RULE(type) \ rule type; \ ast type##_impl = type; \ - template<> inline rule& getRule() { return type; } + inline rule& getRule(identity) { return type; } extern std::unordered_set LuaKeywords; extern std::unordered_set Keywords; @@ -76,11 +79,17 @@ protected: std::stack doStack; }; + + template + inline rule& getRule() { + return getRule(identity()); + } + private: Converter _converter; template - inline rule& getRule() { + inline rule& getRule(identity) { assert(false); return Cut; } -- cgit v1.2.3-55-g6feb