- Rename `scc_lex_parse_is_identifier_header` to `scc_lex_parse_is_identifier_prefix` for clarity and add a TODO comment - Update lexer to use the renamed function for consistency - Fix package and dependency names in `cbuild.toml` (`smcc_pprocesser` → `scc_pprocesser`, `smcc_lex_parser` → `lex_parser`) - Introduce new macro system with header file `pp_macro.h` defining macro types, structures, and management functions - Refactor preprocessor initialization and cleanup in `pprocessor.c` to use new macro table and stream handling - Replace legacy `hashmap` with `scc_pp_macro_table_t` for macro storage - Improve error handling and resource management in preprocessor lifecycle
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_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__ */
|