feat(ast): 添加AST定义和dump工具头文件

新增libs/ast模块的基础定义文件,包括:
- AST节点类型枚举定义,涵盖声明、语句、表达式、类型等各类节点
- AST操作符枚举,定义所有二元、一元、逻辑、算术等操作符
- AST节点结构体定义,包含表达式、语句、声明、类型等具体实现
- AST dump工具接口,支持树形结构输出和颜色显示
- 语义分析回调函数类型定义,为后续语义分析提供基础
This commit is contained in:
zzy
2026-01-28 15:44:59 +08:00
parent e1cd8c5206
commit 79ee7a657a
13 changed files with 4181 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
/**
* @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__ */