refactor(lexer): 移除未使用的期望函数并修复内存分配错误

移除了 scc_lexer_tok_expect 函数,因为它不再被使用。
在 lexer_stream_extend 函数中添加了返回语句,以在内存重新分配失败时正确处理错误。

BREAKING CHANGE: 移除了 scc_lexer_tok_expect 函数
This commit is contained in:
zzy
2026-01-10 17:43:31 +08:00
parent c01e6e1db4
commit 6c801fbb92
3 changed files with 23 additions and 18 deletions

View File

@@ -148,13 +148,4 @@ static inline cbool scc_lexer_tok_match(const scc_lexer_tok_t *tok,
return tok->type == type;
}
static inline cbool scc_lexer_tok_expect(const scc_lexer_tok_t *tok,
scc_tok_type_t type) {
if (!scc_lexer_tok_match(tok, type)) {
LOG_ERROR("expected token %d, got %d\n", type, tok->type);
return false;
}
return true;
}
#endif /* __SCC_LEXER_TOKEN_H__ */

View File

@@ -14,6 +14,7 @@ static void lexer_stream_extend(scc_lexer_stream_t *stream, usize n) {
scc_realloc(null, new_cap * sizeof(scc_lexer_tok_t));
if (!new_data) {
LOG_FATAL("lexer_stream_extend: realloc failed\n");
return;
}
// 将旧缓冲区中的数据拷贝到新缓冲区,保持顺序

View File

@@ -610,8 +610,6 @@ class GccCompiler(Compiler):
"-DTEST_MODE",
"-O0",
"-g",
"--coverage",
"-fprofile-update=atomic",
"-Wall",
"-Wextra",
],
@@ -650,8 +648,8 @@ class ClangCompiler(Compiler):
"-DTEST_MODE",
"-O0",
"-g",
"--coverage",
"-fprofile-update=atomic",
"-fsanitize=address",
"-fno-omit-frame-pointer",
"-Wall",
"-Wextra",
],
@@ -832,15 +830,23 @@ class PackageBuilder:
"完成 %s 目标,耗时 %s (使用 %d 线程)", self.mode.value, time_str, self.jobs
)
def run(self):
def run(self, args: list[str] | None = None):
"""运行主程序"""
if args is None:
args = []
targets = [
t for t in self.context.get_targets() if t.type == TargetType.MAIN_EXEC
]
if len(targets) != 1:
logger.error("没有可运行的目标")
logger.error(translator.translate("no_targets"))
return
subprocess.run(targets[0].output, check=False)
# 过滤掉 '--' 分隔符
filtered_args = [arg for arg in args if arg != "--"]
logger.info("运行程序: %s %s", targets[0].output, " ".join(filtered_args))
subprocess.run([targets[0].output] + filtered_args, check=False)
def clean(self):
"""清理构建产物"""
@@ -1058,9 +1064,14 @@ def create_parser():
add_common_args(build_parser)
build_parser.set_defaults(mode=BuildMode.DEV)
# run 命令
# run 命令 - 添加剩余参数支持
run_parser = subparsers.add_parser("run", help="运行项目")
add_common_args(run_parser)
run_parser.add_argument(
"args",
nargs=argparse.REMAINDER, # 收集所有剩余参数
help="传递给程序的参数",
)
run_parser.set_defaults(mode=BuildMode.DEV)
# test 命令
@@ -1133,7 +1144,9 @@ def main():
)
elif args.command == "run":
builder.build([TargetType.MAIN_EXEC])
builder.run()
# 传递参数给 run 方法
program_args = getattr(args, "args", [])
builder.run(program_args)
elif args.command == "test":
builder.build([TargetType.TEST_EXEC])
builder.tests(args.filter, args.timeout)