OLD | NEW |
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 transition_sentinel ^= | 314 transition_sentinel ^= |
315 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); | 315 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); |
316 transition_sentinel_ = transition_sentinel.raw(); | 316 transition_sentinel_ = transition_sentinel.raw(); |
317 } | 317 } |
318 | 318 |
319 // The interface "Dynamic" is not a VM internal class. It is the type class of | 319 // The interface "Dynamic" is not a VM internal class. It is the type class of |
320 // the "unknown type". For efficiency, we allocate it in the VM isolate. | 320 // the "unknown type". For efficiency, we allocate it in the VM isolate. |
321 // Therefore, it cannot have a heap allocated name (the name is hard coded, | 321 // Therefore, it cannot have a heap allocated name (the name is hard coded, |
322 // see GetSingletonClassIndex) and its array fields cannot be set to the empty | 322 // see GetSingletonClassIndex) and its array fields cannot be set to the empty |
323 // array, but remain null. | 323 // array, but remain null. |
| 324 // |
| 325 // TODO(turnidge): Once the empty array is allocated in the vm |
| 326 // isolate, use it here. |
324 cls = Class::New<Instance>(kDynamicClassId); | 327 cls = Class::New<Instance>(kDynamicClassId); |
325 cls.set_is_finalized(); | 328 cls.set_is_finalized(); |
326 cls.set_is_interface(); | 329 cls.set_is_interface(); |
327 dynamic_class_ = cls.raw(); | 330 dynamic_class_ = cls.raw(); |
328 | 331 |
329 // Allocate the remaining VM internal classes. | 332 // Allocate the remaining VM internal classes. |
330 cls = Class::New<UnresolvedClass>(); | 333 cls = Class::New<UnresolvedClass>(); |
331 unresolved_class_class_ = cls.raw(); | 334 unresolved_class_class_ = cls.raw(); |
332 | 335 |
333 cls = Class::New<Instance>(kVoidClassId); | 336 cls = Class::New<Instance>(kVoidClassId); |
(...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1918 } | 1921 } |
1919 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { | 1922 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { |
1920 if (name.CharAt(j) != accessor_name.CharAt(i)) { | 1923 if (name.CharAt(j) != accessor_name.CharAt(i)) { |
1921 return false; | 1924 return false; |
1922 } | 1925 } |
1923 } | 1926 } |
1924 return true; | 1927 return true; |
1925 } | 1928 } |
1926 | 1929 |
1927 | 1930 |
1928 static bool MatchesPrivateName(const String& name, const String& private_name) { | 1931 // Check to see if mangled_name is equal to bare_name once the private |
1929 intptr_t name_len = name.Length(); | 1932 // key separator is stripped from mangled_name. |
1930 intptr_t private_len = private_name.Length(); | 1933 // |
1931 // The private_name must at least have room for the separator and one key | 1934 // Things are made more complicated by the fact that constructors are |
1932 // character. | 1935 // added *after* the private suffix, so "foo@123.named" should match |
1933 if ((name_len < (private_len + 2)) || (name_len == 0) || (private_len == 0)) { | 1936 // "foo.named". |
| 1937 // |
| 1938 // Also, the private suffix can occur more than once in the name, as in: |
| 1939 // |
| 1940 // _ReceivePortImpl@6be832b._internal@6be832b |
| 1941 // |
| 1942 bool EqualsIgnoringPrivate(const String& mangled_name, |
| 1943 const String& bare_name) { |
| 1944 intptr_t mangled_len = mangled_name.Length(); |
| 1945 intptr_t bare_len = bare_name.Length(); |
| 1946 if (mangled_len < bare_len) { |
| 1947 // No way they can match. |
1934 return false; | 1948 return false; |
1935 } | 1949 } |
1936 | 1950 |
1937 // Check for the private key separator. | 1951 intptr_t mangled_pos = 0; |
1938 if (name.CharAt(private_len) != Scanner::kPrivateKeySeparator) { | 1952 intptr_t bare_pos = 0; |
1939 return false; | 1953 while (mangled_pos < mangled_len) { |
| 1954 int32_t mangled_char = mangled_name.CharAt(mangled_pos); |
| 1955 mangled_pos++; |
| 1956 |
| 1957 if (mangled_char == Scanner::kPrivateKeySeparator) { |
| 1958 // Consume a private key separator. |
| 1959 while (mangled_pos < mangled_len && |
| 1960 mangled_name.CharAt(mangled_pos) != '.') { |
| 1961 mangled_pos++; |
| 1962 } |
| 1963 |
| 1964 // Resume matching characters. |
| 1965 continue; |
| 1966 } |
| 1967 if (bare_pos == bare_len || mangled_char != bare_name.CharAt(bare_pos)) { |
| 1968 return false; |
| 1969 } |
| 1970 bare_pos++; |
1940 } | 1971 } |
1941 | 1972 |
1942 for (intptr_t i = 0; i < private_len; i++) { | 1973 // The strings match if we have reached the end of both strings. |
1943 if (name.CharAt(i) != private_name.CharAt(i)) { | 1974 return (mangled_pos == mangled_len && |
1944 return false; | 1975 bare_pos == bare_len); |
1945 } | |
1946 } | |
1947 return true; | |
1948 } | 1976 } |
1949 | 1977 |
1950 | 1978 |
1951 RawFunction* Class::LookupFunction(const String& name) const { | 1979 RawFunction* Class::LookupFunction(const String& name) const { |
1952 Isolate* isolate = Isolate::Current(); | 1980 Isolate* isolate = Isolate::Current(); |
1953 Array& funcs = Array::Handle(isolate, functions()); | 1981 Array& funcs = Array::Handle(isolate, functions()); |
1954 Function& function = Function::Handle(isolate, Function::null()); | 1982 Function& function = Function::Handle(isolate, Function::null()); |
1955 String& function_name = String::Handle(isolate, String::null()); | 1983 String& function_name = String::Handle(isolate, String::null()); |
1956 intptr_t len = funcs.Length(); | 1984 intptr_t len = funcs.Length(); |
1957 for (intptr_t i = 0; i < len; i++) { | 1985 for (intptr_t i = 0; i < len; i++) { |
1958 function ^= funcs.At(i); | 1986 function ^= funcs.At(i); |
1959 function_name ^= function.name(); | 1987 function_name ^= function.name(); |
1960 if (function_name.Equals(name) || MatchesPrivateName(function_name, name)) { | 1988 if (function_name.Equals(name) || |
| 1989 EqualsIgnoringPrivate(function_name, name)) { |
1961 return function.raw(); | 1990 return function.raw(); |
1962 } | 1991 } |
1963 } | 1992 } |
1964 | 1993 |
1965 // No function found. | 1994 // No function found. |
1966 return Function::null(); | 1995 return Function::null(); |
1967 } | 1996 } |
1968 | 1997 |
1969 | 1998 |
1970 RawFunction* Class::LookupGetterFunction(const String& name) const { | 1999 RawFunction* Class::LookupGetterFunction(const String& name) const { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2052 | 2081 |
2053 RawField* Class::LookupField(const String& name) const { | 2082 RawField* Class::LookupField(const String& name) const { |
2054 Isolate* isolate = Isolate::Current(); | 2083 Isolate* isolate = Isolate::Current(); |
2055 const Array& flds = Array::Handle(isolate, fields()); | 2084 const Array& flds = Array::Handle(isolate, fields()); |
2056 Field& field = Field::Handle(isolate, Field::null()); | 2085 Field& field = Field::Handle(isolate, Field::null()); |
2057 String& field_name = String::Handle(isolate, String::null()); | 2086 String& field_name = String::Handle(isolate, String::null()); |
2058 intptr_t len = flds.Length(); | 2087 intptr_t len = flds.Length(); |
2059 for (intptr_t i = 0; i < len; i++) { | 2088 for (intptr_t i = 0; i < len; i++) { |
2060 field ^= flds.At(i); | 2089 field ^= flds.At(i); |
2061 field_name ^= field.name(); | 2090 field_name ^= field.name(); |
2062 if (field_name.Equals(name) || MatchesPrivateName(field_name, name)) { | 2091 if (field_name.Equals(name) || EqualsIgnoringPrivate(field_name, name)) { |
2063 return field.raw(); | 2092 return field.raw(); |
2064 } | 2093 } |
2065 } | 2094 } |
2066 // No field found. | 2095 // No field found. |
2067 return Field::null(); | 2096 return Field::null(); |
2068 } | 2097 } |
2069 | 2098 |
2070 | 2099 |
2071 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { | 2100 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { |
2072 Isolate* isolate = Isolate::Current(); | 2101 Isolate* isolate = Isolate::Current(); |
(...skipping 8135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10208 const String& str = String::Handle(pattern()); | 10237 const String& str = String::Handle(pattern()); |
10209 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10238 const char* format = "JSRegExp: pattern=%s flags=%s"; |
10210 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10239 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
10211 char* chars = reinterpret_cast<char*>( | 10240 char* chars = reinterpret_cast<char*>( |
10212 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10241 Isolate::Current()->current_zone()->Allocate(len + 1)); |
10213 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10242 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
10214 return chars; | 10243 return chars; |
10215 } | 10244 } |
10216 | 10245 |
10217 } // namespace dart | 10246 } // namespace dart |
OLD | NEW |