-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.cpp
More file actions
245 lines (204 loc) · 6.96 KB
/
Copy pathtype.cpp
File metadata and controls
245 lines (204 loc) · 6.96 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
Copyright (C) 2015-present The DotCpp Authors.
This file is part of .C++, a native C++ implementation of
popular .NET class library APIs developed to facilitate
code reuse between C# and C++.
http://github.com/dotcpp/dotcpp (source)
http://dotcpp.org (documentation)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <dot/precompiled.hpp>
#include <dot/implement.hpp>
#include <dot/system/type.hpp>
#include <dot/system/object_impl.hpp>
#include <dot/system/reflection/method_info.hpp>
#include <dot/system/reflection/constructor_info.hpp>
#include <dot/system/collections/generic/list.hpp>
#include <dot/system/string.hpp>
namespace dot
{
/// Built type_t from the current object.
type_t type_builder_impl::build()
{
type_->fill(this);
// Fill derived types map
type_t base_type = base_;
while (base_type != nullptr)
{
auto iter = type_impl::get_derived_types_map().find(base_type->full_name());
if (iter == type_impl::get_derived_types_map().end())
{
iter = type_impl::get_derived_types_map().insert({base_type->full_name(), make_list<type_t>()}).first;
}
else if (iter->second == nullptr)
{
iter->second = make_list<type_t>();
}
iter->second->add(type_);
base_type = base_type->base_type();
}
return type_;
}
/// Fill data from builder.
void type_impl::fill(const type_builder& data)
{
if (!data->base_.is_empty() && !data->base_->get_methods().is_empty() && data->base_->get_methods()->count())
{
if (data->methods_.is_empty())
{
data->methods_ = make_list<method_info>();
}
list<method_info> base_methods = data->base_->get_methods();
list<method_info> make_methods = make_list<method_info>();
for (method_info meth_info_data : base_methods)
{
make_methods->add(meth_info_data);
}
for (method_info meth_info_data : data->methods_)
{
make_methods->add(meth_info_data);
}
data->methods_ = make_methods;
}
if (!data->methods_.is_empty())
{
this->methods_ = make_list<method_info>(data->methods_->count());
int i = 0;
for (method_info meth_info_data : data->methods_)
{
this->methods_[i++] = meth_info_data;
}
}
else
this->methods_ = make_list<method_info>(0);
if (!data->ctors_.is_empty())
{
this->ctors_ = make_list<constructor_info>(data->ctors_->count());
int i = 0;
for (constructor_info ctor_info_data : data->ctors_)
{
this->ctors_[i++] = ctor_info_data;
}
}
else
this->ctors_ = make_list<constructor_info>(0);
if (!data->base_.is_empty() && !data->base_->get_fields().is_empty() && data->base_->get_fields()->count())
{
if (data->fields_.is_empty())
{
data->fields_ = make_list<field_info>();
}
list<field_info> base_fields = data->base_->get_fields();
list<field_info> make_fields = make_list<field_info>();
for (field_info field_info_data : base_fields)
{
make_fields->add(field_info_data);
}
for (field_info field_info_data : data->fields_)
{
make_fields->add(field_info_data);
}
data->fields_ = make_fields;
}
if (!data->fields_.is_empty())
{
this->fields_ = make_list<field_info>(data->fields_->count());
int i = 0;
for (field_info ctor_info_data : data->fields_)
{
this->fields_[i++] = ctor_info_data;
}
}
else
this->fields_ = make_list<field_info>(0);
if (!data->interfaces_.is_empty())
{
this->interfaces_ = make_list<type_t>(data->interfaces_->count());
int i = 0;
for (type_t interface : data->interfaces_)
{
this->interfaces_[i++] = interface;
}
}
else
this->interfaces_ = make_list<type_t>(0);
if (!data->generic_args_.is_empty())
{
this->generic_args_ = make_list<type_t>(data->generic_args_->count());
int i = 0;
for (type_t arg : data->generic_args_)
{
this->generic_args_[i++] = arg;
}
}
else
this->generic_args_ = make_list<type_t>(0);
this->base_ = data->base_;
this->is_class = data->is_class_;
this->is_enum = data->is_enum_;
}
/// Create from builder.
///
/// This constructor is private. Use type_builder->build() method instead.
type_impl::type_impl(string nspace, string name)
{
this->name_space = nspace;
this->name = name;
}
type_builder_impl::type_builder_impl(string name_space, string name, string cpp_name)
: full_name_(name_space + "." + name)
{
type_ = new type_impl(name_space, name);
type_impl::get_type_map()[full_name_] = type_;
type_impl::get_type_map()[name] = type_;
type_impl::get_type_map()[cpp_name] = type_;
}
method_info type_impl::get_method(string name)
{
if (methods_.is_empty()) return nullptr;
for (auto method : methods_)
{
if (method->name == name)
return method;
}
return nullptr;
}
type_t type_impl::get_interface(string name)
{
if (interfaces_.is_empty()) return nullptr;
for (auto interface : interfaces_)
{
if (interface->name == name)
return interface;
}
return nullptr;
}
field_info type_impl::get_field(string name)
{
if (fields_.is_empty()) return nullptr;
for (auto field : fields_)
{
if (field->name == name)
return field;
}
return nullptr;
}
bool type_impl::equals(object obj)
{
if (obj.is<type_t>())
return this->full_name() == ((type_t)obj)->full_name();
return false;
}
size_t type_impl::hash_code()
{
return this->full_name()->hash_code();
}
}