commit b336be00062e430465ef7d760bcbd1105c325454
parent f31f7fb21f10513db4c9b126a607bf448b5f7ff2
Author: m21c <ho*******@gmail.com>
Date: Sat, 2 Oct 2021 14:13:12 +0200
added type-kinds for structs and union types
Diffstat:
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/compiler.c b/compiler.c
@@ -128,6 +128,8 @@ enum TypeKind {
TFUNCTION,
+ TSTRUCT, TUNION,
+
TMAX
} TypeKind;
@@ -357,6 +359,9 @@ Type prim[] = {
[TTUPLE] = {TTUPLE, defaultloc, NULL, 0, 0, {0}, NULL},
[TFUNCTION] = {TFUNCTION, defaultloc, NULL, 0, 0, {0}, NULL},
+
+ [TSTRUCT] = {TSTRUCT, defaultloc, NULL, 0, 0, {0}, NULL},
+ [TUNION] = {TUNION, defaultloc, NULL, 0, 0, {0}, NULL},
};
int keywordlengths[OSTART - KSTART];
@@ -2215,7 +2220,9 @@ readrecord(Source *source, bool isunion)
* compute size and align, resolve aliases */
module = makedecl(source, recordnode->lhs->u.key, DTYPE);
- module->type = prim + TINT;
+ module->type = maketype(&recordnode->loc, prim + TSTRUCT, NULL);
+
+ module->type->module = module;
return recordnode;
}
@@ -3643,6 +3650,11 @@ printtypetail(FILE *out, Type *type, int indent)
n += printtypetail(out, type->target, indent);
}
+ if (type->module) {
+ n += fprintf(out, "%s", getstring(idents, type->module->key));
+ return n;
+ }
+
switch (type->kind) {
case TARRAY:
n += fprintf(out, "[");