stage1 重构词法分析
This commit is contained in:
@@ -4,32 +4,51 @@
|
||||
#include "spl_ast.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_def_id_t) symbols;
|
||||
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_ast_t *ast;
|
||||
spl_type_t type;
|
||||
spl_scope_node_vec_t scopes;
|
||||
spl_scope_id_t root_scope;
|
||||
spl_scope_id_t current_scope;
|
||||
spl_def_id_t root_def;
|
||||
} 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);
|
||||
typedef VEC(const char *) spl_symbol_path_t;
|
||||
bool spl_scope_find(spl_scope_t *scop, const char *symbol_name, spl_symbol_t *out);
|
||||
|
||||
typedef struct {
|
||||
spl_ast_t *ast;
|
||||
spl_type_t *type;
|
||||
spl_scope_t *scope;
|
||||
spl_symbol_t root;
|
||||
int error_count;
|
||||
} spl_sema_t;
|
||||
|
||||
void spl_sema_init(spl_sema_t *sema);
|
||||
void spl_sema_init(spl_sema_t *sema, spl_ast_t *ast, spl_type_t *type, spl_scope_t *scope);
|
||||
void spl_sema_drop(spl_sema_t *sema);
|
||||
void spl_sema_run(spl_sema_t *sema);
|
||||
void spl_sema_check(spl_sema_t *sema);
|
||||
|
||||
spl_scope_id_t spl_sema_scope_alloc(spl_sema_t *sema);
|
||||
bool spl_sema_scope_insert(spl_sema_t *sema, spl_scope_id_t id, const char *symbol_name,
|
||||
spl_def_id_t symbol_val);
|
||||
typedef VEC(const char *) spl_symbol_path_t;
|
||||
spl_def_id_t spl_sema_scope_find(spl_sema_t *sema, spl_symbol_path_t path);
|
||||
void spl_sema_run(spl_sema_t *sema);
|
||||
void spl_sema_dump(spl_sema_t *sema);
|
||||
|
||||
#endif /* __SPL_SEMA_H__ */
|
||||
|
||||
Reference in New Issue
Block a user