Files
scc/libs/pproc/include/scc_pproc.h
zzy a52ff33e30 feat(ast): 更新AST字面量表示方式
更新AST定义以使用词素字符串代替常量值,
并修改AST转储功能以正确显示字面量内容。

BREAKING CHANGE: AST表达式结构体中literal成员从value改为lexme字段。

refactor(pproc): 重构宏展开和文件包含逻辑

将宏展开函数重构为独立接口,实现文件包含处理逻辑,
改进预处理器的状态管理机制。

fix(sstream): 修复文件流初始化错误码返回

修正文件打开失败时的错误码返回值,确保调用方能正确处理异常情况。
2026-02-19 15:56:05 +08:00

60 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file pprocessor.h
* @brief C语言预处理器核心数据结构与接口
*/
#ifndef __SCC_PPROC_H__
#define __SCC_PPROC_H__
#include "pproc_macro.h"
#include <scc_core.h>
#include <scc_core_ring.h>
#include <scc_lexer.h>
// 预处理器状态结构
// 条件编译状态栈
typedef struct {
int active; // 当前层级是否有效(即应该输出 token
int skip; // 当前层级是否跳过(即不输出 token
// 可根据需要增加状态,如 #if 的结果、#elif 已执行等
} scc_pproc_if_state_t;
typedef SCC_VEC(scc_pproc_if_state_t) scc_pproc_if_stack_t;
typedef struct {
scc_sstream_t sstream;
scc_lexer_t lexer;
scc_lexer_tok_ring_t *ring;
} scc_pproc_file_state_t;
typedef SCC_VEC(scc_pproc_file_state_t *) scc_pproc_file_stack_t;
typedef SCC_VEC(scc_lexer_tok_ring_t *) scc_pproc_ring_vec_t;
typedef struct scc_pproc {
scc_lexer_tok_ring_t *org_ring;
scc_lexer_tok_ring_t *cur_ring;
scc_lexer_tok_ring_t expanded_ring;
scc_strpool_t strpool;
int at_line_start;
scc_pproc_macro_table_t macro_table;
scc_pproc_if_stack_t if_stack;
scc_pproc_file_stack_t file_stack;
scc_lexer_tok_ring_t ring;
int ring_ref_count;
} scc_pproc_t;
void scc_pproc_init(scc_pproc_t *pp, scc_lexer_tok_ring_t *input);
scc_lexer_tok_ring_t *scc_pproc_to_ring(scc_pproc_t *pp, int ring_size);
void scc_pproc_drop(scc_pproc_t *pp);
void scc_pproc_handle_directive(scc_pproc_t *pp);
void scc_pproc_parse_include(scc_pproc_t *pp);
void scc_pproc_parse_macro_arguments(scc_lexer_tok_ring_t *ring,
scc_lexer_tok_vec_t *args, int need_full);
void scc_pproc_parse_function_macro(scc_pproc_t *pp,
const scc_lexer_tok_t *ident);
void scc_pproc_parse_object_macro(scc_pproc_t *pp,
const scc_lexer_tok_t *ident);
#endif /* __SCC_PPROC_H__ */