refactor(format): 移除SCF格式相关文件
移除了libs/format目录下的所有文件,包括: - cbuild.toml构建配置文件 - include/scf.h头文件 - include/scf_impl.h实现头文件 - src/scf.c源文件 - tests/test_scf.c测试文件 - tests/test_scf_x64.c x64架构测试文件 这些文件包含了SCF(scc format)格式的完整实现,但现在不再需要。 feat(lexer): 添加布尔字面量数字生成函数 在lexer工具头文件中添加了两个内联函数用于生成布尔值的数字字面量: - scc_lexer_gen_number_true: 将token类型设为整数字面量,值为"1" - scc_lexer_gen_number_false: 将token类型设为整数字面量,值为"0" refactor(lexer): 改进词法分析器错误处理 - 移除了多余的头文件包含 - 更新错误报告方式,使用SCC_ERROR宏替代LEX_ERROR,提供更准确的错误位置信息 refactor(pproc): 更新预处理器扩展器数据结构 - 将need_rescan字段类型从int改为cbool - 添加need_parse_defined字段用于控制defined操作符解析 - 更新函数签名以支持defined操作符解析参数
This commit is contained in:
30
libs/sstream/include/scc_pos_log.h
Normal file
30
libs/sstream/include/scc_pos_log.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef __SCC_POS_LOG_H__
|
||||
#define __SCC_POS_LOG_H__
|
||||
|
||||
#include "scc_pos.h"
|
||||
#include <scc_core.h>
|
||||
|
||||
extern logger_t __scc_usr_log;
|
||||
|
||||
#define SCC_POS_LOG(level, pos, fmt, ...) \
|
||||
do { \
|
||||
char _full_msg[LOGGER_MAX_BUF_SIZE]; \
|
||||
int _n = snprintf_(_full_msg, sizeof(_full_msg), \
|
||||
"%s:%lu:%lu: ", (pos).name, (pos).line, (pos).col); \
|
||||
snprintf_(_full_msg + _n, sizeof(_full_msg) - _n, fmt, ##__VA_ARGS__); \
|
||||
__scc_usr_log.handler(&__scc_usr_log, level, null, 0, null, "%s", \
|
||||
_full_msg); \
|
||||
} while (0)
|
||||
|
||||
#define SCC_DEBUG(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_DEBUG, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_INFO(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_INFO, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_WARN(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_WARN, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_ERROR(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_ERROR, pos, fmt, ##__VA_ARGS__)
|
||||
#define SCC_FATAL(pos, fmt, ...) \
|
||||
SCC_POS_LOG(LOG_LEVEL_FATAL, pos, fmt, ##__VA_ARGS__)
|
||||
|
||||
#endif /* __SCC_POS_LOG_H__ */
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __SCC_SSTREAM_H__
|
||||
|
||||
#include "scc_pos.h"
|
||||
#include "scc_pos_log.h"
|
||||
#include <scc_core.h>
|
||||
#include <scc_core_ring.h>
|
||||
|
||||
|
||||
56
libs/sstream/src/scc_pos_log.c
Normal file
56
libs/sstream/src/scc_pos_log.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <scc_pos_log.h>
|
||||
|
||||
static int user_log_handler(logger_t *module, log_level_t level,
|
||||
const char *file, int line, const char *func,
|
||||
const char *fmt, ...) {
|
||||
|
||||
/* clang-format off */
|
||||
(void)file; (void)line; (void)func; // 不再使用
|
||||
|
||||
const char *level_str = null;
|
||||
switch (level) {
|
||||
case LOG_LEVEL_DEBUG: level_str = "DEBUG"; break;
|
||||
case LOG_LEVEL_INFO: level_str = "INFO "; break;
|
||||
case LOG_LEVEL_WARN: level_str = "WARN "; break;
|
||||
case LOG_LEVEL_ERROR: level_str = "ERROR"; break;
|
||||
case LOG_LEVEL_FATAL: level_str = "FATAL"; break;
|
||||
case LOG_LEVEL_TRACE: level_str = "TRACE"; break;
|
||||
default: level_str = "NOTSET"; break;
|
||||
}
|
||||
/// @note: 定义 __LOG_NO_COLOR__ 会取消颜色输出
|
||||
#ifndef __LOG_NO_COLOR__
|
||||
const char *color_code;
|
||||
switch (level) {
|
||||
case LOG_LEVEL_DEBUG: color_code = ANSI_FG_CYAN; break;
|
||||
case LOG_LEVEL_INFO: color_code = ANSI_FG_GREEN; break;
|
||||
case LOG_LEVEL_TRACE: color_code = ANSI_FG_BLUE; break;
|
||||
case LOG_LEVEL_WARN: color_code = ANSI_FG_YELLOW; break;
|
||||
case LOG_LEVEL_ERROR: color_code = ANSI_FG_RED; break;
|
||||
case LOG_LEVEL_FATAL: color_code = ANSI_FG_RED ANSI_UNDERLINED; break;
|
||||
default: color_code = ANSI_NONE;
|
||||
}
|
||||
#endif
|
||||
/* clang-format on */
|
||||
char buf[LOGGER_MAX_BUF_SIZE];
|
||||
int off =
|
||||
snprintf_(buf, sizeof(buf), "%s[%s]%s ", color_code ? color_code : "",
|
||||
level_str, color_code ? ANSI_NONE : "");
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf_(buf + off, sizeof(buf) - off, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
log_puts(buf);
|
||||
log_puts("\n");
|
||||
|
||||
if (level == LOG_LEVEL_FATAL)
|
||||
log_exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
logger_t __scc_usr_log = {
|
||||
.name = "user",
|
||||
.handler = user_log_handler,
|
||||
.level = LOG_LEVEL_ALL,
|
||||
};
|
||||
@@ -88,7 +88,9 @@ int scc_sstream_init(scc_sstream_t *stream, const char *fname, int ring_size) {
|
||||
}
|
||||
usize fsize = scc_fsize(file);
|
||||
if (fsize == 0) {
|
||||
LOG_WARN("file size is 0");
|
||||
stream->fill_pos = scc_pos_create();
|
||||
stream->fill_pos.name = fname;
|
||||
SCC_WARN(stream->fill_pos, "file size is 0");
|
||||
scc_fclose(file);
|
||||
return 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user