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

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: amend tests Created 7 years, 3 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 3d06df2278a2a6ae290817d2d91c0804c74117b0..1a22c3d5399bf25c98b052fedb366503b7b77506 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -213,6 +213,60 @@ INVISIBLE_LIST(MARK_FUNCTION)
#undef MARK_FUNCTION
}
+
+// Internal getter and setter prefixes are changed:
+//
+// get:foo -> foo
+// set:foo -> foo=
+RawString* String::StripAccessorPrefix(const String& name) {
rmacnak 2013/09/27 01:38:27 Yuck. This should at least be refactored so it can
+ 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));
+ result = String::Concat(pre_at, Symbols::Equals());
+ result = String::Concat(result, post_at);
+ }
+ }
+
+ return result.raw();
+}
+
+RawString* String::StripPrivateMangling(const String& name) {
+ return name.raw();
+}
+
+
// Takes a vm internal name and makes it suitable for external user.
//
// Examples:
@@ -238,7 +292,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();
@@ -1485,7 +1539,7 @@ RawString* Class::UserVisibleName() const {
default:
if (!IsSignatureClass()) {
const String& name = String::Handle(Name());
- return IdentifierPrettyName(name);
+ return String::IdentifierPrettyName(name);
} else {
return Name();
}
@@ -5050,7 +5104,7 @@ bool Function::HasOptimizedCode() const {
RawString* Function::UserVisibleName() const {
const String& str = String::Handle(name());
- return IdentifierPrettyName(str);
+ return String::IdentifierPrettyName(str);
}
@@ -5467,7 +5521,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);
}
« 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