diff options
author | kdx <kikoodx@paranoici.org> | 2023-12-19 20:17:50 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-12-19 20:17:50 +0100 |
commit | 215f7bbfcefb6b7a84504edd2928a361f95941cf (patch) | |
tree | 2949b9c3e2f6090d51878b777022b1409e72983a | |
parent | cb758dec7115ab4e758871b3cf974f67ae4d69b9 (diff) | |
download | o7c-215f7bbfcefb6b7a84504edd2928a361f95941cf.tar.gz |
placeholder aggregate typing
-rw-r--r-- | Tupfile | 4 | ||||
-rw-r--r-- | inc/type.h | 4 | ||||
-rw-r--r-- | src/main.c | 6 | ||||
-rw-r--r-- | src/type.c | 31 |
4 files changed, 39 insertions, 6 deletions
@@ -1,8 +1,8 @@ CC = gcc LD = gcc SRC = src/*.c src/util/*.c src/parser/*.c src/node/*.c -CFLAGS = -std=c2x -Wall -Wextra -iquoteinc -includeinc/_.h -O0 -g3 -LDFLAGS = -O0 -g3 +CFLAGS = -std=c2x -Wall -Wextra -iquoteinc -includeinc/_.h -O3 +LDFLAGS = -O3 -s LIBS = NAME = o7c @@ -2,7 +2,7 @@ #include "util.h" #include "node.h" -static const char *primary_types[] = { +[[maybe_unused]] static const char *primary_types[] = { // sized integers "i8", "i16", @@ -32,6 +32,7 @@ typedef struct { typedef struct { SliceU8 name; + SliceU8 parent; } TypeAggregate; typedef enum { @@ -50,5 +51,6 @@ typedef struct { Type type_new_alias(Node *node); Type type_new_struct(Node *node); +Type type_new_union(Node *node); vec_decl(Type, Type); @@ -42,14 +42,14 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) VecType_push(types, type_new_alias(node)); break; case NOD_STRUCT: + VecType_push(types, type_new_struct(node)); + break; case NOD_UNION: + VecType_push(types, type_new_union(node)); break; default: break; } } - vec_log(types, "%.*s = %.*s %lu", - X->alias.from.len, X->alias.from.loc, - X->alias.to.len, X->alias.to.loc, X->alias.ptr_depth); return 0; } @@ -14,3 +14,34 @@ type_new_alias(Node *node) } }; } + +Type +type_new_struct(Node *node) +{ + Type this = { + .tag = TYPE_STRUCT, + .aggregate = { + .name = node->tok.s, + .parent = SliceU8_from_ptr(nullptr, 0) + } + }; + + if (node->Lhs != nullptr) + this.aggregate.parent = node->Lhs->tok.s; + + return this; +} + +Type +type_new_union(Node *node) +{ + Type this = { + .tag = TYPE_UNION, + .aggregate = { + .name = node->tok.s, + .parent = SliceU8_from_ptr(nullptr, 0) + } + }; + + return this; +} |