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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2184 | 2184 |
2185 RawFunction* Class::LookupDynamicFunction(const String& name) const { | 2185 RawFunction* Class::LookupDynamicFunction(const String& name) const { |
2186 Function& function = Function::Handle(LookupFunction(name)); | 2186 Function& function = Function::Handle(LookupFunction(name)); |
2187 if (function.IsNull() || !function.IsDynamicFunction()) { | 2187 if (function.IsNull() || !function.IsDynamicFunction()) { |
2188 return Function::null(); | 2188 return Function::null(); |
2189 } | 2189 } |
2190 return function.raw(); | 2190 return function.raw(); |
2191 } | 2191 } |
2192 | 2192 |
2193 | 2193 |
2194 RawFunction* Class::LookupDynamicFunctionAllowPrivate( | |
2195 const String& name) const { | |
2196 Function& function = Function::Handle(LookupFunctionAllowPrivate(name)); | |
2197 if (function.IsNull() || !function.IsDynamicFunction()) { | |
2198 return Function::null(); | |
2199 } | |
2200 return function.raw(); | |
2201 } | |
2202 | |
2203 | |
2194 RawFunction* Class::LookupStaticFunction(const String& name) const { | 2204 RawFunction* Class::LookupStaticFunction(const String& name) const { |
2195 Function& function = Function::Handle(LookupFunction(name)); | 2205 Function& function = Function::Handle(LookupFunction(name)); |
2196 if (function.IsNull() || !function.IsStaticFunction()) { | 2206 if (function.IsNull() || !function.IsStaticFunction()) { |
2197 return Function::null(); | 2207 return Function::null(); |
2198 } | 2208 } |
2199 return function.raw(); | 2209 return function.raw(); |
2200 } | 2210 } |
2201 | 2211 |
2202 | 2212 |
2213 RawFunction* Class::LookupStaticFunctionAllowPrivate(const String& name) const { | |
2214 Function& function = Function::Handle(LookupFunctionAllowPrivate(name)); | |
2215 if (function.IsNull() || !function.IsStaticFunction()) { | |
2216 return Function::null(); | |
2217 } | |
2218 return function.raw(); | |
2219 } | |
2220 | |
2221 | |
2203 RawFunction* Class::LookupConstructor(const String& name) const { | 2222 RawFunction* Class::LookupConstructor(const String& name) const { |
2204 Function& function = Function::Handle(LookupFunction(name)); | 2223 Function& function = Function::Handle(LookupFunction(name)); |
2205 if (function.IsNull() || !function.IsConstructor()) { | 2224 if (function.IsNull() || !function.IsConstructor()) { |
2206 return Function::null(); | 2225 return Function::null(); |
2207 } | 2226 } |
2208 ASSERT(!function.is_static()); | 2227 ASSERT(!function.is_static()); |
2209 return function.raw(); | 2228 return function.raw(); |
2210 } | 2229 } |
2211 | 2230 |
2212 | 2231 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2246 | 2265 |
2247 RawFunction* Class::LookupFunction(const String& name) const { | 2266 RawFunction* Class::LookupFunction(const String& name) const { |
2248 Isolate* isolate = Isolate::Current(); | 2267 Isolate* isolate = Isolate::Current(); |
2249 ASSERT(name.IsOneByteString()); | 2268 ASSERT(name.IsOneByteString()); |
2250 Array& funcs = Array::Handle(isolate, functions()); | 2269 Array& funcs = Array::Handle(isolate, functions()); |
2251 if (funcs.IsNull()) { | 2270 if (funcs.IsNull()) { |
2252 // This can occur, e.g., for Null classes. | 2271 // This can occur, e.g., for Null classes. |
2253 return Function::null(); | 2272 return Function::null(); |
2254 } | 2273 } |
2255 Function& function = Function::Handle(isolate, Function::null()); | 2274 Function& function = Function::Handle(isolate, Function::null()); |
2275 if (name.IsSymbol()) { | |
2276 // Quick Symbol compare. | |
2277 intptr_t len = funcs.Length(); | |
2278 for (intptr_t i = 0; i < len; i++) { | |
2279 function ^= funcs.At(i); | |
2280 if (function.name() == name.raw()) { | |
2281 return function.raw(); | |
2282 } | |
2283 } | |
2284 } else { | |
2285 String& function_name = String::Handle(isolate, String::null()); | |
2286 intptr_t len = funcs.Length(); | |
2287 for (intptr_t i = 0; i < len; i++) { | |
2288 function ^= funcs.At(i); | |
2289 function_name ^= function.name(); | |
2290 if (function_name.Equals(name)) { | |
2291 return function.raw(); | |
2292 } | |
2293 } | |
2294 } | |
2295 // No function found. | |
2296 return Function::null(); | |
2297 } | |
2298 | |
2299 | |
2300 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const { | |
2301 Isolate* isolate = Isolate::Current(); | |
2302 ASSERT(name.IsOneByteString()); | |
2303 Array& funcs = Array::Handle(isolate, functions()); | |
2304 if (funcs.IsNull()) { | |
2305 // This can occur, e.g., for Null classes. | |
2306 return Function::null(); | |
2307 } | |
2308 Function& function = Function::Handle(isolate, Function::null()); | |
2256 String& function_name = String::Handle(isolate, String::null()); | 2309 String& function_name = String::Handle(isolate, String::null()); |
2257 intptr_t len = funcs.Length(); | 2310 intptr_t len = funcs.Length(); |
2258 for (intptr_t i = 0; i < len; i++) { | 2311 for (intptr_t i = 0; i < len; i++) { |
2259 function ^= funcs.At(i); | 2312 function ^= funcs.At(i); |
2260 function_name ^= function.name(); | 2313 function_name ^= function.name(); |
2261 if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) { | 2314 if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) { |
2262 return function.raw(); | 2315 return function.raw(); |
2263 } | 2316 } |
2264 } | 2317 } |
2265 | |
2266 // No function found. | 2318 // No function found. |
2267 return Function::null(); | 2319 return Function::null(); |
2268 } | 2320 } |
2269 | 2321 |
2270 | 2322 |
2271 RawFunction* Class::LookupGetterFunction(const String& name) const { | 2323 RawFunction* Class::LookupGetterFunction(const String& name) const { |
2272 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); | 2324 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); |
2273 } | 2325 } |
2274 | 2326 |
2275 | 2327 |
(...skipping 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5680 return Function::null(); | 5732 return Function::null(); |
5681 } | 5733 } |
5682 | 5734 |
5683 | 5735 |
5684 RawObject* Library::LookupLocalObject(const String& name) const { | 5736 RawObject* Library::LookupLocalObject(const String& name) const { |
5685 intptr_t index; | 5737 intptr_t index; |
5686 return LookupEntry(name, &index); | 5738 return LookupEntry(name, &index); |
5687 } | 5739 } |
5688 | 5740 |
5689 | 5741 |
5690 static bool ShouldBePrivate(const String& name) { | 5742 static bool ShouldBePrivate(const String& name) { |
siva
2013/01/16 23:57:24
I find the name ShouldBePrivate pretty weird.
It s
srdjan
2013/01/17 00:31:11
Reverting this code to original, adding an IsPriva
| |
5691 return | 5743 if (name.Length() <= 1) return false; |
5692 (name.Length() >= 1 && | 5744 if (name.CharAt(0) == '_') return true; |
5693 name.CharAt(0) == '_') || | 5745 if (name.StartsWith(Symbols::PrivateGetterPrefix()) || |
5694 (name.Length() >= 5 && | 5746 name.StartsWith(Symbols::PrivateSetterPrefix())) { |
5695 (name.CharAt(4) == '_' && | 5747 return true; |
5696 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && | 5748 } |
5697 name.CharAt(1) == 'e' && | 5749 // Factory names: List._fromLiteral. |
5698 name.CharAt(2) == 't' && | 5750 // TODO(srdjan): Improve speed by assuming OnebyteStrings. |
siva
2013/01/16 23:57:24
assuming OneByteStrings or ExternalOneByteStrings
srdjan
2013/01/17 00:31:11
Done.
| |
5699 name.CharAt(3) == ':')); | 5751 for (intptr_t i = 1; i < name.Length() - 1; i++) { |
5752 if (name.CharAt(i) == '.') { | |
5753 if (name.CharAt(i + 1) == '_') { | |
5754 return true; | |
5755 } | |
5756 } | |
5757 } | |
siva
2013/01/16 23:57:24
As discussed offline, this additional check here p
srdjan
2013/01/17 00:31:11
Done.
| |
5758 return false; | |
5700 } | 5759 } |
5701 | 5760 |
5702 | 5761 |
5703 RawField* Library::LookupFieldAllowPrivate(const String& name) const { | 5762 RawField* Library::LookupFieldAllowPrivate(const String& name) const { |
5704 // First check if name is found in the local scope of the library. | 5763 // First check if name is found in the local scope of the library. |
5705 Field& field = Field::Handle(LookupLocalField(name)); | 5764 Field& field = Field::Handle(LookupLocalField(name)); |
5706 if (!field.IsNull()) { | 5765 if (!field.IsNull()) { |
5707 return field.raw(); | 5766 return field.raw(); |
5708 } | 5767 } |
5709 | 5768 |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6189 } | 6248 } |
6190 | 6249 |
6191 | 6250 |
6192 RawString* Library::PrivateName(const String& name) const { | 6251 RawString* Library::PrivateName(const String& name) const { |
6193 ASSERT(ShouldBePrivate(name)); | 6252 ASSERT(ShouldBePrivate(name)); |
6194 // ASSERT(strchr(name, '@') == NULL); | 6253 // ASSERT(strchr(name, '@') == NULL); |
6195 String& str = String::Handle(); | 6254 String& str = String::Handle(); |
6196 str ^= name.raw(); | 6255 str ^= name.raw(); |
6197 str = String::Concat(str, String::Handle(this->private_key())); | 6256 str = String::Concat(str, String::Handle(this->private_key())); |
6198 str = Symbols::New(str); | 6257 str = Symbols::New(str); |
6199 return str.raw(); | 6258 return str.raw(); |
siva
2013/01/16 23:57:24
I think the function in it's current form will not
| |
6200 } | 6259 } |
6201 | 6260 |
6202 | 6261 |
6203 RawLibrary* Library::GetLibrary(intptr_t index) { | 6262 RawLibrary* Library::GetLibrary(intptr_t index) { |
6204 Isolate* isolate = Isolate::Current(); | 6263 Isolate* isolate = Isolate::Current(); |
6205 const GrowableObjectArray& libs = | 6264 const GrowableObjectArray& libs = |
6206 GrowableObjectArray::Handle(isolate->object_store()->libraries()); | 6265 GrowableObjectArray::Handle(isolate->object_store()->libraries()); |
6207 ASSERT(!libs.IsNull()); | 6266 ASSERT(!libs.IsNull()); |
6208 if ((0 <= index) && (index < libs.Length())) { | 6267 if ((0 <= index) && (index < libs.Length())) { |
6209 Library& lib = Library::Handle(); | 6268 Library& lib = Library::Handle(); |
(...skipping 6326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12536 } | 12595 } |
12537 return result.raw(); | 12596 return result.raw(); |
12538 } | 12597 } |
12539 | 12598 |
12540 | 12599 |
12541 const char* WeakProperty::ToCString() const { | 12600 const char* WeakProperty::ToCString() const { |
12542 return "_WeakProperty"; | 12601 return "_WeakProperty"; |
12543 } | 12602 } |
12544 | 12603 |
12545 } // namespace dart | 12604 } // namespace dart |
OLD | NEW |