refactor(argparse): 将null替换为nullptr以提高C++兼容性
- 在argparse库中将所有null指针常量替换为nullptr - 更新头文件和源文件中的指针初始化和比较操作 - 修改测试文件中的相关断言检查 - 更新AST定义文件中的注释说明
This commit is contained in:
@@ -15,14 +15,14 @@ static void expr_callback(void *context, scc_ast_node_type_t node_type,
|
||||
void *node) {
|
||||
scc_sema_symtab_t *sema_symtab = context;
|
||||
|
||||
if (node_type == SCC_AST_UNKNOWN || node == null) {
|
||||
if (node_type == SCC_AST_UNKNOWN || node == nullptr) {
|
||||
return;
|
||||
}
|
||||
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, expr->identifier.name);
|
||||
if (node == null) {
|
||||
if (node == nullptr) {
|
||||
SCC_ERROR(expr->base.loc, "sema error: Identifier '%s' not found",
|
||||
expr->identifier.name);
|
||||
} else if (!SCC_AST_IS_A(scc_ast_decl_t, node)) {
|
||||
@@ -48,7 +48,7 @@ static void stmt_callback(void *context, scc_ast_node_type_t node_type,
|
||||
scc_sema_symtab_leave_scope(sema_symtab);
|
||||
return;
|
||||
}
|
||||
if (node_type == SCC_AST_UNKNOWN || node == null) {
|
||||
if (node_type == SCC_AST_UNKNOWN || node == nullptr) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
@@ -66,20 +66,20 @@ static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
scc_sema_symtab_leave_scope(sema_symtab);
|
||||
return;
|
||||
}
|
||||
if (node_type == SCC_AST_UNKNOWN || node == null) {
|
||||
if (node_type == SCC_AST_UNKNOWN || node == nullptr) {
|
||||
return;
|
||||
}
|
||||
scc_ast_decl_t *decl = SCC_AST_CAST_TO(scc_ast_decl_t, node);
|
||||
|
||||
scc_ast_type_t *type = scc_malloc(sizeof(scc_ast_type_t));
|
||||
Assert(type != null);
|
||||
Assert(type != nullptr);
|
||||
|
||||
if (node_type == SCC_AST_DECL_STRUCT) {
|
||||
scc_ast_type_struct_init(type, decl->name, decl, decl->base.loc);
|
||||
// FIXME memory leak
|
||||
scc_str_t name = scc_str_from_cstr("$S_");
|
||||
|
||||
if (decl->name == null) {
|
||||
if (decl->name == nullptr) {
|
||||
decl->name = "<anonymous struct>";
|
||||
}
|
||||
scc_str_append_cstr(&name, decl->name, scc_strlen(decl->name));
|
||||
@@ -88,7 +88,7 @@ static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
} else if (node_type == SCC_AST_DECL_UNION) {
|
||||
scc_ast_type_union_init(type, decl->name, decl, decl->base.loc);
|
||||
scc_str_t name = scc_str_from_cstr("$U_");
|
||||
if (decl->name == null) {
|
||||
if (decl->name == nullptr) {
|
||||
decl->name = "<anonymous union>";
|
||||
}
|
||||
scc_str_append_cstr(&name, decl->name, scc_strlen(decl->name));
|
||||
@@ -97,7 +97,7 @@ static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
} else if (node_type == SCC_AST_DECL_ENUM) {
|
||||
scc_ast_type_enum_init(type, decl->name, decl, decl->base.loc);
|
||||
scc_str_t name = scc_str_from_cstr("$E_");
|
||||
if (decl->name == null) {
|
||||
if (decl->name == nullptr) {
|
||||
decl->name = "<anonymous enum>";
|
||||
}
|
||||
scc_str_append_cstr(&name, decl->name, scc_strlen(decl->name));
|
||||
@@ -111,7 +111,7 @@ static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
// LOG_INFO("enum added %s", enum_decl->name);
|
||||
}
|
||||
} else if (node_type == SCC_AST_DECL_TYPEDEF) {
|
||||
if (decl->name == null) {
|
||||
if (decl->name == nullptr) {
|
||||
SCC_ERROR(decl->base.loc, "typedef without name");
|
||||
return;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
} 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) {
|
||||
if (decl->name == null) {
|
||||
if (decl->name == nullptr) {
|
||||
if (decl->param.type->base.type == SCC_AST_TYPE_BUILTIN &&
|
||||
(decl->param.type->builtin.type ==
|
||||
SCC_AST_BUILTIN_TYPE_VA_LIST ||
|
||||
@@ -132,7 +132,7 @@ static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
}
|
||||
scc_sema_symtab_add_symbol(sema_symtab, decl->name, &decl->base);
|
||||
} else if (node_type == SCC_AST_DECL_FUNC) {
|
||||
if (decl->name == null) {
|
||||
if (decl->name == nullptr) {
|
||||
SCC_ERROR(decl->base.loc, "sema error: Function must have a name");
|
||||
} else {
|
||||
// FIXME 重名函数...
|
||||
@@ -150,12 +150,12 @@ static scc_ast_type_t *got_type_callback(void *context, const char *name) {
|
||||
*type = *(scc_ast_type_t *)node;
|
||||
return type;
|
||||
}
|
||||
return null;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void scc_sema_init(scc_sema_callbacks_t *callbacks) {
|
||||
scc_sema_symtab_t *sema_symtab = scc_malloc(sizeof(scc_sema_symtab_t));
|
||||
if (sema_symtab == null) {
|
||||
if (sema_symtab == nullptr) {
|
||||
LOG_FATAL("out of memory");
|
||||
return;
|
||||
}
|
||||
@@ -176,15 +176,16 @@ void scc_sema_init(scc_sema_callbacks_t *callbacks) {
|
||||
&type->base);
|
||||
|
||||
scc_ast_decl_t *decl = scc_malloc(sizeof(scc_ast_decl_t));
|
||||
scc_ast_decl_val_init(decl, type, "__scc_builtin__", null,
|
||||
scc_ast_decl_val_init(decl, type, "__scc_builtin__", nullptr,
|
||||
scc_pos_create());
|
||||
scc_sema_symtab_add_symbol(sema_symtab, "__func__", &decl->base);
|
||||
|
||||
scc_ast_type_t *built_func_type = scc_malloc(sizeof(scc_ast_type_t));
|
||||
scc_ast_type_function_init(built_func_type, null, null, scc_pos_create());
|
||||
scc_ast_type_function_init(built_func_type, nullptr, nullptr,
|
||||
scc_pos_create());
|
||||
scc_ast_decl_t *builin_func = scc_malloc(sizeof(scc_ast_decl_t));
|
||||
scc_ast_decl_func_init(builin_func, built_func_type, "__scc_builtin_func",
|
||||
null, scc_pos_create());
|
||||
nullptr, scc_pos_create());
|
||||
scc_sema_symtab_add_symbol(sema_symtab, "__scc_builtin_va_start",
|
||||
&builin_func->base);
|
||||
scc_sema_symtab_add_symbol(sema_symtab, "__scc_builtin_va_end",
|
||||
|
||||
Reference in New Issue
Block a user