- Change `scc_macro_table_t` to `scc_pp_macro_table_t` for consistency - Rename `scc_pp_macro_create` to `scc_pp_macro_new` for naming convention - Remove unused `scc_pp_compress_whitespace` function - Update macro table function names: `scc_pp_find_macro` → `scc_pp_macro_table_get`, `scc_pp_remove_macro` → `scc_pp_macro_table_remove` - Add new `scc_pp_macro_table_set` function for setting macros - Update all function signatures to use new type name - Remove commented-out whitespace compression code from implementation
63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
/**
|
|
* @file pprocessor.h
|
|
* @brief C语言预处理器核心数据结构与接口
|
|
*/
|
|
|
|
#ifndef __SCC_PP_H__
|
|
#define __SCC_PP_H__
|
|
|
|
#include <libcore.h>
|
|
#include <libutils.h>
|
|
#include <pp_macro.h>
|
|
|
|
// 条件编译状态
|
|
typedef enum {
|
|
IFState_NONE, // 不在条件编译中
|
|
IFState_TRUE, // 条件为真
|
|
IFState_FALSE, // 条件为假
|
|
IFState_ELSE // 已经执行过else分支
|
|
} if_state_t;
|
|
|
|
// 条件编译栈项
|
|
typedef struct if_stack_item {
|
|
if_state_t state;
|
|
int skip; // 是否跳过当前段
|
|
} if_stack_item_t;
|
|
|
|
// 预处理器状态结构
|
|
typedef struct scc_pproc {
|
|
scc_probe_stream_t *stream; // 输出流
|
|
scc_strpool_t strpool; // 字符串池
|
|
scc_pp_macro_table_t macro_table;
|
|
SCC_VEC(if_stack_item_t) if_stack; // 条件编译栈
|
|
} scc_pproc_t;
|
|
|
|
/**
|
|
* @brief 初始化预处理器
|
|
* @param[out] pp 要初始化的预处理器实例
|
|
* @param[in] input 输入流对象指针
|
|
* @return output 输出流对象指针
|
|
*/
|
|
// TODO 内存释放问题
|
|
scc_probe_stream_t *scc_pproc_init(scc_pproc_t *pp, scc_probe_stream_t *input);
|
|
|
|
/**
|
|
* @brief 销毁预处理器
|
|
* @param[in] pp 预处理器实例
|
|
*/
|
|
void scc_pproc_drop(scc_pproc_t *pp);
|
|
|
|
/// inner private struct
|
|
|
|
typedef SCC_VEC(u8) scc_pp_buffer_t;
|
|
typedef struct pp_stream {
|
|
scc_probe_stream_t stream;
|
|
scc_probe_stream_t *input;
|
|
scc_pproc_t *self;
|
|
|
|
scc_pos_t pos;
|
|
scc_probe_stream_t *tmp_stream;
|
|
} scc_pp_stream_t;
|
|
|
|
#endif /* __SMC_PP_H__ */
|