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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 21092004: Inline CreateLibraryMirror. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
« no previous file with comments | « no previous file | runtime/vm/symbols.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_debugger_api.h" 6 #include "include/dart_debugger_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef.
10 #include "vm/bootstrap_natives.h" 10 #include "vm/bootstrap_natives.h"
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 args.SetAt(1, name); 395 args.SetAt(1, name);
396 args.SetAt(2, owner_mirror); 396 args.SetAt(2, owner_mirror);
397 args.SetAt(3, Instance::Handle()); // Null for type. 397 args.SetAt(3, Instance::Handle()); // Null for type.
398 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); 398 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False());
399 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); 399 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False());
400 400
401 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); 401 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args);
402 } 402 }
403 403
404 404
405 static Dart_Handle CreateLibraryMirrorUsingApi(Dart_Handle lib) {
406 Dart_Handle cls_name = NewString("_LocalLibraryMirrorImpl");
407 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
408 if (Dart_IsError(type)) {
409 return type;
410 }
411 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib);
412 if (Dart_IsError(lazy_lib_mirror)) {
413 return lazy_lib_mirror;
414 }
415 Dart_Handle args[] = {
416 CreateMirrorReference(lib),
417 Dart_LibraryName(lib),
418 Dart_LibraryUrl(lib),
419 };
420 Dart_Handle lib_mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
421 if (Dart_IsError(lib_mirror)) {
422 return lib_mirror;
423 }
424
425 return lib_mirror;
426 }
427
428
429 static RawInstance* CreateClassMirror(const Class& cls, 405 static RawInstance* CreateClassMirror(const Class& cls,
430 const Instance& owner_mirror) { 406 const Instance& owner_mirror) {
431 Instance& retvalue = Instance::Handle(); 407 Instance& retvalue = Instance::Handle();
432 Dart_EnterScope(); 408 Dart_EnterScope();
433 Isolate* isolate = Isolate::Current(); 409 Isolate* isolate = Isolate::Current();
434 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); 410 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw());
435 if (Dart_IsError(cls_handle)) { 411 if (Dart_IsError(cls_handle)) {
436 Dart_PropagateError(cls_handle); 412 Dart_PropagateError(cls_handle);
437 } 413 }
438 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); 414 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name());
439 if (Dart_IsError(name_handle)) { 415 if (Dart_IsError(name_handle)) {
440 Dart_PropagateError(name_handle); 416 Dart_PropagateError(name_handle);
441 } 417 }
442 Dart_Handle lib_mirror = Api::NewHandle(isolate, owner_mirror.raw()); 418 Dart_Handle lib_mirror = Api::NewHandle(isolate, owner_mirror.raw());
443 // TODO(11742): At some point the handle calls will be replaced by inlined 419 // TODO(11742): At some point the handle calls will be replaced by inlined
444 // functionality. 420 // functionality.
445 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle, 421 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle,
446 name_handle, 422 name_handle,
447 lib_mirror); 423 lib_mirror);
448 if (Dart_IsError(result)) { 424 if (Dart_IsError(result)) {
449 Dart_PropagateError(result); 425 Dart_PropagateError(result);
450 } 426 }
451 retvalue ^= Api::UnwrapHandle(result); 427 retvalue ^= Api::UnwrapHandle(result);
452 Dart_ExitScope(); 428 Dart_ExitScope();
453 return retvalue.raw(); 429 return retvalue.raw();
454 } 430 }
455 431
456 432
457 static RawInstance* CreateLibraryMirror(const Library& lib) { 433 static RawInstance* CreateLibraryMirror(const Library& lib) {
458 Instance& retvalue = Instance::Handle(); 434 const Array& args = Array::Handle(Array::New(3));
459 Dart_EnterScope(); 435 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib)));
460 Isolate* isolate = Isolate::Current(); 436 String& str = String::Handle();
461 Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw()); 437 str = lib.name();
462 // TODO(11742): At some point the handle calls will be replaced by inlined 438 args.SetAt(1, str);
463 // functionality. 439 str = lib.url();
464 Dart_Handle result = CreateLibraryMirrorUsingApi(lib_handle); 440 args.SetAt(2, str);
465 if (Dart_IsError(result)) { 441 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args);
466 Dart_PropagateError(result);
467 }
468 retvalue ^= Api::UnwrapHandle(result);
469 Dart_ExitScope();
470 return retvalue.raw();
471 } 442 }
472 443
473 444
474 static RawInstance* CreateTypeMirror(const AbstractType& type) { 445 static RawInstance* CreateTypeMirror(const AbstractType& type) {
475 ASSERT(!type.IsMalformed()); 446 ASSERT(!type.IsMalformed());
476 if (type.HasResolvedTypeClass()) { 447 if (type.HasResolvedTypeClass()) {
477 const Class& cls = Class::Handle(type.type_class()); 448 const Class& cls = Class::Handle(type.type_class());
478 // Handle void and dynamic types. 449 // Handle void and dynamic types.
479 if (cls.IsVoidClass()) { 450 if (cls.IsVoidClass()) {
480 Array& args = Array::Handle(Array::New(1)); 451 Array& args = Array::Handle(Array::New(1));
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 1412
1442 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1413 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1443 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1414 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1444 const Field& field = Field::Handle(ref.GetFieldReferent()); 1415 const Field& field = Field::Handle(ref.GetFieldReferent());
1445 1416
1446 const AbstractType& type = AbstractType::Handle(field.type()); 1417 const AbstractType& type = AbstractType::Handle(field.type());
1447 return CreateTypeMirror(type); 1418 return CreateTypeMirror(type);
1448 } 1419 }
1449 1420
1450 } // namespace dart 1421 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698