feat(ast): 重构AST节点类型定义并实现数组下标访问
- 将scc_ast_node_type_t重命名为scc_ast_node_kind_t以提高语义清晰度 - 为scc_ast_node结构体添加名称定义 - 更新所有相关头文件中的类型引用 - 实现数组下标表达式的IR转换逻辑 - 添加对sizeof和alignof表达式的基本支持 fix(ast2ir): 修复表达式求值和类型处理问题 - 修复数组类型退化为指针的逻辑 - 修复变量声明初始化值检查条件 - 添加结构体和枚举类型的IR生成支持 - 移除未使用的代码段 refactor(ir): 完善IR上下文错误处理 - 为未处理的类型标签添加恐慌处理 - 修复联合类型的哈希计算 chore(build): 更新依赖项配置 - 修正lexer模块中的依赖项名称 style(parser): 清理解析器代码 - 移除未使用的类型哈希表 - 更新语义分析回调函数签名 - 添加属性语法的占位符实现 - 完善内存清理逻辑 test: 添加数组下标和枚举测试用例 - 新增15_array_subscript.c测试数组下标访问 - 新增16_enum.c测试枚举类型功能 - 更新期望结果配置文件
This commit is contained in:
@@ -14,8 +14,6 @@ typedef struct scc_parser {
|
||||
scc_lexer_tok_ring_t *ring;
|
||||
usize checkpoint;
|
||||
|
||||
scc_hashtable_t type_ht;
|
||||
|
||||
scc_sema_callbacks_t sema_callbacks;
|
||||
scc_ast_translation_unit_t *translation_unit;
|
||||
int errcode;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @brief 语义分析回调函数类型
|
||||
*/
|
||||
typedef void (*scc_sema_callback_t)(void *context,
|
||||
scc_ast_node_type_t node_type, void *node);
|
||||
scc_ast_node_kind_t node_type, void *node);
|
||||
|
||||
typedef scc_ast_type_t *(*scc_sema_got_type_t)(void *context, const char *name);
|
||||
|
||||
|
||||
32
libs/parser/src/parse_attr.c
Normal file
32
libs/parser/src/parse_attr.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
ISO/IEC 9899:2024 (en) — N3220 working draft
|
||||
|
||||
(6.7.13.2) attribute-specifier-sequence:
|
||||
attribute-specifier-sequence(opt) attribute-specifier
|
||||
(6.7.13.2) attribute-specifier:
|
||||
[ [ attribute-list ] ]
|
||||
(6.7.13.2) attribute-list:
|
||||
attribute(opt)
|
||||
attribute-list , attribute(opt)
|
||||
(6.7.13.2) attribute:
|
||||
attribute-token attribute-argument-clause(opt)
|
||||
(6.7.13.2) attribute-token:
|
||||
standard-attribute
|
||||
attribute-prefixed-token
|
||||
(6.7.13.2) standard-attribute:
|
||||
identifier
|
||||
(6.7.13.2) attribute-prefixed-token:
|
||||
attribute-prefix :: identifier
|
||||
(6.7.13.2) attribute-prefix:
|
||||
identifier
|
||||
(6.7.13.2) attribute-argument-clause:
|
||||
( balanced-token-sequence(opt) )
|
||||
(6.7.13.2) balanced-token-sequence:
|
||||
balanced-token
|
||||
balanced-token-sequence balanced-token
|
||||
(6.7.13.2) balanced-token:
|
||||
( balanced-token-sequence(opt) )
|
||||
[ balanced-token-sequence(opt) ]
|
||||
{ balanced-token-sequence(opt) }
|
||||
any token other than a parenthesis, a bracket, or a brace
|
||||
*/
|
||||
@@ -537,7 +537,7 @@ static scc_ast_type_t *build_type_from_info(type_spec_info_t *info,
|
||||
return type;
|
||||
}
|
||||
static scc_ast_type_t *parse_record_type(scc_parser_t *parser,
|
||||
scc_ast_node_type_t type_kind) {
|
||||
scc_ast_node_kind_t type_kind) {
|
||||
/*
|
||||
(6.7.2.1)
|
||||
struct-or-union-specifier:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <parser_utils.h>
|
||||
#include <scc_parser.h>
|
||||
|
||||
static void dummy_sema_callback(void *context, scc_ast_node_type_t node_type,
|
||||
static void dummy_sema_callback(void *context, scc_ast_node_kind_t node_type,
|
||||
void *node) {
|
||||
(void)context;
|
||||
(void)node_type;
|
||||
@@ -49,6 +49,8 @@ void scc_parser_init(scc_parser_t *parser, scc_lexer_tok_ring_t *tok_ring,
|
||||
|
||||
void scc_parser_drop(scc_parser_t *parser) {
|
||||
// TODO: 释放 AST 内存
|
||||
scc_ring_free(*parser->ring);
|
||||
scc_sema_drop(&parser->sema_callbacks);
|
||||
}
|
||||
|
||||
scc_ast_translation_unit_t *scc_parse_translation_unit(scc_parser_t *parser) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <scc_sema.h>
|
||||
#include <sema_symtab.h>
|
||||
|
||||
static void type_callback(void *context, scc_ast_node_type_t node_type,
|
||||
static void type_callback(void *context, scc_ast_node_kind_t node_type,
|
||||
void *node) {
|
||||
scc_sema_symtab_t *sema_symtab = context;
|
||||
(void)context;
|
||||
@@ -11,7 +11,7 @@ static void type_callback(void *context, scc_ast_node_type_t node_type,
|
||||
return;
|
||||
}
|
||||
|
||||
static void expr_callback(void *context, scc_ast_node_type_t node_type,
|
||||
static void expr_callback(void *context, scc_ast_node_kind_t node_type,
|
||||
void *node) {
|
||||
scc_sema_symtab_t *sema_symtab = context;
|
||||
|
||||
@@ -37,7 +37,7 @@ static void expr_callback(void *context, scc_ast_node_type_t node_type,
|
||||
return;
|
||||
}
|
||||
|
||||
static void stmt_callback(void *context, scc_ast_node_type_t node_type,
|
||||
static void stmt_callback(void *context, scc_ast_node_kind_t node_type,
|
||||
void *node) {
|
||||
scc_sema_symtab_t *sema_symtab = context;
|
||||
|
||||
@@ -54,7 +54,7 @@ static void stmt_callback(void *context, scc_ast_node_type_t node_type,
|
||||
return;
|
||||
}
|
||||
|
||||
static void decl_callback(void *context, scc_ast_node_type_t node_type,
|
||||
static void decl_callback(void *context, scc_ast_node_kind_t node_type,
|
||||
void *node) {
|
||||
scc_sema_symtab_t *sema_symtab = context;
|
||||
|
||||
@@ -196,4 +196,7 @@ void scc_sema_init(scc_sema_callbacks_t *callbacks) {
|
||||
&builin_func->base);
|
||||
}
|
||||
|
||||
void scc_sema_drop(scc_sema_callbacks_t *callbacks) {}
|
||||
void scc_sema_drop(scc_sema_callbacks_t *callbacks) {
|
||||
// FIXME drop obj
|
||||
scc_sema_symtab_drop(callbacks->context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user