feat(ast): 更新AST dump功能以使用新的树转储接口
- 将头文件中的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 - 更新初始化函数签名以使用新的转储接口类型
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
#include <scc_core_ring.h>
|
||||
#include <scc_pproc.h>
|
||||
|
||||
static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
|
||||
scc_pos_t *pos, int is_system) {
|
||||
scc_cstring_t fpath = scc_cstring_create();
|
||||
static int switch_file_stack(scc_pproc_t *pp, scc_str_t *fname, scc_pos_t *pos,
|
||||
int is_system) {
|
||||
scc_str_t fpath = scc_str_empty();
|
||||
int ret = 0;
|
||||
|
||||
const char *org_fname = pos->name;
|
||||
@@ -12,10 +12,10 @@ static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
|
||||
if (!is_system) {
|
||||
const char parent[] = "/../";
|
||||
// FIXME maybe it can eazy
|
||||
scc_cstring_append_cstr(&fpath, org_fname, scc_strlen(org_fname));
|
||||
scc_cstring_append_cstr(&fpath, parent, scc_strlen(parent));
|
||||
scc_cstring_append(&fpath, fname);
|
||||
ret = scc_fexists(scc_cstring_as_cstr(&fpath));
|
||||
scc_str_append_cstr(&fpath, org_fname, scc_strlen(org_fname));
|
||||
scc_str_append_cstr(&fpath, parent, scc_strlen(parent));
|
||||
scc_str_append(&fpath, fname);
|
||||
ret = scc_fexists(scc_str_as_cstr(&fpath));
|
||||
if (ret == true) {
|
||||
goto FOPEN;
|
||||
}
|
||||
@@ -23,17 +23,17 @@ static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
|
||||
|
||||
/* system default path and -I includes path */
|
||||
scc_vec_foreach(pp->include_paths, i) {
|
||||
scc_cstring_free(&fpath);
|
||||
scc_cstring_t *syspath = &scc_vec_at(pp->include_paths, i);
|
||||
scc_cstring_append(&fpath, syspath);
|
||||
scc_cstring_append_ch(&fpath, '/');
|
||||
scc_cstring_append(&fpath, fname);
|
||||
ret = scc_fexists(scc_cstring_as_cstr(&fpath));
|
||||
scc_str_drop(&fpath);
|
||||
scc_str_t *syspath = &scc_vec_at(pp->include_paths, i);
|
||||
scc_str_append(&fpath, syspath);
|
||||
scc_str_append_ch(&fpath, '/');
|
||||
scc_str_append(&fpath, fname);
|
||||
ret = scc_fexists(scc_str_as_cstr(&fpath));
|
||||
if (ret == true) {
|
||||
goto FOPEN;
|
||||
}
|
||||
}
|
||||
SCC_ERROR(*pos, "include file '%s' not found", scc_cstring_as_cstr(fname));
|
||||
SCC_ERROR(*pos, "include file '%s' not found", scc_str_as_cstr(fname));
|
||||
return -1;
|
||||
FOPEN:
|
||||
if ((int)scc_vec_size(pp->file_stack) >= pp->config.max_include_depth) {
|
||||
@@ -44,7 +44,7 @@ FOPEN:
|
||||
|
||||
scc_pproc_file_t *file = scc_malloc(sizeof(scc_pproc_file_t));
|
||||
Assert(file != null);
|
||||
if (scc_sstream_init(&(file->sstream), scc_cstring_as_cstr(&fpath), 1024)) {
|
||||
if (scc_sstream_init(&(file->sstream), scc_str_as_cstr(&fpath), 1024)) {
|
||||
return -1;
|
||||
}
|
||||
scc_lexer_init(&(file->lexer), scc_sstream_to_ring(&(file->sstream)));
|
||||
@@ -62,21 +62,21 @@ void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok,
|
||||
scc_pos_t pos = include_tok->loc;
|
||||
scc_lexer_tok_drop(include_tok);
|
||||
|
||||
scc_cstring_t line = scc_cstring_create();
|
||||
scc_str_t line = scc_str_empty();
|
||||
while (1) {
|
||||
scc_ring_next_consume(*tok_ring, tok, ok);
|
||||
if (!ok)
|
||||
break;
|
||||
if (scc_get_tok_subtype(tok.type) != SCC_TOK_SUBTYPE_EMPTYSPACE &&
|
||||
scc_get_tok_subtype(tok.type) != SCC_TOK_SUBTYPE_COMMENT) {
|
||||
scc_cstring_append(&line, &tok.lexeme);
|
||||
scc_str_append(&line, &tok.lexeme);
|
||||
}
|
||||
scc_lexer_tok_drop(&tok);
|
||||
}
|
||||
scc_ring_free(*tok_ring);
|
||||
|
||||
const char *includename = scc_cstring_as_cstr(&line);
|
||||
int len = scc_cstring_len(&line);
|
||||
const char *includename = scc_str_as_cstr(&line);
|
||||
int len = scc_str_len(&line);
|
||||
if (len < 2) {
|
||||
goto ERROR;
|
||||
} else if (len == 2) {
|
||||
@@ -94,19 +94,19 @@ void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok,
|
||||
goto ERROR;
|
||||
}
|
||||
}
|
||||
scc_cstring_t fname = scc_cstring_create();
|
||||
scc_str_t fname = scc_str_empty();
|
||||
for (int i = 1; i < len - 1; i++) {
|
||||
scc_cstring_append_ch(&fname, includename[i]);
|
||||
scc_str_append_ch(&fname, includename[i]);
|
||||
}
|
||||
scc_cstring_free(&line);
|
||||
scc_str_drop(&line);
|
||||
int is_system = includename[0] == '<';
|
||||
if (switch_file_stack(pp, &fname, &pos, is_system)) {
|
||||
// LOG_ERROR()
|
||||
}
|
||||
scc_cstring_free(&fname);
|
||||
scc_str_drop(&fname);
|
||||
return;
|
||||
ERROR:
|
||||
SCC_ERROR(pos,
|
||||
"invalid include filename, expected \"FILENAME\" or <FILENAME>");
|
||||
scc_cstring_free(&line);
|
||||
scc_str_drop(&line);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user