添加了新的类型定义 scc_pproc_cstr_vec_t 用于存储包含路径, 并在 scc_pproc 结构中添加 include_paths 字段。实现改进的 switch_file_stack 函数,支持从当前目录、父目录和系统包含路径 中查找头文件,提供更完整的 #include 指令处理能力。 fix(core): 重命名环形缓冲区内联宏避免命名冲突 将 scc_ring_phys 宏重命名为 _scc_ring_phys,并添加其他相关 内部宏如 _scc_ring_cap、_scc_ring_head 等,以避免与外部接口 的命名冲突并提高代码清晰度。 refactor(main): 添加命令行包含路径选项并清理标准库引用 在命令行参数解析中添加 -I/--include 选项支持,允许用户指定 额外的头文件搜索路径。同时移除不必要的 stdio.h 引用并清理 一些调试相关的缓冲区设置。
62 lines
2.0 KiB
C
62 lines
2.0 KiB
C
/**
|
||
* @file pprocessor.h
|
||
* @brief C语言预处理器核心数据结构与接口
|
||
*/
|
||
|
||
#ifndef __SCC_PPROC_H__
|
||
#define __SCC_PPROC_H__
|
||
|
||
#include "pproc_macro.h"
|
||
#include <scc_core.h>
|
||
#include <scc_core_ring.h>
|
||
#include <scc_lexer.h>
|
||
|
||
// 预处理器状态结构
|
||
|
||
// 条件编译状态栈
|
||
typedef struct {
|
||
int active; // 当前层级是否有效(即应该输出 token)
|
||
int skip; // 当前层级是否跳过(即不输出 token)
|
||
// 可根据需要增加状态,如 #if 的结果、#elif 已执行等
|
||
} scc_pproc_if_state_t;
|
||
typedef SCC_VEC(scc_pproc_if_state_t) scc_pproc_if_stack_t;
|
||
|
||
typedef struct {
|
||
scc_sstream_t sstream;
|
||
scc_lexer_t lexer;
|
||
scc_lexer_tok_ring_t *ring;
|
||
} scc_pproc_file_state_t;
|
||
typedef SCC_VEC(scc_pproc_file_state_t *) scc_pproc_file_stack_t;
|
||
typedef SCC_VEC(scc_lexer_tok_ring_t *) scc_pproc_ring_vec_t;
|
||
typedef SCC_VEC(scc_cstring_t) scc_pproc_cstr_vec_t;
|
||
|
||
typedef struct scc_pproc {
|
||
scc_lexer_tok_ring_t *org_ring;
|
||
scc_lexer_tok_ring_t *cur_ring;
|
||
scc_lexer_tok_ring_t expanded_ring;
|
||
scc_strpool_t strpool;
|
||
int at_line_start;
|
||
|
||
scc_pproc_cstr_vec_t include_paths;
|
||
scc_pproc_macro_table_t macro_table;
|
||
scc_pproc_if_stack_t if_stack;
|
||
scc_pproc_file_stack_t file_stack;
|
||
|
||
scc_lexer_tok_ring_t ring;
|
||
int ring_ref_count;
|
||
} scc_pproc_t;
|
||
|
||
void scc_pproc_init(scc_pproc_t *pp, scc_lexer_tok_ring_t *input);
|
||
scc_lexer_tok_ring_t *scc_pproc_to_ring(scc_pproc_t *pp, int ring_size);
|
||
void scc_pproc_drop(scc_pproc_t *pp);
|
||
|
||
void scc_pproc_handle_directive(scc_pproc_t *pp);
|
||
void scc_pproc_parse_include(scc_pproc_t *pp);
|
||
void scc_pproc_parse_macro_arguments(scc_lexer_tok_ring_t *ring,
|
||
scc_lexer_tok_vec_t *args, int need_full);
|
||
void scc_pproc_parse_function_macro(scc_pproc_t *pp,
|
||
const scc_lexer_tok_t *ident);
|
||
void scc_pproc_parse_object_macro(scc_pproc_t *pp,
|
||
const scc_lexer_tok_t *ident);
|
||
#endif /* __SCC_PPROC_H__ */
|