feat(lex_parser, pprocessor): rename identifier header check and add macro system
- 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
This commit is contained in:
@@ -1,30 +1,14 @@
|
||||
// pprocessor.h - 更新后的头文件
|
||||
/**
|
||||
* @file pprocessor.h
|
||||
* @brief C语言预处理器核心数据结构与接口
|
||||
*/
|
||||
|
||||
#ifndef __SMCC_PP_H__
|
||||
#define __SMCC_PP_H__
|
||||
#ifndef __SCC_PP_H__
|
||||
#define __SCC_PP_H__
|
||||
|
||||
#include <libcore.h>
|
||||
#include <libutils.h>
|
||||
|
||||
// 宏定义类型
|
||||
typedef enum {
|
||||
MACRO_OBJECT, // 对象宏
|
||||
MACRO_FUNCTION, // 函数宏
|
||||
} macro_type_t;
|
||||
|
||||
typedef VEC(cstring_t) macro_list_t;
|
||||
|
||||
// 宏定义结构
|
||||
typedef struct smcc_macro {
|
||||
cstring_t name; // 宏名称
|
||||
macro_type_t type; // 宏类型
|
||||
macro_list_t replaces; // 替换列表
|
||||
macro_list_t params; // 参数列表(仅函数宏)
|
||||
} smcc_macro_t;
|
||||
#include <pp_macro.h>
|
||||
|
||||
// 条件编译状态
|
||||
typedef enum {
|
||||
@@ -41,12 +25,12 @@ typedef struct if_stack_item {
|
||||
} if_stack_item_t;
|
||||
|
||||
// 预处理器状态结构
|
||||
typedef struct smcc_preprocessor {
|
||||
core_stream_t *stream; // 输出流
|
||||
strpool_t strpool; // 字符串池
|
||||
hashmap_t macros; // 宏定义表
|
||||
VEC(if_stack_item_t) if_stack; // 条件编译栈
|
||||
} smcc_pp_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 初始化预处理器
|
||||
@@ -54,19 +38,25 @@ typedef struct smcc_preprocessor {
|
||||
* @param[in] input 输入流对象指针
|
||||
* @return output 输出流对象指针
|
||||
*/
|
||||
core_stream_t *pp_init(smcc_pp_t *pp, core_stream_t *input);
|
||||
|
||||
/**
|
||||
* @brief 执行预处理
|
||||
* @param[in] pp 预处理器实例
|
||||
* @return 处理结果
|
||||
*/
|
||||
int pp_process(smcc_pp_t *pp);
|
||||
// TODO 内存释放问题
|
||||
scc_probe_stream_t *scc_pproc_init(scc_pproc_t *pp, scc_probe_stream_t *input);
|
||||
|
||||
/**
|
||||
* @brief 销毁预处理器
|
||||
* @param[in] pp 预处理器实例
|
||||
*/
|
||||
void pp_drop(smcc_pp_t *pp);
|
||||
void scc_pproc_drop(scc_pproc_t *pp);
|
||||
|
||||
#endif /* __SMCC_PP_H__ */
|
||||
/// 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__ */
|
||||
|
||||
Reference in New Issue
Block a user