#ifndef AST_VISIT_H #define AST_VISIT_H #include "ast.h" // 通用节点处理器: ctx 为模块上下文, 返回模块相关值(sema 返回 NULL) typedef void* (*VisitFn)(void* ctx, AstNode* node); // 遍历表 — 按 AstKind 索引, 未处理的条目为 NULL // 新增 AST 节点: 在此表新增一条目, 编译器会警告未初始化的函数指针 enum { VISIT_TABLE_SIZE = 29 }; typedef struct { void* ctx; VisitFn table[VISIT_TABLE_SIZE]; } AstDispatch; // 获取未处理节点类型的默认处理器 VisitFn ast_dispatch_get(AstDispatch* d, AstKind k); void ast_dispatch_set(AstDispatch* d, AstKind k, VisitFn fn); // 统一入口: 查表 + 调用 void* ast_visit(AstDispatch* d, AstNode* node); #endif