重构AST表达式枚举,将COMPOUND_LITERAL重命名为COMPOUND, 更新相关结构体定义以支持复合字面量的左右表达式向量表示。 添加lvalue表达式类型用于左值处理,实现完整的初始化器解析功能, 包括大括号初始化列表、成员访问和数组下标的处理逻辑。 更新表达式解析器为基于优先级的递归下降解析,修复变量声明中 初始化表达式的内存泄漏问题。 完善类型限定符和存储类说明符的重复检查机制,增强语法分析的准确性。
42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
#include <assert.h>
|
|
#include <scc_pproc.h>
|
|
#include <string.h>
|
|
#include <utest/acutest.h>
|
|
|
|
static void test_define_pos(void) {
|
|
int ret = 0;
|
|
scc_sstream_t mem_stream;
|
|
const char *input = "#define OBJ 1\nOBJ";
|
|
ret = scc_sstream_init_by_buffer(&mem_stream, input, strlen(input), false,
|
|
16);
|
|
Assert(ret == 0);
|
|
|
|
scc_lexer_t lexer;
|
|
scc_lexer_init(&lexer, scc_sstream_to_ring(&mem_stream));
|
|
|
|
scc_pproc_t pp;
|
|
scc_pproc_init(&pp, scc_lexer_to_ring(&lexer, 8, true));
|
|
|
|
scc_lexer_tok_ring_t *tok_ring = scc_pproc_to_ring(&pp, 8, true, true);
|
|
scc_lexer_tok_t tok = {0};
|
|
|
|
scc_ring_next_consume(*tok_ring, tok, ret);
|
|
Assert(ret == true);
|
|
TEST_CHECK(tok.loc.line == 2 && tok.loc.col == 1 &&
|
|
scc_strcmp(tok.lexeme.data, "1") == 0);
|
|
TEST_MSG("Expected: %d:%d:%s", 2, 1, "1");
|
|
TEST_MSG("Produced: %zu:%zu:%s", tok.loc.line, tok.loc.col,
|
|
tok.lexeme.data);
|
|
|
|
scc_ring_free(*tok_ring);
|
|
scc_pproc_drop(&pp);
|
|
scc_lexer_drop(&lexer);
|
|
scc_sstream_drop(&mem_stream);
|
|
}
|
|
|
|
#define TEST_LIST_CASE(func_name) {#func_name, func_name}
|
|
TEST_LIST = {
|
|
TEST_LIST_CASE(test_define_pos),
|
|
{NULL, NULL},
|
|
};
|