1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#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))
return t;
}
return NULL;
}
|