|
|
|
|
@ -298,6 +298,9 @@ public:
|
|
|
|
|
sym.scope_level = table_.currentScopeLevel();
|
|
|
|
|
sym.is_initialized = true;
|
|
|
|
|
sym.var_def_ctx = nullptr;
|
|
|
|
|
sym.const_def_ctx = ctx;
|
|
|
|
|
sym.const_def_ctx = ctx;
|
|
|
|
|
std::cout << "保存常量定义上下文: " << name << ", ctx: " << ctx << std::endl;
|
|
|
|
|
// 存储常量值(仅对非数组有效)
|
|
|
|
|
if (!is_array && !init_values.empty()) {
|
|
|
|
|
if (base_type->IsInt32() && init_values[0].kind == SymbolTable::ConstValue::INT) {
|
|
|
|
|
@ -1056,9 +1059,17 @@ private:
|
|
|
|
|
|
|
|
|
|
if (sym->kind == SymbolKind::Variable && sym->var_def_ctx) {
|
|
|
|
|
sema_.BindVarUse(ctx, sym->var_def_ctx);
|
|
|
|
|
std::cout << "绑定变量: " << name << " -> VarDefContext" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
std::cout << "CheckLValue 绑定变量: " << name << std::endl;
|
|
|
|
|
|
|
|
|
|
else if (sym->kind == SymbolKind::Constant && sym->const_def_ctx) {
|
|
|
|
|
sema_.BindConstUse(ctx, sym->const_def_ctx);
|
|
|
|
|
std::cout << "绑定常量: " << name << " -> ConstDefContext" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
std::cout << "CheckLValue 绑定变量: " << name
|
|
|
|
|
<< ", sym->kind: " << (int)sym->kind
|
|
|
|
|
<< ", sym->var_def_ctx: " << sym->var_def_ctx
|
|
|
|
|
<< ", sym->const_def_ctx: " << sym->const_def_ctx << std::endl;
|
|
|
|
|
|
|
|
|
|
bool is_array_access = !ctx->exp().empty();
|
|
|
|
|
bool is_const = (sym->kind == SymbolKind::Constant);
|
|
|
|
|
|
|
|
|
|
|