From 0eaea3f979ef46fe195649ee18400f014957db26 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 18 Feb 2020 13:14:42 +0800 Subject: did some clean up. --- src/MoonP/ast.hpp | 2 +- src/MoonP/moon_ast.h | 6 +++--- src/MoonP/moon_compiler.cpp | 37 ++++++++++++++++++------------------- 3 files changed, 22 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/MoonP/ast.hpp b/src/MoonP/ast.hpp index d576395..104202d 100644 --- a/src/MoonP/ast.hpp +++ b/src/MoonP/ast.hpp @@ -97,7 +97,7 @@ public: virtual int getId() const = 0; template - inline ast_ptr new_ptr() { + inline ast_ptr new_ptr() const { auto item = new T; item->m_begin.m_line = m_begin.m_line; item->m_end.m_line = m_begin.m_line; diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h index 26accbf..917429e 100644 --- a/src/MoonP/moon_ast.h +++ b/src/MoonP/moon_ast.h @@ -13,18 +13,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace parserlib { #define AST_LEAF(type) \ -COUNTER_INC;\ +COUNTER_INC; \ class type##_t : public ast_node \ { \ public: \ virtual int getId() const override { return COUNTER_READ; } #define AST_NODE(type) \ -COUNTER_INC;\ +COUNTER_INC; \ class type##_t : public ast_container \ { \ public: \ - virtual int getId() const override { return COUNTER_READ; } \ + virtual int getId() const override { return COUNTER_READ; } #define AST_MEMBER(type, ...) \ type##_t() { \ diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 23ce6ce..4596542 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -488,7 +488,7 @@ private: return true; case id(): { auto simpleValue = static_cast(item); - if (simpleValue->value. is()) { + if (simpleValue->value.is()) { return true; } return false; @@ -1020,7 +1020,7 @@ private: std::list destructFromExp(ast_node* node) { const node_container* tableItems = nullptr; - if (ast_cast(node)) { + if (ast_is(node)) { auto item = singleValueFrom(node)->item.get(); if (!item) throw std::logic_error(_info.errorMessage("Invalid destructure value."sv, node)); auto tbA = item->getByPath(); @@ -1044,7 +1044,7 @@ private: } auto value = singleValueFrom(pair); auto item = value->item.get(); - if (ast_cast(item) || + if (ast_is(item) || item->getByPath()) { auto subPairs = destructFromExp(pair); for (auto& p : subPairs) { @@ -1088,7 +1088,7 @@ private: if (auto exp = np->value.as()) { if (!isAssignable(exp)) throw std::logic_error(_info.errorMessage("Can't destructure value."sv, exp)); auto item = singleValueFrom(exp)->item.get(); - if (ast_cast(item) || + if (ast_is(item) || item->getByPath()) { auto subPairs = destructFromExp(exp); auto name = _parser.toString(key); @@ -1129,7 +1129,7 @@ private: } break; } - if (np->value.as()) { + if (np->value.is()) { auto subPairs = destructFromExp(pair); for (auto& p : subPairs) { pairs.push_back({p.isVariable, p.name, @@ -1367,7 +1367,7 @@ private: auto var = singleVariableFrom(exp); if (var.empty()) { storingValue = true; - auto desVar = getUnusedName("_des_"); + auto desVar = getUnusedName("_des_"sv); if (assign->values.objects().size() == 1) { auto var = singleVariableFrom(assign->values.objects().front()); if (!var.empty()) { @@ -2016,7 +2016,6 @@ private: arg.name = "self.__class"sv; break; case id(): { - auto sfName = static_cast(selfName->name.get()); arg.name = _parser.toString(sfName->name); arg.assignSelf = s("self."sv) + arg.name; @@ -2083,7 +2082,7 @@ private: auto clsName = static_cast(name); auto nameStr = _parser.toString(clsName->name); if (LuaKeywords.find(nameStr) != LuaKeywords.end()) { - out.push_back(s("self.__class[\""sv) + nameStr + s("\"]")); + out.push_back(s("self.__class[\""sv) + nameStr + s("\"]"sv)); if (invoke) { if (auto invokePtr = invoke.as()) { invokePtr->args.push_front(toAst("self.__class"sv, x)); @@ -2104,7 +2103,7 @@ private: auto sfName = static_cast(name); auto nameStr = _parser.toString(sfName->name); if (LuaKeywords.find(nameStr) != LuaKeywords.end()) { - out.push_back(s("self[\""sv) + nameStr + s("\"]")); + out.push_back(s("self[\""sv) + nameStr + s("\"]"sv)); if (invoke) { if (auto invokePtr = invoke.as()) { invokePtr->args.push_front(toAst("self"sv, x)); @@ -2763,7 +2762,7 @@ private: _buf << join(temp); _buf << assignStr; _buf << indent(int(temp.size())) << lenVar << " = "sv << lenVar << " + 1"sv << nll(comp); - for (int ind = int(temp.size()) - 1; ind > -1 ; --ind) { + for (int ind = int(temp.size()) - 1; ind > -1; --ind) { _buf << indent(ind) << "end"sv << nll(comp); } switch (usage) { @@ -2827,7 +2826,7 @@ private: case id(): { auto star_exp = static_cast(loopTarget); auto listVar = singleVariableFrom(star_exp->value); - auto indexVar = getUnusedName("_index_"); + auto indexVar = getUnusedName("_index_"sv); varAfter.push_back(indexVar); auto value = singleValueFrom(star_exp->value); if (!value) throw std::logic_error(_info.errorMessage("Invalid star syntax."sv, star_exp)); @@ -2869,14 +2868,14 @@ private: temp.pop_back(); } if (listVar.empty()) { - listVar = getUnusedName("_list_"); + listVar = getUnusedName("_list_"sv); varBefore.push_back(listVar); transformChainValue(chain, temp, ExpUsage::Closure); _buf << indent() << "local "sv << listVar << " = "sv << temp.back() << nll(nameList); } std::string maxVar; if (!stopValue.empty()) { - maxVar = getUnusedName("_max_"); + maxVar = getUnusedName("_max_"sv); varBefore.push_back(maxVar); _buf << indent() << "local "sv << maxVar << " = "sv << stopValue << nll(nameList); } @@ -2885,7 +2884,7 @@ private: if (stopValue.empty()) { _buf << "#"sv << listVar; } else { - _buf << maxVar << " < 0 and #"sv << listVar <<" + " << maxVar << " or "sv << maxVar; + _buf << maxVar << " < 0 and #"sv << listVar << " + "sv << maxVar << " or "sv << maxVar; } if (!stepValue.empty()) { _buf << ", "sv << stepValue; @@ -2897,7 +2896,7 @@ private: bool newListVal = false; if (listVar.empty()) { newListVal = true; - listVar = getUnusedName("_list_"); + listVar = getUnusedName("_list_"sv); varBefore.push_back(listVar); } if (!endWithSlice) { @@ -3355,7 +3354,7 @@ private: } } if (!varDefs.empty()) { - temp.push_back(indent() + s("local ") + join(varDefs, ", "sv) + nll(body)); + temp.push_back(indent() + s("local "sv) + join(varDefs, ", "sv) + nll(body)); } } std::string parent, parentVar; @@ -3431,7 +3430,7 @@ private: if (extend) { _buf << indent() << "setmetatable("sv << baseVar << ", "sv << parentVar << ".__base)"sv << nll(classDecl); } - _buf << indent() << classVar << " = setmetatable({" << nll(classDecl); + _buf << indent() << classVar << " = setmetatable({"sv << nll(classDecl); if (!builtins.empty()) { _buf << join(builtins) << ","sv << nll(classDecl); } else { @@ -3472,7 +3471,7 @@ private: pushScope(); auto selfVar = getUnusedName("_self_"sv); addToScope(selfVar); - _buf << indent(1) << "local " << selfVar << " = setmetatable({}, "sv << baseVar << ")"sv << nll(classDecl); + _buf << indent(1) << "local "sv << selfVar << " = setmetatable({}, "sv << baseVar << ")"sv << nll(classDecl); _buf << indent(1) << "cls.__init("sv << selfVar << ", ...)"sv << nll(classDecl); _buf << indent(1) << "return "sv << selfVar << nll(classDecl); popScope(); @@ -4101,7 +4100,7 @@ private: auto assignList = x->new_ptr(); assignList->exprs.push_back(exp); auto assign = x->new_ptr(); - assign->values.push_back(toAst(s("require ") + _parser.toString(import->literal), x)); + assign->values.push_back(toAst(s("require "sv) + _parser.toString(import->literal), x)); auto assignment = x->new_ptr(); assignment->expList.set(assignList); assignment->action.set(assign); -- cgit v1.2.3-55-g6feb