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

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

Issue 19496003: Make ClassMirror.members internal-native and lazy. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if (Dart_IsNull(super_class)) { 530 if (Dart_IsNull(super_class)) {
531 super_class = Dart_GetClass(CoreLib(), NewString("Object")); 531 super_class = Dart_GetClass(CoreLib(), NewString("Object"));
532 } 532 }
533 // TODO(turnidge): Simplify code, now that default classes have been removed. 533 // TODO(turnidge): Simplify code, now that default classes have been removed.
534 Dart_Handle default_class = Dart_Null(); 534 Dart_Handle default_class = Dart_Null();
535 535
536 Dart_Handle intf_mirror = CreateLazyMirror(intf); 536 Dart_Handle intf_mirror = CreateLazyMirror(intf);
537 if (Dart_IsError(intf_mirror)) { 537 if (Dart_IsError(intf_mirror)) {
538 return intf_mirror; 538 return intf_mirror;
539 } 539 }
540 Dart_Handle member_map = CreateMemberMap(intf, intf_mirror);
541 if (Dart_IsError(member_map)) {
542 return member_map;
543 }
544 Dart_Handle constructor_map = CreateConstructorMap(intf, intf_mirror); 540 Dart_Handle constructor_map = CreateConstructorMap(intf, intf_mirror);
545 if (Dart_IsError(constructor_map)) { 541 if (Dart_IsError(constructor_map)) {
546 return constructor_map; 542 return constructor_map;
547 } 543 }
548 Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror); 544 Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror);
549 if (Dart_IsError(type_var_map)) { 545 if (Dart_IsError(type_var_map)) {
550 return type_var_map; 546 return type_var_map;
551 } 547 }
552 548
553 Dart_Handle args[] = { 549 Dart_Handle args[] = {
554 CreateMirrorReference(intf), 550 CreateMirrorReference(intf),
555 Dart_Null(), // "name" 551 Dart_Null(), // "name"
556 Dart_NewBoolean(Dart_IsClass(intf)), 552 Dart_NewBoolean(Dart_IsClass(intf)),
557 lib_mirror, 553 lib_mirror,
558 CreateLazyMirror(super_class), 554 CreateLazyMirror(super_class),
559 CreateImplementsList(intf), 555 CreateImplementsList(intf),
560 CreateLazyMirror(default_class), 556 CreateLazyMirror(default_class),
561 member_map,
562 constructor_map, 557 constructor_map,
563 type_var_map, 558 type_var_map,
564 }; 559 };
565 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 560 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
566 return mirror; 561 return mirror;
567 } 562 }
568 563
569 564
570 static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func, 565 static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func,
571 Dart_Handle owner_mirror) { 566 Dart_Handle owner_mirror) {
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 } 1301 }
1307 1302
1308 1303
1309 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { 1304 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) {
1310 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1305 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1311 const Class& klass = Class::Handle(ref.GetClassReferent()); 1306 const Class& klass = Class::Handle(ref.GetClassReferent());
1312 return CreateLibraryMirror(Library::Handle(klass.library())); 1307 return CreateLibraryMirror(Library::Handle(klass.library()));
1313 } 1308 }
1314 1309
1315 1310
1311 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) {
rmacnak 2013/07/23 01:15:37 I intend to adapt this to be shared with LibraryMi
1312 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
1313 owner_mirror,
1314 arguments->NativeArgAt(0));
1315 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1316 const Class& klass = Class::Handle(ref.GetClassReferent());
1317
1318 const Array& fields = Array::Handle(klass.fields());
1319 // Some special types like 'dynamic' have a null fields list, but they should
1320 // not wind up as the reflectees of ClassMirrors.
siva 2013/07/23 21:14:39 One way to avoid this could be to store empty_arra
rmacnak 2013/07/23 22:57:34 Hm. This irregularity also affects LookupField/Loo
siva 2013/07/23 23:37:07 Need to debug this. On 2013/07/23 22:57:34, Ryan
1321 ASSERT(!fields.IsNull());
1322 const intptr_t num_fields = fields.Length();
1323
1324 const Array& functions = Array::Handle(klass.functions());
1325 // Some special types like 'dynamic' have a null functions list, but they
1326 // should not wind up as the reflectees of ClassMirrors.
1327 ASSERT(!functions.IsNull());
siva 2013/07/23 21:14:39 Ditto about storing empty_array() for functions.
1328 const intptr_t num_functions = functions.Length();
1329
1330 Instance& member_mirror = Instance::Handle();
1331 const GrowableObjectArray& member_mirrors = GrowableObjectArray::Handle(
1332 GrowableObjectArray::New(num_fields + num_functions));
siva 2013/07/23 21:14:39 Since you now the exact number of fields and funct
rmacnak 2013/07/23 22:57:34 We know an upper bound. Some of the functions are
siva 2013/07/23 23:37:07 True but the GrowableArray is going to allocate a
1333
1334 Field& field = Field::Handle();
1335 for (intptr_t i = 0; i < num_fields; i++) {
1336 field ^= fields.At(i);
1337 member_mirror = CreateVariableMirror(field, owner_mirror);
1338 member_mirrors.Add(member_mirror);
1339 }
1340
1341 Function& func = Function::Handle();
1342 for (intptr_t i = 0; i < num_functions; i++) {
1343 func ^= functions.At(i);
1344 if (func.kind() == RawFunction::kRegularFunction ||
1345 func.kind() == RawFunction::kGetterFunction ||
1346 func.kind() == RawFunction::kSetterFunction) {
1347 member_mirror = CreateMethodMirror(func, owner_mirror);
1348 member_mirrors.Add(member_mirror);
1349 }
1350 }
1351
1352 return member_mirrors.raw();
1353 }
1354
1355
1316 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled 1356 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled
1317 // exceptions. Wrap and propagate any compilation errors. 1357 // exceptions. Wrap and propagate any compilation errors.
1318 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, 1358 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver,
1319 const Function& function, 1359 const Function& function,
1320 const String& target_name, 1360 const String& target_name,
1321 const Array& arguments) { 1361 const Array& arguments) {
1322 // Note "arguments" is already the internal arguments with the receiver as 1362 // Note "arguments" is already the internal arguments with the receiver as
1323 // the first element. 1363 // the first element.
1324 Object& result = Object::Handle(); 1364 Object& result = Object::Handle();
1325 if (function.IsNull()) { 1365 if (function.IsNull()) {
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 1915
1876 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1916 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1877 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1917 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1878 const Field& field = Field::Handle(ref.GetFieldReferent()); 1918 const Field& field = Field::Handle(ref.GetFieldReferent());
1879 1919
1880 const AbstractType& type = AbstractType::Handle(field.type()); 1920 const AbstractType& type = AbstractType::Handle(field.type());
1881 return CreateTypeMirror(type); 1921 return CreateTypeMirror(type);
1882 } 1922 }
1883 1923
1884 } // namespace dart 1924 } // 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