refactor(ast): 调整AST结构体和枚举类型的声明表示方式
将结构体、联合和枚举类型的字段表示从向量改为声明指针, 允许name和decl字段为null,更新相关初始化函数的断言检查, 使结构更加灵活并支持不完整类型定义。 BREAKING CHANGE: 修改了scc_ast_type结构体中record和enumeration 子类型的字段表示方法,从fields向量改为decl指针。
This commit is contained in:
@@ -282,33 +282,19 @@ static void dump_type_impl(scc_ast_type_t *type, scc_tree_dump_ctx_t *ctx) {
|
||||
break;
|
||||
case SCC_AST_TYPE_FUNCTION:
|
||||
PRINT_QUOTED_VALUE(ctx, "function");
|
||||
scc_tree_dump_printf(ctx, "\n");
|
||||
if (type->function.return_type) {
|
||||
dump_type_impl(type->function.return_type, ctx);
|
||||
}
|
||||
if (scc_vec_size(type->function.param_types) != 0) {
|
||||
scc_vec_foreach(type->function.param_types, i) {
|
||||
scc_ast_decl_t *param =
|
||||
scc_vec_at(type->function.param_types, i);
|
||||
if (param->name) {
|
||||
// FIXME param name
|
||||
}
|
||||
dump_type_impl(param->param.type, ctx);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SCC_AST_TYPE_STRUCT:
|
||||
if (type->record.name) {
|
||||
BUILD_TYPE_NAME(ctx, "struct ", type->record.name);
|
||||
} else {
|
||||
PRINT_QUOTED_VALUE(ctx, "anonymous struct");
|
||||
PRINT_QUOTED_VALUE(ctx, "<anonymous struct>");
|
||||
}
|
||||
break;
|
||||
case SCC_AST_TYPE_UNION:
|
||||
if (type->record.name) {
|
||||
BUILD_TYPE_NAME(ctx, "union ", type->record.name);
|
||||
} else {
|
||||
PRINT_QUOTED_VALUE(ctx, "anonymous union");
|
||||
PRINT_QUOTED_VALUE(ctx, "<anonymous union>");
|
||||
}
|
||||
break;
|
||||
case SCC_AST_TYPE_ENUM:
|
||||
@@ -339,6 +325,40 @@ static void dump_type_impl(scc_ast_type_t *type, scc_tree_dump_ctx_t *ctx) {
|
||||
dump_child_node((scc_ast_node_t *)type->array.size, ctx, true);
|
||||
}
|
||||
break;
|
||||
case SCC_AST_TYPE_STRUCT:
|
||||
if (type->enumeration.decl) {
|
||||
dump_child_node((scc_ast_node_t *)type->enumeration.decl, ctx,
|
||||
true);
|
||||
}
|
||||
break;
|
||||
case SCC_AST_TYPE_ENUM:
|
||||
if (type->record.decl) {
|
||||
dump_child_node((scc_ast_node_t *)type->record.decl, ctx, true);
|
||||
}
|
||||
break;
|
||||
case SCC_AST_TYPE_FUNCTION:
|
||||
scc_vec_push(ctx->stack, false);
|
||||
scc_tree_print_indent(ctx);
|
||||
SCC_TREE_DUMP_PRINT_PURE(ctx, ctx->node_color, "%s\n", "ReturnType");
|
||||
dump_child_node((scc_ast_node_t *)type->function.return_type, ctx,
|
||||
true);
|
||||
scc_vec_pop(ctx->stack);
|
||||
|
||||
scc_vec_push(ctx->stack, true);
|
||||
if (scc_vec_size(type->function.param_types) != 0) {
|
||||
scc_vec_foreach(type->function.param_types, i) {
|
||||
scc_ast_decl_t *param =
|
||||
scc_vec_at(type->function.param_types, i);
|
||||
if (param->name) {
|
||||
// FIXME param name
|
||||
}
|
||||
dump_type_impl(param->param.type, ctx);
|
||||
}
|
||||
} else {
|
||||
PRINT_QUOTED_VALUE(ctx, "()");
|
||||
}
|
||||
scc_vec_pop(ctx->stack);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -416,10 +436,13 @@ static void dump_expr_impl(scc_ast_expr_t *expr, scc_tree_dump_ctx_t *ctx) {
|
||||
case SCC_AST_EXPR_MEMBER:
|
||||
case SCC_AST_EXPR_PTR_MEMBER:
|
||||
dump_child_node((scc_ast_node_t *)expr->member.base, ctx, false);
|
||||
// 打印成员访问信息
|
||||
scc_vec_push(ctx->stack, true);
|
||||
scc_tree_print_indent(ctx);
|
||||
PRINT_NODE(ctx, "Member [\"%s\"]", expr->member.name);
|
||||
scc_tree_dump_printf(ctx, "\n");
|
||||
SCC_TREE_DUMP_PRINT_PURE(
|
||||
ctx, ctx->node_color, "%s %s\n",
|
||||
expr->base.type == SCC_AST_EXPR_MEMBER ? "Member" : "PtrMember",
|
||||
expr->member.name);
|
||||
scc_vec_pop(ctx->stack);
|
||||
break;
|
||||
|
||||
case SCC_AST_EXPR_CAST:
|
||||
|
||||
Reference in New Issue
Block a user