feat(pproc): 实现C语言预处理器功能并重构项目依赖
- 新增预处理器库(pproc),替代原有的pprocessor模块 - 实现完整的宏定义解析功能,支持对象宏和函数宏 - 添加条件编译指令处理(#if、#ifdef、#ifndef、#else、#elif、#endif) - 实现宏展开机制,包括嵌套宏和递归宏处理 - 添加宏定义测试用例,覆盖基本功能和复杂场景 - 在cbuild.toml中更新依赖配置,移除parser、ast、ast2ir、ir等未完成模块 - 新增lexer工具函数用于token流处理 - 添加宏定义表管理功能,支持宏的创建、查找、删除操作 - 实现宏参数解析和替换列表处理
This commit is contained in:
32
libs/pproc/src/pproc_expand.c
Normal file
32
libs/pproc/src/pproc_expand.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <scc_pproc.h>
|
||||
|
||||
typedef struct {
|
||||
|
||||
} scc_expand_t;
|
||||
|
||||
void scc_pproc_expand_macro(scc_pproc_t *pp, const scc_pp_macro_t *macro) {
|
||||
if (macro->type == SCC_PP_MACRO_NONE) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (macro->type == SCC_PP_MACRO_OBJECT) {
|
||||
scc_vec_foreach(macro->replaces, i) {
|
||||
scc_lexer_tok_t tok = scc_vec_at(macro->replaces, i);
|
||||
if (tok.type == SCC_TOK_BLANK) {
|
||||
tok.lexeme = scc_cstring_from_cstr(" ");
|
||||
} else {
|
||||
tok.lexeme = scc_cstring_copy(&tok.lexeme);
|
||||
}
|
||||
scc_vec_push(pp->cache, tok);
|
||||
}
|
||||
pp->cache_pos = 0;
|
||||
return;
|
||||
}
|
||||
Assert(macro->type == SCC_PP_MACRO_FUNCTION);
|
||||
// Check params match
|
||||
scc_pproc_macro_list_t args;
|
||||
scc_pproc_parse_macro_arguments(pp, &args);
|
||||
scc_vec_foreach(args, i) {}
|
||||
scc_vec_foreach(macro->params, i) {}
|
||||
scc_vec_foreach(macro->replaces, i) {}
|
||||
}
|
||||
Reference in New Issue
Block a user