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

@@ -13,7 +13,7 @@ void scc_hashtable_init(scc_hashtable_t *ht,
ht->tombstone_count = 0;
ht->cmp_func = cmp_func;
ht->hash_func = hash_func;
Assert(ht->cmp_func != null && ht->hash_func != null);
Assert(ht->cmp_func != nullptr && ht->hash_func != nullptr);
}
static int next_power_of_two(int n) {
@@ -29,12 +29,12 @@ static int next_power_of_two(int n) {
static scc_hashtable_entry_t *find_entry(scc_hashtable_t *ht, const void *key,
u32 hash) {
if (ht->entries.cap == 0)
return NULL;
return nullptr;
u32 index = hash & (ht->entries.cap - 1); // 容量是2的幂
u32 probe = 0;
scc_hashtable_entry_t *tombstone = NULL;
scc_hashtable_entry_t *tombstone = nullptr;
while (1) {
scc_hashtable_entry_t *entry = &scc_vec_at(ht->entries, index);
@@ -56,7 +56,7 @@ static scc_hashtable_entry_t *find_entry(scc_hashtable_t *ht, const void *key,
break;
}
LOG_ERROR("hashset_find: hash table is full");
return NULL;
return nullptr;
}
static void adjust_capacity(scc_hashtable_t *ht, usize new_cap) {
@@ -71,7 +71,7 @@ static void adjust_capacity(scc_hashtable_t *ht, usize new_cap) {
ht->entries.size = new_cap;
ht->entries.cap = new_cap;
ht->entries.data =
scc_realloc(NULL, new_cap * sizeof(scc_hashtable_entry_t));
scc_realloc(nullptr, new_cap * sizeof(scc_hashtable_entry_t));
scc_memset(ht->entries.data, 0, new_cap * sizeof(scc_hashtable_entry_t));
// rehash the all of the old data
@@ -99,7 +99,7 @@ void *scc_hashtable_set(scc_hashtable_t *ht, const void *key, void *value) {
u32 hash = ht->hash_func(key);
scc_hashtable_entry_t *entry = find_entry(ht, key, hash);
void *old_value = NULL;
void *old_value = nullptr;
if (entry->state == ENTRY_ACTIVE) {
old_value = entry->value;
} else {
@@ -117,22 +117,22 @@ void *scc_hashtable_set(scc_hashtable_t *ht, const void *key, void *value) {
void *scc_hashtable_get(scc_hashtable_t *ht, const void *key) {
if (ht->entries.cap == 0)
return NULL;
return nullptr;
u32 hash = ht->hash_func(key);
scc_hashtable_entry_t *entry = find_entry(ht, key, hash);
return (entry && entry->state == ENTRY_ACTIVE) ? entry->value : NULL;
return (entry && entry->state == ENTRY_ACTIVE) ? entry->value : nullptr;
}
void *scc_hashtable_del(scc_hashtable_t *ht, const void *key) {
if (ht->entries.cap == 0)
return NULL;
return nullptr;
u32 hash = ht->hash_func(key);
scc_hashtable_entry_t *entry = find_entry(ht, key, hash);
if (entry == NULL || entry->state != ENTRY_ACTIVE)
return NULL;
if (entry == nullptr || entry->state != ENTRY_ACTIVE)
return nullptr;
void *value = entry->value;
entry->state = ENTRY_TOMBSTONE;

View File

@@ -15,7 +15,7 @@ const char *scc_strpool_intern(scc_strpool_t *pool, const char *str) {
char *new_str = scc_malloc(len);
if (!new_str) {
LOG_ERROR("strpool: Failed to allocate memory for string");
return NULL;
return nullptr;
}
scc_memcpy(new_str, str, len);