feat(ast): 重构AST转储功能并添加tree_dump依赖

- 添加tree_dump库作为依赖项到ast模块
- 将ast_dump.h中的转储上下文结构替换为tree_dump.h中的统一实现
- 更新scc_ast_block_item_vec_t类型定义,支持stmt或decl的泛型指针
- 移除ast_dump.c中重复的缩进和上下文管理代码,使用tree_dump提供的功能
- 修改dump函数参数类型从scc_ast_dump_ctx_t为scc_tree_dump_ctx_t
- 在libs目录下新增tree_dump库,包含完整的树形结构转储功能
This commit is contained in:
zzy
2026-01-28 17:29:56 +08:00
parent 79ee7a657a
commit 135e874a76
8 changed files with 135 additions and 108 deletions

View File

@@ -138,8 +138,8 @@ typedef SCC_VEC(scc_ast_expr_t *) scc_ast_expr_vec_t;
typedef SCC_VEC(scc_ast_stmt_t *) scc_ast_stmt_vec_t;
typedef SCC_VEC(scc_ast_decl_t *) scc_ast_decl_vec_t;
// 通过指针实现泛型
typedef SCC_VEC(scc_ast_node_type_t *) scc_ast_block_item_vec_t;
// 通过指针实现泛型 only stmt or decl
typedef SCC_VEC(scc_ast_node_t *) scc_ast_block_item_vec_t;
/**
* @brief 类型表示

View File

@@ -7,21 +7,7 @@
#define __SCC_AST_DUMP_H__
#include "ast_def.h"
typedef SCC_VEC(u8) scc_ast_dump_stack_t;
/**
* @brief AST dump 上下文结构
*/
typedef struct {
int depth; ///< 当前深度
cbool *is_last_child; ///< 每层是否为最后子节点
cbool use_color; ///< 是否使用颜色输出
size_t max_depth; ///< 分配的最大深度
const char *node_color; ///< 节点类型颜色
const char *value_color; ///< 值颜色
const char *branch_color; ///< 分支符号颜色
const char *reset_color; ///< 重置颜色
} scc_ast_dump_ctx_t;
#include <tree_dump.h>
/**
* @brief 以指定格式 dump AST
@@ -29,9 +15,6 @@ typedef struct {
* @param node AST 节点(可以是任意类型的节点)
* @param ctx dump 上下文
*/
void scc_ast_dump_node(scc_ast_node_t *node, scc_ast_dump_ctx_t *ctx);
void scc_ast_dump_ctx_init(scc_ast_dump_ctx_t *ctx, cbool use_color);
void scc_ast_dump_ctx_drop(scc_ast_dump_ctx_t *ctx);
void scc_ast_dump_node(scc_tree_dump_ctx_t *ctx, const scc_ast_node_t *node);
#endif /* __SCC_AST_DUMP_H__ */