feat(pproc): 修改include解析函数以支持位置信息传递

修改了scc_pproc_parse_include函数签名,添加了token参数用于传递位置信息,
使得在处理包含指令时能够提供更准确的错误定位。同时更新了文件切换逻辑,
将位置信息传递给错误日志,提高调试效率。
This commit is contained in:
zzy
2026-02-20 14:28:11 +08:00
parent bc0b1d23e3
commit 9c2b4db22a
3 changed files with 11 additions and 11 deletions

View File

@@ -51,7 +51,7 @@ 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_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok);
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,

View File

@@ -271,8 +271,7 @@ void scc_pproc_handle_directive(scc_pproc_t *pp) {
return;
}
case SCC_PP_TOK_INCLUDE:
scc_lexer_tok_drop(&tok);
scc_pproc_parse_include(pp);
scc_pproc_parse_include(pp, &tok);
return;
case SCC_PP_TOK_IF:
case SCC_PP_TOK_IFDEF:

View File

@@ -2,17 +2,15 @@
#include <scc_pproc.h>
static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
int is_system) {
scc_pos_t *pos, int is_system) {
scc_cstring_t fpath = scc_cstring_create();
int ret = 0;
const char *org_fname = pos->name;
if (!is_system) {
const char parent[] = "/../";
// FIXME maybe it can eazy
const char *org_fname =
(((scc_sstream_t *)(((scc_lexer_t *)pp->org_ring->userdata)
->stream_ref->userdata))
->fname);
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);
@@ -33,7 +31,8 @@ static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
goto FOPEN;
}
}
LOG_ERROR("Include File %c%s%c Not Found", is_system ? '<' : '\"',
LOG_ERROR("In %s:%d:%d include %c%s%c , the file is not found", org_fname,
pos->line, pos->col, is_system ? '<' : '\"',
scc_cstring_as_cstr(fname), is_system ? '>' : '\"');
return -1;
FOPEN:
@@ -50,9 +49,11 @@ FOPEN:
return 0;
}
void scc_pproc_parse_include(scc_pproc_t *pp) {
void scc_pproc_parse_include(scc_pproc_t *pp, scc_lexer_tok_t *include_tok) {
int ok;
scc_lexer_tok_t tok;
scc_pos_t pos = include_tok->loc;
scc_lexer_tok_drop(&tok);
scc_lexer_tok_ring_t *stream = pp->cur_ring;
scc_lexer_tok_vec_t org_toks;
@@ -108,7 +109,7 @@ void scc_pproc_parse_include(scc_pproc_t *pp) {
}
scc_cstring_free(&line);
int is_system = includename[0] == '<';
if (switch_file_stack(pp, &fname, is_system)) {
if (switch_file_stack(pp, &fname, &pos, is_system)) {
// LOG_ERROR()
}
scc_cstring_free(&fname);