From ea97370f973374f863e4296c2bb872be8b5235a3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 12 Aug 2019 09:48:55 +0200 Subject: Before interpreter. Cleanup build script. Begin writing code analyzer tool to find common mistakes --- include/ast.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'include/ast.h') diff --git a/include/ast.h b/include/ast.h index 9f01b1b..d89d099 100644 --- a/include/ast.h +++ b/include/ast.h @@ -90,7 +90,7 @@ struct Ast { struct Scope { Buffer/**/ ast_objects; - HashMap/*(key=BufferView, value=Ast*)*/ named_objects; + HashMapType(BufferView, Ast*) named_objects; /* Value is always an Ast* with type LhsExpr */ Scope *parent; /* Is null unless the scope is a file scope, in which case this is the parser that owns the scope */ Parser *parser; @@ -144,6 +144,14 @@ typedef struct { } value; } VariableType; +typedef enum { + DECL_FLAG_NONE = 0, + DECL_FLAG_EXTERN = 1 << 0, + DECL_FLAG_EXPORT = 1 << 1, + DECL_FLAG_PUB = 1 << 2, + DECL_FLAG_CONST = 1 << 3 +} DeclFlag; + /* Note: When resolving AST, multiple threads can end up resolving the same expressions at the same time. This is intentional. Instead of using mutex for every expression and locking/unlocking everytime @@ -153,14 +161,17 @@ typedef struct { leading to @ast_resolve running again for the same expression. */ struct LhsExpr { - bool is_extern; - bool is_pub; - bool is_const; + u8 decl_flags; BufferView var_name; VariableType type; - Ast *rhs_expr; + nullable Ast *rhs_expr; }; +#define LHS_EXPR_IS_EXTERN(expr) ((expr)->decl_flags & DECL_FLAG_EXTERN) +#define LHS_EXPR_IS_EXPORT(expr) ((expr)->decl_flags & DECL_FLAG_EXPORT) +#define LHS_EXPR_IS_PUB(expr) ((expr)->decl_flags & DECL_FLAG_PUB) +#define LHS_EXPR_IS_CONST(expr) ((expr)->decl_flags & DECL_FLAG_CONST) + struct AssignmentExpr { Ast *lhs_expr; Ast *rhs_expr; @@ -228,8 +239,9 @@ void function_signature_init(FunctionSignature *self); CHECK_RESULT int funcdecl_init(FunctionDecl *self, FunctionSignature *signature, Scope *parent, ArenaAllocator *allocator); CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ArenaAllocator *allocator); CHECK_RESULT int structdecl_init(StructDecl *self, Scope *parent, ArenaAllocator *allocator); +LhsExpr* structdecl_get_field_by_name(StructDecl *self, BufferView field_name); void structfield_init(StructField *self, BufferView name, BufferView type_name); -void lhsexpr_init(LhsExpr *self, bool is_extern, bool is_pub, bool is_const, BufferView var_name); +void lhsexpr_init(LhsExpr *self, DeclFlag decl_flag, BufferView var_name); void assignmentexpr_init(AssignmentExpr *self, Ast *lhs_expr, Ast *rhs_expr); void import_init(Import *self, BufferView path); CHECK_RESULT int string_init(String *self, BufferView str); -- cgit v1.2.3