refactor(argparse): 将null替换为nullptr以提高C++兼容性

- 在argparse库中将所有null指针常量替换为nullptr
- 更新头文件和源文件中的指针初始化和比较操作
- 修改测试文件中的相关断言检查
- 更新AST定义文件中的注释说明
This commit is contained in:
zzy
2026-04-05 20:18:09 +08:00
parent 27d86d5685
commit 4144f7841c
76 changed files with 1430 additions and 998 deletions

View File

@@ -68,15 +68,32 @@ SCC_IR_BUILDER_TYPE_FUNC(f32)
SCC_IR_BUILDER_TYPE_FUNC(f64)
SCC_IR_BUILDER_TYPE_FUNC(f128)
static inline scc_ir_value_ref_t
scc_ir_builder_builtin_memcpy(scc_ir_builder_t *builder,
scc_ir_value_ref_t dest, scc_ir_value_ref_t src,
scc_ir_value_ref_t len) {
scc_ir_value_t value;
scc_ir_value_init(&value, nullptr, SCC_IR_VALUE_TAG_BUILTIN);
value.type = scc_ir_builder_type_void(builder); // memcpy 返回 void*
value.data.builtin.tag = SCC_IR_BUILTIN_TAG_MEMCPY;
value.data.builtin.func.memcpy.dest = dest;
value.data.builtin.func.memcpy.src = src;
value.data.builtin.func.memcpy.size = len;
scc_ir_value_ref_t ref =
scc_ir_module_add_value(builder->ctx.module, &value);
scc_ir_builder_add_instr(builder, ref);
return ref;
}
// TODO
static inline scc_ir_value_ref_t
scc_ir_builder_const_int(scc_ir_builder_t *builder, scc_ir_type_ref_t type,
scc_ir_const_int_t value) {
scc_ir_value_t node;
scc_ir_node_init(&node, null, SCC_IR_VALUE_TAG_CONST_INT);
node.data.const_int = value;
node.type = type;
return scc_ir_module_add_value(&builder->cprog->module, &node);
scc_ir_const_int_t val) {
scc_ir_value_t value;
scc_ir_value_init(&value, nullptr, SCC_IR_VALUE_TAG_CONST_INT);
value.data.const_int = val;
value.type = type;
return scc_ir_module_add_value(&builder->cprog->module, &value);
}
static inline scc_ir_value_ref_t
@@ -86,17 +103,11 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
scc_ir_type_t array_type = {
.tag = SCC_IR_TYPE_ARRAY,
.data.array.base = u8_type,
.data.array.len = len - 1, // 包含 null 结尾
.data.array.len = len - 1, // 包含 nullptr 结尾
};
scc_ir_type_ref_t array_type_ref =
scc_ir_ctx_get_type(&builder->ctx, &array_type);
// 2. 创建指针类型:指向 array_type
scc_ir_type_t ptr_type = {.tag = SCC_IR_TYPE_PTR,
.data.pointer.base = u8_type};
scc_ir_type_ref_t ptr_type_ref =
scc_ir_ctx_get_type(&builder->ctx, &ptr_type);
// 5. 创建聚合节点
scc_ir_value_t const_array_value = {
.tag = SCC_IR_VALUE_TAG_CONST_ARRAY,
@@ -111,10 +122,10 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
}
buff[len - 2] = '\0';
scc_vec_unsafe_from_buffer(const_array_value.data.const_array.elements,
buff, len - 1);
(u8 *)buff, len - 1);
scc_ir_value_ref_t const_array_ref =
scc_ir_module_add_value(builder->ctx.module, &const_array_value);
Assert(const_array_ref != SCC_IR_REF_NULL);
Assert(const_array_ref != SCC_IR_REF_nullptr);
// 3. 创建全局变量节点,类型为指针,初始值指向常量数组
char *name = scc_malloc(32);
@@ -124,7 +135,7 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
builder->ctx.module, &(scc_ir_value_t){
.name = name,
.tag = SCC_IR_VALUE_TAG_GLOBAL_ALLOC,
.type = ptr_type_ref,
.type = array_type_ref,
.data.global_alloc.value = const_array_ref,
});
scc_snprintf(name, 32, "$G%u", global_value_ref);
@@ -135,7 +146,7 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
builder->ctx.module, &(scc_ir_value_t){
.tag = SCC_IR_VALUE_TAG_GET_PTR,
.data.get_ptr.src_addr = global_value_ref,
.data.get_ptr.index = SCC_IR_VALUE_TAG_NULL,
.data.get_ptr.index = SCC_IR_VALUE_TAG_NULLPTR,
});
scc_ir_builder_add_instr(builder, pointer_to_global_value);
return pointer_to_global_value;
@@ -144,7 +155,7 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
/**
* @brief 开始构建函数
* @param func_ref 函数引用
* @param param_names 参数名列表(可为NULL
* @param param_names 参数名列表(可为nullptr
* @return void
*/
void scc_ir_builder_begin_func(scc_ir_builder_t *builder,
@@ -164,7 +175,7 @@ scc_ir_func_ref_t scc_ir_builder_current_func(scc_ir_builder_t *builder);
/**
* @brief 创建一个新的基本块,并自动添加到当前函数中,但不改变当前块。
* @param builder IR构建器
* @param label 基本块标签(可为 NULL,自动生成)
* @param label 基本块标签(可为 nullptr,自动生成)
* @return 新基本块的引用
*/
scc_ir_bblock_ref_t scc_ir_builder_bblock(scc_ir_builder_t *builder,
@@ -172,7 +183,7 @@ scc_ir_bblock_ref_t scc_ir_builder_bblock(scc_ir_builder_t *builder,
/**
* @brief 开始构建新的基本块
* @param label 基本块标签(可为NULL,自动生成)
* @param label 基本块标签(可为nullptr,自动生成)
* @return 基本块引用
*/
scc_ir_bblock_ref_t scc_ir_builder_begin_bblock(scc_ir_builder_t *builder,
@@ -193,7 +204,7 @@ void scc_ir_builder_set_current_bblock(scc_ir_builder_t *builder,
/**
* @brief 创建alloca指令在当前基本块中
* @param type 分配的类型
* @param name 变量名(可为NULL
* @param name 变量名(可为nullptr
*/
scc_ir_value_ref_t scc_ir_builder_alloca(scc_ir_builder_t *builder,
scc_ir_type_ref_t type,