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,18 +4,19 @@
#include "SysYParser.h"
#include "ir/IR.h"
#include "utils/Log.h"
bool IRGenImpl::GenStmt(SysYParser::StmtContext& stmt) {
if (stmt.returnStmt()) {
GenReturnStmt(*stmt.returnStmt());
return true;
}
throw std::runtime_error("[irgen] 暂不支持的语句类型");
throw std::runtime_error(FormatError("irgen", "暂不支持的语句类型"));
}
void IRGenImpl::GenReturnStmt(SysYParser::ReturnStmtContext& ret) {
if (!ret.exp()) {
throw std::runtime_error("[irgen] return 缺少表达式");
throw std::runtime_error(FormatError("irgen", "return 缺少表达式"));
}
ir::Value* v = GenExpr(*ret.exp());
builder_.CreateRet(v);