fix(argparse): 修复参数解析错误处理逻辑
当解析过程中出现错误时,应该继续循环而不是直接跳出, 确保完整的错误处理流程能够执行。 fix(ast2ir): 修复函数调用表达式中的类型检查 在每次迭代中重新获取指针以避免向量重分配问题, 并添加类型引用断言确保参数类型有效性。 fix(lexer): 添加词法分析器资源释放 在main函数中正确释放tok_ring资源,防止内存泄漏。 test: 更新测试用例输出字符串格式 将测试用例中的输出字符串从全小写更新为首字母大写, 保持代码风格一致性。
This commit is contained in:
@@ -280,7 +280,7 @@ int scc_argparse_parse(scc_argparse_t *parser, int argc, const char **argv) {
|
|||||||
init_context(&ctx, parser, argc, argv); // 初始化上下文
|
init_context(&ctx, parser, argc, argv); // 初始化上下文
|
||||||
int errcode = SCC_ARGPARSE_ERR_NONE;
|
int errcode = SCC_ARGPARSE_ERR_NONE;
|
||||||
|
|
||||||
while (!ctx.parsing_done &&
|
while (!ctx.parsing_done && errcode == SCC_ARGPARSE_ERR_NONE &&
|
||||||
scc_optparse_parse(&ctx.optparse, &ctx.result)) {
|
scc_optparse_parse(&ctx.optparse, &ctx.result)) {
|
||||||
if (parser->need_debug) {
|
if (parser->need_debug) {
|
||||||
scc_printf("debug:[%c:%s:%d] %s\n",
|
scc_printf("debug:[%c:%s:%d] %s\n",
|
||||||
@@ -292,7 +292,7 @@ int scc_argparse_parse(scc_argparse_t *parser, int argc, const char **argv) {
|
|||||||
|
|
||||||
if (ctx.result.error) {
|
if (ctx.result.error) {
|
||||||
errcode = transite_error(&ctx);
|
errcode = transite_error(&ctx);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.result.opt != nullptr) {
|
if (ctx.result.opt != nullptr) {
|
||||||
|
|||||||
@@ -884,10 +884,11 @@ scc_hir_value_ref_t scc_ast2ir_expr(scc_ast2ir_ctx_t *ctx,
|
|||||||
arg_node = scc_ast2ir_expr(ctx, arg_expr, false);
|
arg_node = scc_ast2ir_expr(ctx, arg_expr, false);
|
||||||
if ((int)i < fixed_count) {
|
if ((int)i < fixed_count) {
|
||||||
// 固定参数:转换为形参类型
|
// 固定参数:转换为形参类型
|
||||||
// 每次迭代重新获取指针(scc_ast2ir_expr 可能触发 types 向量 realloc)
|
// 每次迭代重新获取指针(scc_ast2ir_expr 可能触发 types 向量
|
||||||
|
// realloc)
|
||||||
scc_hir_module_t *module = scc_ast2ir_mir_module(ctx);
|
scc_hir_module_t *module = scc_ast2ir_mir_module(ctx);
|
||||||
const scc_hir_type_t *ft = scc_hir_module_get_type(
|
const scc_hir_type_t *ft =
|
||||||
module, func_type_ref);
|
scc_hir_module_get_type(module, func_type_ref);
|
||||||
scc_hir_type_ref_t param_type =
|
scc_hir_type_ref_t param_type =
|
||||||
scc_vec_at(ft->data.function.params, i);
|
scc_vec_at(ft->data.function.params, i);
|
||||||
arg_node =
|
arg_node =
|
||||||
@@ -898,6 +899,7 @@ scc_hir_value_ref_t scc_ast2ir_expr(scc_ast2ir_ctx_t *ctx,
|
|||||||
scc_hir_module_t *module = scc_ast2ir_mir_module(ctx);
|
scc_hir_module_t *module = scc_ast2ir_mir_module(ctx);
|
||||||
scc_hir_type_ref_t arg_type_ref =
|
scc_hir_type_ref_t arg_type_ref =
|
||||||
scc_hir_module_get_value(module, arg_node)->type;
|
scc_hir_module_get_value(module, arg_node)->type;
|
||||||
|
Assert(arg_type_ref != 0);
|
||||||
scc_hir_type_tag_t arg_tag =
|
scc_hir_type_tag_t arg_tag =
|
||||||
scc_hir_module_get_type(module, arg_type_ref)->tag;
|
scc_hir_module_get_type(module, arg_type_ref)->tag;
|
||||||
scc_hir_type_ref_t promoted =
|
scc_hir_type_ref_t promoted =
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ int main(int argc, const char **argv, const char **envp) {
|
|||||||
} else {
|
} else {
|
||||||
print_file(tok_ring, fp);
|
print_file(tok_ring, fp);
|
||||||
}
|
}
|
||||||
|
scc_lexer_drop_ring(tok_ring);
|
||||||
need_end = true;
|
need_end = true;
|
||||||
goto lexer_drop;
|
goto lexer_drop;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
puts("hello world!");
|
puts("Hello World!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
printf("hello printf: %d\n", 123);
|
printf("Hello printf: %d\n", 123);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user