Index: runtime/vm/object.cc |
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
index f25f106c3a0ca8e11e0d3a6daef9e46e0c15172f..051cb042da6e2a14544f47298daafbed961e361e 100644 |
--- a/runtime/vm/object.cc |
+++ b/runtime/vm/object.cc |
@@ -213,6 +213,7 @@ INVISIBLE_LIST(MARK_FUNCTION) |
#undef MARK_FUNCTION |
} |
+ |
// Takes a vm internal name and makes it suitable for external user. |
// |
// Examples: |
@@ -238,7 +239,7 @@ INVISIBLE_LIST(MARK_FUNCTION) |
// _MyClass@6b3832b. -> _MyClass |
// _MyClass@6b3832b.named -> _MyClass.named |
// |
-static RawString* IdentifierPrettyName(const String& name) { |
+RawString* String::IdentifierPrettyName(const String& name) { |
if (name.Equals(Symbols::TopLevel())) { |
// Name of invisible top-level class. |
return Symbols::Empty().raw(); |
@@ -312,6 +313,51 @@ static RawString* IdentifierPrettyName(const String& name) { |
} |
+RawString* String::IdentifierPrettyNameRetainPrivate(const String& name) { |
+ intptr_t len = name.Length(); |
+ intptr_t start = 0; |
+ intptr_t at_pos = -1; // Position of '@' in the name, if any. |
+ bool is_setter = false; |
+ |
+ for (intptr_t i = start; i < len; i++) { |
+ if (name.CharAt(i) == ':') { |
+ ASSERT(start == 0); // Only one : is possible in getters or setters. |
+ if (name.CharAt(0) == 's') { |
+ is_setter = true; |
+ } |
+ start = i + 1; |
+ } else if (name.CharAt(i) == '@') { |
+ ASSERT(at_pos == -1); // Only one @ is supported. |
+ at_pos = i; |
+ } |
+ } |
+ |
+ if (start == 0) { |
+ // This unmangled_name is fine as it is. |
+ return name.raw(); |
+ } |
+ |
+ String& result = |
+ String::Handle(String::SubString(name, start, (len - start))); |
+ |
+ if (is_setter) { |
+ // Setters need to end with '='. |
+ if (at_pos == -1) { |
+ return String::Concat(result, Symbols::Equals()); |
+ } else { |
+ String& pre_at = |
+ String::Handle(String::SubString(result, 0, at_pos - 4)); |
+ String& post_at = |
+ String::Handle(String::SubString(name, at_pos, len - at_pos)); |
siva
2013/09/30 23:47:12
const String& pre_at = .....;
const String* post_a
|
+ result = String::Concat(pre_at, Symbols::Equals()); |
+ result = String::Concat(result, post_at); |
+ } |
+ } |
+ |
+ return result.raw(); |
+} |
+ |
+ |
template<typename type> |
static bool IsSpecialCharacter(type value) { |
return ((value == '"') || |
@@ -1488,7 +1534,7 @@ RawString* Class::UserVisibleName() const { |
default: |
if (!IsSignatureClass()) { |
const String& name = String::Handle(Name()); |
- return IdentifierPrettyName(name); |
+ return String::IdentifierPrettyName(name); |
} else { |
return Name(); |
} |
@@ -5059,7 +5105,7 @@ bool Function::HasOptimizedCode() const { |
RawString* Function::UserVisibleName() const { |
const String& str = String::Handle(name()); |
- return IdentifierPrettyName(str); |
+ return String::IdentifierPrettyName(str); |
} |
@@ -5476,7 +5522,7 @@ RawField* Field::Clone(const Class& new_owner) const { |
RawString* Field::UserVisibleName() const { |
const String& str = String::Handle(name()); |
- return IdentifierPrettyName(str); |
+ return String::IdentifierPrettyName(str); |
} |