- 将头文件中的tree_dump.h替换为scc_tree_dump.h - 修改函数签名将scc_tree_dump_ctx_t改为scc_tree_dump_t - 移除过时的宏定义和内联函数实现 - 使用新的scc_tree_dump_* API替代旧的PRINT_*宏 - 简化类型、表达式、语句和声明的转储逻辑 - 统一使用新的树转储接口进行节点和值的输出 feat(ast2ir): 实现逻辑运算符和一元运算符的IR转换 - 添加scc_ast2ir_logical_expr函数处理&&和||运算符 - 实现短路求值逻辑,包含分支控制流 - 添加对一元正号运算符的支持 - 实现取地址和间接寻址运算符 - 添加字符字面量解析支持转义序列 fix(ir): 修复字符串常量构建中的长度计算错误 - 修正数组长度计算从len+1改为len-1 - 调整字符串内容复制逻辑跳过引号边界 - 修正内存分配大小与实际数据长度匹配 refactor(ir): 更新IR转储模块使用统一的树转储接口 - 将IR转储上下文中的tree_dump_ctx_t替换为scc_tree_dump_t - 更新初始化函数签名以使用新的转储接口类型
55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
#ifndef __SCC_LEXER_UTILS_H__
|
|
#define __SCC_LEXER_UTILS_H__
|
|
|
|
#include "scc_lexer.h"
|
|
|
|
static inline void scc_lexer_gen_number_true(scc_lexer_tok_t *tok) {
|
|
Assert(tok != null && tok->type == SCC_TOK_UNKNOWN);
|
|
tok->type = SCC_TOK_INT_LITERAL;
|
|
tok->lexeme = scc_str_from_cstr("1");
|
|
}
|
|
|
|
static inline void scc_lexer_gen_number_false(scc_lexer_tok_t *tok) {
|
|
Assert(tok != null && tok->type == SCC_TOK_UNKNOWN);
|
|
tok->type = SCC_TOK_INT_LITERAL;
|
|
tok->lexeme = scc_str_from_cstr("0");
|
|
}
|
|
|
|
static inline cbool scc_lexer_peek_non_blank(scc_lexer_tok_ring_t *stream,
|
|
scc_lexer_tok_t *out) {
|
|
cbool ok;
|
|
while (1) {
|
|
scc_ring_peek(*stream, *out, ok);
|
|
if (!ok || out->type != SCC_TOK_BLANK)
|
|
break;
|
|
scc_ring_next_consume(*stream, *out, ok);
|
|
scc_lexer_tok_drop(out);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
static inline cbool scc_lexer_next_non_blank(scc_lexer_tok_ring_t *stream,
|
|
scc_lexer_tok_t *out) {
|
|
cbool ok;
|
|
if (!scc_lexer_peek_non_blank(stream, out))
|
|
return false;
|
|
scc_ring_next_consume(*stream, *out, ok);
|
|
return true;
|
|
}
|
|
|
|
static inline void scc_lexer_skip_until_newline(scc_lexer_tok_ring_t *stream) {
|
|
scc_lexer_tok_t tok;
|
|
cbool ok;
|
|
while (1) {
|
|
scc_ring_next_consume(*stream, tok, ok);
|
|
if (!ok)
|
|
break;
|
|
scc_tok_type_t type = tok.type;
|
|
scc_lexer_tok_drop(&tok);
|
|
if (type == SCC_TOK_ENDLINE)
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endif /* __SCC_LEXER_UTILS_H__ */
|