refactor(argparse): 将null替换为nullptr以提高C++兼容性
- 在argparse库中将所有null指针常量替换为nullptr - 更新头文件和源文件中的指针初始化和比较操作 - 修改测试文件中的相关断言检查 - 更新AST定义文件中的注释说明
This commit is contained in:
@@ -176,7 +176,7 @@ struct scc_ast_type {
|
||||
} pointer;
|
||||
struct {
|
||||
scc_ast_type_t *element;
|
||||
scc_ast_expr_t *size; // 可为 null <=> 不定长数组
|
||||
scc_ast_expr_t *size; // 可为 nullptr <=> 不定长数组
|
||||
} array;
|
||||
struct {
|
||||
scc_ast_type_t *return_type;
|
||||
@@ -184,7 +184,7 @@ struct scc_ast_type {
|
||||
} function;
|
||||
struct {
|
||||
const char *name;
|
||||
scc_ast_decl_t *decl; // can be null
|
||||
scc_ast_decl_t *decl; // can be nullptr
|
||||
} record;
|
||||
struct {
|
||||
const char *name;
|
||||
@@ -354,7 +354,7 @@ struct scc_ast_stmt {
|
||||
struct {
|
||||
scc_ast_expr_t *cond;
|
||||
scc_ast_stmt_t *then_stmt;
|
||||
scc_ast_stmt_t *opt_else_stmt; // stmt or null
|
||||
scc_ast_stmt_t *opt_else_stmt; // stmt or nullptr
|
||||
} if_stmt;
|
||||
// while do-while 语句
|
||||
struct {
|
||||
@@ -363,9 +363,9 @@ struct scc_ast_stmt {
|
||||
} while_stmt;
|
||||
// for 语句
|
||||
struct {
|
||||
scc_ast_node_t *init; // expr or decl or null
|
||||
scc_ast_expr_t *cond; // 可为 null
|
||||
scc_ast_expr_t *incr; // 可为 null
|
||||
scc_ast_node_t *init; // expr or decl or nullptr
|
||||
scc_ast_expr_t *cond; // 可为 nullptr
|
||||
scc_ast_expr_t *incr; // 可为 nullptr
|
||||
scc_ast_stmt_t *body;
|
||||
} for_stmt;
|
||||
// switch 语句
|
||||
@@ -388,7 +388,7 @@ struct scc_ast_stmt {
|
||||
} jump;
|
||||
// return 语句
|
||||
struct {
|
||||
scc_ast_expr_t *expr; // 可为 null
|
||||
scc_ast_expr_t *expr; // 可为 nullptr
|
||||
} return_stmt;
|
||||
// goto 语句
|
||||
struct {
|
||||
@@ -416,12 +416,12 @@ struct scc_ast_decl {
|
||||
// 变量声明
|
||||
struct {
|
||||
scc_ast_type_t *type;
|
||||
scc_ast_expr_t *init; // 可为 NULL
|
||||
scc_ast_expr_t *init; // 可为 nullptr
|
||||
} var;
|
||||
// 函数声明
|
||||
struct {
|
||||
scc_ast_type_t *type; // 函数类型
|
||||
scc_ast_stmt_t *body; // 可为 null 表示只有声明
|
||||
scc_ast_stmt_t *body; // 可为 nullptr 表示只有声明
|
||||
} func;
|
||||
// 参数声明
|
||||
struct {
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
#include "ast_def.h"
|
||||
#include "ast_dump.h"
|
||||
|
||||
// decls can be null but maybe warning
|
||||
// decls can be nullptr but maybe warning
|
||||
static inline void
|
||||
scc_ast_translation_unit_init(scc_ast_translation_unit_t *translation_unit,
|
||||
scc_ast_decl_vec_t *decls, scc_pos_t loc) {
|
||||
Assert(translation_unit != null);
|
||||
Assert(translation_unit != nullptr);
|
||||
translation_unit->base.type = SCC_AST_TRANSLATION_UNIT;
|
||||
translation_unit->base.loc = loc;
|
||||
if (decls == null) {
|
||||
if (decls == nullptr) {
|
||||
scc_vec_init(translation_unit->declarations);
|
||||
} else {
|
||||
translation_unit->declarations = *decls;
|
||||
@@ -22,21 +22,21 @@ scc_ast_translation_unit_init(scc_ast_translation_unit_t *translation_unit,
|
||||
static inline void scc_ast_decl_list_init(scc_ast_decl_t *decl,
|
||||
scc_ast_decl_vec_t *list_move,
|
||||
scc_pos_t loc) {
|
||||
Assert(decl != null && list_move != null);
|
||||
Assert(decl != nullptr && list_move != nullptr);
|
||||
decl->base.loc = loc;
|
||||
decl->base.type = SCC_AST_DECL_LIST;
|
||||
decl->name = null;
|
||||
decl->name = nullptr;
|
||||
decl->list.vars = *list_move;
|
||||
scc_vec_init(*list_move);
|
||||
}
|
||||
|
||||
// name and var_init can be null
|
||||
// name and var_init can be nullptr
|
||||
static inline void scc_ast_decl_unsafe_val_init(scc_ast_decl_t *decl,
|
||||
scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_expr_t *var_init,
|
||||
scc_pos_t loc) {
|
||||
Assert(decl != null && type != null);
|
||||
Assert(decl != nullptr && type != nullptr);
|
||||
decl->base.loc = loc;
|
||||
decl->base.type = SCC_AST_DECL_VAR;
|
||||
decl->name = name;
|
||||
@@ -44,12 +44,12 @@ static inline void scc_ast_decl_unsafe_val_init(scc_ast_decl_t *decl,
|
||||
decl->var.init = var_init;
|
||||
}
|
||||
|
||||
// var_init can be null
|
||||
// var_init can be nullptr
|
||||
static inline void scc_ast_decl_val_init(scc_ast_decl_t *decl,
|
||||
scc_ast_type_t *type, const char *name,
|
||||
scc_ast_expr_t *var_init,
|
||||
scc_pos_t loc) {
|
||||
Assert(decl != null && name != null && type != null);
|
||||
Assert(decl != nullptr && name != nullptr && type != nullptr);
|
||||
decl->base.loc = loc;
|
||||
decl->base.type = SCC_AST_DECL_VAR;
|
||||
decl->name = name;
|
||||
@@ -57,12 +57,12 @@ static inline void scc_ast_decl_val_init(scc_ast_decl_t *decl,
|
||||
decl->var.init = var_init;
|
||||
}
|
||||
|
||||
// body can be null
|
||||
// body can be nullptr
|
||||
static inline void scc_ast_decl_func_init(scc_ast_decl_t *decl,
|
||||
scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_stmt_t *body, scc_pos_t loc) {
|
||||
Assert(decl != null && name != null && type != null);
|
||||
Assert(decl != nullptr && name != nullptr && type != nullptr);
|
||||
decl->base.loc = loc;
|
||||
decl->base.type = SCC_AST_DECL_FUNC;
|
||||
decl->name = name;
|
||||
@@ -71,11 +71,11 @@ static inline void scc_ast_decl_func_init(scc_ast_decl_t *decl,
|
||||
decl->func.body = body;
|
||||
}
|
||||
|
||||
// name can be null
|
||||
// name can be nullptr
|
||||
static inline void scc_ast_decl_param_init(scc_ast_decl_t *decl,
|
||||
scc_ast_type_t *type,
|
||||
const char *name, scc_pos_t loc) {
|
||||
Assert(decl != null && type != null);
|
||||
Assert(decl != nullptr && type != nullptr);
|
||||
decl->base.loc = loc;
|
||||
decl->base.type = SCC_AST_DECL_PARAM;
|
||||
decl->name = name;
|
||||
@@ -87,11 +87,11 @@ static inline void _scc_ast_decl_record_init(scc_ast_decl_t *decl,
|
||||
const char *name,
|
||||
scc_ast_decl_vec_t *fields_move,
|
||||
scc_pos_t loc) {
|
||||
Assert(decl != null);
|
||||
Assert(decl != nullptr);
|
||||
decl->base.loc = loc;
|
||||
decl->base.type = type;
|
||||
decl->name = name;
|
||||
if (fields_move == null) {
|
||||
if (fields_move == nullptr) {
|
||||
scc_vec_init(decl->record.fields);
|
||||
} else {
|
||||
decl->record.fields = *fields_move;
|
||||
@@ -99,7 +99,7 @@ static inline void _scc_ast_decl_record_init(scc_ast_decl_t *decl,
|
||||
}
|
||||
}
|
||||
|
||||
// name and fields can be null
|
||||
// name and fields can be nullptr
|
||||
static inline void scc_ast_decl_struct_init(scc_ast_decl_t *decl,
|
||||
const char *name,
|
||||
scc_ast_decl_vec_t *fields_move,
|
||||
@@ -108,7 +108,7 @@ static inline void scc_ast_decl_struct_init(scc_ast_decl_t *decl,
|
||||
loc);
|
||||
}
|
||||
|
||||
// name and fields can be null
|
||||
// name and fields can be nullptr
|
||||
static inline void scc_ast_decl_union_init(scc_ast_decl_t *decl,
|
||||
const char *name,
|
||||
scc_ast_decl_vec_t *fields_move,
|
||||
@@ -116,7 +116,7 @@ static inline void scc_ast_decl_union_init(scc_ast_decl_t *decl,
|
||||
_scc_ast_decl_record_init(decl, SCC_AST_DECL_UNION, name, fields_move, loc);
|
||||
}
|
||||
|
||||
// name and fields can be null
|
||||
// name and fields can be nullptr
|
||||
static inline void scc_ast_decl_enum_init(scc_ast_decl_t *decl,
|
||||
const char *name,
|
||||
scc_ast_decl_vec_t *fields_move,
|
||||
@@ -128,20 +128,20 @@ static inline void scc_ast_decl_typedef_init(scc_ast_decl_t *decl,
|
||||
const char *name,
|
||||
scc_ast_type_t *type,
|
||||
scc_pos_t loc) {
|
||||
Assert(decl != null && name != null && type != null);
|
||||
Assert(decl != nullptr && name != nullptr && type != nullptr);
|
||||
decl->base.loc = loc;
|
||||
decl->base.type = SCC_AST_DECL_TYPEDEF;
|
||||
decl->name = name;
|
||||
decl->typedef_decl.type = type;
|
||||
}
|
||||
|
||||
// items can be null
|
||||
// items can be nullptr
|
||||
static inline void scc_ast_stmt_compound_init(
|
||||
scc_ast_stmt_t *stmt, scc_ast_block_item_vec_t *items_move, scc_pos_t loc) {
|
||||
Assert(stmt != null);
|
||||
Assert(stmt != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_COMPOUND;
|
||||
if (items_move == null) {
|
||||
if (items_move == nullptr) {
|
||||
scc_vec_init(stmt->compound.block_items);
|
||||
} else {
|
||||
stmt->compound.block_items = *items_move;
|
||||
@@ -149,22 +149,22 @@ static inline void scc_ast_stmt_compound_init(
|
||||
}
|
||||
}
|
||||
|
||||
// expr can be null
|
||||
// expr can be nullptr
|
||||
static inline void scc_ast_stmt_expr_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *expr, scc_pos_t loc) {
|
||||
Assert(stmt != null);
|
||||
Assert(stmt != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_EXPR;
|
||||
stmt->expr.expr = expr;
|
||||
}
|
||||
|
||||
// opt_else can be null
|
||||
// opt_else can be nullptr
|
||||
static inline void scc_ast_stmt_if_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *cond,
|
||||
scc_ast_stmt_t *then,
|
||||
scc_ast_stmt_t *opt_else,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null && cond != null && then != null);
|
||||
Assert(stmt != nullptr && cond != nullptr && then != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_IF;
|
||||
stmt->if_stmt.cond = cond;
|
||||
@@ -176,7 +176,7 @@ static inline void scc_ast_stmt_while_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *cond,
|
||||
scc_ast_stmt_t *body,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null && cond != null && body != null);
|
||||
Assert(stmt != nullptr && cond != nullptr && body != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_WHILE;
|
||||
stmt->while_stmt.cond = cond;
|
||||
@@ -187,7 +187,7 @@ static inline void scc_ast_stmt_do_while_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *cond,
|
||||
scc_ast_stmt_t *body,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null && cond != null && body != null);
|
||||
Assert(stmt != nullptr && cond != nullptr && body != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_DO_WHILE;
|
||||
stmt->while_stmt.cond = cond;
|
||||
@@ -200,7 +200,7 @@ static inline void scc_ast_stmt_for_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *cond,
|
||||
scc_ast_expr_t *incr,
|
||||
scc_ast_stmt_t *body, scc_pos_t loc) {
|
||||
Assert(stmt != null && body != null);
|
||||
Assert(stmt != nullptr && body != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_FOR;
|
||||
stmt->for_stmt.init = init;
|
||||
@@ -213,7 +213,7 @@ static inline void scc_ast_stmt_switch_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *cond,
|
||||
scc_ast_stmt_t *body,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null && cond != null && body != null);
|
||||
Assert(stmt != nullptr && cond != nullptr && body != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_SWITCH;
|
||||
stmt->switch_stmt.cond = cond;
|
||||
@@ -223,7 +223,7 @@ static inline void scc_ast_stmt_switch_init(scc_ast_stmt_t *stmt,
|
||||
static inline void scc_ast_stmt_case_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *cond,
|
||||
scc_ast_stmt_t *body, scc_pos_t loc) {
|
||||
Assert(stmt != null && cond != null && body != null);
|
||||
Assert(stmt != nullptr && cond != nullptr && body != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_CASE;
|
||||
stmt->case_stmt.expr = cond;
|
||||
@@ -233,7 +233,7 @@ static inline void scc_ast_stmt_case_init(scc_ast_stmt_t *stmt,
|
||||
static inline void scc_ast_stmt_default_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_stmt_t *body,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null && body != null);
|
||||
Assert(stmt != nullptr && body != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_DEFAULT;
|
||||
stmt->default_stmt.stmt = body;
|
||||
@@ -241,25 +241,25 @@ static inline void scc_ast_stmt_default_init(scc_ast_stmt_t *stmt,
|
||||
|
||||
static inline void scc_ast_stmt_break_init(scc_ast_stmt_t *stmt,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null);
|
||||
Assert(stmt != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_BREAK;
|
||||
stmt->jump._target = null;
|
||||
stmt->jump._target = nullptr;
|
||||
}
|
||||
|
||||
static inline void scc_ast_stmt_continue_init(scc_ast_stmt_t *stmt,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null);
|
||||
Assert(stmt != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_CONTINUE;
|
||||
stmt->jump._target = null;
|
||||
stmt->jump._target = nullptr;
|
||||
}
|
||||
|
||||
// expr can be null
|
||||
// expr can be nullptr
|
||||
static inline void scc_ast_stmt_return_init(scc_ast_stmt_t *stmt,
|
||||
scc_ast_expr_t *expr,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null);
|
||||
Assert(stmt != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_RETURN;
|
||||
stmt->return_stmt.expr = expr;
|
||||
@@ -267,18 +267,18 @@ static inline void scc_ast_stmt_return_init(scc_ast_stmt_t *stmt,
|
||||
|
||||
static inline void scc_ast_stmt_goto_init(scc_ast_stmt_t *stmt,
|
||||
const char *label, scc_pos_t loc) {
|
||||
Assert(stmt != null && label != null);
|
||||
Assert(stmt != nullptr && label != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_GOTO;
|
||||
stmt->goto_stmt.label = label;
|
||||
stmt->goto_stmt._target = null;
|
||||
stmt->goto_stmt._target = nullptr;
|
||||
}
|
||||
|
||||
static inline void scc_ast_stmt_label_init(scc_ast_stmt_t *stmt,
|
||||
const char *label,
|
||||
scc_ast_stmt_t *body,
|
||||
scc_pos_t loc) {
|
||||
Assert(stmt != null);
|
||||
Assert(stmt != nullptr);
|
||||
stmt->base.loc = loc;
|
||||
stmt->base.type = SCC_AST_STMT_LABEL;
|
||||
stmt->label_stmt.label = label;
|
||||
@@ -290,7 +290,7 @@ static inline void scc_ast_expr_binary_init(scc_ast_expr_t *expr,
|
||||
scc_ast_expr_t *lhs,
|
||||
scc_ast_expr_t *rhs,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && lhs != null && rhs != null);
|
||||
Assert(expr != nullptr && lhs != nullptr && rhs != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_BINARY;
|
||||
expr->binary.op = op;
|
||||
@@ -302,7 +302,7 @@ static inline void scc_ast_expr_unary_init(scc_ast_expr_t *expr,
|
||||
scc_ast_expr_op_t op,
|
||||
scc_ast_expr_t *operand,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && operand != null);
|
||||
Assert(expr != nullptr && operand != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_UNARY;
|
||||
expr->unary.op = op;
|
||||
@@ -314,8 +314,8 @@ static inline void scc_ast_expr_cond_init(scc_ast_expr_t *expr,
|
||||
scc_ast_expr_t *then_expr,
|
||||
scc_ast_expr_t *else_expr,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && cond != null && then_expr != null &&
|
||||
else_expr != null);
|
||||
Assert(expr != nullptr && cond != nullptr && then_expr != nullptr &&
|
||||
else_expr != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_COND;
|
||||
expr->cond.cond = cond;
|
||||
@@ -323,16 +323,16 @@ static inline void scc_ast_expr_cond_init(scc_ast_expr_t *expr,
|
||||
expr->cond.else_expr = else_expr;
|
||||
}
|
||||
|
||||
// args can be null
|
||||
// args can be nullptr
|
||||
static inline void scc_ast_expr_call_init(scc_ast_expr_t *expr,
|
||||
scc_ast_expr_t *callee,
|
||||
scc_ast_expr_vec_t *args,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && callee != null);
|
||||
Assert(expr != nullptr && callee != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_CALL;
|
||||
expr->call.callee = callee;
|
||||
if (args == null) {
|
||||
if (args == nullptr) {
|
||||
scc_vec_init(expr->call.args);
|
||||
} else {
|
||||
expr->call.args = *args;
|
||||
@@ -344,7 +344,7 @@ static inline void scc_ast_expr_array_subscript_init(scc_ast_expr_t *expr,
|
||||
scc_ast_expr_t *array,
|
||||
scc_ast_expr_t *index,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && array != null && index != null);
|
||||
Assert(expr != nullptr && array != nullptr && index != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_ARRAY_SUBSCRIPT;
|
||||
expr->subscript.array = array;
|
||||
@@ -356,7 +356,7 @@ static inline void _scc_ast_expr_member_init(scc_ast_expr_t *expr,
|
||||
scc_ast_expr_t *object,
|
||||
const char *member,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && object != null && member != null);
|
||||
Assert(expr != nullptr && object != nullptr && member != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = type;
|
||||
expr->member.base = object;
|
||||
@@ -382,31 +382,31 @@ static inline void scc_ast_expr_cast_init(scc_ast_expr_t *expr,
|
||||
scc_ast_type_t *type,
|
||||
scc_ast_expr_t *operand,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && type != null && operand != null);
|
||||
Assert(expr != nullptr && type != nullptr && operand != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_CAST;
|
||||
expr->cast.type = type;
|
||||
expr->cast.expr = operand;
|
||||
}
|
||||
|
||||
// type and target_expr can be null but it only one of them can be null
|
||||
// type and target_expr can be nullptr but it only one of them can be nullptr
|
||||
static inline void scc_ast_expr_sizeof_init(scc_ast_expr_t *expr,
|
||||
scc_ast_type_t *type,
|
||||
scc_ast_expr_t *target_expr,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null);
|
||||
Assert(expr != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_SIZE_OF;
|
||||
expr->attr_of.type = type;
|
||||
expr->attr_of.expr = target_expr;
|
||||
}
|
||||
|
||||
// type and target_expr can be null but it only one of them can be null
|
||||
// type and target_expr can be nullptr but it only one of them can be nullptr
|
||||
static inline void scc_ast_expr_alignof_init(scc_ast_expr_t *expr,
|
||||
scc_ast_type_t *type,
|
||||
scc_ast_expr_t *target_expr,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null);
|
||||
Assert(expr != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type =
|
||||
SCC_AST_EXPR_SIZE_OF; // 注意:这里使用了 SIZE_OF,可能需要改为 ALIGN_OF
|
||||
@@ -414,25 +414,25 @@ static inline void scc_ast_expr_alignof_init(scc_ast_expr_t *expr,
|
||||
expr->attr_of.expr = target_expr;
|
||||
}
|
||||
|
||||
// lhs_exprs and rhs_exprs can be null
|
||||
// lhs_exprs and rhs_exprs can be nullptr
|
||||
static inline void scc_ast_expr_compound_init(scc_ast_expr_t *expr,
|
||||
scc_ast_expr_t *base,
|
||||
scc_ast_expr_vec_t *lhs_exprs,
|
||||
scc_ast_expr_vec_t *rhs_exprs,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && base != null);
|
||||
Assert(expr != nullptr && base != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_COMPOUND;
|
||||
expr->compound.base = base;
|
||||
|
||||
if (lhs_exprs == null) {
|
||||
if (lhs_exprs == nullptr) {
|
||||
scc_vec_init(expr->compound.lhs_exprs);
|
||||
} else {
|
||||
expr->compound.lhs_exprs = *lhs_exprs;
|
||||
scc_vec_init(*lhs_exprs);
|
||||
}
|
||||
|
||||
if (rhs_exprs == null) {
|
||||
if (rhs_exprs == nullptr) {
|
||||
scc_vec_init(expr->compound.rhs_exprs);
|
||||
} else {
|
||||
expr->compound.rhs_exprs = *rhs_exprs;
|
||||
@@ -444,7 +444,7 @@ static inline void scc_ast_expr_literal_init(scc_ast_expr_t *expr,
|
||||
scc_ast_node_type_t type,
|
||||
const char *value, cbool owned,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && value != null);
|
||||
Assert(expr != nullptr && value != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = type;
|
||||
expr->literal.lexme = value;
|
||||
@@ -481,17 +481,17 @@ static inline void scc_ast_expr_literal_string_init(scc_ast_expr_t *expr,
|
||||
static inline void scc_ast_expr_identifier_init(scc_ast_expr_t *expr,
|
||||
const char *name,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && name != null);
|
||||
Assert(expr != nullptr && name != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_IDENTIFIER;
|
||||
expr->identifier.name = name;
|
||||
expr->identifier._target = null;
|
||||
expr->identifier._target = nullptr;
|
||||
}
|
||||
|
||||
static inline void scc_ast_expr_lvalue_init(scc_ast_expr_t *expr,
|
||||
scc_ast_type_t *type,
|
||||
scc_pos_t loc) {
|
||||
Assert(expr != null && type != null);
|
||||
Assert(expr != nullptr && type != nullptr);
|
||||
expr->base.loc = loc;
|
||||
expr->base.type = SCC_AST_EXPR_LVALUE;
|
||||
expr->lvalue.type = type;
|
||||
@@ -501,7 +501,7 @@ static inline void scc_ast_expr_lvalue_init(scc_ast_expr_t *expr,
|
||||
static inline void scc_ast_type_builtin_init(scc_ast_type_t *type,
|
||||
scc_ast_builtin_type_t builtin,
|
||||
scc_pos_t loc) {
|
||||
Assert(type != null);
|
||||
Assert(type != nullptr);
|
||||
type->base.loc = loc;
|
||||
type->base.type = SCC_AST_TYPE_BUILTIN;
|
||||
type->builtin.type = builtin;
|
||||
@@ -511,19 +511,19 @@ static inline void scc_ast_type_builtin_init(scc_ast_type_t *type,
|
||||
static inline void scc_ast_type_pointer_init(scc_ast_type_t *type,
|
||||
scc_ast_type_t *pointee,
|
||||
scc_pos_t loc) {
|
||||
Assert(type != null && pointee != null);
|
||||
Assert(type != nullptr && pointee != nullptr);
|
||||
type->base.loc = loc;
|
||||
type->base.type = SCC_AST_TYPE_POINTER;
|
||||
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
||||
type->pointer.pointee = pointee;
|
||||
}
|
||||
|
||||
// size can be null
|
||||
// size can be nullptr
|
||||
static inline void scc_ast_type_array_init(scc_ast_type_t *type,
|
||||
scc_ast_type_t *element,
|
||||
scc_ast_expr_t *size,
|
||||
scc_pos_t loc) {
|
||||
Assert(type != null && element != null);
|
||||
Assert(type != nullptr && element != nullptr);
|
||||
type->base.loc = loc;
|
||||
type->base.type = SCC_AST_TYPE_ARRAY;
|
||||
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
||||
@@ -531,17 +531,17 @@ static inline void scc_ast_type_array_init(scc_ast_type_t *type,
|
||||
type->array.size = size;
|
||||
}
|
||||
|
||||
// return_type and params can be null
|
||||
// return_type and params can be nullptr
|
||||
static inline void scc_ast_type_function_init(scc_ast_type_t *type,
|
||||
scc_ast_type_t *return_type,
|
||||
scc_ast_decl_vec_t *params,
|
||||
scc_pos_t loc) {
|
||||
Assert(type != null);
|
||||
Assert(type != nullptr);
|
||||
type->base.loc = loc;
|
||||
type->base.type = SCC_AST_TYPE_FUNCTION;
|
||||
type->function.return_type = return_type;
|
||||
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
||||
if (params == null) {
|
||||
if (params == nullptr) {
|
||||
scc_vec_init(type->function.params);
|
||||
} else {
|
||||
type->function.params = *params;
|
||||
@@ -554,7 +554,7 @@ static inline void _scc_ast_type_record_init(scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_decl_t *decl,
|
||||
scc_pos_t loc) {
|
||||
Assert(type != null);
|
||||
Assert(type != nullptr);
|
||||
type->base.loc = loc;
|
||||
type->base.type = type_kind;
|
||||
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
||||
@@ -562,7 +562,7 @@ static inline void _scc_ast_type_record_init(scc_ast_type_t *type,
|
||||
type->record.decl = decl;
|
||||
}
|
||||
|
||||
// name and decl can be null
|
||||
// name and decl can be nullptr
|
||||
static inline void scc_ast_type_struct_init(scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_decl_t *decl,
|
||||
@@ -570,7 +570,7 @@ static inline void scc_ast_type_struct_init(scc_ast_type_t *type,
|
||||
_scc_ast_type_record_init(type, SCC_AST_TYPE_STRUCT, name, decl, loc);
|
||||
}
|
||||
|
||||
// name and decl can be null
|
||||
// name and decl can be nullptr
|
||||
static inline void scc_ast_type_union_init(scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_decl_t *decl,
|
||||
@@ -578,7 +578,7 @@ static inline void scc_ast_type_union_init(scc_ast_type_t *type,
|
||||
_scc_ast_type_record_init(type, SCC_AST_TYPE_UNION, name, decl, loc);
|
||||
}
|
||||
|
||||
// name and decl can be null
|
||||
// name and decl can be nullptr
|
||||
static inline void scc_ast_type_enum_init(scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_decl_t *decl, scc_pos_t loc) {
|
||||
@@ -589,7 +589,7 @@ static inline void scc_ast_type_typedef_init(scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_decl_t *target,
|
||||
scc_pos_t loc) {
|
||||
Assert(type != null && target != null);
|
||||
Assert(type != nullptr && target != nullptr);
|
||||
type->base.loc = loc;
|
||||
type->base.type = SCC_AST_TYPE_TYPEDEF;
|
||||
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
||||
|
||||
@@ -269,7 +269,7 @@ static void dump_type_impl(scc_ast_type_t *type, scc_tree_dump_t *td) {
|
||||
break;
|
||||
case SCC_AST_TYPE_ARRAY:
|
||||
dump_child_node(td, (scc_ast_node_t *)type->array.element,
|
||||
type->array.size == NULL);
|
||||
type->array.size == nullptr);
|
||||
if (type->array.size)
|
||||
dump_child_node(td, (scc_ast_node_t *)type->array.size, true);
|
||||
break;
|
||||
@@ -499,7 +499,7 @@ static void dump_decl_impl(scc_ast_decl_t *decl, scc_tree_dump_t *td) {
|
||||
case SCC_AST_DECL_VAR:
|
||||
if (decl->var.type) {
|
||||
dump_child_node(td, (scc_ast_node_t *)decl->var.type,
|
||||
decl->var.init == NULL);
|
||||
decl->var.init == nullptr);
|
||||
if (decl->var.init)
|
||||
dump_child_node(td, (scc_ast_node_t *)decl->var.init, true);
|
||||
}
|
||||
@@ -507,7 +507,7 @@ static void dump_decl_impl(scc_ast_decl_t *decl, scc_tree_dump_t *td) {
|
||||
case SCC_AST_DECL_FUNC:
|
||||
if (decl->func.type) {
|
||||
dump_child_node(td, (scc_ast_node_t *)decl->func.type,
|
||||
decl->func.body == NULL);
|
||||
decl->func.body == nullptr);
|
||||
if (decl->func.body)
|
||||
dump_child_node(td, (scc_ast_node_t *)decl->func.body, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user