refactor(ast): 调整AST结构体和枚举类型的声明表示方式
将结构体、联合和枚举类型的字段表示从向量改为声明指针, 允许name和decl字段为null,更新相关初始化函数的断言检查, 使结构更加灵活并支持不完整类型定义。 BREAKING CHANGE: 修改了scc_ast_type结构体中record和enumeration 子类型的字段表示方法,从fields向量改为decl指针。
This commit is contained in:
@@ -155,25 +155,6 @@ A.2.4 External definitions
|
||||
#include <scc_parser.h>
|
||||
|
||||
scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
|
||||
/**
|
||||
* ISO/IEC 9899:TC3
|
||||
* 6.7 Declarations
|
||||
* Syntax
|
||||
*
|
||||
* declaration:
|
||||
* declaration-specifiers init-declarator-list(opt) ;
|
||||
* declaration-specifiers:
|
||||
* storage-class-specifier declaration-specifiers(opt)
|
||||
* type-specifier declaration-specifiers(opt)
|
||||
* type-qualifier declaration-specifiers(opt)
|
||||
* function-specifier declaration-specifiers(opt)
|
||||
* init-declarator-list:
|
||||
* init-declarator
|
||||
* init-declarator-list , init-declarator
|
||||
* init-declarator:
|
||||
* declarator
|
||||
* declarator = initializer
|
||||
*/
|
||||
cbool ok;
|
||||
scc_lexer_tok_t tok;
|
||||
|
||||
@@ -184,8 +165,20 @@ scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
|
||||
}
|
||||
|
||||
if (SCC_AST_IS_A(scc_ast_type_t, type_or_decl)) {
|
||||
LOG_WARN("declaration dose not declare anything");
|
||||
return null;
|
||||
scc_ast_type_t *type = SCC_AST_CAST_TO(scc_ast_type_t, type_or_decl);
|
||||
if (type->base.type == SCC_AST_TYPE_STRUCT ||
|
||||
type->base.type == SCC_AST_TYPE_UNION) {
|
||||
Assert(type->record.decl != null);
|
||||
decl = type->record.decl;
|
||||
scc_free(type_or_decl); // FIXME
|
||||
} else if (type->base.type == SCC_AST_TYPE_ENUM) {
|
||||
Assert(type->enumeration.decl != null);
|
||||
decl = type->enumeration.decl;
|
||||
scc_free(type_or_decl); // FIXME
|
||||
} else {
|
||||
LOG_WARN("declaration dose not declare anything");
|
||||
return null;
|
||||
}
|
||||
} else if (SCC_AST_IS_A(scc_ast_decl_t, type_or_decl)) {
|
||||
decl = SCC_AST_CAST_TO(scc_ast_decl_t, type_or_decl);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user