fix(frontend): 补充不支持语法的警告输出

This commit is contained in:
jing
2026-03-07 22:43:08 +08:00
parent 92f719b7dd
commit 847dc7a5cf
6 changed files with 44 additions and 8 deletions

View File

@@ -28,7 +28,7 @@ void IRGenImpl::GenBlock(const ast::Block& block) {
void IRGenImpl::GenVarDecl(const ast::VarDecl& decl) {
auto it = locals_.find(decl.name);
if (it == locals_.end()) {
throw std::runtime_error("变量栈槽未创建: " + decl.name);
throw std::runtime_error("[irgen] 变量栈槽未创建: " + decl.name);
}
ir::Value* init = nullptr;

View File

@@ -16,7 +16,7 @@ ir::Value* IRGenImpl::GenExpr(const ast::Expr& expr) {
if (auto var = dynamic_cast<const ast::VarExpr*>(&expr)) {
auto it = locals_.find(var->name);
if (it == locals_.end()) {
throw std::runtime_error("变量未找到: " + var->name);
throw std::runtime_error("[irgen] 变量未找到: " + var->name);
}
std::string name = ir::DefaultContext().NextTemp();
return builder_.CreateLoad(it->second, name);
@@ -33,5 +33,5 @@ ir::Value* IRGenImpl::GenExpr(const ast::Expr& expr) {
return builder_.CreateBinary(ir::Opcode::Add, lhs, rhs, name);
}
}
throw std::runtime_error("不支持的表达式类型");
throw std::runtime_error("[irgen] 暂不支持的表达式类型");
}

View File

@@ -16,7 +16,7 @@ IRGenImpl::IRGenImpl(ir::Module& module)
void IRGenImpl::Gen(const ast::CompUnit& ast) {
if (!ast.func || !ast.func->body) {
throw std::runtime_error("AST 不完整:缺少 main 定义");
throw std::runtime_error("[irgen] AST 不完整:缺少 main 定义");
}
GenBlock(*ast.func->body);
}

View File

@@ -15,5 +15,5 @@ void IRGenImpl::GenStmt(const ast::Stmt& stmt) {
builder_.CreateRet(v);
return;
}
throw std::runtime_error("不支持的语句类型");
throw std::runtime_error("[irgen] 暂不支持的语句类型");
}