feat(pproc): 实现预处理器条件编译和可变参数宏支持
- 添加了完整的条件编译功能,包括 #if、#elif、#else、#endif 指令 - 实现了数值常量表达式的解析和求值 - 支持嵌套条件编译和与其他指令混合使用 - 实现了可变参数宏定义和 __VA_ARGS__ 替换功能 - 改进了宏展开机制以正确处理可变参数宏 - 重构了预处理器指令处理逻辑,提高了代码可维护性 - 添加了相应的单元测试用例验证新功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <pproc_expand.h>
|
||||
#include <scc_core_ring.h>
|
||||
#include <scc_pproc.h>
|
||||
|
||||
static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
|
||||
@@ -56,31 +57,16 @@ FOPEN:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok) {
|
||||
void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok,
|
||||
scc_lexer_tok_ring_t *tok_ring) {
|
||||
int ok;
|
||||
scc_lexer_tok_t tok;
|
||||
scc_pos_t pos = include_tok->loc;
|
||||
scc_lexer_tok_drop(include_tok);
|
||||
|
||||
scc_lexer_tok_ring_t *stream = pp->cur_ring;
|
||||
scc_lexer_tok_vec_t org_toks;
|
||||
scc_vec_init(org_toks);
|
||||
while (1) {
|
||||
scc_ring_peek(*stream, tok, ok);
|
||||
if (ok == false)
|
||||
break;
|
||||
scc_ring_next_consume(*stream, tok, ok);
|
||||
scc_vec_push(org_toks, tok);
|
||||
// FIXME endline needed?
|
||||
if (tok.type == SCC_TOK_ENDLINE)
|
||||
break;
|
||||
}
|
||||
|
||||
scc_lexer_tok_ring_t out_ring;
|
||||
scc_pproc_expand_by_vec(&pp->macro_table, &org_toks, &out_ring);
|
||||
scc_cstring_t line = scc_cstring_create();
|
||||
while (1) {
|
||||
scc_ring_next_consume(out_ring, tok, ok);
|
||||
scc_ring_next_consume(*tok_ring, tok, ok);
|
||||
if (!ok)
|
||||
break;
|
||||
if (scc_get_tok_subtype(tok.type) != SCC_TOK_SUBTYPE_EMPTYSPACE &&
|
||||
@@ -89,7 +75,7 @@ void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok) {
|
||||
}
|
||||
scc_lexer_tok_drop(&tok);
|
||||
}
|
||||
scc_ring_free(out_ring);
|
||||
scc_ring_free(*tok_ring);
|
||||
|
||||
const char *includename = scc_cstring_as_cstr(&line);
|
||||
int len = scc_cstring_len(&line);
|
||||
|
||||
Reference in New Issue
Block a user