stage1 大量重构
This commit is contained in:
1 parent
e4347cc3ea
commit
2a84b61e3d
18 files changed
+1831
-1354
No files matched your search
+13
-38
@@ -4,48 +4,23 @@
|
||||
#include "spl_ast.h"
|
||||
#include "spl_attr.h"
|
||||
#include "spl_diag.h"
|
||||
#include "spl_lang_type.h"
|
||||
#include "spl_mpa.h"
|
||||
#include "spl_scope.h"
|
||||
#include "spl_type.h"
|
||||
|
||||
typedef enum {
|
||||
SPL_SYMBOL_KIND_ERROR,
|
||||
SPL_SYMBOL_KIND_VAR,
|
||||
SPL_SYMBOL_KIND_MEMBER,
|
||||
SPL_SYMBOL_KIND_FN,
|
||||
SPL_SYMBOL_KIND_TYPE,
|
||||
} spl_symbol_kind_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
spl_symbol_kind_t kind;
|
||||
spl_def_id_t node;
|
||||
} spl_symbol_t;
|
||||
|
||||
typedef usize spl_scope_id_t; /* 0 is error */
|
||||
|
||||
typedef struct {
|
||||
spl_scope_id_t parent;
|
||||
MAP(const char *, spl_symbol_t) symbols;
|
||||
} spl_scope_node_t;
|
||||
typedef VEC(spl_scope_node_t) spl_scope_node_vec_t;
|
||||
|
||||
typedef struct {
|
||||
spl_scope_node_vec_t scopes;
|
||||
spl_scope_id_t root_scope;
|
||||
spl_scope_id_t current_scope;
|
||||
} spl_scope_t;
|
||||
|
||||
void spl_scope_init(spl_scope_t *scope);
|
||||
void spl_scope_drop(spl_scope_t *scope);
|
||||
spl_scope_id_t spl_scope_alloc(spl_scope_t *scope);
|
||||
bool spl_scope_insert(spl_scope_t *scope, spl_scope_id_t id, spl_symbol_t symbol);
|
||||
bool spl_scope_find(spl_scope_t *scop, const char *symbol_name, spl_symbol_t *out);
|
||||
|
||||
typedef VEC(const char *) spl_symbol_path_t;
|
||||
typedef struct spl_module_loader spl_module_loader_t;
|
||||
struct spl_module_loader {
|
||||
/* 从 from_fname 所在目录解析 path;返回该文件的 ast(已 init + parse)。
|
||||
失败(文件不存在 / parse 错误 / 环)返回 NULL。
|
||||
loader 拥有 ast 的生命周期;sema 不负责释放。 */
|
||||
spl_ast_t *(*load)(void *user, const char *from_fname, const char *path, spl_diag_t *diag);
|
||||
void *user;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
spl_ast_t *ast;
|
||||
spl_type_t *type;
|
||||
spl_lang_type_t *type;
|
||||
spl_scope_t *scope;
|
||||
spl_symbol_t root;
|
||||
spl_attr_t *attr;
|
||||
@@ -53,11 +28,11 @@ typedef struct {
|
||||
spl_lang_type_id_t current_fn_ret_tid;
|
||||
spl_lang_type_id_t current_loop_break_tid;
|
||||
spl_symbol_path_t label_stack;
|
||||
|
||||
const spl_module_loader_t *loader;
|
||||
spl_diag_t *diag;
|
||||
} spl_sema_t;
|
||||
|
||||
void spl_sema_init(spl_sema_t *sema, spl_ast_t *ast, spl_type_t *type, spl_scope_t *scope,
|
||||
void spl_sema_init(spl_sema_t *sema, spl_ast_t *ast, spl_lang_type_t *type, spl_scope_t *scope,
|
||||
spl_attr_t *attr);
|
||||
void spl_sema_drop(spl_sema_t *sema);
|
||||
|
||||
|
||||
Reference in new issue
Block a user