feat(sem)修改变量绑定

mxr 3 weeks ago
parent 74f325c6fd
commit 9efcdde353

@ -407,24 +407,6 @@ public:
if (!sym) {
throw std::runtime_error(FormatError("sema", "使用了未定义的变量: " + name));
}
// ========== 关键修复:绑定变量使用到定义 ==========
if (sym) {
std::cerr << "[DEBUG] 找到符号: " << sym->name
<< ", kind: " << (int)sym->kind
<< ", var_def_ctx: " << sym->var_def_ctx << std::endl;
if (sym->var_def_ctx) {
std::cout << "[DEBUG] 绑定变量使用" << std::endl;
sema_.BindVarUse(ctx, sym->var_def_ctx);
}
}
else if (sym->kind == SymbolKind::Parameter) {
// 对于函数参数,需要特殊处理
// 参数可能没有对应的 VarDefContext需要创建一个
// 或者通过其他方式标识
std::cout << "[DEBUG] 参数变量: " << name << " (无法绑定到 VarDefContext)" << std::endl;
// 可以创建一个临时标识,但这里先不处理
}
// ============================================
// 检查数组访问
bool is_array_access = !ctx->exp().empty();
std::cout << "[DEBUG] name: " << name
@ -1071,7 +1053,10 @@ private:
if (!sym) {
throw std::runtime_error(FormatError("sema", "未定义的变量: " + name));
}
if (sym->kind == SymbolKind::Variable && sym->var_def_ctx) {
sema_.BindVarUse(ctx, sym->var_def_ctx);
}
std::cout << "CheckLValue 绑定变量: " << name << std::endl;
bool is_array_access = !ctx->exp().empty();

Loading…
Cancel
Save