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

Unified 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: rebase 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index e25cbe99cfb52ebce4df24f15d906e3939e0f8a4..c5c78208cc48d12b422bc163d04137c6e90e347b 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 {
+ const String& pre_at =
+ String::Handle(String::SubString(result, 0, at_pos - 4));
+ const String& post_at =
+ String::Handle(String::SubString(name, at_pos, len - at_pos));
+ 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();
}
@@ -5089,7 +5135,7 @@ bool Function::HasOptimizedCode() const {
RawString* Function::UserVisibleName() const {
const String& str = String::Handle(name());
- return IdentifierPrettyName(str);
+ return String::IdentifierPrettyName(str);
}
@@ -5506,7 +5552,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);
}

Powered by Google App Engine
This is Rietveld 408576698