aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/type.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/prc1/type.c')
-rw-r--r--src/prc1/type.c57
1 files changed, 14 insertions, 43 deletions
diff --git a/src/prc1/type.c b/src/prc1/type.c
index 92cc53f..cdd8f72 100644
--- a/src/prc1/type.c
+++ b/src/prc1/type.c
@@ -4,6 +4,7 @@
#include "lex.h"
#include "parse.h"
#include "prv.h"
+#include "triplet.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -159,61 +160,31 @@ char *type_name(const struct type *t)
return ret;
}
-const struct type *type_ufind(const struct fn *fn, const char *s)
+const struct type *type_ufind(const struct fn *fn, const char *tr,
+ const char *s)
{
- static const struct type builtins[] =
- {
- {.type = BUILTIN, .u.b = {"void"}},
- {.type = BUILTIN, .u.b = {"char"}, .sz = 1, .sign = 1, .align = 1},
- {.type = BUILTIN, .u.b = {"schar"}, .sz = 1, .sign = 1, .align = 1},
- {.type = BUILTIN, .u.b = {"short"}, .sz = 2, .sign = 1, .align = 2},
- {.type = BUILTIN, .u.b = {"int"}, .sz = 4, .sign = 1, .align = 4},
- {.type = BUILTIN, .u.b = {"long"}, .sz = 8, .sign = 1, .align = 8},
- {.type = BUILTIN, .u.b = {"longlong"}, .sz = 8, .sign = 1, .align = 8},
- {.type = BUILTIN, .u.b = {"uchar"}, .sz = 1, .align = 1},
- {.type = BUILTIN, .u.b = {"ushort"}, .sz = 2, .align = 2},
- {.type = BUILTIN, .u.b = {"uint"}, .sz = 4, .align = 4},
- {.type = BUILTIN, .u.b = {"ulong"}, .sz = 8, .align = 8},
- {.type = BUILTIN, .u.b = {"ulonglong"}, .sz = 8, .align = 8}
- };
-
const struct td *td = fn->td;
+ const struct type *t;
- if (fn->parent)
- {
- const struct type *t = type_find(fn->parent, s);
-
- if (t)
- return t;
- }
-
- for (size_t i = 0; i < sizeof builtins / sizeof *builtins; i++)
- {
- const struct type *t = &builtins[i];
-
- if (!strcmp(t->u.b.name, s))
- return t;
- }
-
- if (td)
+ if (fn->parent && (t = type_find(fn->parent, tr, s)))
+ return t;
+ else if ((t = triplet_type(tr, s)))
+ return t;
+ else if (td)
for (const struct type *t = td->types; t; t = t->next)
if (!strcmp(t->tk->s, s))
return t;
for (size_t i = 0; i < fn->nimps; i++)
- {
- const struct type *t = type_ufind(fn->imps[i].ast.fns, s);
-
- if (t)
+ if ((t = type_ufind(fn->imps[i].ast.fns, tr, s)))
return t;
- }
return NULL;
}
-const struct type *type_find(const struct fn *fn, const char *s)
+const struct type *type_find(const struct fn *fn, const char *tr, const char *s)
{
- const struct type *t = type_ufind(fn, s);
+ const struct type *t = type_ufind(fn, tr, s);
if (t && t->type == T)
return t->u.t.alias;
@@ -270,7 +241,7 @@ static int aetc(const struct lex *l, struct prv *p)
static int aid(const struct lex *l, struct prv *p)
{
const struct tk *qty = p->stk + 2;
- const struct type *ct = type_find(fn_cur(p), qty->s);
+ const struct type *ct = type_find(fn_cur(p), triplet(p), qty->s);
struct type *t;
unsigned long long v;
@@ -410,7 +381,7 @@ static int t(const struct lex *l, struct prv *p)
{
const struct fn *fn = fn_cur(p);
const struct tk *tk = p->stk;
- const struct type *t = type_find(fn, tk->s);
+ const struct type *t = type_find(fn, triplet(p), tk->s);
struct type *tt = p->t;
if (!t)