Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(826)

Side by Side Diff: runtime/vm/object.cc

Issue 24631003: Add proper API for creating private symbols wrt a library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: amend tests Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 static void MarkInvisibleFunctions() { 207 static void MarkInvisibleFunctions() {
208 #define MARK_FUNCTION(lib, class_name, function_name) \ 208 #define MARK_FUNCTION(lib, class_name, function_name) \
209 MarkFunctionAsInvisible(Library::Handle(Library::lib()), \ 209 MarkFunctionAsInvisible(Library::Handle(Library::lib()), \
210 #class_name, #function_name); \ 210 #class_name, #function_name); \
211 211
212 INVISIBLE_LIST(MARK_FUNCTION) 212 INVISIBLE_LIST(MARK_FUNCTION)
213 #undef MARK_FUNCTION 213 #undef MARK_FUNCTION
214 } 214 }
215 215
216
217 // Internal getter and setter prefixes are changed:
218 //
219 // get:foo -> foo
220 // set:foo -> foo=
221 RawString* String::StripAccessorPrefix(const String& name) {
rmacnak 2013/09/27 01:38:27 Yuck. This should at least be refactored so it can
222 intptr_t len = name.Length();
223 intptr_t start = 0;
224 intptr_t at_pos = -1; // Position of '@' in the name, if any.
225 bool is_setter = false;
226
227 for (intptr_t i = start; i < len; i++) {
228 if (name.CharAt(i) == ':') {
229 ASSERT(start == 0); // Only one : is possible in getters or setters.
230 if (name.CharAt(0) == 's') {
231 is_setter = true;
232 }
233 start = i + 1;
234 } else if (name.CharAt(i) == '@') {
235 ASSERT(at_pos == -1); // Only one @ is supported.
236 at_pos = i;
237 }
238 }
239
240 if (start == 0) {
241 // This unmangled_name is fine as it is.
242 return name.raw();
243 }
244
245 String& result =
246 String::Handle(String::SubString(name, start, (len - start)));
247
248 if (is_setter) {
249 // Setters need to end with '='.
250 if (at_pos == -1) {
251 return String::Concat(result, Symbols::Equals());
252 } else {
253 String& pre_at =
254 String::Handle(String::SubString(result, 0, at_pos - 4));
255 String& post_at =
256 String::Handle(String::SubString(name, at_pos, len - at_pos));
257 result = String::Concat(pre_at, Symbols::Equals());
258 result = String::Concat(result, post_at);
259 }
260 }
261
262 return result.raw();
263 }
264
265 RawString* String::StripPrivateMangling(const String& name) {
266 return name.raw();
267 }
268
269
216 // Takes a vm internal name and makes it suitable for external user. 270 // Takes a vm internal name and makes it suitable for external user.
217 // 271 //
218 // Examples: 272 // Examples:
219 // 273 //
220 // Internal getter and setter prefixes are changed: 274 // Internal getter and setter prefixes are changed:
221 // 275 //
222 // get:foo -> foo 276 // get:foo -> foo
223 // set:foo -> foo= 277 // set:foo -> foo=
224 // 278 //
225 // Private name mangling is removed, possibly multiple times: 279 // Private name mangling is removed, possibly multiple times:
226 // 280 //
227 // _ReceivePortImpl@6be832b -> _ReceivePortImpl 281 // _ReceivePortImpl@6be832b -> _ReceivePortImpl
228 // _ReceivePortImpl@6be832b._internal@6be832b -> _ReceivePortImpl._internal 282 // _ReceivePortImpl@6be832b._internal@6be832b -> _ReceivePortImpl._internal
229 // _C@0x2b4ab9cc&_E@0x2b4ab9cc&_F@0x2b4ab9cc -> _C&_E&_F 283 // _C@0x2b4ab9cc&_E@0x2b4ab9cc&_F@0x2b4ab9cc -> _C&_E&_F
230 // 284 //
231 // The trailing . on the default constructor name is dropped: 285 // The trailing . on the default constructor name is dropped:
232 // 286 //
233 // List. -> List 287 // List. -> List
234 // 288 //
235 // And so forth: 289 // And so forth:
236 // 290 //
237 // get:foo@6be832b -> foo 291 // get:foo@6be832b -> foo
238 // _MyClass@6b3832b. -> _MyClass 292 // _MyClass@6b3832b. -> _MyClass
239 // _MyClass@6b3832b.named -> _MyClass.named 293 // _MyClass@6b3832b.named -> _MyClass.named
240 // 294 //
241 static RawString* IdentifierPrettyName(const String& name) { 295 RawString* String::IdentifierPrettyName(const String& name) {
242 if (name.Equals(Symbols::TopLevel())) { 296 if (name.Equals(Symbols::TopLevel())) {
243 // Name of invisible top-level class. 297 // Name of invisible top-level class.
244 return Symbols::Empty().raw(); 298 return Symbols::Empty().raw();
245 } 299 }
246 300
247 // First remove all private name mangling. 301 // First remove all private name mangling.
248 String& unmangled_name = String::Handle(Symbols::Empty().raw()); 302 String& unmangled_name = String::Handle(Symbols::Empty().raw());
249 String& segment = String::Handle(); 303 String& segment = String::Handle();
250 intptr_t start_pos = 0; 304 intptr_t start_pos = 0;
251 for (intptr_t i = 0; i < name.Length(); i++) { 305 for (intptr_t i = 0; i < name.Length(); i++) {
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 return Symbols::Float32x4List().raw(); 1532 return Symbols::Float32x4List().raw();
1479 case kTypedDataFloat32ArrayCid: 1533 case kTypedDataFloat32ArrayCid:
1480 case kExternalTypedDataFloat32ArrayCid: 1534 case kExternalTypedDataFloat32ArrayCid:
1481 return Symbols::Float32List().raw(); 1535 return Symbols::Float32List().raw();
1482 case kTypedDataFloat64ArrayCid: 1536 case kTypedDataFloat64ArrayCid:
1483 case kExternalTypedDataFloat64ArrayCid: 1537 case kExternalTypedDataFloat64ArrayCid:
1484 return Symbols::Float64List().raw(); 1538 return Symbols::Float64List().raw();
1485 default: 1539 default:
1486 if (!IsSignatureClass()) { 1540 if (!IsSignatureClass()) {
1487 const String& name = String::Handle(Name()); 1541 const String& name = String::Handle(Name());
1488 return IdentifierPrettyName(name); 1542 return String::IdentifierPrettyName(name);
1489 } else { 1543 } else {
1490 return Name(); 1544 return Name();
1491 } 1545 }
1492 } 1546 }
1493 UNREACHABLE(); 1547 UNREACHABLE();
1494 } 1548 }
1495 1549
1496 1550
1497 RawType* Class::SignatureType() const { 1551 RawType* Class::SignatureType() const {
1498 ASSERT(IsSignatureClass()); 1552 ASSERT(IsSignatureClass());
(...skipping 3544 matching lines...) Expand 10 before | Expand all | Expand 10 after
5043 } 5097 }
5044 5098
5045 5099
5046 bool Function::HasOptimizedCode() const { 5100 bool Function::HasOptimizedCode() const {
5047 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized(); 5101 return HasCode() && Code::Handle(raw_ptr()->code_).is_optimized();
5048 } 5102 }
5049 5103
5050 5104
5051 RawString* Function::UserVisibleName() const { 5105 RawString* Function::UserVisibleName() const {
5052 const String& str = String::Handle(name()); 5106 const String& str = String::Handle(name());
5053 return IdentifierPrettyName(str); 5107 return String::IdentifierPrettyName(str);
5054 } 5108 }
5055 5109
5056 5110
5057 RawString* Function::QualifiedUserVisibleName() const { 5111 RawString* Function::QualifiedUserVisibleName() const {
5058 String& tmp = String::Handle(); 5112 String& tmp = String::Handle();
5059 const Class& cls = Class::Handle(Owner()); 5113 const Class& cls = Class::Handle(Owner());
5060 5114
5061 if (IsClosureFunction()) { 5115 if (IsClosureFunction()) {
5062 if (IsLocalFunction() && !IsImplicitClosureFunction()) { 5116 if (IsLocalFunction() && !IsImplicitClosureFunction()) {
5063 const Function& parent = Function::Handle(parent_function()); 5117 const Function& parent = Function::Handle(parent_function());
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
5460 clone.set_dependent_code(Object::null_array()); 5514 clone.set_dependent_code(Object::null_array());
5461 if (!clone.is_static()) { 5515 if (!clone.is_static()) {
5462 clone.SetOffset(0); 5516 clone.SetOffset(0);
5463 } 5517 }
5464 return clone.raw(); 5518 return clone.raw();
5465 } 5519 }
5466 5520
5467 5521
5468 RawString* Field::UserVisibleName() const { 5522 RawString* Field::UserVisibleName() const {
5469 const String& str = String::Handle(name()); 5523 const String& str = String::Handle(name());
5470 return IdentifierPrettyName(str); 5524 return String::IdentifierPrettyName(str);
5471 } 5525 }
5472 5526
5473 5527
5474 intptr_t Field::guarded_list_length() const { 5528 intptr_t Field::guarded_list_length() const {
5475 return Smi::Value(raw_ptr()->guarded_list_length_); 5529 return Smi::Value(raw_ptr()->guarded_list_length_);
5476 } 5530 }
5477 5531
5478 5532
5479 void Field::set_guarded_list_length(intptr_t list_length) const { 5533 void Field::set_guarded_list_length(intptr_t list_length) const {
5480 raw_ptr()->guarded_list_length_ = Smi::New(list_length); 5534 raw_ptr()->guarded_list_length_ = Smi::New(list_length);
(...skipping 9684 matching lines...) Expand 10 before | Expand all | Expand 10 after
15165 return "_MirrorReference"; 15219 return "_MirrorReference";
15166 } 15220 }
15167 15221
15168 15222
15169 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15223 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15170 JSONObject jsobj(stream); 15224 JSONObject jsobj(stream);
15171 } 15225 }
15172 15226
15173 15227
15174 } // namespace dart 15228 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/resolver.h » ('j') | tests/lib/lib.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698