- 添加 va_list、bool、signed/unsigned 各种整数类型等内置类型 - 重新排列内置类型枚举顺序,增加 UNKNOWN 类型 - 为复合字面量、指针类型、数组类型添加初始化函数 - 添加结构体、联合体、枚举、typedef 类型的初始化函数 - 更新类型转储功能以支持新的内置类型显示 refactor(parser): 优化类型解析和声明处理逻辑 - 修改类型解析函数返回类型为通用 AST 节点 - 重构声明解析逻辑,支持变量和函数声明的不同处理路径 - 更新语法分析规则中的空格标记处理 - 简化表达式解析中的错误处理流程 fix(ast): 修复参数声明和类型转储相关问题 - 修正参数声明初始化函数中对 name 参数可为空的处理 - 修复类型转储中修饰符显示和指针类型显示问题 - 更新 AST 转储中空值检查使用正确的 null 比较
75 lines
2.0 KiB
C
75 lines
2.0 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);
|
|
}
|
|
|
|
#endif /* __SCC_PARSER_UTILS_H__ */
|