-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-table.cc
57 lines (45 loc) · 1.48 KB
/
type-table.cc
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
#include <type-table.h>
#include <cool-tree.h>
#include <unordered_set>
#include <vector>
#define SET_CONTAINS(map, element) (map.find(element) != map.end())
// prototypes
void inheritance_from_basic_classes_detection(Classes classes);
void inheritance_from_undefined_class(Classes classes);
void misuse_of_self_type(Classes classes);
void redefinition_of_classes_detection(Classes classes);
void redefinition_of_basic_classes_detection(Classes classes);
TypeTable::TypeTable(Classes classes)
{
initialize_constants();
// insert all the types in the set
for(int i = 0, n = classes->len(); i < n; i++)
all_defined_types.insert(classes->nth(i)->get_name());
basic_types = {Int, Str, Bool};
built_in_types = {Int, Str, Bool, Object, IO};
reserved_types = { SELF_TYPE, prim_slot };
reserved_identifiers = { self };
vector<Symbol> all_special_types = {prim_slot, SELF_TYPE, Int, Str, Bool, Object, IO};
for(auto type : all_special_types)
all_defined_types.insert(type);
}
bool TypeTable::contains(Symbol type)
{
return SET_CONTAINS(all_defined_types, type);
}
bool TypeTable::is_basic_type(Symbol type)
{
return SET_CONTAINS(basic_types, type);
}
bool TypeTable::is_reserved_type(Symbol type)
{
return SET_CONTAINS(reserved_types, type);
}
bool TypeTable::is_reserved_identifier(Symbol id)
{
return SET_CONTAINS(reserved_identifiers, id);
}
bool TypeTable::is_built_in_type(Symbol id)
{
return SET_CONTAINS(built_in_types, id);
}