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

@@ -22,7 +22,7 @@ static scc_lexer_tok_t stringify_argument(scc_pproc_expand_t *ctx,
scc_str_append_ch(&str, '\"'); // 左引号
int need_space = 0; // 是否需要插入空格
scc_lexer_tok_t *tok = null;
scc_lexer_tok_t *tok = nullptr;
scc_vec_foreach(*arg_tokens, i) {
tok = &scc_vec_at(*arg_tokens, i);
if (tok->type == SCC_TOK_BLANK) {
@@ -61,10 +61,10 @@ static scc_lexer_tok_t concatenate_tokens(scc_pproc_expand_t *ctx,
const scc_lexer_tok_t *left,
const scc_lexer_tok_t *right) {
scc_str_t new_lex = scc_str_from_cstr("");
if (left != null) {
if (left != nullptr) {
scc_str_append(&new_lex, &left->lexeme);
}
if (right != null) {
if (right != nullptr) {
scc_str_append(&new_lex, &right->lexeme);
}
@@ -154,7 +154,7 @@ void scc_pproc_expand_by_src(scc_pproc_macro_table_t *macro_table,
scc_lexer_tok_vec_t output_vec;
scc_pproc_expand_by_vec(macro_table, &expaned_buffer, &output_vec, false,
need_keep_org_pos);
Assert(output->cap == 0 && output->data == null); // FIXME hack it
Assert(output->cap == 0 && output->data == nullptr); // FIXME hack it
*output = scc_lexer_array_to_ring(&output_vec);
}
@@ -186,7 +186,7 @@ static void disable(scc_pproc_expand_t *expand_ctx,
const scc_pproc_macro_t *macro) {
scc_pproc_macro_t *expanded_macro =
scc_pproc_macro_new(&macro->name, macro->type);
if (expanded_macro == null) {
if (expanded_macro == nullptr) {
LOG_FATAL("Out of memory");
}
scc_pproc_macro_table_set(expand_ctx->expanded_set, expanded_macro);
@@ -200,7 +200,7 @@ static void enable(scc_pproc_expand_t *expand_ctx,
static cbool need_skip(scc_pproc_expand_t *expand_ctx,
const scc_pproc_macro_t *macro) {
return scc_pproc_macro_table_get(expand_ctx->expanded_set, &macro->name) !=
null;
nullptr;
}
static inline void
@@ -322,7 +322,7 @@ static void rescan(scc_pproc_expand_t *expand_ctx,
scc_pproc_macro_t *end_macro =
scc_pproc_macro_table_get(expand_ctx->macro_table, &end_tok->lexeme);
if (end_macro == null || end_macro->type != SCC_PP_MACRO_FUNCTION) {
if (end_macro == nullptr || end_macro->type != SCC_PP_MACRO_FUNCTION) {
goto RETURN;
}
@@ -387,12 +387,12 @@ static void concact(scc_pproc_expand_t *ctx, scc_lexer_tok_vec_t *tok_buffer,
scc_lexer_tok_t *left;
if (left_idx < 0) {
left = null;
left = nullptr;
left_idx = 0; // FIXME for free tok_buffer
} else {
left = &scc_vec_at(*tok_buffer, left_idx);
if (gnu_va_arg_extend && left->type == SCC_TOK_COMMA) {
left = null;
left = nullptr;
}
}
@@ -468,7 +468,7 @@ static inline void expand_function_macro(scc_pproc_expand_t *ctx,
scc_lexer_tok_t *right_tok;
if (right_idx >= (int)scc_vec_size(macro->replaces)) {
right_tok = null;
right_tok = nullptr;
} else {
right_tok = &scc_vec_at(macro->replaces, right_idx);
}
@@ -488,7 +488,7 @@ static inline void expand_function_macro(scc_pproc_expand_t *ctx,
}
scc_lexer_tok_t *right =
scc_vec_size(right_vec) ? &scc_vec_at(right_vec, 0) : null;
scc_vec_size(right_vec) ? &scc_vec_at(right_vec, 0) : nullptr;
// GNU ## extention
if (scc_strcmp(scc_str_as_cstr(&(right_tok->lexeme)),
@@ -559,7 +559,7 @@ static inline void expand_object_macro(scc_pproc_expand_t *ctx,
scc_lexer_tok_t *right;
if (right_idx >= (int)scc_vec_size(macro->replaces)) {
right = null;
right = nullptr;
} else {
right = &scc_vec_at(macro->replaces, right_idx);
}
@@ -588,7 +588,7 @@ static cbool parse_defined(scc_pproc_expand_t *expand_ctx, scc_pos_t *tok_pos) {
}
if (scc_pproc_macro_table_get(expand_ctx->macro_table,
&next_tok.lexeme) == null) {
&next_tok.lexeme) == nullptr) {
scc_lexer_tok_drop(&next_tok);
scc_lexer_gen_number_false(&next_tok);
} else {
@@ -609,7 +609,7 @@ static cbool parse_defined(scc_pproc_expand_t *expand_ctx, scc_pos_t *tok_pos) {
} else if (scc_get_tok_subtype(next_tok.type) ==
SCC_TOK_SUBTYPE_IDENTIFIER) {
if (scc_pproc_macro_table_get(expand_ctx->macro_table,
&next_tok.lexeme) == null) {
&next_tok.lexeme) == nullptr) {
scc_lexer_tok_drop(&next_tok);
scc_lexer_gen_number_false(&next_tok);
} else {
@@ -649,7 +649,7 @@ void scc_pproc_expand_macro(scc_pproc_expand_t *expand_ctx) {
scc_pproc_macro_t *macro =
scc_pproc_macro_table_get(expand_ctx->macro_table, &tok.lexeme);
if (macro == null || need_skip(expand_ctx, macro)) {
if (macro == nullptr || need_skip(expand_ctx, macro)) {
// FIXME maybe keyword is error or don't parse c keyword or number
tok.type += SCC_TOK_DISABLED;
scc_vec_push(expand_ctx->output, tok);