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

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

Issue 10687004: Implement method and variable reflection in dart:mirrors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 } 1924 }
1925 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { 1925 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) {
1926 if (name.CharAt(j) != accessor_name.CharAt(i)) { 1926 if (name.CharAt(j) != accessor_name.CharAt(i)) {
1927 return false; 1927 return false;
1928 } 1928 }
1929 } 1929 }
1930 return true; 1930 return true;
1931 } 1931 }
1932 1932
1933 1933
1934 static bool MatchesPrivateName(const String& name, const String& private_name) { 1934 // Check to see if munged_name is equal to bare_name once the private
cshapiro 2012/06/28 23:57:47 Maybe just make this an equality test and eliminat
turnidge 2012/07/09 23:45:17 Done.
1935 intptr_t name_len = name.Length(); 1935 // key separator is stripped from munged_name.
1936 intptr_t private_len = private_name.Length(); 1936 //
1937 // The private_name must at least have room for the separator and one key 1937 // If there is no private key separator in munged name, the function
1938 // character. 1938 // returns false even if the strings are identical.
1939 if ((name_len < (private_len + 2)) || (name_len == 0) || (private_len == 0)) { 1939 //
1940 // Things are made more complicated by the fact that constructors are
1941 // added *after* the private suffix, so "foo@123.named" should match
1942 // "foo.named".
1943 //
1944 // Also, the private suffix can occur more than once in the name, as in:
1945 //
1946 // _ReceivePortImpl@6be832b._internal@6be832b
1947 //
1948 bool MatchesIgnorePrivate(const String& munged_name, const String& bare_name) {
cshapiro 2012/06/28 23:57:47 Ignoring? Mangled?
turnidge 2012/07/09 23:45:17 Done.
1949 intptr_t munged_len = munged_name.Length();
1950 intptr_t bare_len = bare_name.Length();
1951 if (munged_len <= bare_len) {
1952 // No way they can match.
1940 return false; 1953 return false;
1941 } 1954 }
1942 1955
1943 // Check for the private key separator. 1956 bool found_private_key = false;
1944 if (name.CharAt(private_len) != Scanner::kPrivateKeySeparator) { 1957 intptr_t munged_pos = 0;
1945 return false; 1958 intptr_t bare_pos = 0;
1959 while (munged_pos < munged_len) {
1960 int32_t munged_char = munged_name.CharAt(munged_pos);
1961 munged_pos++;
1962
1963 if (munged_char == Scanner::kPrivateKeySeparator) {
1964 // Consume a private key separator.
1965 while (munged_pos < munged_len &&
1966 munged_name.CharAt(munged_pos) != '.') {
1967 munged_pos++;
1968 }
1969 found_private_key = true;
1970
1971 // Resume matching characters.
1972 continue;
1973 }
1974 if (bare_pos == bare_len || munged_char != bare_name.CharAt(bare_pos)) {
1975 return false;
1976 }
1977 bare_pos++;
1946 } 1978 }
1947 1979
1948 for (intptr_t i = 0; i < private_len; i++) { 1980 // The strings match if we found the private key and we reached the
1949 if (name.CharAt(i) != private_name.CharAt(i)) { 1981 // end of both strings.
1950 return false; 1982 return (found_private_key &&
1951 } 1983 munged_pos == munged_len &&
1952 } 1984 bare_pos == bare_len);
1953 return true;
1954 } 1985 }
1955 1986
1956 1987
1957 RawFunction* Class::LookupFunction(const String& name) const { 1988 RawFunction* Class::LookupFunction(const String& name) const {
1958 Isolate* isolate = Isolate::Current(); 1989 Isolate* isolate = Isolate::Current();
1959 Array& funcs = Array::Handle(isolate, functions()); 1990 Array& funcs = Array::Handle(isolate, functions());
1960 Function& function = Function::Handle(isolate, Function::null()); 1991 Function& function = Function::Handle(isolate, Function::null());
1961 String& function_name = String::Handle(isolate, String::null()); 1992 String& function_name = String::Handle(isolate, String::null());
1962 intptr_t len = funcs.Length(); 1993 intptr_t len = funcs.Length();
1963 for (intptr_t i = 0; i < len; i++) { 1994 for (intptr_t i = 0; i < len; i++) {
1964 function ^= funcs.At(i); 1995 function ^= funcs.At(i);
1965 function_name ^= function.name(); 1996 function_name ^= function.name();
1966 if (function_name.Equals(name) || MatchesPrivateName(function_name, name)) { 1997 if (function_name.Equals(name) ||
1998 MatchesIgnorePrivate(function_name, name)) {
1967 return function.raw(); 1999 return function.raw();
1968 } 2000 }
1969 } 2001 }
1970 2002
1971 // No function found. 2003 // No function found.
1972 return Function::null(); 2004 return Function::null();
1973 } 2005 }
1974 2006
1975 2007
1976 RawFunction* Class::LookupGetterFunction(const String& name) const { 2008 RawFunction* Class::LookupGetterFunction(const String& name) const {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 2090
2059 RawField* Class::LookupField(const String& name) const { 2091 RawField* Class::LookupField(const String& name) const {
2060 Isolate* isolate = Isolate::Current(); 2092 Isolate* isolate = Isolate::Current();
2061 const Array& flds = Array::Handle(isolate, fields()); 2093 const Array& flds = Array::Handle(isolate, fields());
2062 Field& field = Field::Handle(isolate, Field::null()); 2094 Field& field = Field::Handle(isolate, Field::null());
2063 String& field_name = String::Handle(isolate, String::null()); 2095 String& field_name = String::Handle(isolate, String::null());
2064 intptr_t len = flds.Length(); 2096 intptr_t len = flds.Length();
2065 for (intptr_t i = 0; i < len; i++) { 2097 for (intptr_t i = 0; i < len; i++) {
2066 field ^= flds.At(i); 2098 field ^= flds.At(i);
2067 field_name ^= field.name(); 2099 field_name ^= field.name();
2068 if (field_name.Equals(name) || MatchesPrivateName(field_name, name)) { 2100 if (field_name.Equals(name) || MatchesIgnorePrivate(field_name, name)) {
2069 return field.raw(); 2101 return field.raw();
2070 } 2102 }
2071 } 2103 }
2072 // No field found. 2104 // No field found.
2073 return Field::null(); 2105 return Field::null();
2074 } 2106 }
2075 2107
2076 2108
2077 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { 2109 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const {
2078 Isolate* isolate = Isolate::Current(); 2110 Isolate* isolate = Isolate::Current();
(...skipping 8137 matching lines...) Expand 10 before | Expand all | Expand 10 after
10216 const String& str = String::Handle(pattern()); 10248 const String& str = String::Handle(pattern());
10217 const char* format = "JSRegExp: pattern=%s flags=%s"; 10249 const char* format = "JSRegExp: pattern=%s flags=%s";
10218 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10250 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10219 char* chars = reinterpret_cast<char*>( 10251 char* chars = reinterpret_cast<char*>(
10220 Isolate::Current()->current_zone()->Allocate(len + 1)); 10252 Isolate::Current()->current_zone()->Allocate(len + 1));
10221 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10253 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10222 return chars; 10254 return chars;
10223 } 10255 }
10224 10256
10225 } // namespace dart 10257 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698