diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-05-07 21:22:38 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-05-07 21:22:38 +0300 |
commit | 0e0c41af58a0f4ec5a39ce77822de71e5523fcba (patch) | |
tree | 4a02b2f93e61411cbfc6084b0855dba51b326cd9 /src/ast.c | |
parent | 1fadcec6d7b26d34edf3b5b3a293deea0edb4139 (diff) | |
download | fwd-gnc.tar.gz fwd-gnc.zip |
implement enough type analysis for vector examplegnc
+ Big commit, scary
+ Some details still a bit up in the air, mainly about move checking
structure member access ('register' types are freely copied I guess,
same as in rust? How about user types?)
Diffstat (limited to 'src/ast.c')
-rw-r--r-- | src/ast.c | 51 |
1 files changed, 47 insertions, 4 deletions
@@ -243,6 +243,22 @@ void ast_dump(int depth, struct ast *n) DUMP(AST_NOT); DUMP(AST_REF); DUMP(AST_DEREF); + DUMP(AST_NIL_CHECK); + DUMP(AST_BNEG); + DUMP(AST_SIZEOF); + DUMP(AST_AS); + DUMP(AST_ARR); + DUMP(AST_ASSIGN); + DUMP(AST_CONSTRUCTION); + DUMP(AST_CONSTRUCT); + DUMP(AST_SELF); + DUMP(AST_FORGET); + DUMP(AST_PASTE); + DUMP(AST_IMPLEMENTS); + DUMP(AST_TEMPLATE); + DUMP(AST_INSTANCE); + DUMP(AST_SUPERTEMPLATE); + DUMP(AST_INSTANCE_CONT); DUMP(AST_CONST_INT); DUMP(AST_CONST_CHAR); DUMP(AST_CONST_BOOL); @@ -320,6 +336,9 @@ struct ast *clone_ast(struct ast *n) if (n->a3) new->a3 = clone_ast_list(n->a3); + if (n->t2) + new->t2 = clone_type_list(n->t2); + /** @todo rebuild opt group? */ return new; @@ -351,13 +370,14 @@ struct type *clone_type(struct type *type) return NULL; new->k = type->k; - if (type->id && !(new->id = strdup(type->id))) - return NULL; + if (type->id) + new->id = strdup(type->id); - if (type->t0 && !(new->t0 = clone_type_list(type->t0))) - return NULL; + if (type->t0) + new->t0 = clone_type_list(type->t0); new->group = type->group; + new->loc = type->loc; return new; } @@ -589,6 +609,13 @@ bool types_match(struct type *a, struct type *b) if (!a && b) return false; + /* nil matches any kind of pointer */ + if (is_ptr_type(a->k) && b->k == TYPE_NIL) + return true; + + if (a->k == TYPE_NIL && is_ptr_type(b->k)) + return true; + if (a->k != b->k) return false; @@ -662,6 +689,22 @@ const char *ast_str(enum ast_kind k) CASE(AST_NOT); CASE(AST_REF); CASE(AST_DEREF); + CASE(AST_NIL_CHECK); + CASE(AST_BNEG); + CASE(AST_SIZEOF); + CASE(AST_AS); + CASE(AST_ARR); + CASE(AST_ASSIGN); + CASE(AST_CONSTRUCTION); + CASE(AST_CONSTRUCT); + CASE(AST_SELF); + CASE(AST_FORGET); + CASE(AST_PASTE); + CASE(AST_IMPLEMENTS); + CASE(AST_TEMPLATE); + CASE(AST_INSTANCE); + CASE(AST_SUPERTEMPLATE); + CASE(AST_INSTANCE_CONT); CASE(AST_CONST_INT); CASE(AST_CONST_CHAR); CASE(AST_CONST_BOOL); |