From 94d3f46fac1c305192b8dc236774d982d6db4ed7 Mon Sep 17 00:00:00 2001 From: zzy <2450266535@qq.com> Date: Fri, 12 Dec 2025 21:33:51 +0800 Subject: [PATCH] refactor(lex_parser): replace core_pos_* functions with scc_pos_* equivalents Update all position tracking calls in lex_parser.c to use the scc_pos_* function family (scc_pos_next, scc_pos_next_line) instead of the deprecated core_pos_* variants. This ensures consistency with the scc naming convention and prepares for future removal of the old core functions. --- libs/lex_parser/src/lex_parser.c | 42 +++++++++++++++--------------- libs/lexer/src/lexer.c | 8 +++--- runtime/libcore/include/core_pos.h | 4 +-- runtime/log/include/log.c | 12 --------- runtime/log/include/log.h | 15 ----------- 5 files changed, 27 insertions(+), 54 deletions(-) diff --git a/libs/lex_parser/src/lex_parser.c b/libs/lex_parser/src/lex_parser.c index 710bbde..d249d53 100644 --- a/libs/lex_parser/src/lex_parser.c +++ b/libs/lex_parser/src/lex_parser.c @@ -10,10 +10,10 @@ void lex_parse_skip_endline(scc_probe_stream_t *input, scc_pos_t *pos) { if (ch == '\n') { scc_probe_stream_consume(input); } - core_pos_next_line(pos); + scc_pos_next_line(pos); } else if (ch == '\n') { scc_probe_stream_consume(input); - core_pos_next_line(pos); + scc_pos_next_line(pos); } else { LOG_WARN("not a newline character"); } @@ -74,7 +74,7 @@ void lex_parse_skip_line(scc_probe_stream_t *input, scc_pos_t *pos) { return; } else { scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); } } } @@ -85,11 +85,11 @@ void lex_parse_skip_block_comment(scc_probe_stream_t *input, scc_pos_t *pos) { int ch; scc_probe_stream_reset(stream); ch = scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); // FIXME Assertion Assert(ch == '/'); ch = scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); Assert(ch == '*'); // all ready match `/*` @@ -107,12 +107,12 @@ void lex_parse_skip_block_comment(scc_probe_stream_t *input, scc_pos_t *pos) { continue; } scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); if (ch == '*') { ch = scc_probe_stream_peek(stream); if (ch == '/') { scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); return; } } @@ -131,7 +131,7 @@ void lex_parse_skip_whitespace(scc_probe_stream_t *input, scc_pos_t *pos) { } scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); } } @@ -167,7 +167,7 @@ static inline cbool _lex_parse_uint(scc_probe_stream_t *input, scc_pos_t *pos, } scc_probe_stream_consume(input); - core_pos_next(pos); + scc_pos_next(pos); n = n * base + tmp; // TODO number overflow } @@ -202,17 +202,17 @@ int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) { goto ERR; } scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); ch = scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); if (ch == core_stream_eof) { LOG_WARN("Unexpected EOF at middle"); goto ERR; } else if (ch == '\\') { ch = scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); if (ch == '0') { // 数字转义序列 // \nnn 任意八进制值 码元 nnn @@ -239,7 +239,7 @@ int lex_parse_char(scc_probe_stream_t *input, scc_pos_t *pos) { } if ((ch = scc_probe_stream_consume(stream)) != '\'') { LOG_ERROR("Unclosed character literal '%c' at end, expect `'`", ch); - core_pos_next(pos); + scc_pos_next(pos); goto ERR; } @@ -273,7 +273,7 @@ cbool lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos, goto ERR; } scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); scc_cstring_t str = scc_cstring_from_cstr(""); while (1) { @@ -298,12 +298,12 @@ cbool lex_parse_string(scc_probe_stream_t *input, scc_pos_t *pos, } } else if (ch == '"') { scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); break; } scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); scc_cstring_append_ch(&str, ch); } @@ -339,7 +339,7 @@ cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos, if (ch == '0') { // 消费 '0' scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); // 查看下一个字符 ch = scc_probe_stream_peek(stream); @@ -347,12 +347,12 @@ cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos, // 十六进制 base = 16; scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); } else if (ch == 'b' || ch == 'B') { // 二进制 (C23扩展) base = 2; scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); } else if (ch >= '0' && ch <= '7') { // 八进制 base = 8; @@ -384,7 +384,7 @@ cbool lex_parse_number(scc_probe_stream_t *input, scc_pos_t *pos, // 我们需要消费这个数字并返回它的值 if (ch >= '1' && ch <= '9') { scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); *output = ch - '0'; return true; } @@ -421,7 +421,7 @@ cbool lex_parse_identifier(scc_probe_stream_t *input, scc_pos_t *pos, while (1) { scc_cstring_append_ch(output, ch); scc_probe_stream_consume(stream); - core_pos_next(pos); + scc_pos_next(pos); ch = scc_probe_stream_peek(stream); if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch >= '0' && ch <= '9')) { diff --git a/libs/lexer/src/lexer.c b/libs/lexer/src/lexer.c index 5f44f43..b6b6971 100644 --- a/libs/lexer/src/lexer.c +++ b/libs/lexer/src/lexer.c @@ -105,7 +105,7 @@ static void parse_line(scc_lexer_t *lexer, lexer_tok_t *token) { for (int i = 0; i < (int)sizeof(line); i++) { ch = scc_probe_stream_consume(stream); - core_pos_next(&lexer->pos); + scc_pos_next(&lexer->pos); if (ch != line[i]) { LEX_WARN("Maroc does not support in lexer rather in preprocessor, " "it will be ignored"); @@ -453,13 +453,13 @@ void scc_lexer_get_token(scc_lexer_t *lexer, lexer_tok_t *token) { goto once_char; triple_char: scc_probe_stream_consume(stream); - core_pos_next(&lexer->pos); + scc_pos_next(&lexer->pos); double_char: scc_probe_stream_consume(stream); - core_pos_next(&lexer->pos); + scc_pos_next(&lexer->pos); once_char: scc_probe_stream_consume(stream); - core_pos_next(&lexer->pos); + scc_pos_next(&lexer->pos); token->type = type; END: LEX_DEBUG("get token `%s` in %s:%d:%d", scc_get_tok_name(token->type), diff --git a/runtime/libcore/include/core_pos.h b/runtime/libcore/include/core_pos.h index 26677d4..9d076d3 100644 --- a/runtime/libcore/include/core_pos.h +++ b/runtime/libcore/include/core_pos.h @@ -14,12 +14,12 @@ static inline scc_pos_t scc_pos_init() { return (scc_pos_t){scc_cstring_new(), 1, 1, 0}; } -static inline void core_pos_next(scc_pos_t *pos) { +static inline void scc_pos_next(scc_pos_t *pos) { pos->offset++; pos->col++; } -static inline void core_pos_next_line(scc_pos_t *pos) { +static inline void scc_pos_next_line(scc_pos_t *pos) { pos->offset++; pos->line++; pos->col = 1; diff --git a/runtime/log/include/log.c b/runtime/log/include/log.c index b023f10..df0dfd4 100644 --- a/runtime/log/include/log.c +++ b/runtime/log/include/log.c @@ -79,12 +79,6 @@ void init_logger(logger_t *logger, const char *name) { log_set_level(logger, LOG_LEVEL_ALL); } -logger_t *log_get(const char *name) { - // TODO for -Wunused-parameter - (void)name; - return &__default_logger_root; -} - void log_set_level(logger_t *logger, int level) { if (logger) logger->level = level; @@ -98,9 +92,3 @@ void log_set_handler(logger_t *logger, log_handler handler) { else __default_logger_root.handler = handler; } - -void logger_destroy(logger_t *logger) { - // TODO for -Wunused-parameter - (void)logger; - return; -} diff --git a/runtime/log/include/log.h b/runtime/log/include/log.h index aed4760..3bf3219 100644 --- a/runtime/log/include/log.h +++ b/runtime/log/include/log.h @@ -96,16 +96,6 @@ extern logger_t __default_logger_root; */ void init_logger(logger_t *logger, const char *name); -// TODO log_set(); 暂未实现 日志注册 - -/** - * @brief 获取或创建日志器实例 - * @param[in] name 日志器名称(NULL表示获取默认日志器) - * @return 日志器实例指针 - * @warning 若没有找到相应日志器则会返回根日志器 - */ -logger_t *log_get(const char *name); - /** * @brief 设置日志级别 * @param[in] logger 目标日志器实例 @@ -120,11 +110,6 @@ void log_set_level(logger_t *logger, int level); */ void log_set_handler(logger_t *logger, log_handler handler); -/** - * @todo TODO impliment - */ -void logger_destroy(logger_t *logger); - #ifndef LOG_MAX_MAROC_BUF_SIZE #define LOG_MAX_MAROC_BUF_SIZE LOGGER_MAX_BUF_SIZE ///< 宏展开缓冲区尺寸 #endif