stage1 人工重构ast以及type部分 修复vm的UB行为
This commit is contained in:
@@ -1,18 +1,7 @@
|
||||
// WRITE BY AI
|
||||
/* spl_ast.c SPL AST 模块:LL(1) 递归下降解析 + valid/dump/drop
|
||||
*
|
||||
* 设计:节点 kind 是唯一身份(扁平化)。无 `SPL_AST_EXPR`/`SPL_AST_BLOCK_ITEM`
|
||||
* 等外壳类别--每个表达式/语句/类型节点直接用具体 kind。
|
||||
* 子节点以 spl_ast_node_ref 引用(ref 0 = 空),union 数据由 kind 决定解释。
|
||||
*/
|
||||
|
||||
#include "spl_ast.h"
|
||||
#include "spl_dbg.h"
|
||||
#include "spl_dumptree.h"
|
||||
#include "spl_tok.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *sdupn(const char *s, usize n) {
|
||||
char *r = malloc(n + 1);
|
||||
@@ -38,8 +27,8 @@ typedef struct {
|
||||
spl_ast_t *ast;
|
||||
usize pos;
|
||||
int failed;
|
||||
int stop_as; /* 0 时后缀表达式不KW_AS(for 头部序列专用) */
|
||||
int stop_agg; /* 0 IDENT '{' 不作结构体字面量(if/while/match 头部专用) */
|
||||
int stop_as; /* 0 时后缀表达式不KW_AS for 专用 */
|
||||
int stop_agg; /* 0 IDENT '{' 不作结构体字面量 if/while/match 时专用 */
|
||||
} parser_t;
|
||||
|
||||
static inline int is_trivia(spl_tok_type_t t) { return t == TOK_ENDLINE || t == TOK_LINE_COMMENT; }
|
||||
@@ -71,7 +60,7 @@ static spl_ast_node_ref_t new_node(parser_t *p, spl_ast_node_kind_t kind, const
|
||||
n.kind = kind;
|
||||
if (tok) {
|
||||
n.dbg.dbg_name = spl_ast_kind_name(kind);
|
||||
n.dbg.fpath = tok->fname;
|
||||
n.dbg.fname = tok->fname;
|
||||
n.dbg.line = (int)tok->line;
|
||||
n.dbg.col = (int)tok->col;
|
||||
}
|
||||
@@ -1852,7 +1841,7 @@ static void dump_node(spl_ast_t *ast, spl_ast_node_ref_t node_ref, dump_stack_t
|
||||
for (usize i = 0; i < vec_size(*stack); i++)
|
||||
printf("%s", vec_at(*stack, i) ? " " : "| ");
|
||||
printf("%s%s #%zu", last ? "`-" : "|-", spl_ast_kind_name(node->kind), node_ref);
|
||||
if (node->dbg.fpath)
|
||||
if (node->dbg.fname)
|
||||
printf(" (%d:%d)", node->dbg.line, node->dbg.col);
|
||||
printf("\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user