- 将头文件中的tree_dump.h替换为scc_tree_dump.h - 修改函数签名将scc_tree_dump_ctx_t改为scc_tree_dump_t - 移除过时的宏定义和内联函数实现 - 使用新的scc_tree_dump_* API替代旧的PRINT_*宏 - 简化类型、表达式、语句和声明的转储逻辑 - 统一使用新的树转储接口进行节点和值的输出 feat(ast2ir): 实现逻辑运算符和一元运算符的IR转换 - 添加scc_ast2ir_logical_expr函数处理&&和||运算符 - 实现短路求值逻辑,包含分支控制流 - 添加对一元正号运算符的支持 - 实现取地址和间接寻址运算符 - 添加字符字面量解析支持转义序列 fix(ir): 修复字符串常量构建中的长度计算错误 - 修正数组长度计算从len+1改为len-1 - 调整字符串内容复制逻辑跳过引号边界 - 修正内存分配大小与实际数据长度匹配 refactor(ir): 更新IR转储模块使用统一的树转储接口 - 将IR转储上下文中的tree_dump_ctx_t替换为scc_tree_dump_t - 更新初始化函数签名以使用新的转储接口类型
90 lines
2.8 KiB
C
90 lines
2.8 KiB
C
/**
|
|
* @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 {
|
|
cbool found_true;
|
|
cbool seen_else;
|
|
cbool active;
|
|
} scc_pproc_if_t;
|
|
typedef SCC_VEC(scc_pproc_if_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_t;
|
|
typedef SCC_VEC(scc_pproc_file_t *) scc_pproc_file_stack_t;
|
|
|
|
typedef SCC_VEC(scc_lexer_tok_ring_t *) scc_pproc_ring_vec_t;
|
|
typedef SCC_VEC(scc_str_t) scc_pproc_cstr_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;
|
|
int enable;
|
|
|
|
scc_pproc_cstr_vec_t include_paths;
|
|
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;
|
|
cbool ring_need_comment;
|
|
cbool ring_need_empty;
|
|
|
|
struct {
|
|
int max_include_depth;
|
|
cbool keep_original_pos;
|
|
} config;
|
|
} 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,
|
|
cbool need_empty, cbool need_comment);
|
|
void scc_pproc_drop(scc_pproc_t *pp);
|
|
|
|
static inline void scc_pproc_add_include_path(scc_pproc_t *pp,
|
|
const scc_str_t *path) {
|
|
scc_vec_push(pp->include_paths, scc_str_copy(path));
|
|
}
|
|
|
|
static inline void scc_pproc_add_include_path_cstr(scc_pproc_t *pp,
|
|
const char *path) {
|
|
scc_vec_push(pp->include_paths, scc_str_from_cstr(path));
|
|
}
|
|
|
|
void scc_pproc_handle_directive(scc_pproc_t *pp);
|
|
|
|
cbool scc_pproc_parse_if_need_skip(scc_pproc_t *pp, scc_tok_type_t type);
|
|
cbool scc_pproc_parse_if_defined(scc_pproc_t *pp, scc_tok_type_t type,
|
|
const scc_lexer_tok_t *tok);
|
|
cbool scc_pproc_parse_if_condition(scc_pproc_t *pp, scc_tok_type_t type,
|
|
scc_lexer_tok_ring_t *tok_ring);
|
|
void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok,
|
|
scc_lexer_tok_ring_t *tok_ring);
|
|
|
|
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__ */
|