/** * @file ast_dump.h * @brief AST dump 工具,支持多种输出格式(插件化设计) */ #ifndef __SCC_AST_DUMP_H__ #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; /** * @brief 以指定格式 dump AST * * @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); #endif /* __SCC_AST_DUMP_H__ */