| 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 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 } | 1956 } |
| 1957 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { | 1957 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { |
| 1958 if (name.CharAt(j) != accessor_name.CharAt(i)) { | 1958 if (name.CharAt(j) != accessor_name.CharAt(i)) { |
| 1959 return false; | 1959 return false; |
| 1960 } | 1960 } |
| 1961 } | 1961 } |
| 1962 return true; | 1962 return true; |
| 1963 } | 1963 } |
| 1964 | 1964 |
| 1965 | 1965 |
| 1966 // Check to see if mangled_name is equal to bare_name once the private | |
| 1967 // key separator is stripped from mangled_name. | |
| 1968 // | |
| 1969 // Things are made more complicated by the fact that constructors are | |
| 1970 // added *after* the private suffix, so "foo@123.named" should match | |
| 1971 // "foo.named". | |
| 1972 // | |
| 1973 // Also, the private suffix can occur more than once in the name, as in: | |
| 1974 // | |
| 1975 // _ReceivePortImpl@6be832b._internal@6be832b | |
| 1976 // | |
| 1977 bool EqualsIgnoringPrivate(const String& mangled_name, | |
| 1978 const String& bare_name) { | |
| 1979 intptr_t mangled_len = mangled_name.Length(); | |
| 1980 intptr_t bare_len = bare_name.Length(); | |
| 1981 if (mangled_len < bare_len) { | |
| 1982 // No way they can match. | |
| 1983 return false; | |
| 1984 } | |
| 1985 | |
| 1986 intptr_t mangled_pos = 0; | |
| 1987 intptr_t bare_pos = 0; | |
| 1988 while (mangled_pos < mangled_len) { | |
| 1989 int32_t mangled_char = mangled_name.CharAt(mangled_pos); | |
| 1990 mangled_pos++; | |
| 1991 | |
| 1992 if (mangled_char == Scanner::kPrivateKeySeparator) { | |
| 1993 // Consume a private key separator. | |
| 1994 while (mangled_pos < mangled_len && | |
| 1995 mangled_name.CharAt(mangled_pos) != '.') { | |
| 1996 mangled_pos++; | |
| 1997 } | |
| 1998 | |
| 1999 // Resume matching characters. | |
| 2000 continue; | |
| 2001 } | |
| 2002 if (bare_pos == bare_len || mangled_char != bare_name.CharAt(bare_pos)) { | |
| 2003 return false; | |
| 2004 } | |
| 2005 bare_pos++; | |
| 2006 } | |
| 2007 | |
| 2008 // The strings match if we have reached the end of both strings. | |
| 2009 return (mangled_pos == mangled_len && | |
| 2010 bare_pos == bare_len); | |
| 2011 } | |
| 2012 | |
| 2013 | |
| 2014 RawFunction* Class::LookupFunction(const String& name) const { | 1966 RawFunction* Class::LookupFunction(const String& name) const { |
| 2015 Isolate* isolate = Isolate::Current(); | 1967 Isolate* isolate = Isolate::Current(); |
| 1968 ASSERT(name.IsOneByteString()); |
| 1969 const OneByteString& lookup_name = OneByteString::Cast(name); |
| 2016 Array& funcs = Array::Handle(isolate, functions()); | 1970 Array& funcs = Array::Handle(isolate, functions()); |
| 2017 Function& function = Function::Handle(isolate, Function::null()); | 1971 Function& function = Function::Handle(isolate, Function::null()); |
| 2018 String& function_name = String::Handle(isolate, String::null()); | 1972 OneByteString& function_name = |
| 1973 OneByteString::Handle(isolate, OneByteString::null()); |
| 2019 intptr_t len = funcs.Length(); | 1974 intptr_t len = funcs.Length(); |
| 2020 for (intptr_t i = 0; i < len; i++) { | 1975 for (intptr_t i = 0; i < len; i++) { |
| 2021 function ^= funcs.At(i); | 1976 function ^= funcs.At(i); |
| 2022 function_name ^= function.name(); | 1977 function_name ^= function.name(); |
| 2023 if (function_name.Equals(name) || | 1978 if (function_name.EqualsIgnoringPrivateKey(lookup_name)) { |
| 2024 EqualsIgnoringPrivate(function_name, name)) { | |
| 2025 return function.raw(); | 1979 return function.raw(); |
| 2026 } | 1980 } |
| 2027 } | 1981 } |
| 2028 | 1982 |
| 2029 // No function found. | 1983 // No function found. |
| 2030 return Function::null(); | 1984 return Function::null(); |
| 2031 } | 1985 } |
| 2032 | 1986 |
| 2033 | 1987 |
| 2034 RawFunction* Class::LookupGetterFunction(const String& name) const { | 1988 RawFunction* Class::LookupGetterFunction(const String& name) const { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2109 } | 2063 } |
| 2110 return field.raw(); | 2064 return field.raw(); |
| 2111 } | 2065 } |
| 2112 // No field found. | 2066 // No field found. |
| 2113 return Field::null(); | 2067 return Field::null(); |
| 2114 } | 2068 } |
| 2115 | 2069 |
| 2116 | 2070 |
| 2117 RawField* Class::LookupField(const String& name) const { | 2071 RawField* Class::LookupField(const String& name) const { |
| 2118 Isolate* isolate = Isolate::Current(); | 2072 Isolate* isolate = Isolate::Current(); |
| 2073 ASSERT(name.IsOneByteString()); |
| 2074 const OneByteString& lookup_name = OneByteString::Cast(name); |
| 2119 const Array& flds = Array::Handle(isolate, fields()); | 2075 const Array& flds = Array::Handle(isolate, fields()); |
| 2120 Field& field = Field::Handle(isolate, Field::null()); | 2076 Field& field = Field::Handle(isolate, Field::null()); |
| 2121 String& field_name = String::Handle(isolate, String::null()); | 2077 OneByteString& field_name = |
| 2078 OneByteString::Handle(isolate, OneByteString::null()); |
| 2122 intptr_t len = flds.Length(); | 2079 intptr_t len = flds.Length(); |
| 2123 for (intptr_t i = 0; i < len; i++) { | 2080 for (intptr_t i = 0; i < len; i++) { |
| 2124 field ^= flds.At(i); | 2081 field ^= flds.At(i); |
| 2125 field_name ^= field.name(); | 2082 field_name ^= field.name(); |
| 2126 if (field_name.Equals(name) || EqualsIgnoringPrivate(field_name, name)) { | 2083 if (field_name.EqualsIgnoringPrivateKey(lookup_name)) { |
| 2127 return field.raw(); | 2084 return field.raw(); |
| 2128 } | 2085 } |
| 2129 } | 2086 } |
| 2130 // No field found. | 2087 // No field found. |
| 2131 return Field::null(); | 2088 return Field::null(); |
| 2132 } | 2089 } |
| 2133 | 2090 |
| 2134 | 2091 |
| 2135 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { | 2092 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { |
| 2136 Isolate* isolate = Isolate::Current(); | 2093 Isolate* isolate = Isolate::Current(); |
| (...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4045 Heap::kOld); | 4002 Heap::kOld); |
| 4046 return reinterpret_cast<RawFunction*>(raw); | 4003 return reinterpret_cast<RawFunction*>(raw); |
| 4047 } | 4004 } |
| 4048 | 4005 |
| 4049 | 4006 |
| 4050 RawFunction* Function::New(const String& name, | 4007 RawFunction* Function::New(const String& name, |
| 4051 RawFunction::Kind kind, | 4008 RawFunction::Kind kind, |
| 4052 bool is_static, | 4009 bool is_static, |
| 4053 bool is_const, | 4010 bool is_const, |
| 4054 intptr_t token_pos) { | 4011 intptr_t token_pos) { |
| 4012 ASSERT(name.IsOneByteString()); |
| 4055 const Function& result = Function::Handle(Function::New()); | 4013 const Function& result = Function::Handle(Function::New()); |
| 4056 result.set_parameter_types(Array::Handle(Array::Empty())); | 4014 result.set_parameter_types(Array::Handle(Array::Empty())); |
| 4057 result.set_parameter_names(Array::Handle(Array::Empty())); | 4015 result.set_parameter_names(Array::Handle(Array::Empty())); |
| 4058 result.set_name(name); | 4016 result.set_name(name); |
| 4059 result.set_kind(kind); | 4017 result.set_kind(kind); |
| 4060 result.set_is_static(is_static); | 4018 result.set_is_static(is_static); |
| 4061 result.set_is_const(is_const); | 4019 result.set_is_const(is_const); |
| 4062 result.set_token_pos(token_pos); | 4020 result.set_token_pos(token_pos); |
| 4063 result.set_end_token_pos(token_pos); | 4021 result.set_end_token_pos(token_pos); |
| 4064 result.set_num_fixed_parameters(0); | 4022 result.set_num_fixed_parameters(0); |
| 4065 result.set_num_optional_parameters(0); | 4023 result.set_num_optional_parameters(0); |
| 4066 result.set_usage_counter(0); | 4024 result.set_usage_counter(0); |
| 4067 result.set_deoptimization_counter(0); | 4025 result.set_deoptimization_counter(0); |
| 4068 result.set_is_optimizable(true); | 4026 result.set_is_optimizable(true); |
| 4069 result.set_is_native(false); | 4027 result.set_is_native(false); |
| 4070 return result.raw(); | 4028 return result.raw(); |
| 4071 } | 4029 } |
| 4072 | 4030 |
| 4073 | 4031 |
| 4074 RawFunction* Function::NewClosureFunction(const String& name, | 4032 RawFunction* Function::NewClosureFunction(const String& name, |
| 4075 const Function& parent, | 4033 const Function& parent, |
| 4076 intptr_t token_pos) { | 4034 intptr_t token_pos) { |
| 4035 ASSERT(name.IsOneByteString()); |
| 4077 ASSERT(!parent.IsNull()); | 4036 ASSERT(!parent.IsNull()); |
| 4078 const Class& parent_class = Class::Handle(parent.owner()); | 4037 const Class& parent_class = Class::Handle(parent.owner()); |
| 4079 ASSERT(!parent_class.IsNull()); | 4038 ASSERT(!parent_class.IsNull()); |
| 4080 const Function& result = Function::Handle( | 4039 const Function& result = Function::Handle( |
| 4081 Function::New(name, | 4040 Function::New(name, |
| 4082 RawFunction::kClosureFunction, | 4041 RawFunction::kClosureFunction, |
| 4083 /* is_static = */ parent.is_static(), | 4042 /* is_static = */ parent.is_static(), |
| 4084 /* is_const = */ false, | 4043 /* is_const = */ false, |
| 4085 token_pos)); | 4044 token_pos)); |
| 4086 result.set_parent_function(parent); | 4045 result.set_parent_function(parent); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4402 Field::InstanceSize(), | 4361 Field::InstanceSize(), |
| 4403 Heap::kOld); | 4362 Heap::kOld); |
| 4404 return reinterpret_cast<RawField*>(raw); | 4363 return reinterpret_cast<RawField*>(raw); |
| 4405 } | 4364 } |
| 4406 | 4365 |
| 4407 | 4366 |
| 4408 RawField* Field::New(const String& name, | 4367 RawField* Field::New(const String& name, |
| 4409 bool is_static, | 4368 bool is_static, |
| 4410 bool is_final, | 4369 bool is_final, |
| 4411 intptr_t token_pos) { | 4370 intptr_t token_pos) { |
| 4371 ASSERT(name.IsOneByteString()); |
| 4412 const Field& result = Field::Handle(Field::New()); | 4372 const Field& result = Field::Handle(Field::New()); |
| 4413 result.set_name(name); | 4373 result.set_name(name); |
| 4414 result.set_is_static(is_static); | 4374 result.set_is_static(is_static); |
| 4415 if (is_static) { | 4375 if (is_static) { |
| 4416 result.set_value(Instance::Handle()); | 4376 result.set_value(Instance::Handle()); |
| 4417 } else { | 4377 } else { |
| 4418 result.SetOffset(0); | 4378 result.SetOffset(0); |
| 4419 } | 4379 } |
| 4420 result.set_is_final(is_final); | 4380 result.set_is_final(is_final); |
| 4421 result.set_token_pos(token_pos); | 4381 result.set_token_pos(token_pos); |
| (...skipping 3931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8353 return true; | 8313 return true; |
| 8354 } | 8314 } |
| 8355 | 8315 |
| 8356 if (!other.IsString() || other.IsNull()) { | 8316 if (!other.IsString() || other.IsNull()) { |
| 8357 return false; | 8317 return false; |
| 8358 } | 8318 } |
| 8359 | 8319 |
| 8360 const String& other_string = String::Cast(other); | 8320 const String& other_string = String::Cast(other); |
| 8361 if (this->HasHash() && other_string.HasHash() && | 8321 if (this->HasHash() && other_string.HasHash() && |
| 8362 (this->Hash() != other_string.Hash())) { | 8322 (this->Hash() != other_string.Hash())) { |
| 8363 // Both sides have a hash code and it does not match. | 8323 return false; // Both sides have a hash code and it does not match. |
| 8364 return false; | |
| 8365 } | 8324 } |
| 8366 | 8325 return Equals(other_string, 0, other_string.Length()); |
| 8367 intptr_t len = this->Length(); | |
| 8368 if (len != other_string.Length()) { | |
| 8369 // Lengths don't match. | |
| 8370 return false; | |
| 8371 } | |
| 8372 | |
| 8373 for (intptr_t i = 0; i < len; i++) { | |
| 8374 if (this->CharAt(i) != other_string.CharAt(i)) { | |
| 8375 return false; | |
| 8376 } | |
| 8377 } | |
| 8378 return true; | |
| 8379 } | |
| 8380 | |
| 8381 | |
| 8382 bool String::Equals(const String& str, | |
| 8383 intptr_t begin_index, | |
| 8384 intptr_t len) const { | |
| 8385 ASSERT(begin_index >= 0); | |
| 8386 ASSERT(begin_index == 0 || begin_index < str.Length()); | |
| 8387 ASSERT(len >= 0); | |
| 8388 ASSERT(len <= str.Length()); | |
| 8389 if (len != this->Length()) { | |
| 8390 // Lengths don't match. | |
| 8391 return false; | |
| 8392 } | |
| 8393 | |
| 8394 for (intptr_t i = 0; i < len; i++) { | |
| 8395 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | |
| 8396 return false; | |
| 8397 } | |
| 8398 } | |
| 8399 return true; | |
| 8400 } | 8326 } |
| 8401 | 8327 |
| 8402 | 8328 |
| 8403 bool String::Equals(const char* str) const { | 8329 bool String::Equals(const char* str) const { |
| 8404 for (intptr_t i = 0; i < this->Length(); ++i) { | 8330 for (intptr_t i = 0; i < this->Length(); ++i) { |
| 8405 if (*str == '\0') { | 8331 if (*str == '\0') { |
| 8406 // Lengths don't match. | 8332 // Lengths don't match. |
| 8407 return false; | 8333 return false; |
| 8408 } | 8334 } |
| 8409 int32_t ch; | 8335 int32_t ch; |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9119 *(dststr.CharAddr(index)) = *CharAddr(i); | 9045 *(dststr.CharAddr(index)) = *CharAddr(i); |
| 9120 index += 1; | 9046 index += 1; |
| 9121 } | 9047 } |
| 9122 } | 9048 } |
| 9123 return dststr.raw(); | 9049 return dststr.raw(); |
| 9124 } | 9050 } |
| 9125 return OneByteString::null(); | 9051 return OneByteString::null(); |
| 9126 } | 9052 } |
| 9127 | 9053 |
| 9128 | 9054 |
| 9055 // Check to see if 'name' matches 'this' as is or |
| 9056 // once the private key separator is stripped from name. |
| 9057 // |
| 9058 // Things are made more complicated by the fact that constructors are |
| 9059 // added *after* the private suffix, so "foo@123.named" should match |
| 9060 // "foo.named". |
| 9061 // |
| 9062 // Also, the private suffix can occur more than once in the name, as in: |
| 9063 // |
| 9064 // _ReceivePortImpl@6be832b._internal@6be832b |
| 9065 // |
| 9066 bool OneByteString::EqualsIgnoringPrivateKey(const OneByteString& name) const { |
| 9067 if (raw() == name.raw()) { |
| 9068 return true; // Both handles point to the same raw instance. |
| 9069 } |
| 9070 intptr_t len = Length(); |
| 9071 intptr_t name_len = name.Length(); |
| 9072 if (len == name_len) { |
| 9073 for (intptr_t i = 0; i < len; i++) { |
| 9074 if (*(CharAddr(i)) != *(name.CharAddr(i))) { |
| 9075 return false; |
| 9076 } |
| 9077 } |
| 9078 return true; |
| 9079 } |
| 9080 if (len < name_len) { |
| 9081 return false; // No way they can match. |
| 9082 } |
| 9083 intptr_t pos = 0; |
| 9084 intptr_t name_pos = 0; |
| 9085 while (pos < len) { |
| 9086 int32_t ch = *(CharAddr(pos)); |
| 9087 pos++; |
| 9088 |
| 9089 if (ch == Scanner::kPrivateKeySeparator) { |
| 9090 // Consume a private key separator. |
| 9091 while (pos < len && *(CharAddr(pos)) != '.') { |
| 9092 pos++; |
| 9093 } |
| 9094 // Resume matching characters. |
| 9095 continue; |
| 9096 } |
| 9097 if (name_pos == name_len || ch != *(name.CharAddr(name_pos))) { |
| 9098 return false; |
| 9099 } |
| 9100 name_pos++; |
| 9101 } |
| 9102 |
| 9103 // We have reached the end of mangled_name string. |
| 9104 ASSERT(pos == len); |
| 9105 return (name_pos == name_len); |
| 9106 } |
| 9107 |
| 9108 |
| 9129 RawOneByteString* OneByteString::New(intptr_t len, | 9109 RawOneByteString* OneByteString::New(intptr_t len, |
| 9130 Heap::Space space) { | 9110 Heap::Space space) { |
| 9131 Isolate* isolate = Isolate::Current(); | 9111 Isolate* isolate = Isolate::Current(); |
| 9132 | 9112 |
| 9133 const Class& cls = | 9113 const Class& cls = |
| 9134 Class::Handle(isolate->object_store()->one_byte_string_class()); | 9114 Class::Handle(isolate->object_store()->one_byte_string_class()); |
| 9135 OneByteString& result = OneByteString::Handle(); | 9115 OneByteString& result = OneByteString::Handle(); |
| 9136 { | 9116 { |
| 9137 RawObject* raw = Object::Allocate(cls, | 9117 RawObject* raw = Object::Allocate(cls, |
| 9138 OneByteString::InstanceSize(len), | 9118 OneByteString::InstanceSize(len), |
| (...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10800 const String& str = String::Handle(pattern()); | 10780 const String& str = String::Handle(pattern()); |
| 10801 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10781 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10802 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10782 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10803 char* chars = reinterpret_cast<char*>( | 10783 char* chars = reinterpret_cast<char*>( |
| 10804 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10784 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 10805 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10785 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10806 return chars; | 10786 return chars; |
| 10807 } | 10787 } |
| 10808 | 10788 |
| 10809 } // namespace dart | 10789 } // namespace dart |
| OLD | NEW |