Skip to content

Commit

Permalink
⚡ fix(Gen): 修复对类的调用可能会炸
Browse files Browse the repository at this point in the history
  • Loading branch information
wangziwenhk committed Aug 9, 2024
1 parent b03300a commit 3bdc6fa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Riddle {
typedef std::unordered_map<std::string, std::unordered_map<std::string, std::function<llvm::Value *(llvm::IRBuilder<> &, llvm::Value *)>>> castMapTy;
typedef std::unordered_map<std::string, std::unordered_map<llvm::Type *, std::pmr::unordered_map<llvm::Type *, std::function<llvm::Value *(llvm::IRBuilder<> &, llvm::Value *, llvm::Value *)>>>> binaryOpMapTeleTy;
typedef std::unordered_map<std::string, std::unordered_map<llvm::Type *, std::unordered_map<llvm::Type *, std::function<llvm::Value *(llvm::IRBuilder<> &, llvm::Value *, llvm::Value *)>>>> binaryOpMapTeleTy;
const static castMapTy castMapTemplate = {
{"int",
{
Expand Down
10 changes: 4 additions & 6 deletions src/Tools/Managers/VarManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
#include <stdexcept>

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();
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Managers/VarManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Riddle {
std::stack<std::unordered_map<std::string, bool>> Defined;

private:
bool isDefined(std::string name);
bool isDefined(const std::string &name);

public://函数区
VarManager() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/Visitors/GenVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace Riddle {
const auto type = any_cast<llvm::Type *>(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<ClassNode>(ParentStack.top()).get().types);
}
Expand All @@ -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<ClassNode>(ParentStack.top());
theClass.get().funcs[ctx->funcName->getText()] = module->getOrInsertFunction(funcPkgName, funcType);
} else {
Expand Down

0 comments on commit 3bdc6fa

Please sign in to comment.