feat(argparse): 添加命令行参数约束和错误处理功能

- 添加了命令行参数约束相关数据结构定义
- 新增错误上下文字段用于更好的错误提示
- 实现了参数验证功能,包括必需参数检查和值选择验证
- 改进错误处理流程,支持添加帮助信息和使用说明
- 优化调试输出格式,增加更多错误场景的处理

fix(parser): 修复语义分析器资源释放问题

- 在scc_sema_drop函数中添加空指针检查,避免空指针释放导致崩溃

refactor(dump): 重构AST节点转储实现

- 将树形转储上下文重构为更简洁的数据结构
- 修改转储回调函数签名以支持更好的缓冲区管理
- 优化内存拷贝操作,提高转储性能

style(amd64): 移除未使用的变量声明

- 删除scc_mcode_amd64_mov_r64_m64_sib函数中未使用的disp8变量
This commit is contained in:
zzy
2026-04-11 11:42:31 +08:00
parent 053c6abf51
commit 630e22b73b
9 changed files with 136 additions and 99 deletions

View File

@@ -11,9 +11,13 @@
// 4. 支持配置文件解析
// 5. 支持国际化i18n
/// @brief 命令行参数约束
typedef struct scc_argparse_spec scc_argparse_spec_t;
/// @brief 命令行参数 eg. someting
typedef struct scc_argparse_arg scc_argparse_arg_t;
/// @brief 命令行参数选项 eg. -a --long
typedef struct scc_argparse_opt scc_argparse_opt_t;
/// @brief 命令集合
typedef struct scc_argparse_cmd scc_argparse_cmd_t;
typedef SCC_VEC(scc_argparse_arg_t) scc_argparse_arg_vec_t;
@@ -44,6 +48,7 @@ typedef enum scc_argparse_err {
} scc_argparse_err_t;
typedef SCC_VEC(const char *) scc_argparse_list_t;
// 约束规范结构体
struct scc_argparse_spec {
scc_argparse_val_type_t value_type; // 值类型
@@ -111,6 +116,8 @@ typedef struct {
cbool need_help;
cbool need_version;
cbool need_debug;
cbool need_error_add_help;
cbool need_error_add_usage;
} scc_argparse_t;
typedef SCC_VEC(scc_optparse_opt_t) scc_optparse_opt_vec_t;
@@ -119,10 +126,10 @@ typedef struct {
scc_argparse_cmd_t *current_cmd; // 当前正在解析的命令
scc_optparse_t optparse; // 底层解析器
scc_optparse_opt_vec_t opts; // 当前命令的选项列表
scc_optparse_result_t result;
int positional_index; // 当前处理的位置参数索引
cbool parsing_done; // 是否已完成解析
scc_argparse_lang_t lang;
scc_optparse_result_t result; // 底层解析结果
const void *err_ctx; // 错误上下文(期待的参数或者当前解析的参数)
int positional_index; // 当前处理的位置参数索引
cbool parsing_done; // 是否已完成解析
} scc_argparse_context_t;
void scc_argparse_init(scc_argparse_t *parser, const char *program_name,
@@ -144,7 +151,7 @@ void scc_argparse_cmd_add_subcmd(scc_argparse_cmd_t *cmd,
void scc_argparse_print_help(scc_argparse_t *parser, scc_argparse_cmd_t *cmd);
void scc_argparse_print_error(scc_argparse_context_t *ctx,
scc_argparse_err_t err);
scc_argparse_t *parser, scc_argparse_err_t err);
static inline void scc_argparse_spec_init(scc_argparse_spec_t *spec) {
spec->value_type = SCC_ARGPARSE_VAL_TYPE_STRING;