refactor(ast2ir): 重构ABI类型系统并修复union结构问题
- 将scc_ast_def.h中的attr_of从union改为struct以修复结构定义问题 - 添加type_abi依赖到ast2ir模块的cbuild.toml配置文件中 - 重命名scc_ast2ir.h中的abi字段为type_abi,并更新相关初始化函数签名 - 移除废弃的scc_abi_type.h和相关平台ABI头文件 - 添加辅助函数is_variadic_marker和fixed_param_count用于处理可变参数 - 添加数组和聚合类型初始化的辅助函数
This commit is contained in:
@@ -21,10 +21,14 @@ typedef struct scc_lexer {
|
||||
scc_lexer_tok_ring_t ring;
|
||||
int ring_ref_count;
|
||||
int jump_macro;
|
||||
int max_token_len; /**< 最大 token 长度, 0=不限制 */
|
||||
} scc_lexer_t;
|
||||
|
||||
void scc_lexer_init(scc_lexer_t *lexer, scc_sstream_ring_t *stream_ref);
|
||||
|
||||
/** @brief 设置最大 token 长度限制, 超过时报错。0=不限制(默认) */
|
||||
void scc_lexer_set_max_token_len(scc_lexer_t *lexer, int max_len);
|
||||
|
||||
/**
|
||||
* @brief 获取原始token
|
||||
* @param[in] lexer 词法分析器实例
|
||||
|
||||
@@ -44,6 +44,11 @@ void scc_lexer_init(scc_lexer_t *lexer, scc_sstream_ring_t *stream_ref) {
|
||||
lexer->stream_ref = stream_ref;
|
||||
lexer->ring_ref_count = 0;
|
||||
lexer->jump_macro = false;
|
||||
lexer->max_token_len = 0; /* 0=不限制, 兼容旧行为 */
|
||||
}
|
||||
|
||||
void scc_lexer_set_max_token_len(scc_lexer_t *lexer, int max_len) {
|
||||
lexer->max_token_len = max_len;
|
||||
}
|
||||
|
||||
static inline cbool is_whitespace(int ch) {
|
||||
@@ -80,6 +85,11 @@ static inline cbool next_char(scc_lexer_t *lexer, scc_str_t *lexeme,
|
||||
scc_ring_next(*lexer->stream_ref, *out, ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
if (lexer->max_token_len > 0 &&
|
||||
scc_str_len(lexeme) >= (usize)lexer->max_token_len) {
|
||||
LOG_ERROR("token exceeds maximum length (%d)", lexer->max_token_len);
|
||||
return false;
|
||||
}
|
||||
scc_str_append_ch(lexeme, out->character);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user