refactor(hashtable): 简化哈希表初始化接口并优化文件打开模式
- 将哈希表初始化从两步设置改为一步完成,直接传递哈希函数和比较函数 - 重构scc_hashtable_init函数签名,接受函数指针参数 - 更新内部字段名从key_cmp为cmp_func以保持一致性 - 添加类型定义scc_hashtable_hash_func_t和scc_hashtable_equal_func_t - 修改PAL层文件操作接口,使用枚举模式替代固定只读模式 - 更新IR上下文、预处理器宏表等组件使用新的初始化方式 - 移除AST头文件中未使用的语义分析回调类型定义 - 修复预处理器中的空指针访问问题
This commit is contained in:
@@ -120,24 +120,15 @@ void scc_ir_ctx_init(scc_ir_cprog_ctx_t *ctx) {
|
||||
scc_vec_init(ctx->bblocks);
|
||||
scc_vec_init(ctx->funcs);
|
||||
|
||||
// 设置哈希函数
|
||||
ctx->uid2nodes.hash_func = hash_key;
|
||||
ctx->uid2nodes.key_cmp = cmp_key;
|
||||
ctx->uid2types.hash_func = hash_key;
|
||||
ctx->uid2types.key_cmp = cmp_key;
|
||||
ctx->uid2bblocks.hash_func = hash_key;
|
||||
ctx->uid2bblocks.key_cmp = cmp_key;
|
||||
ctx->uid2funcs.hash_func = hash_key;
|
||||
ctx->uid2funcs.key_cmp = cmp_key;
|
||||
// 初始化哈希表
|
||||
scc_hashtable_init(&ctx->uid2nodes);
|
||||
scc_hashtable_init(&ctx->uid2types);
|
||||
scc_hashtable_init(&ctx->uid2bblocks);
|
||||
scc_hashtable_init(&ctx->uid2funcs);
|
||||
scc_hashtable_init(&ctx->uid2nodes, hash_key, cmp_key);
|
||||
scc_hashtable_init(&ctx->uid2types, hash_key, cmp_key);
|
||||
scc_hashtable_init(&ctx->uid2bblocks, hash_key, cmp_key);
|
||||
scc_hashtable_init(&ctx->uid2funcs, hash_key, cmp_key);
|
||||
|
||||
ctx->type_uniquing.hash_func = (void *)hash_type;
|
||||
ctx->type_uniquing.key_cmp = (void *)cmp_type;
|
||||
scc_hashtable_init(&ctx->type_uniquing);
|
||||
scc_hashtable_init(&ctx->type_uniquing,
|
||||
(scc_hashtable_hash_func_t)hash_type,
|
||||
(scc_hashtable_equal_func_t)cmp_type);
|
||||
|
||||
// 预留UID 0 作为无效引用
|
||||
ctx->node_uid = 1;
|
||||
|
||||
Reference in New Issue
Block a user