feat(parser): 启用parser和ast模块并重构解析器结构
- 在cbuild.toml中启用parser和ast依赖项 - 将AST内置类型枚举重命名为SCC_AST_BUILTIN_TYPE_*前缀格式 - 修复ast_def.h中的类型字段命名,将builtin改为type - 添加逗号操作符支持到表达式操作符枚举中 - 更新字面量表达式的lexeme字段为const char*指针和owned标志 - 重构解析器头文件结构,分离为parser.h、parser_utils.h、scc_sema.h等 - 实现新的解析器工具函数,包括预览、消费、回溯等功能 - 更新声明解析逻辑,使用新的解析器接口进行token处理 - 添加符号表语义分析功能框架 - 修复词法分析器中token移动时的空指针检查 - 统一使用scc_tree_dump_printf替代直接的scc_printf调用
This commit is contained in:
@@ -127,31 +127,31 @@ static const char *get_node_type_str(scc_ast_node_type_t type) {
|
||||
// 获取内置类型名称
|
||||
static const char *get_builtin_type_str(scc_ast_builtin_type_t type) {
|
||||
switch (type) {
|
||||
case TYPE_VOID:
|
||||
case SCC_AST_BUILTIN_TYPE_VOID:
|
||||
return "void";
|
||||
case TYPE_CHAR:
|
||||
case SCC_AST_BUILTIN_TYPE_CHAR:
|
||||
return "char";
|
||||
case TYPE_SHORT:
|
||||
case SCC_AST_BUILTIN_TYPE_SHORT:
|
||||
return "short";
|
||||
case TYPE_INT:
|
||||
case SCC_AST_BUILTIN_TYPE_INT:
|
||||
return "int";
|
||||
case TYPE_LONG:
|
||||
case SCC_AST_BUILTIN_TYPE_LONG:
|
||||
return "long";
|
||||
case TYPE_LONG_LONG:
|
||||
case SCC_AST_BUILTIN_TYPE_LONG_LONG:
|
||||
return "long long";
|
||||
case TYPE_FLOAT:
|
||||
case SCC_AST_BUILTIN_TYPE_FLOAT:
|
||||
return "float";
|
||||
case TYPE_DOUBLE:
|
||||
case SCC_AST_BUILTIN_TYPE_DOUBLE:
|
||||
return "double";
|
||||
case TYPE_LONG_DOUBLE:
|
||||
case SCC_AST_BUILTIN_TYPE_LONG_DOUBLE:
|
||||
return "long double";
|
||||
case TYPE_BOOL:
|
||||
case SCC_AST_BUILTIN_TYPE_BOOL:
|
||||
return "_Bool";
|
||||
case TYPE_COMPLEX_FLOAT:
|
||||
case SCC_AST_BUILTIN_TYPE_COMPLEX_FLOAT:
|
||||
return "float _Complex";
|
||||
case TYPE_COMPLEX_DOUBLE:
|
||||
case SCC_AST_BUILTIN_TYPE_COMPLEX_DOUBLE:
|
||||
return "double _Complex";
|
||||
case TYPE_COMPLEX_LONG_DOUBLE:
|
||||
case SCC_AST_BUILTIN_TYPE_COMPLEX_LONG_DOUBLE:
|
||||
return "long double _Complex";
|
||||
default:
|
||||
return "<unknown>";
|
||||
@@ -259,7 +259,9 @@ static inline void start_node_dump(scc_ast_node_t *node,
|
||||
}
|
||||
|
||||
// 通用的结束节点打印函数
|
||||
static inline void end_node_dump(scc_tree_dump_ctx_t *ctx) { scc_printf("\n"); }
|
||||
static inline void end_node_dump(scc_tree_dump_ctx_t *ctx) {
|
||||
scc_tree_dump_printf(ctx, "\n");
|
||||
}
|
||||
|
||||
// 通用的递归转储辅助函数
|
||||
static inline void dump_child_node(scc_ast_node_t *child,
|
||||
@@ -276,10 +278,11 @@ static inline void dump_child_node(scc_ast_node_t *child,
|
||||
#define BUILD_TYPE_NAME(ctx, prefix, name) \
|
||||
do { \
|
||||
if (ctx->use_color) { \
|
||||
scc_printf("%s'%s%s%s'%s", ctx->value_color, prefix, name, \
|
||||
ctx->reset_color, ctx->reset_color); \
|
||||
scc_tree_dump_printf(ctx, "%s'%s%s%s'%s", ctx->value_color, \
|
||||
prefix, name, ctx->reset_color, \
|
||||
ctx->reset_color); \
|
||||
} else { \
|
||||
scc_printf("'%s%s'", prefix, name); \
|
||||
scc_tree_dump_printf(ctx, "'%s%s'", prefix, name); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -293,18 +296,18 @@ static void dump_type_impl(scc_ast_type_t *type, scc_tree_dump_ctx_t *ctx) {
|
||||
// 根据类型输出特定信息
|
||||
switch (type->base.type) {
|
||||
case SCC_AST_TYPE_BUILTIN:
|
||||
PRINT_QUOTED_VALUE(ctx, get_builtin_type_str(type->builtin.builtin));
|
||||
PRINT_QUOTED_VALUE(ctx, get_builtin_type_str(type->builtin.type));
|
||||
break;
|
||||
case SCC_AST_TYPE_POINTER:
|
||||
if (type->pointer.pointee &&
|
||||
type->pointer.pointee->base.type == SCC_AST_TYPE_BUILTIN) {
|
||||
const char *base_type =
|
||||
get_builtin_type_str(type->pointer.pointee->builtin.builtin);
|
||||
get_builtin_type_str(type->pointer.pointee->builtin.type);
|
||||
if (ctx->use_color) {
|
||||
scc_printf("%s'%s *'%s", ctx->value_color, base_type,
|
||||
ctx->reset_color);
|
||||
scc_tree_dump_printf(ctx, "%s'%s *'%s", ctx->value_color,
|
||||
base_type, ctx->reset_color);
|
||||
} else {
|
||||
scc_printf("'%s *'", base_type);
|
||||
scc_tree_dump_printf(ctx, "'%s *'", base_type);
|
||||
}
|
||||
} else {
|
||||
PRINT_QUOTED_VALUE(ctx, "pointer");
|
||||
@@ -315,7 +318,7 @@ static void dump_type_impl(scc_ast_type_t *type, scc_tree_dump_ctx_t *ctx) {
|
||||
break;
|
||||
case SCC_AST_TYPE_FUNCTION:
|
||||
PRINT_QUOTED_VALUE(ctx, "function");
|
||||
scc_printf("\n");
|
||||
scc_tree_dump_printf(ctx, "\n");
|
||||
if (type->function.return_type) {
|
||||
dump_type_impl(type->function.return_type, ctx);
|
||||
}
|
||||
@@ -451,7 +454,7 @@ static void dump_expr_impl(scc_ast_expr_t *expr, scc_tree_dump_ctx_t *ctx) {
|
||||
// 打印成员访问信息
|
||||
scc_tree_print_indent(ctx);
|
||||
PRINT_NODE(ctx, "Member [\"%s\"]", expr->member.member_name);
|
||||
scc_printf("\n");
|
||||
scc_tree_dump_printf(ctx, "\n");
|
||||
break;
|
||||
|
||||
case SCC_AST_EXPR_CAST:
|
||||
|
||||
0
libs/ast/src/scc_ast.c
Normal file
0
libs/ast/src/scc_ast.c
Normal file
Reference in New Issue
Block a user