#ifndef __SCC_AST_H__ #define __SCC_AST_H__ #include "scc_ast_def.h" typedef struct scc_ast_ctx { scc_ast_canon_type_vec_t canonical_type_pool; scc_ast_canon_type_t *builtin_types[SCC_AST_BUILTIN_TYPE_COUNT]; scc_ast_node_vec_t all_nodes; } scc_ast_ctx_t; void scc_ast_ctx_init(scc_ast_ctx_t *ctx); void scc_ast_ctx_drop(scc_ast_ctx_t *ctx); scc_ast_canon_type_t *scc_ast_ctx_get_builtin_type(scc_ast_ctx_t *ctx, scc_ast_builtin_type_t kind); scc_ast_canon_type_t *scc_ast_ctx_alloc_type(scc_ast_ctx_t *ctx); static inline void *scc_ast_ctx_alloc_node(scc_ast_ctx_t *ctx, usize size) { void *ptr = scc_malloc(size); if (ptr == nullptr) { Panic("Out of memory"); } scc_memset(ptr, 0, size); scc_vec_push(ctx->all_nodes, (scc_ast_node_t *)ptr); return ptr; } #define SCC_AST_ALLOC(ctx, type) \ ((type *)scc_ast_ctx_alloc_node(ctx, sizeof(type))) #define SCC_AST_ALLOC_QUAL_TYPE(ctx) SCC_AST_ALLOC(ctx, scc_ast_qual_type_t) #define SCC_AST_ALLOC_DECL(ctx) SCC_AST_ALLOC(ctx, scc_ast_decl_t) #define SCC_AST_ALLOC_EXPR(ctx) SCC_AST_ALLOC(ctx, scc_ast_expr_t) #define SCC_AST_ALLOC_STMT(ctx) SCC_AST_ALLOC(ctx, scc_ast_stmt_t) // have defined cannoical_type type static inline void scc_ast_type_builtin_init(scc_ast_qual_type_t *type, scc_ast_ctx_t *ctx, scc_ast_builtin_type_t builtin_type, scc_pos_t loc) { Assert(type != nullptr); type->base.loc = loc; type->base.type = SCC_AST_TYPE_BUILTIN; type->type = scc_ast_ctx_get_builtin_type(ctx, builtin_type); type->quals = (scc_ast_decl_specifier_t){0}; // FIXME } #endif /* __SCC_AST_H__*/