refactor(ast): 统一记录类型结构并移除成员访问操作符
- 移除了枚举类型的独立结构定义,统一使用record结构 - 移除了成员访问操作符SCC_AST_OP_MEMBER_ACCESS和SCC_AST_OP_PTR_MEMBER_ACCESS - 更新了for循环语句中init字段的类型从scc_ast_type_t*到scc_ast_node_t* - 修改了声明初始化函数以支持统一的记录类型处理 fix(ast2ir): 完善二元表达式处理和for循环代码生成 - 重构了赋值操作符的处理逻辑,通过临时表达式实现复合赋值 - 添加了对for循环语句的完整IR代码生成功能 - 修复了if-else语句中错误的基本块跳转问题 - 改进了标识符未找到时的错误提示信息 chore: 清理代码和修复潜在问题 - 移除了未使用的自动标签生成功能 - 统一了IR基本块标签格式化输出 - 修复了机器码生成中的寄存器存储控制流问题 - 改进了词法分析器中十六进制数字的处理逻辑
This commit is contained in:
@@ -10,6 +10,10 @@ typedef enum {
|
||||
SCC_PP_MACRO_NONE, // 不是宏
|
||||
SCC_PP_MACRO_OBJECT, // 对象宏
|
||||
SCC_PP_MACRO_FUNCTION, // 函数宏
|
||||
SCC_PP_MACRO_BUILTIN__FILE__,
|
||||
SCC_PP_MACRO_BUILTIN__LINE__,
|
||||
SCC_PP_MACRO_BUILTIN__DATE__, // TODO
|
||||
SCC_PP_MACRO_BUILTIN__TIME__, // TODO
|
||||
} scc_pproc_macro_type_t;
|
||||
|
||||
typedef SCC_VEC(scc_lexer_tok_vec_t) scc_pproc_macro_extened_params_t;
|
||||
|
||||
@@ -658,10 +658,14 @@ void scc_pproc_expand_macro(scc_pproc_expand_t *expand_ctx) {
|
||||
expand_ctx->need_rescan = true;
|
||||
|
||||
expand_ctx->call_pos = tok.loc;
|
||||
if (macro->type == SCC_PP_MACRO_OBJECT) {
|
||||
|
||||
switch (macro->type) {
|
||||
case SCC_PP_MACRO_OBJECT: {
|
||||
scc_lexer_tok_drop(&tok);
|
||||
expand_object_macro(expand_ctx, macro);
|
||||
} else if (macro->type == SCC_PP_MACRO_FUNCTION) {
|
||||
break;
|
||||
}
|
||||
case SCC_PP_MACRO_FUNCTION: {
|
||||
scc_lexer_tok_t expect_tok;
|
||||
scc_ring_peek(*expand_ctx->input, expect_tok, ok);
|
||||
if (ok == false || expect_tok.type != SCC_TOK_L_PAREN) {
|
||||
@@ -671,8 +675,30 @@ void scc_pproc_expand_macro(scc_pproc_expand_t *expand_ctx) {
|
||||
|
||||
scc_lexer_tok_drop(&tok);
|
||||
expand_function_macro(expand_ctx, macro);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
// FIXME 这可能不符合c语义
|
||||
case SCC_PP_MACRO_BUILTIN__FILE__:
|
||||
scc_cstring_free(&tok.lexeme);
|
||||
scc_cstring_append_ch(&tok.lexeme, '"');
|
||||
scc_cstring_append_cstr(&tok.lexeme, tok.loc.name,
|
||||
scc_strlen(tok.loc.name));
|
||||
scc_cstring_append_ch(&tok.lexeme, '"');
|
||||
tok.type = SCC_TOK_STRING_LITERAL;
|
||||
scc_vec_push(expand_ctx->output, tok);
|
||||
break;
|
||||
case SCC_PP_MACRO_BUILTIN__LINE__:
|
||||
scc_cstring_free(&tok.lexeme);
|
||||
char *buff = scc_malloc(32);
|
||||
scc_snprintf(buff, 32, "%zu", tok.loc.line);
|
||||
tok.lexeme = scc_cstring_from_cstr(buff);
|
||||
scc_free(buff);
|
||||
tok.type = SCC_TOK_INT_LITERAL;
|
||||
scc_vec_push(expand_ctx->output, tok);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,23 @@ CONTINUE:
|
||||
goto CONTINUE;
|
||||
}
|
||||
|
||||
void scc_pproc_add_builtin_macros(scc_pproc_macro_table_t *macro_table) {
|
||||
struct {
|
||||
const char *name;
|
||||
scc_pproc_macro_type_t type;
|
||||
} builin_table[] = {
|
||||
{"__FILE__", SCC_PP_MACRO_BUILTIN__FILE__},
|
||||
{"__LINE__", SCC_PP_MACRO_BUILTIN__LINE__},
|
||||
};
|
||||
for (usize i = 0; i < SCC_ARRLEN(builin_table); i += 1) {
|
||||
scc_cstring_t builtin_name =
|
||||
scc_cstring_from_cstr(builin_table[i].name);
|
||||
scc_pproc_macro_t *builtin =
|
||||
scc_pproc_macro_new(&builtin_name, builin_table[i].type);
|
||||
scc_pproc_macro_table_set(macro_table, builtin);
|
||||
}
|
||||
}
|
||||
|
||||
void scc_pproc_init(scc_pproc_t *pp, scc_lexer_tok_ring_t *input) {
|
||||
Assert(pp != null && input != null);
|
||||
pp->org_ring = input;
|
||||
@@ -115,10 +132,7 @@ void scc_pproc_init(scc_pproc_t *pp, scc_lexer_tok_ring_t *input) {
|
||||
|
||||
pp->config.max_include_depth = 32;
|
||||
pp->config.keep_original_pos = true;
|
||||
}
|
||||
|
||||
void scc_pproc_add_builtin_macros() {
|
||||
// TODO
|
||||
scc_pproc_add_builtin_macros(&pp->macro_table);
|
||||
}
|
||||
|
||||
static cbool fill_token(scc_lexer_tok_t *tok, void *userdata) {
|
||||
|
||||
Reference in New Issue
Block a user