新增 scc_argparse_list_t 类型用于处理多个字符串值的参数, 并添加相应的配置函数 scc_argparse_spec_setup_list。 fix(lexer): 调整关键字标记处理逻辑 将关键字子类型从 SCC_TOK_SUBTYPE_KEYWORD 改为 SCC_TOK_SUBTYPE_IDENTIFIER,并移除相关的枚举定义。 refactor(lexer): 优化跳过换行功能实现 修改 scc_lexer_skip_until_newline 函数实现,改进循环逻辑和错误处理。 feat(pproc): 完善预处理器条件编译支持 重构条件编译状态管理,添加对 #ifdef、#ifndef、#elifdef、 #else、#endif 等指令的支持,并实现嵌套条件处理。 refactor(pproc): 优化文件包含路径处理 添加最大包含深度限制,改进包含路径添加功能, 修复文件状态结构命名。 docs(log): 更新日志模块标准库依赖 调整 stdarg.h 包含逻辑,更新编译器内置宏定义名称。 feat(core): 扩展核心类型定义 添加基础数据类型别名定义,完善类型系统支持。 feat(main): 实现命令行包含路径参数 添加 -I/--include 参数支持,允许用户指定额外的头文件搜索路径。
78 lines
2.3 KiB
C
78 lines
2.3 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 {
|
|
cbool found_true;
|
|
cbool seen_else;
|
|
cbool active;
|
|
} scc_pproc_if_t;
|
|
typedef SCC_VEC(scc_pproc_if_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_t;
|
|
typedef SCC_VEC(scc_pproc_file_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;
|
|
int enable;
|
|
|
|
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;
|
|
|
|
struct {
|
|
int max_include_depth;
|
|
} config;
|
|
} 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);
|
|
|
|
static inline void scc_pproc_add_include_path(scc_pproc_t *pp,
|
|
const scc_cstring_t *path) {
|
|
scc_vec_push(pp->include_paths, scc_cstring_copy(path));
|
|
}
|
|
|
|
static inline void scc_pproc_add_include_path_cstr(scc_pproc_t *pp,
|
|
const char *path) {
|
|
scc_vec_push(pp->include_paths, scc_cstring_from_cstr(path));
|
|
}
|
|
|
|
void scc_pproc_handle_directive(scc_pproc_t *pp);
|
|
void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok);
|
|
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__ */
|