diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-05-09 02:56:07 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-05-21 01:17:25 +0200 |
| commit | 7cdb37d35e6978c245ca656ba9d55df0a6e362e6 (patch) | |
| tree | 79d8c0f6526d0eedbbec617cd78a62a3f1c9a1f3 /type.c | |
| download | slcob-7cdb37d35e6978c245ca656ba9d55df0a6e362e6.tar.gz | |
Add project skeleton
Diffstat (limited to 'type.c')
| -rw-r--r-- | type.c | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -0,0 +1,51 @@ +#include "type.h" +#include "parse.h" +#include <string.h> + +const struct type *type_find(const struct fn *fn, const char *s) +{ + static const struct type builtins[] = + { + {.type = BUILTIN, .u.b.name = "void"}, + {.type = BUILTIN, .u.b.name = "byte", .sz = 1, .sign = 1}, + {.type = BUILTIN, .u.b.name = "halfword", .sz = 2, .sign = 1}, + {.type = BUILTIN, .u.b.name = "word", .sz = 4, .sign = 1}, + {.type = BUILTIN, .u.b.name = "long", .sz = 8, .sign = 1}, + {.type = BUILTIN, .u.b.name = "ubyte", .sz = 1}, + {.type = BUILTIN, .u.b.name = "uhalfword", .sz = 2}, + {.type = BUILTIN, .u.b.name = "uword", .sz = 4}, + {.type = BUILTIN, .u.b.name = "ulong", .sz = 8} + }; + + const struct td *td = fn->td; + + 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) + for (size_t i = 0; i < td->ntypes; i++) + { + const struct type *t = &td->types[i]; + + if (!strcmp(t->tk->s, s)) + { + if (t->type == T) + { + const struct type *a = t->u.t.alias; + const char *name = a->type == BUILTIN ? + a->u.b.name : a->tk->s; + + return type_find(fn, name); + } + else + return t; + } + } + + return NULL; +} |
