diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-03-09 00:43:13 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 9428fceb0cacf5ff9e19116de658bcffb98efc6f (patch) | |
tree | b281b6e047195c4f9c49de98919c8b99171dccec /include/ast.h | |
parent | 18fb99add7f0d4b710debcbf5c154f9c1d841845 (diff) |
Add check for duplicate variable names
Diffstat (limited to 'include/ast.h')
-rw-r--r-- | include/ast.h | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/include/ast.h b/include/ast.h index 7911a59..1d40a89 100644 --- a/include/ast.h +++ b/include/ast.h @@ -5,8 +5,13 @@ #include "std/buffer.h" #include "std/misc.h" #include "std/scoped_allocator.h" +#include "std/hash_map.h" #include "binop_type.h" +/* General error */ +#define AST_ERR -1 +#define AST_ERR_DEF_DUP -20 + typedef struct FunctionDecl FunctionDecl; typedef struct FunctionCall FunctionCall; typedef struct LhsExpr LhsExpr; @@ -45,9 +50,14 @@ typedef struct { AstType type; } Ast; +struct Scope { + Buffer ast_objects; + HashMap/*(key=BufferView, value=Ast)*/ named_objects; +}; + struct FunctionDecl { BufferView name; - Buffer body; + Scope body; }; struct FunctionCall { @@ -90,11 +100,8 @@ struct Binop { bool grouped; }; -struct Scope { - Buffer ast_objects; -}; - Ast ast_none(); +BufferView ast_get_name(Ast *self); CHECK_RESULT int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator); CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ScopedAllocator *allocator); @@ -103,7 +110,9 @@ void import_init(Import *self, BufferView path); CHECK_RESULT int string_init(String *self, BufferView str); void number_init(Number *self, i64 value, bool is_integer); void binop_init(Binop *self); + CHECK_RESULT int scope_init(Scope *self, ScopedAllocator *allocator); +CHECK_RESULT int scope_add_child(Scope *self, Ast *child); void scope_resolve(Scope *self); #endif |