feat(pproc): 修改include解析函数以支持位置信息传递
修改了scc_pproc_parse_include函数签名,添加了token参数用于传递位置信息, 使得在处理包含指令时能够提供更准确的错误定位。同时更新了文件切换逻辑, 将位置信息传递给错误日志,提高调试效率。
This commit is contained in:
@@ -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_drop(scc_pproc_t *pp);
|
||||||
|
|
||||||
void scc_pproc_handle_directive(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,
|
void scc_pproc_parse_macro_arguments(scc_lexer_tok_ring_t *ring,
|
||||||
scc_lexer_tok_vec_t *args, int need_full);
|
scc_lexer_tok_vec_t *args, int need_full);
|
||||||
void scc_pproc_parse_function_macro(scc_pproc_t *pp,
|
void scc_pproc_parse_function_macro(scc_pproc_t *pp,
|
||||||
|
|||||||
@@ -271,8 +271,7 @@ void scc_pproc_handle_directive(scc_pproc_t *pp) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case SCC_PP_TOK_INCLUDE:
|
case SCC_PP_TOK_INCLUDE:
|
||||||
scc_lexer_tok_drop(&tok);
|
scc_pproc_parse_include(pp, &tok);
|
||||||
scc_pproc_parse_include(pp);
|
|
||||||
return;
|
return;
|
||||||
case SCC_PP_TOK_IF:
|
case SCC_PP_TOK_IF:
|
||||||
case SCC_PP_TOK_IFDEF:
|
case SCC_PP_TOK_IFDEF:
|
||||||
|
|||||||
@@ -2,17 +2,15 @@
|
|||||||
#include <scc_pproc.h>
|
#include <scc_pproc.h>
|
||||||
|
|
||||||
static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
|
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();
|
scc_cstring_t fpath = scc_cstring_create();
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
const char *org_fname = pos->name;
|
||||||
|
|
||||||
if (!is_system) {
|
if (!is_system) {
|
||||||
const char parent[] = "/../";
|
const char parent[] = "/../";
|
||||||
// FIXME maybe it can eazy
|
// 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, org_fname, scc_strlen(org_fname));
|
||||||
scc_cstring_append_cstr(&fpath, parent, scc_strlen(parent));
|
scc_cstring_append_cstr(&fpath, parent, scc_strlen(parent));
|
||||||
scc_cstring_append(&fpath, fname);
|
scc_cstring_append(&fpath, fname);
|
||||||
@@ -33,7 +31,8 @@ static int switch_file_stack(scc_pproc_t *pp, scc_cstring_t *fname,
|
|||||||
goto FOPEN;
|
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 ? '>' : '\"');
|
scc_cstring_as_cstr(fname), is_system ? '>' : '\"');
|
||||||
return -1;
|
return -1;
|
||||||
FOPEN:
|
FOPEN:
|
||||||
@@ -50,9 +49,11 @@ FOPEN:
|
|||||||
return 0;
|
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;
|
int ok;
|
||||||
scc_lexer_tok_t tok;
|
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_ring_t *stream = pp->cur_ring;
|
||||||
scc_lexer_tok_vec_t org_toks;
|
scc_lexer_tok_vec_t org_toks;
|
||||||
@@ -108,7 +109,7 @@ void scc_pproc_parse_include(scc_pproc_t *pp) {
|
|||||||
}
|
}
|
||||||
scc_cstring_free(&line);
|
scc_cstring_free(&line);
|
||||||
int is_system = includename[0] == '<';
|
int is_system = includename[0] == '<';
|
||||||
if (switch_file_stack(pp, &fname, is_system)) {
|
if (switch_file_stack(pp, &fname, &pos, is_system)) {
|
||||||
// LOG_ERROR()
|
// LOG_ERROR()
|
||||||
}
|
}
|
||||||
scc_cstring_free(&fname);
|
scc_cstring_free(&fname);
|
||||||
|
|||||||
Reference in New Issue
Block a user