feat(ast): 修改函数调用表达式的结构定义
在AST定义中将函数调用表达式的name字段替换为callee字段, 以支持更复杂的函数调用场景。同时更新了相关的初始化函数、 转储函数和解析逻辑,使函数调用表达式能够正确处理callee节点。 BREAKING CHANGE: 函数调用表达式的结构发生了改变,从使用name字符串 改为使用callee表达式节点。
This commit is contained in:
@@ -145,7 +145,7 @@ A.2.4 External definitions
|
||||
function-definition
|
||||
declaration
|
||||
(6.9.1) function-definition:
|
||||
declaration-specifiers declarator declaration-listopt compound-statement
|
||||
declaration-specifiers declarator declaration-list(opt) compound-statement
|
||||
(6.9.1) declaration-list:
|
||||
declaration
|
||||
declaration-list declaration
|
||||
@@ -210,6 +210,9 @@ scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
|
||||
scc_ast_expr_t *init = scc_parse_expression(parser);
|
||||
scc_ast_decl_val_init(decl, type, scc_cstring_as_cstr(&tok.lexeme),
|
||||
init);
|
||||
if (!scc_parser_consume_if(parser, SCC_TOK_SEMICOLON)) {
|
||||
LOG_ERROR("expect semicolon");
|
||||
}
|
||||
goto RETURN;
|
||||
}
|
||||
// TODO
|
||||
@@ -250,7 +253,9 @@ scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
|
||||
Assert(decl->func.body->base.type == SCC_AST_STMT_COMPOUND);
|
||||
|
||||
RETURN:
|
||||
parser->sema_callbacks.on_decl(parser->sema_callbacks.context,
|
||||
decl->base.type, decl);
|
||||
if (decl) {
|
||||
parser->sema_callbacks.on_decl(parser->sema_callbacks.context,
|
||||
decl->base.type, decl);
|
||||
}
|
||||
return decl;
|
||||
}
|
||||
|
||||
@@ -760,7 +760,7 @@ static scc_ast_expr_t *parse_postfix_expression(scc_parser_t *parser) {
|
||||
scc_lexer_tok_drop(&lp);
|
||||
|
||||
scc_ast_expr_t *call = expr_create(parser, SCC_AST_EXPR_CALL);
|
||||
call->call._target = left;
|
||||
call->call.callee = left;
|
||||
scc_vec_init(call->call.args);
|
||||
|
||||
// 解析参数列表
|
||||
|
||||
@@ -249,16 +249,12 @@ static scc_ast_stmt_t *parse_for_statement(scc_parser_t *parser) {
|
||||
scc_ast_stmt_t *body = null;
|
||||
|
||||
// TODO use decl or expr
|
||||
init = (scc_ast_type_t *)scc_parse_expression(parser);
|
||||
init = (scc_ast_type_t *)scc_parse_declaration(parser);
|
||||
if (init == null) {
|
||||
init = (scc_ast_type_t *)scc_parse_declaration(parser);
|
||||
}
|
||||
if (init == null) {
|
||||
LOG_ERROR("Expected expression or declaration in for statement.");
|
||||
}
|
||||
|
||||
if (!scc_parser_consume_if(parser, SCC_TOK_SEMICOLON)) {
|
||||
LOG_ERROR("Expected semicolon in for statement.");
|
||||
init = (scc_ast_type_t *)scc_parse_expression(parser);
|
||||
if (!scc_parser_consume_if(parser, SCC_TOK_SEMICOLON)) {
|
||||
LOG_ERROR("Expected semicolon in for statement.");
|
||||
}
|
||||
}
|
||||
|
||||
cond = scc_parse_expression(parser);
|
||||
@@ -309,7 +305,9 @@ static scc_ast_stmt_t *parse_jump_statement(scc_parser_t *parser) {
|
||||
static scc_ast_stmt_t *parse_expression_statement(scc_parser_t *parser) {
|
||||
|
||||
if (scc_parser_consume_if(parser, SCC_TOK_SEMICOLON)) {
|
||||
return null;
|
||||
scc_ast_stmt_t *stmt = ast_stmt_alloc();
|
||||
scc_ast_stmt_expr_init(stmt, null);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
scc_ast_expr_t *expr = scc_parse_expression(parser);
|
||||
@@ -430,7 +428,9 @@ scc_ast_stmt_t *scc_parse_statement(scc_parser_t *parser) {
|
||||
stmt = parse_expression_statement(parser);
|
||||
RETURN:
|
||||
scc_parser_reset(parser);
|
||||
parser->sema_callbacks.on_stmt(parser->sema_callbacks.context,
|
||||
stmt->base.type, stmt);
|
||||
if (stmt) {
|
||||
parser->sema_callbacks.on_stmt(parser->sema_callbacks.context,
|
||||
stmt->base.type, stmt);
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user