From 3bdc6fa68245ed9727eee77843855dd066e23eb1 Mon Sep 17 00:00:00 2001 From: wangziwenhk Date: Fri, 9 Aug 2024 15:44:31 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20fix(Gen):=20=E4=BF=AE=E5=A4=8D=E5=AF=B9?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E8=B0=83=E7=94=A8=E5=8F=AF=E8=83=BD=E4=BC=9A?= =?UTF-8?q?=E7=82=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Setup.h | 2 +- src/Tools/Managers/VarManager.cpp | 10 ++++------ src/Tools/Managers/VarManager.h | 2 +- src/Visitors/GenVisitor.cpp | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) 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 {