refactor(dev): unify user-facing diagnostics

This commit is contained in:
Lane0218
2026-03-11 21:42:33 +08:00
parent 9070775187
commit e9d7b4a058
10 changed files with 56 additions and 40 deletions

View File

@@ -4,6 +4,7 @@
#include "SysYParser.h"
#include "ir/IR.h"
#include "utils/Log.h"
void IRGenImpl::GenBlock(SysYParser::BlockContext& block) {
for (auto* item : block.blockItem()) {
@@ -24,7 +25,7 @@ bool IRGenImpl::GenBlockItem(SysYParser::BlockItemContext& item) {
if (item.stmt()) {
return GenStmt(*item.stmt());
}
throw std::runtime_error("[irgen] 暂不支持的 blockItem 类型");
throw std::runtime_error(FormatError("irgen", "暂不支持的语句或声明"));
}
void IRGenImpl::GenDecl(SysYParser::DeclContext& decl) {
@@ -32,13 +33,13 @@ void IRGenImpl::GenDecl(SysYParser::DeclContext& decl) {
GenVarDecl(*decl.varDecl());
return;
}
throw std::runtime_error("[irgen] 暂不支持的声明类型");
throw std::runtime_error(FormatError("irgen", "暂不支持的声明类型"));
}
void IRGenImpl::GenVarDecl(SysYParser::VarDeclContext& decl) {
const std::string name = decl.Ident()->getText();
if (locals_.find(name) != locals_.end()) {
throw std::runtime_error("[irgen] 重复定义变量: " + name);
throw std::runtime_error(FormatError("irgen", "重复定义变量: " + name));
}
auto* slot = builder_.CreateAllocaI32(ir::DefaultContext().NextTemp());
locals_[name] = slot;