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

@@ -25,7 +25,7 @@ static inline sccf_sym_t *
sccf_builder_get_symbol_unsafe(sccf_builder_t *builder, const char *name) {
usize idx = sccf_builder_get_symbol_idx(builder, name);
if (idx == 0) {
return null;
return nullptr;
}
return &scc_vec_at(builder->symtab, idx);
}

View File

@@ -34,12 +34,12 @@ static inline u8 *sccf_sect_header_table(u8 *base) {
* @brief 获取指定索引的节头指针
* @param base 文件缓冲区起始地址
* @param idx 节索引 (0 <= idx < sect_header_num)
* @return 指向该节头的指针, 若索引无效返回 null
* @return 指向该节头的指针, 若索引无效返回 nullptr
*/
static inline sccf_sect_header_t *sccf_sect_header(u8 *base, usize idx) {
sccf_header_t *hdr = (sccf_header_t *)base;
if (idx >= (usize)hdr->sect_header_num)
return null;
return nullptr;
u8 *table = sccf_sect_header_table(base);
return (sccf_sect_header_t *)(table + idx * sizeof(sccf_sect_header_t));
}
@@ -76,11 +76,11 @@ static inline usize sccf_sect_data_offset(u8 *base, usize idx) {
* @brief 获取指定索引的节数据起始地址
* @param base 文件缓冲区起始地址
* @param idx 节索引
* @return 数据起始地址, 若索引无效返回 null
* @return 数据起始地址, 若索引无效返回 nullptr
*/
static inline u8 *sccf_sect_data(u8 *base, usize idx) {
usize off = sccf_sect_data_offset(base, idx);
return (off == 0) ? null : base + off;
return (off == 0) ? nullptr : base + off;
}
/** @} */

View File

@@ -14,11 +14,11 @@ void sccf_builder_init(sccf_builder_t *builder) {
scc_vec_init(builder->relocs);
scc_vec_init(builder->symtab);
builder->entry_symbol_name = null;
builder->entry_symbol_name = nullptr;
///< Push null
///< Push nullptr
scc_vec_push(builder->strtab, (char)'\0');
///< Push null
///< Push nullptr
scc_vec_push(builder->symtab, (sccf_sym_t){0});
}
@@ -69,12 +69,12 @@ void sccf_builder_add_section(sccf_builder_t *builder,
}
const sccf_t *sccf_builder_to_sccf(sccf_builder_t *builder) {
if (builder->entry_symbol_name == null) {
if (builder->entry_symbol_name == nullptr) {
builder->sccf.header.entry_point = 0;
} else {
sccf_sym_t *sym =
sccf_builder_get_symbol_unsafe(builder, builder->entry_symbol_name);
if (sym == null || sym->sccf_sect_type != SCCF_SECT_CODE) {
if (sym == nullptr || sym->sccf_sect_type != SCCF_SECT_CODE) {
LOG_ERROR("entry symbol %s not found");
builder->sccf.header.entry_point = 0;
} else {
@@ -125,14 +125,14 @@ const sccf_t *sccf_builder_to_sccf(sccf_builder_t *builder) {
}
void sccf_builder_to_buffer(sccf_builder_t *builder, sccf_buffer_t *buffer) {
Assert(builder != null && buffer != null);
Assert(builder != nullptr && buffer != nullptr);
sccf_write(sccf_builder_to_sccf(builder), buffer);
}
void sccf_builder_to_file(sccf_builder_t *builder, const char *file_path) {
Assert(builder != null && file_path != null);
Assert(builder != nullptr && file_path != nullptr);
scc_file_t fp = scc_fopen(file_path, SCC_FILE_WRITE);
if (fp == null) {
if (fp == nullptr) {
LOG_ERROR("file can't open %s", file_path);
return;
}