summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-12-19 20:17:50 +0100
committerkdx <kikoodx@paranoici.org>2023-12-19 20:17:50 +0100
commit215f7bbfcefb6b7a84504edd2928a361f95941cf (patch)
tree2949b9c3e2f6090d51878b777022b1409e72983a
parentcb758dec7115ab4e758871b3cf974f67ae4d69b9 (diff)
downloado7c-215f7bbfcefb6b7a84504edd2928a361f95941cf.tar.gz
placeholder aggregate typing
-rw-r--r--Tupfile4
-rw-r--r--inc/type.h4
-rw-r--r--src/main.c6
-rw-r--r--src/type.c31
4 files changed, 39 insertions, 6 deletions
diff --git a/Tupfile b/Tupfile
index db36ea8..b871946 100644
--- a/Tupfile
+++ b/Tupfile
@@ -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
diff --git a/inc/type.h b/inc/type.h
index 27c384e..d7accb8 100644
--- a/inc/type.h
+++ b/inc/type.h
@@ -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);
diff --git a/src/main.c b/src/main.c
index e3a5dea..dfc0290 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
}
diff --git a/src/type.c b/src/type.c
index 49c7cb1..1f4d494 100644
--- a/src/type.c
+++ b/src/type.c
@@ -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;
+}