feat: 添加预处理器宏定义的字符串化和连接操作支持
- 实现了 # 和 ## 预处理器操作符的功能 - 添加了 token 深拷贝和移动函数以支持宏展开 - 修改预处理器展开逻辑以正确处理宏参数替换 - 增加了宏参数分割时对空白字符的处理 fix: 修复预处理器宏展开中的内存管理和逻辑错误 - 修正了宏展开集合的数据结构初始化方式 - 修复了函数式宏调用时括号匹配的判断逻辑 - 改进了宏参数解析过程中空白字符的处理 - 解决了 token 在宏展开过程中的所有权管理问题 chore: 为 justfile 添加文件统计命令并优化构建配置 - 新增 count-file 命令用于统计代码文件数量 - 调整了输出文件的默认命名规则 - 优化了词法分析器 token 释放时的字段重置逻辑
This commit is contained in:
@@ -187,6 +187,11 @@ scc_tok_subtype_t scc_get_tok_subtype(scc_tok_type_t type);
|
||||
const char *scc_get_tok_name(scc_tok_type_t type);
|
||||
|
||||
static inline void scc_lexer_tok_drop(scc_lexer_tok_t *tok) {
|
||||
tok->type = SCC_TOK_UNKNOWN;
|
||||
tok->loc.col = 0;
|
||||
tok->loc.line = 0;
|
||||
tok->loc.name = null;
|
||||
tok->loc.offset = 0;
|
||||
scc_cstring_free(&tok->lexeme);
|
||||
}
|
||||
|
||||
@@ -195,4 +200,20 @@ static inline cbool scc_lexer_tok_match(const scc_lexer_tok_t *tok,
|
||||
return tok->type == type;
|
||||
}
|
||||
|
||||
// 深拷贝 token
|
||||
static inline scc_lexer_tok_t scc_lexer_tok_copy(const scc_lexer_tok_t *src) {
|
||||
scc_lexer_tok_t dst = *src;
|
||||
dst.lexeme = scc_cstring_copy(&src->lexeme);
|
||||
return dst;
|
||||
}
|
||||
|
||||
// 移动 token(源 token 不再拥有 lexeme)
|
||||
static inline void scc_lexer_tok_move(scc_lexer_tok_t *dst,
|
||||
scc_lexer_tok_t *src) {
|
||||
*dst = *src;
|
||||
src->lexeme.data = null;
|
||||
src->lexeme.size = 0;
|
||||
src->lexeme.cap = 0;
|
||||
}
|
||||
|
||||
#endif /* __SCC_LEXER_TOKEN_H__ */
|
||||
|
||||
Reference in New Issue
Block a user