feat(ast2ir): 添加左值标识支持以改善表达式处理
- 在 scc_ast2ir_expr 函数中添加 is_lvalue 参数来区分左值和右值表达式 - 更新二元表达式处理逻辑,特别是赋值操作符的处理 - 改进标识符表达式的处理,根据是否为左值决定返回存储位置还是加载值 - 修复哈希比较函数的实现 - 移除调试相关的注释代码 refactor(parser): 优化语法分析器错误处理和控制流 - 移除不必要的错误恢复辅助注释 - 修改表达式解析的控制流程,将直接返回改为使用 break 语句 - 添加语义分析回调,在解析完成后进行标识符查找和验证 refactor(sema): 增强语义分析阶段的符号表管理 - 改进标识符查找逻辑,增加对非变量标识符的检查 - 扩展声明处理范围,包括变量和参数声明的符号表注册 - 为函数声明添加作用域管理 fix(parser): 修正单元测试中的类型定义 - 将 long long 类型定义改为 int 类型,解决测试兼容性问题 refactor(sccf): 重构文件格式定义和构建器实现 - 重命名符号类型枚举值 OBJECT 为 EXTERN - 重命名段类型枚举值 RELOC 为 RELOCS - 修正结构体字段命名的一致性问题 - 重新设计 SCCF 构建器的数据结构和API - 添加符号表、字符串表和重定位表的构建支持 refactor(target): 重命名Windows PE相关类型定义 - 将 scc_winpe_* 类型重命名为 scc_pe_* 以保持命名一致性 chore: 添加 sccf2target 模块用于格式转换 - 创建新的库模块用于 SCCF 到目标格式的转换 - 实现 PE 格式转换的基本功能 - 添加示例程序演示格式转换过程
This commit is contained in:
@@ -18,15 +18,21 @@ static void expr_callback(void *context, scc_ast_node_type_t node_type,
|
||||
if (node_type == SCC_AST_UNKNOWN || node == null) {
|
||||
return;
|
||||
}
|
||||
scc_ast_expr_t *decl = SCC_AST_CAST_TO(scc_ast_expr_t, node);
|
||||
scc_ast_expr_t *expr = SCC_AST_CAST_TO(scc_ast_expr_t, node);
|
||||
if (node_type == SCC_AST_EXPR_IDENTIFIER) {
|
||||
scc_ast_node_t *node =
|
||||
scc_sema_symtab_lookup_symbol(sema_symtab, decl->identifier.name);
|
||||
scc_sema_symtab_lookup_symbol(sema_symtab, expr->identifier.name);
|
||||
if (node == null) {
|
||||
SCC_ERROR(decl->base.loc, "Identifier '%s' not found",
|
||||
decl->identifier.name);
|
||||
SCC_ERROR(expr->base.loc, "Identifier '%s' not found",
|
||||
expr->identifier.name);
|
||||
} else if (!SCC_AST_IS_A(scc_ast_decl_t, node)) {
|
||||
SCC_ERROR(expr->base.loc, "Identifier '%s' is not a variable",
|
||||
expr->identifier.name);
|
||||
} else {
|
||||
expr->identifier._target = SCC_AST_CAST_TO(scc_ast_decl_t, node);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,6 +56,8 @@ static void stmt_callback(void *context, scc_ast_node_type_t node_type,
|
||||
static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
void *node) {
|
||||
scc_sema_symtab_t *sema_symtab = context;
|
||||
|
||||
// Function declaration scope
|
||||
if (node_type == scc_ast_decl_t_BEGIN) {
|
||||
scc_sema_symtab_enter_scope(sema_symtab);
|
||||
return;
|
||||
@@ -67,27 +75,31 @@ static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
if (decl->name == null) {
|
||||
return;
|
||||
}
|
||||
if (decl->base.type == SCC_AST_DECL_STRUCT) {
|
||||
if (node_type == SCC_AST_DECL_STRUCT) {
|
||||
scc_ast_type_struct_init(type, decl->name, decl, decl->base.loc);
|
||||
scc_cstring_t name = scc_cstring_from_cstr("$S_");
|
||||
scc_cstring_append_cstr(&name, decl->name, scc_strlen(decl->name));
|
||||
scc_sema_symtab_add_symbol(sema_symtab, scc_cstring_as_cstr(&name),
|
||||
&type->base);
|
||||
} else if (decl->base.type == SCC_AST_DECL_UNION) {
|
||||
} else if (node_type == SCC_AST_DECL_UNION) {
|
||||
scc_ast_type_union_init(type, decl->name, decl, decl->base.loc);
|
||||
scc_cstring_t name = scc_cstring_from_cstr("$U_");
|
||||
scc_cstring_append_cstr(&name, decl->name, scc_strlen(decl->name));
|
||||
scc_sema_symtab_add_symbol(sema_symtab, scc_cstring_as_cstr(&name),
|
||||
&type->base);
|
||||
} else if (decl->base.type == SCC_AST_DECL_ENUM) {
|
||||
} else if (node_type == SCC_AST_DECL_ENUM) {
|
||||
scc_ast_type_enum_init(type, decl->name, decl, decl->base.loc);
|
||||
scc_cstring_t name = scc_cstring_from_cstr("$E_");
|
||||
scc_cstring_append_cstr(&name, decl->name, scc_strlen(decl->name));
|
||||
scc_sema_symtab_add_symbol(sema_symtab, scc_cstring_as_cstr(&name),
|
||||
&type->base);
|
||||
} else if (decl->base.type == SCC_AST_DECL_TYPEDEF) {
|
||||
} else if (node_type == SCC_AST_DECL_TYPEDEF) {
|
||||
scc_ast_type_typedef_init(type, decl->name, decl, decl->base.loc);
|
||||
scc_sema_symtab_add_symbol(sema_symtab, decl->name, &type->base);
|
||||
} else if (node_type == SCC_AST_DECL_VAR) {
|
||||
scc_sema_symtab_add_symbol(sema_symtab, decl->name, &decl->base);
|
||||
} else if (node_type == SCC_AST_DECL_PARAM) {
|
||||
scc_sema_symtab_add_symbol(sema_symtab, decl->name, &decl->base);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user