diff --git a/src/Setup.h b/src/Setup.h index 56a256e..c0e130c 100644 --- a/src/Setup.h +++ b/src/Setup.h @@ -9,7 +9,7 @@ namespace Riddle { typedef std::unordered_map &, llvm::Value *)>>> castMapTy; - typedef std::unordered_map &, llvm::Value *, llvm::Value *)>>>> binaryOpMapTeleTy; + typedef std::unordered_map &, llvm::Value *, llvm::Value *)>>>> binaryOpMapTeleTy; const static castMapTy castMapTemplate = { {"int", { diff --git a/src/Tools/Managers/VarManager.cpp b/src/Tools/Managers/VarManager.cpp index 743621e..b29a3e7 100644 --- a/src/Tools/Managers/VarManager.cpp +++ b/src/Tools/Managers/VarManager.cpp @@ -2,13 +2,11 @@ #include namespace Riddle { - bool VarManager::isDefined(std::string name) { - auto it = NamedVar.find(name); + bool VarManager::isDefined(const std::string &name) { + const auto it = NamedVar.find(name); if(it == NamedVar.end()) return false; - else if(it->second.empty()) - return false; - else - return true; + if(it->second.empty()) return false; + return true; } void VarManager::push() { Defined.emplace(); diff --git a/src/Tools/Managers/VarManager.h b/src/Tools/Managers/VarManager.h index 3660643..0d47cf6 100644 --- a/src/Tools/Managers/VarManager.h +++ b/src/Tools/Managers/VarManager.h @@ -12,7 +12,7 @@ namespace Riddle { std::stack> Defined; private: - bool isDefined(std::string name); + bool isDefined(const std::string &name); public://函数区 VarManager() = default; diff --git a/src/Visitors/GenVisitor.cpp b/src/Visitors/GenVisitor.cpp index 9886248..b676692 100644 --- a/src/Visitors/GenVisitor.cpp +++ b/src/Visitors/GenVisitor.cpp @@ -80,7 +80,7 @@ namespace Riddle { const auto type = any_cast(visit(ctx->returnType)); resultType = type; } - if(isClassDefine(ParentStack.top())) { + if(ParentStack.size() && isClassDefine(ParentStack.top())) { args.names.insert(args.names.begin(), "this"); args.types.insert(args.types.begin(), std::get(ParentStack.top()).get().types); } @@ -93,7 +93,7 @@ namespace Riddle { llvm::BasicBlock *oldBlock = Builder.GetInsertBlock(); Builder.SetInsertPoint(entry); // 对于类中方法的定义 - if(isClassDefine(ParentStack.top())) { + if(ParentStack.size() && isClassDefine(ParentStack.top())) { const auto theClass = std::get(ParentStack.top()); theClass.get().funcs[ctx->funcName->getText()] = module->getOrInsertFunction(funcPkgName, funcType); } else {