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:
90
libs/pprocessor/include/pp_macro.h
Normal file
90
libs/pprocessor/include/pp_macro.h
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef __SCC_PP_MACRO_H__
|
||||
#define __SCC_PP_MACRO_H__
|
||||
|
||||
#include <libcore.h>
|
||||
#include <libutils.h>
|
||||
|
||||
// 宏定义类型
|
||||
typedef enum {
|
||||
SCC_PP_MACRO_OBJECT, // 对象宏
|
||||
SCC_PP_MACRO_FUNCTION, // 函数宏
|
||||
} scc_pp_macro_type_t;
|
||||
|
||||
typedef SCC_VEC(scc_cstring_t) scc_pp_macro_list_t;
|
||||
|
||||
// 宏定义结构
|
||||
typedef struct scc_macro {
|
||||
scc_cstring_t name; // 宏名称
|
||||
scc_pp_macro_type_t type; // 宏类型
|
||||
scc_pp_macro_list_t replaces; // 替换列表
|
||||
scc_pp_macro_list_t params; // 参数列表(仅函数宏)
|
||||
} scc_pp_macro_t;
|
||||
|
||||
typedef struct scc_macro_table {
|
||||
scc_hashtable_t table; // 宏定义表
|
||||
} scc_macro_table_t;
|
||||
|
||||
/**
|
||||
* @brief 创建宏对象
|
||||
* @param name 宏名称
|
||||
* @param type 宏类型
|
||||
* @return 创建的宏对象指针,失败返回NULL
|
||||
*/
|
||||
scc_pp_macro_t *scc_pp_macro_create(const scc_cstring_t *name,
|
||||
scc_pp_macro_type_t type);
|
||||
|
||||
/**
|
||||
* @brief 销毁宏对象
|
||||
* @param macro 要销毁的宏对象
|
||||
*/
|
||||
void scc_pp_macro_drop(scc_pp_macro_t *macro);
|
||||
|
||||
/**
|
||||
* @brief 压缩空白字符
|
||||
* @param tokens token列表
|
||||
* @return 压缩后的字符串
|
||||
*/
|
||||
scc_cstring_t scc_pp_compress_whitespace(const scc_pp_macro_list_t *tokens);
|
||||
|
||||
/**
|
||||
* @brief 添加对象宏
|
||||
* @param pp 预处理器实例
|
||||
* @param name 宏名称
|
||||
* @param replacement 替换文本列表
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
cbool scc_pp_add_object_macro(scc_macro_table_t *pp, const scc_cstring_t *name,
|
||||
const scc_pp_macro_list_t *replacement);
|
||||
|
||||
/**
|
||||
* @brief 添加函数宏
|
||||
* @param pp 预处理器实例
|
||||
* @param name 宏名称
|
||||
* @param params 参数列表
|
||||
* @param replacement 替换文本列表
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
cbool scc_pp_add_function_macro(scc_macro_table_t *pp,
|
||||
const scc_cstring_t *name,
|
||||
const scc_pp_macro_list_t *params,
|
||||
const scc_pp_macro_list_t *replacement);
|
||||
|
||||
/**
|
||||
* @brief 查找宏定义
|
||||
* @param pp 预处理器实例
|
||||
* @param name 宏名称
|
||||
* @return 找到的宏对象指针,未找到返回NULL
|
||||
*/
|
||||
scc_pp_macro_t *scc_pp_find_macro(scc_macro_table_t *pp, scc_cstring_t *name);
|
||||
|
||||
/**
|
||||
* @brief 从预处理器中删除宏
|
||||
* @param pp 预处理器实例
|
||||
* @param name 宏名称
|
||||
* @return 成功删除返回true,未找到返回false
|
||||
*/
|
||||
cbool scc_pp_remove_macro(scc_macro_table_t *pp, const scc_cstring_t *name);
|
||||
|
||||
void scc_pp_marco_table_init(scc_macro_table_t *macros);
|
||||
void scc_pp_macro_table_drop(scc_macro_table_t *macros);
|
||||
#endif /* __SCC_PP_MACRO_H__ */
|
||||
Reference in New Issue
Block a user