| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2292 // is longer than necessary. | 2292 // is longer than necessary. |
| 2293 return super_class.TypeTest(test_kind, | 2293 return super_class.TypeTest(test_kind, |
| 2294 type_arguments, | 2294 type_arguments, |
| 2295 other, | 2295 other, |
| 2296 other_type_arguments, | 2296 other_type_arguments, |
| 2297 malformed_error); | 2297 malformed_error); |
| 2298 } | 2298 } |
| 2299 | 2299 |
| 2300 | 2300 |
| 2301 bool Class::IsTopLevel() const { | 2301 bool Class::IsTopLevel() const { |
| 2302 return String::Handle(Name()).Equals("::"); | 2302 return Name() == Symbols::TopLevel().raw(); |
| 2303 } | 2303 } |
| 2304 | 2304 |
| 2305 | 2305 |
| 2306 RawFunction* Class::LookupDynamicFunction(const String& name) const { | 2306 RawFunction* Class::LookupDynamicFunction(const String& name) const { |
| 2307 Function& function = Function::Handle(LookupFunction(name)); | 2307 return LookupFunction(name, kInstance); |
| 2308 if (function.IsNull() || !function.IsDynamicFunction()) { | |
| 2309 return Function::null(); | |
| 2310 } | |
| 2311 return function.raw(); | |
| 2312 } | 2308 } |
| 2313 | 2309 |
| 2314 | 2310 |
| 2315 RawFunction* Class::LookupDynamicFunctionAllowPrivate( | 2311 RawFunction* Class::LookupDynamicFunctionAllowPrivate( |
| 2316 const String& name) const { | 2312 const String& name) const { |
| 2317 Function& function = Function::Handle(LookupFunctionAllowPrivate(name)); | 2313 return LookupFunctionAllowPrivate(name, kInstance); |
| 2318 if (function.IsNull() || !function.IsDynamicFunction()) { | |
| 2319 return Function::null(); | |
| 2320 } | |
| 2321 return function.raw(); | |
| 2322 } | 2314 } |
| 2323 | 2315 |
| 2324 | 2316 |
| 2325 RawFunction* Class::LookupStaticFunction(const String& name) const { | 2317 RawFunction* Class::LookupStaticFunction(const String& name) const { |
| 2326 Function& function = Function::Handle(LookupFunction(name)); | 2318 return LookupFunction(name, kStatic); |
| 2327 if (function.IsNull() || !function.IsStaticFunction()) { | |
| 2328 return Function::null(); | |
| 2329 } | |
| 2330 return function.raw(); | |
| 2331 } | 2319 } |
| 2332 | 2320 |
| 2333 | 2321 |
| 2334 RawFunction* Class::LookupStaticFunctionAllowPrivate(const String& name) const { | 2322 RawFunction* Class::LookupStaticFunctionAllowPrivate(const String& name) const { |
| 2335 Function& function = Function::Handle(LookupFunctionAllowPrivate(name)); | 2323 return LookupFunctionAllowPrivate(name, kStatic); |
| 2336 if (function.IsNull() || !function.IsStaticFunction()) { | |
| 2337 return Function::null(); | |
| 2338 } | |
| 2339 return function.raw(); | |
| 2340 } | 2324 } |
| 2341 | 2325 |
| 2342 | 2326 |
| 2343 RawFunction* Class::LookupConstructor(const String& name) const { | 2327 RawFunction* Class::LookupConstructor(const String& name) const { |
| 2344 Function& function = Function::Handle(LookupFunction(name)); | 2328 return LookupFunction(name, kConstructor); |
| 2345 if (function.IsNull() || !function.IsConstructor()) { | |
| 2346 return Function::null(); | |
| 2347 } | |
| 2348 ASSERT(!function.is_static()); | |
| 2349 return function.raw(); | |
| 2350 } | 2329 } |
| 2351 | 2330 |
| 2352 | 2331 |
| 2353 RawFunction* Class::LookupConstructorAllowPrivate(const String& name) const { | 2332 RawFunction* Class::LookupConstructorAllowPrivate(const String& name) const { |
| 2354 Function& function = Function::Handle(LookupFunctionAllowPrivate(name)); | 2333 return LookupFunctionAllowPrivate(name, kConstructor); |
| 2355 if (function.IsNull() || !function.IsConstructor()) { | |
| 2356 return Function::null(); | |
| 2357 } | |
| 2358 ASSERT(!function.is_static()); | |
| 2359 return function.raw(); | |
| 2360 } | 2334 } |
| 2361 | 2335 |
| 2362 | 2336 |
| 2363 RawFunction* Class::LookupFactory(const String& name) const { | 2337 RawFunction* Class::LookupFactory(const String& name) const { |
| 2364 Function& function = Function::Handle(LookupFunction(name)); | 2338 return LookupFunction(name, kFactory); |
| 2365 if (function.IsNull() || !function.IsFactory()) { | 2339 } |
| 2366 return Function::null(); | 2340 |
| 2367 } | 2341 |
| 2368 ASSERT(function.is_static()); | 2342 RawFunction* Class::LookupFunction(const String& name) const { |
| 2369 return function.raw(); | 2343 return LookupFunction(name, kAny); |
| 2344 } |
| 2345 |
| 2346 |
| 2347 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const { |
| 2348 return LookupFunctionAllowPrivate(name, kAny); |
| 2370 } | 2349 } |
| 2371 | 2350 |
| 2372 | 2351 |
| 2373 // Returns true if 'prefix' and 'accessor_name' match 'name'. | 2352 // Returns true if 'prefix' and 'accessor_name' match 'name'. |
| 2374 static bool MatchesAccessorName(const String& name, | 2353 static bool MatchesAccessorName(const String& name, |
| 2375 const char* prefix, | 2354 const char* prefix, |
| 2376 intptr_t prefix_length, | 2355 intptr_t prefix_length, |
| 2377 const String& accessor_name) { | 2356 const String& accessor_name) { |
| 2378 intptr_t name_len = name.Length(); | 2357 intptr_t name_len = name.Length(); |
| 2379 intptr_t accessor_name_len = accessor_name.Length(); | 2358 intptr_t accessor_name_len = accessor_name.Length(); |
| 2380 | 2359 |
| 2381 if (name_len != (accessor_name_len + prefix_length)) { | 2360 if (name_len != (accessor_name_len + prefix_length)) { |
| 2382 return false; | 2361 return false; |
| 2383 } | 2362 } |
| 2384 for (intptr_t i = 0; i < prefix_length; i++) { | 2363 for (intptr_t i = 0; i < prefix_length; i++) { |
| 2385 if (name.CharAt(i) != prefix[i]) { | 2364 if (name.CharAt(i) != prefix[i]) { |
| 2386 return false; | 2365 return false; |
| 2387 } | 2366 } |
| 2388 } | 2367 } |
| 2389 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { | 2368 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { |
| 2390 if (name.CharAt(j) != accessor_name.CharAt(i)) { | 2369 if (name.CharAt(j) != accessor_name.CharAt(i)) { |
| 2391 return false; | 2370 return false; |
| 2392 } | 2371 } |
| 2393 } | 2372 } |
| 2394 return true; | 2373 return true; |
| 2395 } | 2374 } |
| 2396 | 2375 |
| 2397 | 2376 |
| 2398 RawFunction* Class::LookupFunction(const String& name) const { | 2377 RawFunction* Class::CheckFunctionType(const Function& func, intptr_t type) { |
| 2378 if (type == kInstance) { |
| 2379 if (func.IsDynamicFunction()) { |
| 2380 return func.raw(); |
| 2381 } |
| 2382 } else if (type == kStatic) { |
| 2383 if (func.IsStaticFunction()) { |
| 2384 return func.raw(); |
| 2385 } |
| 2386 } else if (type == kConstructor) { |
| 2387 if (func.IsConstructor()) { |
| 2388 ASSERT(!func.is_static()); |
| 2389 return func.raw(); |
| 2390 } |
| 2391 } else if (type == kFactory) { |
| 2392 if (func.IsFactory()) { |
| 2393 ASSERT(func.is_static()); |
| 2394 return func.raw(); |
| 2395 } |
| 2396 } else if (type == kAny) { |
| 2397 return func.raw(); |
| 2398 } |
| 2399 return Function::null(); |
| 2400 } |
| 2401 |
| 2402 |
| 2403 RawFunction* Class::LookupFunction(const String& name, intptr_t type) const { |
| 2399 Isolate* isolate = Isolate::Current(); | 2404 Isolate* isolate = Isolate::Current(); |
| 2400 if (EnsureIsFinalized(isolate) != Error::null()) { | 2405 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2401 return Function::null(); | 2406 return Function::null(); |
| 2402 } | 2407 } |
| 2403 Array& funcs = Array::Handle(isolate, functions()); | 2408 Array& funcs = Array::Handle(isolate, functions()); |
| 2404 if (funcs.IsNull()) { | 2409 if (funcs.IsNull()) { |
| 2405 // This can occur, e.g., for Null classes. | 2410 // This can occur, e.g., for Null classes. |
| 2406 return Function::null(); | 2411 return Function::null(); |
| 2407 } | 2412 } |
| 2408 Function& function = Function::Handle(isolate, Function::null()); | 2413 Function& function = Function::Handle(isolate); |
| 2409 const intptr_t len = funcs.Length(); | 2414 const intptr_t len = funcs.Length(); |
| 2410 if (name.IsSymbol()) { | 2415 if (name.IsSymbol()) { |
| 2411 // Quick Symbol compare. | 2416 // Quick Symbol compare. |
| 2412 NoGCScope no_gc; | 2417 NoGCScope no_gc; |
| 2413 for (intptr_t i = 0; i < len; i++) { | 2418 for (intptr_t i = 0; i < len; i++) { |
| 2414 function ^= funcs.At(i); | 2419 function ^= funcs.At(i); |
| 2415 if (function.name() == name.raw()) { | 2420 if (function.name() == name.raw()) { |
| 2416 return function.raw(); | 2421 return CheckFunctionType(function, type); |
| 2417 } | 2422 } |
| 2418 } | 2423 } |
| 2419 } else { | 2424 } else { |
| 2420 String& function_name = String::Handle(isolate, String::null()); | 2425 String& function_name = String::Handle(isolate); |
| 2421 for (intptr_t i = 0; i < len; i++) { | 2426 for (intptr_t i = 0; i < len; i++) { |
| 2422 function ^= funcs.At(i); | 2427 function ^= funcs.At(i); |
| 2423 function_name ^= function.name(); | 2428 function_name ^= function.name(); |
| 2424 if (function_name.Equals(name)) { | 2429 if (function_name.Equals(name)) { |
| 2425 return function.raw(); | 2430 return CheckFunctionType(function, type); |
| 2426 } | 2431 } |
| 2427 } | 2432 } |
| 2428 } | 2433 } |
| 2429 // No function found. | 2434 // No function found. |
| 2430 return Function::null(); | 2435 return Function::null(); |
| 2431 } | 2436 } |
| 2432 | 2437 |
| 2433 | 2438 |
| 2434 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const { | 2439 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, |
| 2440 intptr_t type) const { |
| 2435 Isolate* isolate = Isolate::Current(); | 2441 Isolate* isolate = Isolate::Current(); |
| 2436 if (EnsureIsFinalized(isolate) != Error::null()) { | 2442 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2437 return Function::null(); | 2443 return Function::null(); |
| 2438 } | 2444 } |
| 2439 Array& funcs = Array::Handle(isolate, functions()); | 2445 Array& funcs = Array::Handle(isolate, functions()); |
| 2440 if (funcs.IsNull()) { | 2446 if (funcs.IsNull()) { |
| 2441 // This can occur, e.g., for Null classes. | 2447 // This can occur, e.g., for Null classes. |
| 2442 return Function::null(); | 2448 return Function::null(); |
| 2443 } | 2449 } |
| 2444 Function& function = Function::Handle(isolate, Function::null()); | 2450 Function& function = Function::Handle(isolate); |
| 2445 String& function_name = String::Handle(isolate, String::null()); | 2451 String& function_name = String::Handle(isolate); |
| 2446 intptr_t len = funcs.Length(); | 2452 intptr_t len = funcs.Length(); |
| 2447 for (intptr_t i = 0; i < len; i++) { | 2453 for (intptr_t i = 0; i < len; i++) { |
| 2448 function ^= funcs.At(i); | 2454 function ^= funcs.At(i); |
| 2449 function_name ^= function.name(); | 2455 function_name ^= function.name(); |
| 2450 if (String::EqualsIgnoringPrivateKey(function_name, name)) { | 2456 if (String::EqualsIgnoringPrivateKey(function_name, name)) { |
| 2451 return function.raw(); | 2457 return CheckFunctionType(function, type); |
| 2452 } | 2458 } |
| 2453 } | 2459 } |
| 2454 // No function found. | 2460 // No function found. |
| 2455 return Function::null(); | 2461 return Function::null(); |
| 2456 } | 2462 } |
| 2457 | 2463 |
| 2458 | 2464 |
| 2459 RawFunction* Class::LookupGetterFunction(const String& name) const { | 2465 RawFunction* Class::LookupGetterFunction(const String& name) const { |
| 2460 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); | 2466 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); |
| 2461 } | 2467 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2510 (token_pos <= func.end_token_pos())) { | 2516 (token_pos <= func.end_token_pos())) { |
| 2511 return func.raw(); | 2517 return func.raw(); |
| 2512 } | 2518 } |
| 2513 } | 2519 } |
| 2514 // No function found. | 2520 // No function found. |
| 2515 return Function::null(); | 2521 return Function::null(); |
| 2516 } | 2522 } |
| 2517 | 2523 |
| 2518 | 2524 |
| 2519 RawField* Class::LookupInstanceField(const String& name) const { | 2525 RawField* Class::LookupInstanceField(const String& name) const { |
| 2520 Isolate* isolate = Isolate::Current(); | 2526 return LookupField(name, kInstance); |
| 2521 if (EnsureIsFinalized(isolate) != Error::null()) { | |
| 2522 return Field::null(); | |
| 2523 } | |
| 2524 ASSERT(is_finalized()); | |
| 2525 const Field& field = Field::Handle(isolate, LookupField(name)); | |
| 2526 if (!field.IsNull()) { | |
| 2527 if (field.is_static()) { | |
| 2528 // Name matches but it is not of the correct kind, return NULL. | |
| 2529 return Field::null(); | |
| 2530 } | |
| 2531 return field.raw(); | |
| 2532 } | |
| 2533 // No field found. | |
| 2534 return Field::null(); | |
| 2535 } | 2527 } |
| 2536 | 2528 |
| 2537 | 2529 |
| 2538 RawField* Class::LookupStaticField(const String& name) const { | 2530 RawField* Class::LookupStaticField(const String& name) const { |
| 2539 Isolate* isolate = Isolate::Current(); | 2531 return LookupField(name, kStatic); |
| 2540 if (EnsureIsFinalized(isolate) != Error::null()) { | |
| 2541 return Field::null(); | |
| 2542 } | |
| 2543 ASSERT(is_finalized()); | |
| 2544 const Field& field = Field::Handle(isolate, LookupField(name)); | |
| 2545 if (!field.IsNull()) { | |
| 2546 if (!field.is_static()) { | |
| 2547 // Name matches but it is not of the correct kind, return NULL. | |
| 2548 return Field::null(); | |
| 2549 } | |
| 2550 return field.raw(); | |
| 2551 } | |
| 2552 // No field found. | |
| 2553 return Field::null(); | |
| 2554 } | 2532 } |
| 2555 | 2533 |
| 2556 | 2534 |
| 2557 RawField* Class::LookupField(const String& name) const { | 2535 RawField* Class::LookupField(const String& name) const { |
| 2536 return LookupField(name, kAny); |
| 2537 } |
| 2538 |
| 2539 |
| 2540 RawField* Class::LookupField(const String& name, intptr_t type) const { |
| 2558 Isolate* isolate = Isolate::Current(); | 2541 Isolate* isolate = Isolate::Current(); |
| 2559 if (EnsureIsFinalized(isolate) != Error::null()) { | 2542 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2560 return Field::null(); | 2543 return Field::null(); |
| 2561 } | 2544 } |
| 2562 const Array& flds = Array::Handle(isolate, fields()); | 2545 const Array& flds = Array::Handle(isolate, fields()); |
| 2563 Field& field = Field::Handle(isolate, Field::null()); | 2546 Field& field = Field::Handle(isolate, Field::null()); |
| 2564 String& field_name = String::Handle(isolate, String::null()); | 2547 String& field_name = String::Handle(isolate, String::null()); |
| 2565 intptr_t len = flds.Length(); | 2548 intptr_t len = flds.Length(); |
| 2566 for (intptr_t i = 0; i < len; i++) { | 2549 for (intptr_t i = 0; i < len; i++) { |
| 2567 field ^= flds.At(i); | 2550 field ^= flds.At(i); |
| 2568 field_name ^= field.name(); | 2551 field_name ^= field.name(); |
| 2569 if (String::EqualsIgnoringPrivateKey(field_name, name)) { | 2552 if (String::EqualsIgnoringPrivateKey(field_name, name)) { |
| 2570 return field.raw(); | 2553 if (type == kInstance) { |
| 2554 if (!field.is_static()) { |
| 2555 return field.raw(); |
| 2556 } |
| 2557 } else if (type == kStatic) { |
| 2558 if (field.is_static()) { |
| 2559 return field.raw(); |
| 2560 } |
| 2561 } else if (type == kAny) { |
| 2562 return field.raw(); |
| 2563 } |
| 2564 return Field::null(); |
| 2571 } | 2565 } |
| 2572 } | 2566 } |
| 2573 // No field found. | 2567 // No field found. |
| 2574 return Field::null(); | 2568 return Field::null(); |
| 2575 } | 2569 } |
| 2576 | 2570 |
| 2577 | 2571 |
| 2578 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { | 2572 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { |
| 2579 Isolate* isolate = Isolate::Current(); | 2573 Isolate* isolate = Isolate::Current(); |
| 2580 const Library& lib = Library::Handle(isolate, library()); | 2574 const Library& lib = Library::Handle(isolate, library()); |
| (...skipping 10755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13336 } | 13330 } |
| 13337 return result.raw(); | 13331 return result.raw(); |
| 13338 } | 13332 } |
| 13339 | 13333 |
| 13340 | 13334 |
| 13341 const char* WeakProperty::ToCString() const { | 13335 const char* WeakProperty::ToCString() const { |
| 13342 return "_WeakProperty"; | 13336 return "_WeakProperty"; |
| 13343 } | 13337 } |
| 13344 | 13338 |
| 13345 } // namespace dart | 13339 } // namespace dart |
| OLD | NEW |