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

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

Issue 20216002: Make ClassMirror.typeVariables lazy and convert dependencies to native code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Get rid of TypeVariableMirror dependency 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/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 350 }
351 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror); 351 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror);
352 if (Dart_IsError(result)) { 352 if (Dart_IsError(result)) {
353 return result; 353 return result;
354 } 354 }
355 } 355 }
356 return mirror_list; 356 return mirror_list;
357 } 357 }
358 358
359 359
360 static Dart_Handle CreateTypeVariableMirrorUsingApi(Dart_Handle type_var,
361 Dart_Handle type_var_name,
362 Dart_Handle owner_mirror) {
363 ASSERT(Dart_IsTypeVariable(type_var));
364 Dart_Handle cls_name = NewString("_LocalTypeVariableMirrorImpl");
365 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
366 if (Dart_IsError(type)) {
367 return type;
368 }
369
370 Dart_Handle upper_bound = Dart_TypeVariableUpperBound(type_var);
371 if (Dart_IsError(upper_bound)) {
372 return upper_bound;
373 }
374
375 Dart_Handle args[] = {
376 CreateMirrorReference(type_var),
377 type_var_name,
378 owner_mirror,
379 CreateLazyMirror(upper_bound),
380 };
381 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
382 return mirror;
383 }
384
385
386 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, 360 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param,
387 const Instance& owner_mirror) { 361 const Instance& owner_mirror) {
388 Instance& retvalue = Instance::Handle(); 362 const Array& args = Array::Handle(Array::New(3));
389 Dart_EnterScope(); 363 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(param)));
390 Isolate* isolate = Isolate::Current(); 364 args.SetAt(1, String::Handle(param.name()));
391 Dart_Handle param_handle = Api::NewHandle(isolate, param.raw()); 365 args.SetAt(2, owner_mirror);
392 if (Dart_IsError(param_handle)) { 366 return CreateMirror(Symbols::_LocalTypeVariableMirrorImpl(), args);
393 Dart_PropagateError(param_handle);
394 }
395 Dart_Handle name_handle = Api::NewHandle(isolate, param.Name());
396 if (Dart_IsError(name_handle)) {
397 Dart_PropagateError(name_handle);
398 }
399 // Until we get rid of lazy mirrors, we must have owners.
400 Dart_Handle owner_handle;
401 if (owner_mirror.IsNull()) {
402 owner_handle = Api::NewHandle(isolate, param.parameterized_class());
403 if (Dart_IsError(owner_handle)) {
404 Dart_PropagateError(owner_handle);
405 }
406 owner_handle = CreateLazyMirror(owner_handle);
407 if (Dart_IsError(owner_handle)) {
408 Dart_PropagateError(owner_handle);
409 }
410 } else {
411 owner_handle = Api::NewHandle(isolate, owner_mirror.raw());
412 if (Dart_IsError(owner_handle)) {
413 Dart_PropagateError(owner_handle);
414 }
415 }
416 // TODO(11742): At some point the handle calls will be replaced by inlined
417 // functionality.
418 Dart_Handle result = CreateTypeVariableMirrorUsingApi(param_handle,
419 name_handle,
420 owner_handle);
421 if (Dart_IsError(result)) {
422 Dart_PropagateError(result);
423 }
424 retvalue ^= Api::UnwrapHandle(result);
425 Dart_ExitScope();
426 return retvalue.raw();
427 } 367 }
428 368
429 369
430 static Dart_Handle CreateTypeVariableMap(Dart_Handle owner, 370 // We create a list in native code and let Dart code create the actual ordered
431 Dart_Handle owner_mirror) { 371 // map then.
432 ASSERT(Dart_IsClass(owner)); 372 static RawInstance* CreateTypeVariableList(const Class& cls,
433 // TODO(turnidge): This should be an immutable map. 373 const Instance& cls_mirror) {
434 Dart_Handle map = MapNew(); 374 ASSERT(cls.IsClass());
435 if (Dart_IsError(map)) { 375 TypeArguments& args = TypeArguments::Handle(cls.type_parameters());
436 return map; 376 const Array& result = Array::Handle(Array::New(args.Length()));
377 TypeParameter& type = TypeParameter::Handle();
378 Instance& mirror = Instance::Handle();
379 for (intptr_t i = 0; i < args.Length(); ++i) {
380 type ^= args.TypeAt(i);
381 ASSERT(type.IsTypeParameter());
382 mirror ^= CreateTypeVariableMirror(type, cls_mirror);
383 result.SetAt(i, mirror);
437 } 384 }
siva 2013/07/25 22:48:43 As discussed offline, let us investigate if we cou
438 385 return result.raw();
439 Dart_Handle names = Dart_GetTypeVariableNames(owner);
440 if (Dart_IsError(names)) {
441 return names;
442 }
443 intptr_t len;
444 Dart_Handle result = Dart_ListLength(names, &len);
445 if (Dart_IsError(result)) {
446 return result;
447 }
448 for (intptr_t i = 0; i < len; i++) {
449 Dart_Handle type_var_name = Dart_ListGetAt(names, i);
450 Dart_Handle type_var = Dart_LookupTypeVariable(owner, type_var_name);
451 if (Dart_IsError(type_var)) {
452 return type_var;
453 }
454 ASSERT(!Dart_IsNull(type_var));
455 Dart_Handle type_var_mirror =
456 CreateTypeVariableMirrorUsingApi(type_var, type_var_name, owner_mirror);
457 if (Dart_IsError(type_var_mirror)) {
458 return type_var_mirror;
459 }
460 result = MapAdd(map, type_var_name, type_var_mirror);
461 if (Dart_IsError(result)) {
462 return result;
463 }
464 }
465 return map;
466 } 386 }
467 387
468 388
469 static Dart_Handle CreateTypedefMirror(Dart_Handle cls, 389 static Dart_Handle CreateTypedefMirror(Dart_Handle cls,
470 Dart_Handle cls_name, 390 Dart_Handle cls_name,
471 Dart_Handle owner_mirror) { 391 Dart_Handle owner_mirror) {
472 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl"); 392 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl");
473 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); 393 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL);
474 if (Dart_IsError(mirror_type)) { 394 if (Dart_IsError(mirror_type)) {
475 return mirror_type; 395 return mirror_type;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 Dart_Handle default_class = Dart_Null(); 441 Dart_Handle default_class = Dart_Null();
522 442
523 Dart_Handle intf_mirror = CreateLazyMirror(intf); 443 Dart_Handle intf_mirror = CreateLazyMirror(intf);
524 if (Dart_IsError(intf_mirror)) { 444 if (Dart_IsError(intf_mirror)) {
525 return intf_mirror; 445 return intf_mirror;
526 } 446 }
527 Dart_Handle constructor_map = CreateConstructorMap(intf, intf_mirror); 447 Dart_Handle constructor_map = CreateConstructorMap(intf, intf_mirror);
528 if (Dart_IsError(constructor_map)) { 448 if (Dart_IsError(constructor_map)) {
529 return constructor_map; 449 return constructor_map;
530 } 450 }
531 Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror);
532 if (Dart_IsError(type_var_map)) {
533 return type_var_map;
534 }
535 451
536 Dart_Handle args[] = { 452 Dart_Handle args[] = {
537 CreateMirrorReference(intf), 453 CreateMirrorReference(intf),
538 Dart_Null(), // "name" 454 Dart_Null(), // "name"
539 Dart_NewBoolean(Dart_IsClass(intf)), 455 Dart_NewBoolean(Dart_IsClass(intf)),
540 lib_mirror, 456 lib_mirror,
541 CreateLazyMirror(super_class), 457 CreateLazyMirror(super_class),
542 CreateImplementsList(intf), 458 CreateImplementsList(intf),
543 CreateLazyMirror(default_class), 459 CreateLazyMirror(default_class),
544 constructor_map, 460 constructor_map
545 type_var_map,
546 }; 461 };
547 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 462 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
548 return mirror; 463 return mirror;
549 } 464 }
550 465
551 466
552 static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func, 467 static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func,
553 Dart_Handle owner_mirror) { 468 Dart_Handle owner_mirror) {
554 // TODO(11742): Unwrapping is needed until the whole method is converted. 469 // TODO(11742): Unwrapping is needed until the whole method is converted.
555 Isolate* isolate = Isolate::Current(); 470 Isolate* isolate = Isolate::Current();
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 member_mirror = CreateMethodMirror(func, owner_mirror); 1055 member_mirror = CreateMethodMirror(func, owner_mirror);
1141 member_mirrors.Add(member_mirror); 1056 member_mirrors.Add(member_mirror);
1142 } 1057 }
1143 } 1058 }
1144 } 1059 }
1145 1060
1146 return member_mirrors.raw(); 1061 return member_mirrors.raw();
1147 } 1062 }
1148 1063
1149 1064
1065 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 2) {
1066 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1067 GET_NON_NULL_NATIVE_ARGUMENT(Instance, mirror, arguments->NativeArgAt(1));
1068 const Class& klass = Class::Handle(ref.GetClassReferent());
1069 return CreateTypeVariableList(klass, mirror);
1070 }
1071
1072
1073 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_owner, 1) {
1074 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1075 const TypeParameter& param = TypeParameter::Handle(
1076 ref.GetTypeParameterReferent());
1077 return CreateClassMirror(Class::Handle(param.parameterized_class()),
1078 Instance::null_instance());
1079 }
1080
1081
1082 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_upper_bound, 1) {
1083 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1084 const TypeParameter& param = TypeParameter::Handle(
1085 ref.GetTypeParameterReferent());
1086 return CreateTypeMirror(AbstractType::Handle(param.bound()));
1087 }
1088
1089
1150 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled 1090 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled
1151 // exceptions. Wrap and propagate any compilation errors. 1091 // exceptions. Wrap and propagate any compilation errors.
1152 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, 1092 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver,
1153 const Function& function, 1093 const Function& function,
1154 const String& target_name, 1094 const String& target_name,
1155 const Array& arguments) { 1095 const Array& arguments) {
1156 // Note "arguments" is already the internal arguments with the receiver as 1096 // Note "arguments" is already the internal arguments with the receiver as
1157 // the first element. 1097 // the first element.
1158 Object& result = Object::Handle(); 1098 Object& result = Object::Handle();
1159 if (function.IsNull()) { 1099 if (function.IsNull()) {
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 1710
1771 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1711 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1772 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1712 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1773 const Field& field = Field::Handle(ref.GetFieldReferent()); 1713 const Field& field = Field::Handle(ref.GetFieldReferent());
1774 1714
1775 const AbstractType& type = AbstractType::Handle(field.type()); 1715 const AbstractType& type = AbstractType::Handle(field.type());
1776 return CreateTypeMirror(type); 1716 return CreateTypeMirror(type);
1777 } 1717 }
1778 1718
1779 } // namespace dart 1719 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698