- 为所有模块添加统一的 scc_*_log.h 日志头文件,删除旧的 lexer_log.h/c - 将运行时日志从 scc_utils 迁移到 scc_core 目录,统一日志管理 - 在解析器表达式/语句/类型解析中添加 LOG_TRACE 调试日志 - 实现 SCCF 链接器 (sccf_linker) 支持多目标文件链接 - 重构 CLI 主程序 (main.c/config.c),新增 cmd_log.h 调试支持 - 优化 x86 指令编码操作数对齐检查 - 修复预处理器的指令处理和宏展开逻辑
83 lines
2.2 KiB
C
83 lines
2.2 KiB
C
#ifndef __SCC_PARSER_UTILS_H__
|
|
#define __SCC_PARSER_UTILS_H__
|
|
|
|
#include "scc_parser.h"
|
|
|
|
static inline const scc_lexer_tok_t *scc_parser_peek(scc_parser_t *parser) {
|
|
cbool ok = false;
|
|
const scc_lexer_tok_t *tok = nullptr;
|
|
scc_ring_unsafe_peek_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return nullptr;
|
|
}
|
|
return tok;
|
|
}
|
|
|
|
static inline const scc_lexer_tok_t *scc_parser_next(scc_parser_t *parser) {
|
|
cbool ok = false;
|
|
const scc_lexer_tok_t *tok = nullptr;
|
|
scc_ring_unsafe_next_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return nullptr;
|
|
}
|
|
return tok;
|
|
}
|
|
|
|
static inline cbool scc_parser_consume_if(scc_parser_t *parser,
|
|
scc_tok_type_t type) {
|
|
cbool ok = false;
|
|
scc_lexer_tok_t *tok = nullptr;
|
|
scc_ring_unsafe_peek_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return nullptr;
|
|
}
|
|
if (tok->type == type) {
|
|
scc_lexer_tok_drop(tok);
|
|
scc_ring_unsafe_pure_next_consume(*parser->ring);
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static inline void scc_parser_store(scc_parser_t *parser) {
|
|
parser->checkpoint = _scc_ring_probe(*parser->ring);
|
|
}
|
|
|
|
static inline void scc_parser_restore(scc_parser_t *parser) {
|
|
_scc_ring_probe(*parser->ring) = parser->checkpoint;
|
|
}
|
|
|
|
// tok can nullptr it will be safty free
|
|
static inline cbool scc_parser_next_consume(scc_parser_t *parser,
|
|
scc_lexer_tok_t *tok) {
|
|
cbool ok = false;
|
|
scc_lexer_tok_t *raw_tok_ref = nullptr;
|
|
scc_ring_unsafe_next_ref_consume(*parser->ring, raw_tok_ref, ok);
|
|
if (tok == nullptr) {
|
|
scc_lexer_tok_drop(raw_tok_ref);
|
|
} else {
|
|
scc_lexer_tok_move(tok, raw_tok_ref);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
static inline void scc_parser_commit(scc_parser_t *parser) {
|
|
// Memory leak
|
|
scc_ring_consume(*parser->ring);
|
|
}
|
|
|
|
static inline void scc_parser_reset(scc_parser_t *parser) {
|
|
scc_ring_reset(*parser->ring);
|
|
}
|
|
|
|
static inline scc_pos_t scc_parser_got_current_pos(scc_parser_t *parser) {
|
|
const scc_lexer_tok_t *tok = scc_parser_peek(parser);
|
|
scc_pos_t pos = scc_pos_create();
|
|
if (tok != nullptr)
|
|
pos = tok->loc;
|
|
return pos;
|
|
}
|
|
|
|
#endif /* __SCC_PARSER_UTILS_H__ */
|