-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatatype.c
70 lines (57 loc) · 1.3 KB
/
datatype.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "compiler.h"
bool
datatype_is_struct_or_union (struct datatype* dtype)
{
return dtype->type == DATA_TYPE_STRUCT || dtype->type == DATA_TYPE_UNION;
}
bool
datatype_is_struct_or_union_for_name (const char* name)
{
return S_EQ(name, "struct") || S_EQ(name, "union");
}
size_t
datatype_size_for_array_access (struct datatype* dtype)
{
if (datatype_is_struct_or_union(dtype) && dtype->flags & DATATYPE_FLAG_IS_POINTER && dtype->pointer_depth == 1)
{
/* `struct abc* abc; abc[0]` */
return dtype->size;
}
return datatype_size(dtype);
}
size_t
datatype_element_size (struct datatype* dtype)
{
if (dtype->flags & DATATYPE_FLAG_IS_POINTER)
{
return DATA_SIZE_DWORD;
}
return dtype->size;
}
size_t
datatype_size_no_ptr (struct datatype* dtype)
{
if (dtype->flags & DATATYPE_FLAG_IS_ARRAY)
{
return dtype->array.size;
}
return dtype->size;
}
size_t
datatype_size (struct datatype* dtype)
{
if (dtype->flags & DATATYPE_FLAG_IS_POINTER && dtype->pointer_depth > 0)
{
return DATA_SIZE_DWORD;
}
if (dtype->flags & DATATYPE_FLAG_IS_ARRAY)
{
return dtype->array.size;
}
return dtype->size;
}
bool
datatype_is_primitive (struct datatype* dtype)
{
return !datatype_is_struct_or_union(dtype);
}