- 添加 scc_parse_assignment_expression 函数用于解析赋值表达式 - 添加 scc_parser_constant_expression 函数用于解析常量表达式 - 修改 cast 表达式解析逻辑,修复类型转换解析问题 - 改进错误处理机制,使用 SCC_ERROR 替代 LOG_ERROR 并提供准确位置信息 - 移除未使用的变量声明,优化代码结构 refactor(ast): 调整类型定义中的 typedef 类型存储结构 - 将 scc_ast_type 中的 underlying 字段改为 decl 字段 - 更新相关初始化函数以适配新的字段名称 - 修复枚举类型初始化时缺失的 decl 字段设置 feat(ast): 添加类型转换、sizeof 和 alignof 表达式的初始化函数 - 实现 scc_ast_expr_cast_init 用于初始化类型转换表达式 - 实现 scc_ast_expr_sizeof_init 用于初始化 sizeof 表达式 - 实现 scc_ast_expr_alignof_init 用于初始化 alignof 表达式 - 完善表达式类型的支持 chore(parser): 增加语义分析回调接口和位置获取工具函数 - 添加 scc_parse_decl_sema、scc_parse_type_sema 等语义分析辅助函数 - 提供 scc_parser_got_current_pos 函数获取当前解析位置 - 增强错误报告的准确性 refactor(dump): 完善 AST 转储功能,支持 break 和 continue 语句 - 为 SCC_AST_STMT_BREAK 和 SCC_AST_STMT_CONTINUE 添加转储支持 - 优化转储函数的分支处理结构
84 lines
2.2 KiB
C
84 lines
2.2 KiB
C
#ifndef __SCC_PARSER_UTILS_H__
|
|
#define __SCC_PARSER_UTILS_H__
|
|
|
|
#include "scc_parser.h"
|
|
|
|
static inline const scc_lexer_tok_t *scc_parser_peek(scc_parser_t *parser) {
|
|
cbool ok = false;
|
|
const scc_lexer_tok_t *tok = null;
|
|
scc_ring_unsafe_peek_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return null;
|
|
}
|
|
return tok;
|
|
}
|
|
|
|
static inline const scc_lexer_tok_t *scc_parser_next(scc_parser_t *parser) {
|
|
cbool ok = false;
|
|
const scc_lexer_tok_t *tok = null;
|
|
scc_ring_unsafe_next_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return null;
|
|
}
|
|
return tok;
|
|
}
|
|
|
|
static inline cbool scc_parser_consume_if(scc_parser_t *parser,
|
|
scc_tok_type_t type) {
|
|
cbool ok = false;
|
|
scc_lexer_tok_t *tok = null;
|
|
scc_ring_unsafe_peek_ref(*parser->ring, tok, ok);
|
|
if (ok == false) {
|
|
return null;
|
|
}
|
|
if (tok->type == type) {
|
|
scc_lexer_tok_drop(tok);
|
|
scc_ring_unsafe_pure_next_consume(*parser->ring);
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static inline void scc_parser_store(scc_parser_t *parser) {
|
|
parser->checkpoint = _scc_ring_probe(*parser->ring);
|
|
}
|
|
|
|
static inline void scc_parser_restore(scc_parser_t *parser) {
|
|
_scc_ring_probe(*parser->ring) = parser->checkpoint;
|
|
}
|
|
|
|
// tok can null it will be safty free
|
|
static inline cbool scc_parser_next_consume(scc_parser_t *parser,
|
|
scc_lexer_tok_t *tok) {
|
|
cbool ok = false;
|
|
scc_lexer_tok_t *raw_tok_ref = null;
|
|
scc_ring_unsafe_next_ref_consume(*parser->ring, raw_tok_ref, ok);
|
|
if (tok == null) {
|
|
scc_lexer_tok_drop(raw_tok_ref);
|
|
} else {
|
|
scc_lexer_tok_move(tok, raw_tok_ref);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
static inline void scc_parser_commit(scc_parser_t *parser) {
|
|
// Memory leak
|
|
scc_ring_consume(*parser->ring);
|
|
}
|
|
|
|
static inline void scc_parser_reset(scc_parser_t *parser) {
|
|
scc_ring_reset(*parser->ring);
|
|
}
|
|
|
|
#include <scc_pos_log.h>
|
|
static inline scc_pos_t scc_parser_got_current_pos(scc_parser_t *parser) {
|
|
const scc_lexer_tok_t *tok = scc_parser_peek(parser);
|
|
scc_pos_t pos = scc_pos_create();
|
|
if (tok != null)
|
|
pos = tok->loc;
|
|
return pos;
|
|
}
|
|
|
|
#endif /* __SCC_PARSER_UTILS_H__ */
|