OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 | 181 |
182 // Takes a vm internal name and makes it suitable for external user. | 182 // Takes a vm internal name and makes it suitable for external user. |
183 // | 183 // |
184 // Examples: | 184 // Examples: |
185 // | 185 // |
186 // Internal getter and setter prefixes are changed: | 186 // Internal getter and setter prefixes are changed: |
187 // | 187 // |
188 // get:foo -> foo | 188 // get:foo -> foo |
189 // set:foo -> foo= | 189 // set:foo -> foo= |
190 // | 190 // |
191 // Private name mangling is removed, possibly twice: | 191 // Private name mangling is removed, possibly multiple times: |
192 // | 192 // |
193 // _ReceivePortImpl@6be832b -> _ReceivePortImpl | 193 // _ReceivePortImpl@6be832b -> _ReceivePortImpl |
194 // _ReceivePortImpl@6be832b._internal@6be832b -> +ReceivePortImpl._internal | 194 // _ReceivePortImpl@6be832b._internal@6be832b -> _ReceivePortImpl._internal |
195 // _C@0x2b4ab9cc&_E@0x2b4ab9cc&_F@0x2b4ab9cc -> _C&_E&_F | |
195 // | 196 // |
196 // The trailing . on the default constructor name is dropped: | 197 // The trailing . on the default constructor name is dropped: |
197 // | 198 // |
198 // List. -> List | 199 // List. -> List |
199 // | 200 // |
200 // And so forth: | 201 // And so forth: |
201 // | 202 // |
202 // get:foo@6be832b -> foo | 203 // get:foo@6be832b -> foo |
203 // _MyClass@6b3832b. -> _MyClass | 204 // _MyClass@6b3832b. -> _MyClass |
204 // _MyClass@6b3832b.named -> _MyClass.named | 205 // _MyClass@6b3832b.named -> _MyClass.named |
205 // | 206 // |
206 static RawString* IdentifierPrettyName(const String& name) { | 207 static RawString* IdentifierPrettyName(const String& name) { |
207 intptr_t len = name.Length(); | |
208 intptr_t start = 0; | |
209 intptr_t at_pos = len; // Position of '@' in the name. | |
210 intptr_t dot_pos = len; // Position of '.' in the name. | |
211 bool is_setter = false; | |
212 | |
213 if (name.Equals(Symbols::TopLevel())) { | 208 if (name.Equals(Symbols::TopLevel())) { |
214 // Name of invisible top-level class. | 209 // Name of invisible top-level class. |
215 return Symbols::Empty().raw(); | 210 return Symbols::Empty().raw(); |
216 } | 211 } |
217 for (int i = start; i < name.Length(); i++) { | 212 |
218 if (name.CharAt(i) == ':') { | 213 // First remove all private name mangling. |
219 ASSERT(start == 0); | 214 String& unmangled_name = String::Handle(Symbols::Empty().raw()); |
220 if (name.CharAt(0) == 's') { | 215 String& segment = String::Handle(); |
216 intptr_t start_pos = 0; | |
217 for (intptr_t i = 0; i < name.Length(); i++) { | |
218 if (name.CharAt(i) == '@') { | |
219 // Append the current segment to the unmangled name. | |
220 segment = String::SubString(name, start_pos, (i - start_pos)); | |
221 unmangled_name = String::Concat(unmangled_name, segment); | |
222 | |
223 // Advance until past the name mangling. | |
224 i++; // Skip the '@'. | |
225 while ((i < name.Length()) && | |
226 (name.CharAt(i) != '&') && | |
227 (name.CharAt(i) != '.')) { | |
228 i++; | |
229 } | |
230 start_pos = i; | |
231 i--; // Account for for-loop increment. | |
hausner
2013/07/03 16:24:58
DBC: Drop the 'for', just use 'while'. It's cleane
| |
232 } | |
233 } | |
234 if (start_pos == 0) { | |
235 // No name unmangling needed, reuse the name that was passed in. | |
236 unmangled_name = name.raw(); | |
237 } else if (name.Length() != start_pos) { | |
238 // Append the last segment. | |
239 segment = String::SubString(name, start_pos, (name.Length() - start_pos)); | |
240 unmangled_name = String::Concat(unmangled_name, segment); | |
241 } | |
242 | |
243 intptr_t len = unmangled_name.Length(); | |
244 intptr_t start = 0; | |
245 intptr_t dot_pos = -1; // Position of '.' in the name, if any. | |
246 bool is_setter = false; | |
247 | |
248 for (intptr_t i = start; i < len; i++) { | |
249 if (unmangled_name.CharAt(i) == ':') { | |
250 ASSERT(start == 0); // Only one : is possible in getters or setters. | |
251 if (unmangled_name.CharAt(0) == 's') { | |
221 is_setter = true; | 252 is_setter = true; |
222 } | 253 } |
223 start = i + 1; | 254 start = i + 1; |
224 } else if (name.CharAt(i) == '@') { | 255 } else if (unmangled_name.CharAt(i) == '.') { |
225 ASSERT(at_pos == len); | 256 ASSERT(dot_pos == -1); // Only one dot is supported. |
hausner
2013/07/03 16:24:58
What about the case of a qualified (imported) memb
| |
226 at_pos = i; | |
227 } else if (name.CharAt(i) == '.') { | |
228 dot_pos = i; | 257 dot_pos = i; |
229 break; | |
230 } | |
231 } | |
232 intptr_t limit = (at_pos < dot_pos ? at_pos : dot_pos); | |
233 if (start == 0 && limit == len) { | |
234 // This name is fine as it is. | |
235 return name.raw(); | |
236 } | |
237 | |
238 const String& result = | |
239 String::Handle(String::SubString(name, start, (limit - start))); | |
240 | |
241 // Look for a second '@' now to correctly handle names like | |
242 // "_ReceivePortImpl@6be832b._internal@6be832b". | |
243 at_pos = len; | |
244 for (int i = dot_pos; i < name.Length(); i++) { | |
245 if (name.CharAt(i) == '@') { | |
246 ASSERT(at_pos == len); | |
247 at_pos = i; | |
248 } | 258 } |
249 } | 259 } |
250 | 260 |
251 intptr_t suffix_len = at_pos - dot_pos; | 261 if ((start == 0) && (dot_pos == -1)) { |
252 if (suffix_len > 1) { | 262 // This unmangled_name is fine as it is. |
253 // This is a named constructor. Add the name back to the string. | 263 return unmangled_name.raw(); |
254 const String& suffix = | |
255 String::Handle(String::SubString(name, dot_pos, suffix_len)); | |
256 return String::Concat(result, suffix); | |
257 } | 264 } |
258 | 265 |
266 // Drop the trailing dot if needed. | |
267 intptr_t end = ((dot_pos + 1) == len) ? dot_pos : len; | |
268 | |
269 const String& result = | |
270 String::Handle(String::SubString(unmangled_name, start, (end - start))); | |
271 | |
259 if (is_setter) { | 272 if (is_setter) { |
260 // Setters need to end with '='. | 273 // Setters need to end with '='. |
261 return String::Concat(result, Symbols::Equals()); | 274 return String::Concat(result, Symbols::Equals()); |
262 } | 275 } |
263 | 276 |
264 return result.raw(); | 277 return result.raw(); |
265 } | 278 } |
266 | 279 |
267 | 280 |
268 template<typename type> | 281 template<typename type> |
(...skipping 13431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13700 return reinterpret_cast<RawMirrorReference*>(raw); | 13713 return reinterpret_cast<RawMirrorReference*>(raw); |
13701 } | 13714 } |
13702 | 13715 |
13703 | 13716 |
13704 const char* MirrorReference::ToCString() const { | 13717 const char* MirrorReference::ToCString() const { |
13705 return "_MirrorReference"; | 13718 return "_MirrorReference"; |
13706 } | 13719 } |
13707 | 13720 |
13708 | 13721 |
13709 } // namespace dart | 13722 } // namespace dart |
OLD | NEW |