stage1 人工重构ast.c
This commit is contained in:
437
stage1/spl_ast.h
437
stage1/spl_ast.h
@@ -2,31 +2,133 @@
|
||||
#define __SPL_AST_H__
|
||||
|
||||
#include "../stage0/include/utils.h"
|
||||
#include "spl_dbg.h"
|
||||
#include "spl_lexer.h"
|
||||
#include "spl_tok.h"
|
||||
|
||||
typedef enum {
|
||||
SPL_AST_CONTAINER_ITEM,
|
||||
SPL_AST_FN_DECL,
|
||||
SPL_AST_FN_DEFINE,
|
||||
SPL_AST_TYPE_DECL,
|
||||
SPL_AST_VAR_DECL,
|
||||
SPL_AST_CONST_DECL,
|
||||
SPL_AST_MEMBER_DECL,
|
||||
SPL_AST__COMPTIME_STMT, /*不实现*/
|
||||
SPL_AST__DIRECTIVE_BLOCK, /*不实现*/
|
||||
/* clang-format off */
|
||||
#define SPL_AST_KIND_TABLE \
|
||||
X(SPL_AST_NONE, V0, none) \
|
||||
X(SPL_AST_CONTAINER_ITEM, V0, container_item) \
|
||||
X(SPL_AST_FN_DECL, V0, fn_decl) \
|
||||
X(SPL_AST_FN_DEFINE, V0, fn_define) \
|
||||
X(SPL_AST_TYPE_DECL, V0, type_decl) \
|
||||
X(SPL_AST_VAR_DECL, V0, var_decl) \
|
||||
X(SPL_AST_CONST_DECL, V0, const_decl) \
|
||||
X(SPL_AST_MEMBER_DECL, V0, member_decl) \
|
||||
X(SPL_AST__COMPTIME_STMT, V0, comptime_stmt) \
|
||||
X(SPL_AST__DIRECTIVE_BLOCK, V0, directive_block) \
|
||||
X(SPL_AST_PARAM_DECL, V0, param_decl) \
|
||||
X(SPL_AST_ATTR_ITEM, V0, attr_item) \
|
||||
X(SPL_AST_ARGG_INIT_ITEM, V0, argg_init_item) \
|
||||
X(SPL_AST_IF_STATEMENT, V0, if_statement) \
|
||||
X(SPL_AST_IFVAR_STATEMENT, V0, ifvar_statement) \
|
||||
X(SPL_AST_WHILE_STATEMENT, V0, while_statement) \
|
||||
X(SPL_AST_LOOP_STATEMENT, V0, loop_statement) \
|
||||
X(SPL_AST_FOR_STATEMENT, V0, for_statement) \
|
||||
X(SPL_AST_MATCH_STATEMENT, V0, match_statement) \
|
||||
X(SPL_AST_RET_STATEMENT, V0, ret_statement) \
|
||||
X(SPL_AST_BREAK_STATEMENT, V0, break_statement) \
|
||||
X(SPL_AST_CONTINUE_STATEMENT, V0, continue_statement) \
|
||||
X(SPL_AST_DEFER_STATEMENT, V0, defer_statement) \
|
||||
X(SPL_AST_TRY_STATEMENT, V0, try_statement) \
|
||||
X(SPL_AST_CATCH_STATEMENT, V0, catch_statement) \
|
||||
X(SPL_AST_ERRDEFER_STATEMEMT, V0, errdefer_statement) \
|
||||
X(SPL_AST_EXPR_STATEMENT, V0, expr_statement) \
|
||||
X(SPL_AST_PACKED_EXPR, V0, packed_expr) \
|
||||
X(SPL_AST_ASSIGN_EXPR, V0, assign_expr) \
|
||||
X(SPL_AST_ASSIGN_ADD_EXPR, V0, assign_add_expr) \
|
||||
X(SPL_AST_ASSIGN_SUB_EXPR, V0, assign_sub_expr) \
|
||||
X(SPL_AST_ASSIGN_MUL_EXPR, V0, assign_mul_expr) \
|
||||
X(SPL_AST_ASSIGN_DIV_EXPR, V0, assign_div_expr) \
|
||||
X(SPL_AST_ASSIGN_MOD_EXPR, V0, assign_mod_expr) \
|
||||
X(SPL_AST_ASSIGN_AND_EXPR, V0, assign_and_expr) \
|
||||
X(SPL_AST_ASSIGN_OR_EXPR, V0, assign_or_expr) \
|
||||
X(SPL_AST_ASSIGN_XOR_EXPR, V0, assign_xor_expr) \
|
||||
X(SPL_AST_ASSIGN_LSHIFT_EXPR, V0, assign_lshift_expr) \
|
||||
X(SPL_AST_ASSIGN_USHIFT_EXPR, V0, assign_ushift_expr) \
|
||||
X(SPL_AST_BOOL_OR_EXPR, V0, bool_or_expr) \
|
||||
X(SPL_AST_BOOL_AND_EXPR, V0, bool_and_expr) \
|
||||
X(SPL_AST_BIT_OR_EXPR, V0, bit_or_expr) \
|
||||
X(SPL_AST_BIT_XOR_EXPR, V0, bit_xor_expr) \
|
||||
X(SPL_AST_BIT_AND_EXPR, V0, bit_and_expr) \
|
||||
X(SPL_AST_CMP_EQ_EXPR, V0, cmp_eq_expr) \
|
||||
X(SPL_AST_CMP_NE_EXPR, V0, cmp_ne_expr) \
|
||||
X(SPL_AST_CMP_LE_EXPR, V0, cmp_le_expr) \
|
||||
X(SPL_AST_CMP_GE_EXPR, V0, cmp_ge_expr) \
|
||||
X(SPL_AST_CMP_LT_EXPR, V0, cmp_lt_expr) \
|
||||
X(SPL_AST_CMP_GT_EXPR, V0, cmp_gt_expr) \
|
||||
X(SPL_AST_RANGE_EXPR, V0, range_expr) \
|
||||
X(SPL_AST_LSHIFT_EXPR, V0, lshift_expr) \
|
||||
X(SPL_AST_RSHIFT_EXPR, V0, rshift_expr) \
|
||||
X(SPL_AST_ADD_EXPR, V0, add_expr) \
|
||||
X(SPL_AST_SUB_EXPR, V0, sub_expr) \
|
||||
X(SPL_AST_MUL_EXPR, V0, mul_expr) \
|
||||
X(SPL_AST_DIV_EXPR, V0, div_expr) \
|
||||
X(SPL_AST_MOD_EXPR, V0, mod_expr) \
|
||||
X(SPL_AST_MINUS_EXPR, V0, minus_expr) \
|
||||
X(SPL_AST_NOT_EXPR, V0, not_expr) \
|
||||
X(SPL_AST_BIT_NOT_EXPR, V0, bit_not_expr) \
|
||||
X(SPL_AST_ADDRESS_EXPR, V0, address_expr) \
|
||||
X(SPL_AST_CALL_EXPR, V0, call_expr) \
|
||||
X(SPL_AST_FIELD_EXPR, V0, field_expr) \
|
||||
X(SPL_AST_DEREF_EXPR, V0, deref_expr) \
|
||||
X(SPL_AST_INDEX_EXPR, V0, index_expr) \
|
||||
X(SPL_AST_SLICE_EXPR, V0, slice_expr) \
|
||||
X(SPL_AST_AS_EXPR, V0, as_expr) \
|
||||
X(SPL_AST_EXPR_INTEGER_LIT, V0, integer_lit) \
|
||||
X(SPL_AST_EXPR_FLOAT_LIT, V0, float_lit) \
|
||||
X(SPL_AST_EXPR_CHAR_LIT, V0, char_lit) \
|
||||
X(SPL_AST_EXPR_STRING_LIT, V0, string_lit) \
|
||||
X(SPL_AST_EXPR_TRUE, V0, true_lit) \
|
||||
X(SPL_AST_EXPR_FALSE, V0, false_lit) \
|
||||
X(SPL_AST_EXPR_NULL, V0, null_lit) \
|
||||
X(SPL_AST_EXPR_UNDEFINED, V0, undefined_lit) \
|
||||
X(SPL_AST_EXPR_IDENT, V0, ident_expr) \
|
||||
X(SPL_AST_ARGGREGATE_INIT, V0, aggregate_init) \
|
||||
X(SPL_AST_EXPR_EXPR, V0, expr_expr) \
|
||||
X(SPL_AST_ARRAY_LIT, V0, array_lit) \
|
||||
X(SPL_AST_BUILTIN_EXPR, V0, builtin_expr) \
|
||||
X(SPL_AST_BLOCK_EXPR, V0, block_expr) \
|
||||
X(SPL_AST_BASE_TYPE_FN, V0, base_type_fn) \
|
||||
X(SPL_AST_BASE_TYPE_PATH, V0, base_type_path) \
|
||||
X(SPL_AST_TYPE_POINTER, V0, type_pointer) \
|
||||
X(SPL_AST_TYPE_ARRAY, V0, type_array) \
|
||||
X(SPL_AST_TYPE_SLICE, V0, type_slice) \
|
||||
X(SPL_AST_TYPE_STRUCT, V0, type_struct) \
|
||||
X(SPL_AST_TYPE_UNION, V0, type_union) \
|
||||
X(SPL_AST_TYPE_ENUM, V0, type_enum) \
|
||||
X(SPL_AST_TYPE_VOID, V0, type_void) \
|
||||
X(SPL_AST_TYPE_BOOL, V0, type_bool) \
|
||||
X(SPL_AST_TYPE_OPAQUE, V0, type_opaque) \
|
||||
X(SPL_AST_TYPE_I8, V0, type_i8) \
|
||||
X(SPL_AST_TYPE_U8, V0, type_u8) \
|
||||
X(SPL_AST_TYPE_I16, V0, type_i16) \
|
||||
X(SPL_AST_TYPE_U16, V0, type_u16) \
|
||||
X(SPL_AST_TYPE_I32, V0, type_i32) \
|
||||
X(SPL_AST_TYPE_U32, V0, type_u32) \
|
||||
X(SPL_AST_TYPE_I64, V0, type_i64) \
|
||||
X(SPL_AST_TYPE_U64, V0, type_u64) \
|
||||
X(SPL_AST_TYPE_ISIZE, V0, type_isize) \
|
||||
X(SPL_AST_TYPE_USIZE, V0, type_usize) \
|
||||
X(SPL_AST_TYPE__F32, V0, type_f32) \
|
||||
X(SPL_AST_TYPE__F64, V0, type_f64) \
|
||||
X(SPL_AST_TYPE_ANY, V0, type_any) \
|
||||
X(SPL_AST_TYPE_IDENT, V0, type_ident) \
|
||||
|
||||
SPL_AST_BLOCK_ITEM,
|
||||
SPL_AST_EXPR,
|
||||
SPL_AST_TYPE_EXPR,
|
||||
SPL_AST_ATTR_LIST,
|
||||
/* clang-format on*/
|
||||
|
||||
typedef enum {
|
||||
#ifdef X
|
||||
#undef X
|
||||
#endif
|
||||
#define X(name, ...) name,
|
||||
SPL_AST_KIND_TABLE
|
||||
#undef X
|
||||
SPL_AST_COUNT,
|
||||
} spl_ast_node_kind_t;
|
||||
|
||||
typedef struct {
|
||||
const char *fname;
|
||||
int line;
|
||||
int col;
|
||||
} spl_ast_loc_t;
|
||||
const char *spl_ast_kind_name(spl_ast_node_kind_t kind);
|
||||
|
||||
struct spl_ast_node;
|
||||
typedef struct spl_ast_node spl_ast_node_t;
|
||||
@@ -34,13 +136,12 @@ typedef usize spl_ast_node_ref_t;
|
||||
typedef VEC(spl_ast_node_ref_t) spl_ast_node_ref_vec_t;
|
||||
struct spl_ast_node {
|
||||
spl_ast_node_kind_t kind;
|
||||
spl_ast_loc_t loc;
|
||||
spl_dbg_node_t dbg;
|
||||
|
||||
usize resolved_def_id;
|
||||
union {
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t attr_list; /* attr_item */
|
||||
spl_ast_node_ref_t self; /* self */
|
||||
spl_ast_node_ref_vec_t members; /* container_decl 列表 */
|
||||
} container_item;
|
||||
|
||||
@@ -54,7 +155,7 @@ struct spl_ast_node {
|
||||
const char *name;
|
||||
spl_ast_node_ref_vec_t param_list; /* param_decl */
|
||||
spl_ast_node_ref_t type_expr;
|
||||
spl_ast_node_ref_vec_t block; /* block_item */
|
||||
spl_ast_node_ref_vec_t block; /* 语句/尾表达式 */
|
||||
} fn_decl;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t attr_list; /* attr_item */
|
||||
@@ -77,149 +178,60 @@ struct spl_ast_node {
|
||||
const char *name;
|
||||
spl_ast_node_ref_t type_expr;
|
||||
spl_ast_node_ref_t expr;
|
||||
} var_decl;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t attr_list; /* attr_item */
|
||||
spl_ast_node_ref_t type_expr;
|
||||
const char *name;
|
||||
spl_ast_node_ref_t expr;
|
||||
} const_decl;
|
||||
} var_const_decl;
|
||||
|
||||
/* 语句数据:kind 决定解释哪个成员 */
|
||||
struct {
|
||||
enum {
|
||||
SPL_AST_IF_STATEMENT,
|
||||
SPL_AST_IFVAR_STATEMENT,
|
||||
SPL_AST_WHILE_STATEMENT,
|
||||
SPL_AST_LOOP_STATEMENT,
|
||||
SPL_AST_FOR_STATEMENT,
|
||||
SPL_AST_MATCH_STATEMENT,
|
||||
SPL_AST_RET_STATEMENT,
|
||||
SPL_AST_BREAK_STATEMENT,
|
||||
SPL_AST_CONTINUE_STATEMENT,
|
||||
SPL_AST_DEFER_STATEMENT,
|
||||
SPL_AST_VARDECL,
|
||||
SPL_AST_CONSTDECL,
|
||||
SPL_AST_TYPEDECL,
|
||||
SPL_AST_EXPR_STATEMENT,
|
||||
} kind;
|
||||
union {
|
||||
struct {
|
||||
spl_ast_node_ref_t expr;
|
||||
spl_ast_node_ref_vec_t if_block; /* block_item */
|
||||
spl_ast_node_ref_vec_t else_block; /* block_item */
|
||||
} if_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t packed_expr;
|
||||
spl_ast_node_ref_vec_t if_block; /* block_item */
|
||||
spl_ast_node_ref_vec_t else_block; /* block_item */
|
||||
} ifvar_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t expr;
|
||||
spl_ast_node_ref_vec_t while_block; /* block_item */
|
||||
} while_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t loop_block; /* block_item */
|
||||
} loop_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t expr_vec;
|
||||
VEC(char *) ident_vec;
|
||||
spl_ast_node_ref_vec_t block; /* block_item */
|
||||
} for_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t expr;
|
||||
spl_ast_node_ref_vec_t paced_exprs; /* packed_expr */
|
||||
spl_ast_node_ref_vec_t match_block; /* block_item */
|
||||
} match_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t expr;
|
||||
} ret_statement;
|
||||
struct {
|
||||
} break_statement;
|
||||
struct {
|
||||
} continue_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t block_or_statement; /* block_item/statement */
|
||||
} defer_statement;
|
||||
spl_ast_node_ref_t var_decl;
|
||||
spl_ast_node_ref_t const_decl;
|
||||
spl_ast_node_ref_t type_decl;
|
||||
spl_ast_node_ref_t expr_statement;
|
||||
};
|
||||
} block_item;
|
||||
spl_ast_node_ref_t expr;
|
||||
spl_ast_node_ref_vec_t if_block; /* 语句 */
|
||||
spl_ast_node_ref_vec_t else_block; /* 语句 */
|
||||
} if_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t packed_expr;
|
||||
spl_ast_node_ref_vec_t if_block; /* 语句 */
|
||||
spl_ast_node_ref_vec_t else_block; /* 语句 */
|
||||
} ifvar_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t expr;
|
||||
spl_ast_node_ref_vec_t while_block; /* 语句 */
|
||||
} while_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t loop_block; /* 语句 */
|
||||
} loop_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t expr_vec;
|
||||
VEC(char *) ident_vec;
|
||||
spl_ast_node_ref_vec_t block; /* 语句 */
|
||||
} for_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t expr;
|
||||
spl_ast_node_ref_vec_t paced_exprs; /* packed_expr */
|
||||
spl_ast_node_ref_vec_t match_block; /* 语句 */
|
||||
} match_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_t expr;
|
||||
} ret_statement;
|
||||
struct {
|
||||
} break_statement;
|
||||
struct {
|
||||
} continue_statement;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t block_or_statement; /* 语句 */
|
||||
} defer_statement;
|
||||
|
||||
struct {
|
||||
const char *ident;
|
||||
const char *bind_ident;
|
||||
spl_ast_node_ref_t expr;
|
||||
} packed_expr;
|
||||
|
||||
struct {
|
||||
enum {
|
||||
SPL_AST_ASSIGN_EXPR,
|
||||
SPL_AST_ASSIGN_ADD_EXPR,
|
||||
SPL_AST_ASSIGN_sUB_EXPR,
|
||||
SPL_AST_ASSIGN_MUL_EXPR,
|
||||
SPL_AST_ASSIGN_DIV_EXPR,
|
||||
SPL_AST_ASSIGN_MOD_EXPR,
|
||||
SPL_AST_ASSIGN_AND_EXPR,
|
||||
SPL_AST_ASSIGN_OR_EXPR,
|
||||
SPL_AST_ASSIGN_XOR_EXPR,
|
||||
SPL_AST_ASSIGN_LSHIFT_EXPR,
|
||||
SPL_AST_ASSIGN_USHIFT_EXPR,
|
||||
|
||||
SPL_AST_BOOLOR_EXPR,
|
||||
SPL_AST_BOOLAND_EXPR,
|
||||
SPL_AST_BITOR_EXPR,
|
||||
SPL_AST_BITXOR_EXPR,
|
||||
SPL_AST_BITAND_EXPR,
|
||||
|
||||
SPL_AST_CMPEQ_EXPR,
|
||||
SPL_AST_CMPNE_EXPR,
|
||||
|
||||
SPL_AST_CMP_LE_EXPR,
|
||||
SPL_AST_CMP_GE_EXPR,
|
||||
SPL_AST_CMP_LT_EXPR,
|
||||
SPL_AST_CMP_GT_EXPR,
|
||||
|
||||
SPL_AST_RANGE_EXPR,
|
||||
|
||||
SPL_AST_LSHIFT_EXPR,
|
||||
SPL_AST_RSHIFT_EXPR,
|
||||
|
||||
SPL_AST_ADD_EXPR,
|
||||
SPL_AST_SUB_EXPR,
|
||||
|
||||
SPL_AST_MUL_EXPR,
|
||||
SPL_AST_DIV_EXPR,
|
||||
SPL_AST_MOD_EXPR,
|
||||
|
||||
SPL_AST_PREFIX_EXPR, /* left ref node */
|
||||
SPL_AST_POSTFIX_EXPR, /* left ref node */
|
||||
SPL_AST_PRIMARY_EXPR, /* left ref node */
|
||||
} op;
|
||||
struct {
|
||||
spl_ast_node_ref_t left;
|
||||
spl_ast_node_ref_t right;
|
||||
} op_expr;
|
||||
} expr;
|
||||
spl_ast_node_ref_t left;
|
||||
spl_ast_node_ref_t right;
|
||||
} op_expr;
|
||||
struct {
|
||||
enum {
|
||||
SPL_AST_MINUS_EXPR,
|
||||
SPL_AST_BANG_EXPR,
|
||||
SPL_AST_TILDE_EXPR,
|
||||
SPL_AST_AMPERSAND_EXPR,
|
||||
SPL_AST_ASTERISK_EXPR,
|
||||
} kind;
|
||||
spl_ast_node_ref_t postfix_expr;
|
||||
} prefix_expr;
|
||||
struct {
|
||||
enum {
|
||||
SPL_AST_CALL_EXPR,
|
||||
SPL_AST_FIELD_EXPR,
|
||||
SPL_AST_DEREF_EXPR,
|
||||
SPL_AST_INDEX_EXPR,
|
||||
SPL_AST_SLICE_EXPR,
|
||||
SPL_AST_AS_EXPR,
|
||||
} kind;
|
||||
spl_ast_node_ref_t primary_expr;
|
||||
union {
|
||||
spl_ast_node_ref_vec_t call_expr;
|
||||
@@ -232,66 +244,53 @@ struct spl_ast_node {
|
||||
spl_ast_node_ref_t type_expr;
|
||||
};
|
||||
} postfix_expr;
|
||||
|
||||
struct {
|
||||
enum {
|
||||
SPL_AST_INTEGER,
|
||||
SPL_AST_FLOAT,
|
||||
SPL_AST_CHAR_LIT,
|
||||
SPL_AST_STRING_LIT,
|
||||
SPL_AST_TRUE,
|
||||
SPL_AST_FALSE,
|
||||
SPL_AST_NULL,
|
||||
SPL_AST_IDENT,
|
||||
SPL_AST_ARGGREGATE_INIT,
|
||||
SPL_AST_EXPR_EXPR,
|
||||
SPL_AST_ARRAY_LIT,
|
||||
SPL_AST_BUILTIN_EXPR,
|
||||
SPL_AST_BLOCK_EXPR,
|
||||
} kind;
|
||||
union {
|
||||
isize integer_expr;
|
||||
double float_expr;
|
||||
char char_lit_expr;
|
||||
const char *string_lit_expr; /* parsed c string */
|
||||
isize integer_expr;
|
||||
double float_expr;
|
||||
char char_lit_expr;
|
||||
const char *string_lit_expr; /* parsed c string */
|
||||
const char *ident;
|
||||
|
||||
struct {
|
||||
const char *name;
|
||||
spl_ast_node_ref_vec_t expr; /* aggregate_init_item */
|
||||
} aggregate_init;
|
||||
|
||||
spl_ast_node_ref_t expr;
|
||||
struct {
|
||||
isize integer;
|
||||
spl_ast_node_ref_t type_expr;
|
||||
spl_ast_node_ref_vec_t expr_list;
|
||||
} array_lit_expr;
|
||||
struct {
|
||||
const char *ident;
|
||||
|
||||
struct {
|
||||
const char *name;
|
||||
spl_ast_node_ref_vec_t expr; /* aggregate_init_item */
|
||||
} aggregate_init;
|
||||
|
||||
spl_ast_node_ref_t expr;
|
||||
struct {
|
||||
isize integer;
|
||||
spl_ast_node_ref_t type_expr;
|
||||
spl_ast_node_ref_vec_t expr_list;
|
||||
} array_lit_expr;
|
||||
struct {
|
||||
const char *ident;
|
||||
spl_ast_node_ref_vec_t expr_list;
|
||||
} builtin_expr;
|
||||
spl_ast_node_ref_vec_t block_expr; /* block_item */
|
||||
};
|
||||
spl_ast_node_ref_vec_t expr_list;
|
||||
} builtin_expr;
|
||||
spl_ast_node_ref_vec_t block_expr; /* 语句 */
|
||||
} primary_expr;
|
||||
|
||||
struct {
|
||||
const char *ident;
|
||||
spl_ast_node_ref_t expr;
|
||||
} aggregate_init_item;
|
||||
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t type_prefixs; /* prefix_type */
|
||||
spl_ast_node_ref_vec_t attr_list; /* attr_item */
|
||||
enum {
|
||||
SPL_AST_BASE_TYPE_FN,
|
||||
SPL_AST_BASE_TYPE_PATH,
|
||||
SPL_AST_TYPE_STRUCT,
|
||||
SPL_AST_TYPE_UNION,
|
||||
SPL_AST_TYPE_ENUM,
|
||||
} kind;
|
||||
|
||||
const char *spl_base_type;
|
||||
spl_ast_node_ref_vec_t attr_list; /* attr_item */
|
||||
union {
|
||||
spl_ast_node_ref_vec_t type_path; /* type_atom */
|
||||
struct {
|
||||
VEC(const char *) ident_vec;
|
||||
} type_path;
|
||||
struct {
|
||||
spl_ast_node_ref_t element;
|
||||
spl_ast_node_ref_t size;
|
||||
} array_type;
|
||||
struct {
|
||||
spl_ast_node_ref_t element;
|
||||
} slice_type;
|
||||
struct {
|
||||
spl_ast_node_ref_t pointee;
|
||||
} pointer_type;
|
||||
struct {
|
||||
spl_ast_node_ref_vec_t param_list; /* param_decl */
|
||||
spl_ast_node_ref_t type_expr;
|
||||
@@ -299,42 +298,16 @@ struct spl_ast_node {
|
||||
spl_ast_node_ref_vec_t aggregate_list; /* container_decl */
|
||||
};
|
||||
} type_expr;
|
||||
struct {
|
||||
/* ASTERISK = 1, [] = 2, else = 0*/
|
||||
int pointer;
|
||||
/* if array_size != 0 then pointer == 2 */
|
||||
int array_size;
|
||||
} prefix_type;
|
||||
struct {
|
||||
enum {
|
||||
SPL_AST_TYPE_VOID,
|
||||
SPL_AST_TYPE_BOOL,
|
||||
SPL_AST_TYPE_I8,
|
||||
SPL_AST_TYPE_U8,
|
||||
SPL_AST_TYPE_I16,
|
||||
SPL_AST_TYPE_U16,
|
||||
SPL_AST_TYPE_I32,
|
||||
SPL_AST_TYPE_U32,
|
||||
SPL_AST_TYPE_I64,
|
||||
SPL_AST_TYPE_U64,
|
||||
SPL_AST_TYPE_ISIZE,
|
||||
SPL_AST_TYPE_USIZE,
|
||||
SPL_AST_TYPE__F32, /*不实现*/
|
||||
SPL_AST_TYPE__F64, /*不实现*/
|
||||
SPL_AST_TYPE_PTR,
|
||||
SPL_AST_TYPE_ANY,
|
||||
SPL_AST_TYPE_IDENT,
|
||||
} kind;
|
||||
const char *ident;
|
||||
} type_atom;
|
||||
};
|
||||
};
|
||||
|
||||
typedef VEC(spl_ast_node_t) spl_ast_node_vec_t;
|
||||
typedef VEC(char*)spl_ast_cstr_ref_vec_t;
|
||||
typedef struct {
|
||||
int parsed;
|
||||
spl_tok_vec_t input;
|
||||
spl_ast_node_vec_t buckets;
|
||||
spl_ast_node_vec_t node_buckets;
|
||||
spl_ast_cstr_ref_vec_t str_buckets;
|
||||
spl_ast_node_ref_t root;
|
||||
} spl_ast_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user