refactor(argparse): 将null替换为nullptr以提高C++兼容性
- 在argparse库中将所有null指针常量替换为nullptr - 更新头文件和源文件中的指针初始化和比较操作 - 修改测试文件中的相关断言检查 - 更新AST定义文件中的注释说明
This commit is contained in:
@@ -33,7 +33,7 @@ typedef struct scc_macro_table {
|
||||
* @brief 创建宏对象
|
||||
* @param name 宏名称
|
||||
* @param type 宏类型
|
||||
* @return 创建的宏对象指针,失败返回NULL
|
||||
* @return 创建的宏对象指针,失败返回nullptr
|
||||
*/
|
||||
scc_pproc_macro_t *scc_pproc_macro_new(const scc_str_t *name,
|
||||
scc_pproc_macro_type_t type);
|
||||
@@ -81,7 +81,7 @@ scc_pproc_macro_t *scc_pproc_macro_table_set(scc_pproc_macro_table_t *pp,
|
||||
* @brief 查找宏定义
|
||||
* @param pp 预处理器实例
|
||||
* @param name 宏名称
|
||||
* @return 找到的宏对象指针,未找到返回NULL
|
||||
* @return 找到的宏对象指针,未找到返回nullptr
|
||||
*/
|
||||
scc_pproc_macro_t *scc_pproc_macro_table_get(scc_pproc_macro_table_t *pp,
|
||||
const scc_str_t *name);
|
||||
|
||||
@@ -49,7 +49,7 @@ static inline int keyword_cmp(const char *name, int len) {
|
||||
|
||||
void scc_pproc_parse_macro_arguments(scc_lexer_tok_ring_t *ring,
|
||||
scc_lexer_tok_vec_t *args, int need_full) {
|
||||
Assert(ring != null && args != null);
|
||||
Assert(ring != nullptr && args != nullptr);
|
||||
scc_lexer_tok_t tok = {0};
|
||||
int depth = 0;
|
||||
int ok;
|
||||
@@ -337,7 +337,7 @@ void scc_pproc_handle_directive(scc_pproc_t *pp) {
|
||||
case SCC_PP_TOK_ELSE:
|
||||
case SCC_PP_TOK_ENDIF: {
|
||||
scc_lexer_tok_drop(&tok);
|
||||
scc_pproc_parse_if_defined(pp, type, null);
|
||||
scc_pproc_parse_if_defined(pp, type, nullptr);
|
||||
scc_lexer_skip_until_newline(pp->cur_ring);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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(¯o->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, ¯o->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);
|
||||
|
||||
@@ -83,7 +83,7 @@ cbool scc_pproc_parse_if_defined(scc_pproc_t *pp, scc_tok_type_t type,
|
||||
int defined = 0;
|
||||
if (tok) {
|
||||
defined = (scc_pproc_macro_table_get(&pp->macro_table,
|
||||
&(tok->lexeme)) != null);
|
||||
&(tok->lexeme)) != nullptr);
|
||||
}
|
||||
switch (type) {
|
||||
case SCC_PP_TOK_IFDEF:
|
||||
|
||||
@@ -43,7 +43,7 @@ FOPEN:
|
||||
}
|
||||
|
||||
scc_pproc_file_t *file = scc_malloc(sizeof(scc_pproc_file_t));
|
||||
Assert(file != null);
|
||||
Assert(file != nullptr);
|
||||
if (scc_sstream_init(&(file->sstream), scc_str_as_cstr(&fpath), 1024)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ scc_pproc_macro_t *scc_pproc_macro_new(const scc_str_t *name,
|
||||
scc_pproc_macro_t *macro = scc_malloc(sizeof(scc_pproc_macro_t));
|
||||
if (!macro) {
|
||||
LOG_ERROR("Failed to allocate memory for macro");
|
||||
return null;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
macro->name = scc_str_copy(name);
|
||||
@@ -96,7 +96,7 @@ cbool scc_pproc_add_function_macro(scc_pproc_macro_table_t *macros,
|
||||
|
||||
scc_pproc_macro_t *scc_pproc_macro_table_set(scc_pproc_macro_table_t *pp,
|
||||
scc_pproc_macro_t *macro) {
|
||||
Assert(pp != null && macro != null && scc_str_len(¯o->name) != 0);
|
||||
Assert(pp != nullptr && macro != nullptr && scc_str_len(¯o->name) != 0);
|
||||
scc_pproc_macro_t *old = scc_hashtable_set(&pp->table, ¯o->name, macro);
|
||||
if (old && old != macro) {
|
||||
LOG_WARN("same macro name `%s`", scc_str_as_cstr(¯o->name));
|
||||
@@ -142,7 +142,7 @@ static int hash_cmp(const void *key1, const void *key2) {
|
||||
}
|
||||
|
||||
void scc_pproc_marco_table_init(scc_pproc_macro_table_t *macros) {
|
||||
Assert(macros != null);
|
||||
Assert(macros != nullptr);
|
||||
scc_hashtable_init(¯os->table, hash_func, hash_cmp);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ static int macro_free(const void *key, void *value, void *context) {
|
||||
}
|
||||
|
||||
void scc_pproc_macro_table_drop(scc_pproc_macro_table_t *macros) {
|
||||
Assert(macros != null);
|
||||
scc_hashtable_foreach(¯os->table, macro_free, null);
|
||||
Assert(macros != nullptr);
|
||||
scc_hashtable_foreach(¯os->table, macro_free, nullptr);
|
||||
scc_hashtable_drop(¯os->table);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <scc_pproc.h>
|
||||
|
||||
static int pproc_next_one_file(scc_pproc_t *pp, scc_lexer_tok_t *out) {
|
||||
scc_lexer_tok_ring_t *stream = null;
|
||||
scc_lexer_tok_ring_t *stream = nullptr;
|
||||
scc_lexer_tok_t tok = {0};
|
||||
int ok = 0;
|
||||
CONTINUE:
|
||||
@@ -57,7 +57,7 @@ CONTINUE:
|
||||
// maybe expanded
|
||||
scc_pproc_macro_t *macro =
|
||||
scc_pproc_macro_table_get(&pp->macro_table, &tok.lexeme);
|
||||
if (macro == null) {
|
||||
if (macro == nullptr) {
|
||||
scc_ring_next_consume(*stream, *out, ok);
|
||||
return ok;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ void scc_pproc_add_builtin_macros(scc_pproc_macro_table_t *macro_table) {
|
||||
}
|
||||
|
||||
void scc_pproc_init(scc_pproc_t *pp, scc_lexer_tok_ring_t *input) {
|
||||
Assert(pp != null && input != null);
|
||||
Assert(pp != nullptr && input != nullptr);
|
||||
pp->org_ring = input;
|
||||
pp->cur_ring = pp->org_ring;
|
||||
scc_ring_init(pp->expanded_ring, 0, 0, 0);
|
||||
@@ -171,7 +171,7 @@ scc_lexer_tok_ring_t *scc_pproc_to_ring(scc_pproc_t *pp, int ring_size,
|
||||
|
||||
// 销毁预处理器
|
||||
void scc_pproc_drop(scc_pproc_t *pp) {
|
||||
if (pp == null)
|
||||
if (pp == nullptr)
|
||||
return;
|
||||
Assert(pp->cur_ring == pp->org_ring);
|
||||
scc_lexer_drop_ring(pp->org_ring);
|
||||
|
||||
@@ -134,5 +134,5 @@ TEST_LIST = {
|
||||
TEST_LIST_CASE(test_define_double_pos),
|
||||
TEST_LIST_CASE(test_define_param_pos),
|
||||
TEST_LIST_CASE(test_define_stringify_pos),
|
||||
{NULL, NULL},
|
||||
{nullptr, nullptr},
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@ static cbool process_input(const char *input, scc_str_t *output) {
|
||||
do { \
|
||||
scc_str_t output; \
|
||||
process_input(input, &output); \
|
||||
assert(output.data != NULL); \
|
||||
assert(output.data != nullptr); \
|
||||
TEST_CHECK(strcmp(output.data, expect) == 0); \
|
||||
TEST_MSG("Expected: %s", expect); \
|
||||
TEST_MSG("Produced: %s", output.data); \
|
||||
@@ -50,8 +50,8 @@ static cbool process_input(const char *input, scc_str_t *output) {
|
||||
do { \
|
||||
scc_str_t output; \
|
||||
process_input(input, &output); \
|
||||
assert(output.data != NULL); \
|
||||
TEST_CHECK(strstr(output.data, expect) != NULL); \
|
||||
assert(output.data != nullptr); \
|
||||
TEST_CHECK(strstr(output.data, expect) != nullptr); \
|
||||
TEST_MSG("Expected: %s", expect); \
|
||||
TEST_MSG("Produced: %s", output.data); \
|
||||
scc_str_drop(&output); \
|
||||
@@ -649,5 +649,5 @@ TEST_LIST = {
|
||||
TEST_LIST_CASE(test_real_case),
|
||||
|
||||
TEST_LIST_CASE(test_c99_docs),
|
||||
{NULL, NULL},
|
||||
{nullptr, nullptr},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user