AALanguage
The best language for those who have nothing to do
Loading...
Searching...
No Matches
TableIdentifiers.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <vector>
4
#include <unordered_map>
5
#include <string>
6
7
13
enum
ExprType
{
14
Bool
,
Char
,
Double
,
UDouble
,
Float
,
UFloat
,
Int
,
UInt
,
Long
,
ULong
,
Short
,
UShort
,
Byte
,
String
,
Void
,
Large
,
Unknown
15
};
16
23
static
int
type_prior[17] = { 0, 1, 11, 12, 7, 8, 5, 6, 9, 10, 3, 4, 2, 0, 0, 13, 0 };
24
28
struct
Type
{
30
ExprType
expr_type
;
32
bool
is_const
;
34
bool
is_array
;
36
int
array_size
;
40
Type
(
ExprType
expr_type_,
bool
is_const_,
bool
is_array_,
int
array_size_ = -1) {
41
expr_type
= expr_type_;
42
is_const
= is_const_;
43
is_array
= is_array_;
44
array_size
= array_size_;
45
}
54
Type
() {
55
expr_type
=
ExprType::Unknown
;
56
is_const
=
is_array
=
false
;
57
array_size
= -1;
58
}
66
bool
operator==
(
const
Type
& other)
const
{
67
return
expr_type
== other.
expr_type
&&
is_const
== other.
is_const
&&
is_array
== other.
is_array
&&
array_size
== other.
array_size
;
68
}
76
bool
operator!=
(
const
Type
& other)
const
{
77
return
!(*
this
== other);
78
}
79
};
80
84
struct
Identifier
{
86
std::string
name
;
88
Type
type
;
90
void
*
value
;
94
Identifier
(std::string name_,
Type
type_,
void
* value_ =
nullptr
) {
95
name
= name_;
96
type
= type_;
97
value
= value_;
98
}
106
bool
operator==
(
const
Identifier
& other)
const
{
107
return
type
== other.
type
;
108
}
109
};
110
114
struct
TableIdentifiers
{
116
TableIdentifiers
*
parent
=
nullptr
;
118
std::vector<TableIdentifiers*>
children
;
120
std::unordered_map<std::string, Identifier*>
identifiers
;
126
~TableIdentifiers
() {
127
for
(
auto
& u :
children
) {
128
if
(!
children
.empty())
break
;
129
if
(u !=
nullptr
)
130
delete
u;
131
u =
nullptr
;
132
}
133
for
(
auto
& u :
identifiers
) {
134
if
(!
identifiers
.empty())
break
;
135
if
(u.second !=
nullptr
)
136
delete
u.second;
137
u.second =
nullptr
;
138
}
139
}
140
};
141
145
struct
Function
{
147
std::string
name
;
149
int
not_default_pref
= 0;
151
Type
type
;
153
std::vector<Type>
identifiers
;
155
std::vector<int>
params_init
;
157
std::vector<Identifier*>
params_ptrs
;
159
int
ptr
;
161
TableIdentifiers
*
TID
;
165
Function
(std::string name_,
Type
type_,
TableIdentifiers
* tid_, std::vector<Type> identifiers_, std::vector<int> params_init_, std::vector<Identifier*> params_ptrs_,
166
int
ptr_,
int
not_default_pref_ = 0) {
167
name
= name_;
168
type
= type_;
169
identifiers
= identifiers_;
170
not_default_pref
= not_default_pref_;
171
ptr
= ptr_;
172
params_init
= params_init_;
173
params_ptrs
= params_ptrs_;
174
TID
= tid_;
175
}
183
bool
operator==
(
const
Function
& f)
const
{
184
if
(
identifiers
.size() != f.
identifiers
.size())
return
false
;
185
bool
flag =
true
;
186
for
(
int
i = 0; i <
identifiers
.size(); ++i) {
187
flag &=
identifiers
[i].expr_type == f.
identifiers
[i].expr_type &&
identifiers
[i].is_array == f.
identifiers
[i].is_array;
188
}
189
190
return
name
== f.
name
&& flag;
191
}
192
};
193
195
class
FunctionHasher
{
196
public
:
206
std::size_t
operator()
(
const
Function
& f)
const
{
207
std::size_t seed = f.
identifiers
.size();
208
for
(
auto
& i : f.
identifiers
) {
209
seed ^= std::hash<int>{}((int)i.expr_type + (i.is_array << 8) + (i.array_size << 10)) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
210
}
211
return
std::hash<std::string>{}(f.
name
) ^ (seed + 0x9e3779b9 + (seed << 6) + (seed >> 2));
212
}
213
};
D:
GitHub
AALanguage2
AALanguage
TableIdentifiers.h
Generated by
1.10.0