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

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

Issue 21624006: ParameterMirror: Implement some missing getters. (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/lib/mirrors_impl.dart » ('j') | tests/lib/mirrors/stringify.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 "lib/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 27 matching lines...) Expand all
38 UNREACHABLE(); 38 UNREACHABLE();
39 } 39 }
40 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); 40 ASSERT(id_obj.IsSmi() || id_obj.IsMint());
41 Integer& id = Integer::Handle(); 41 Integer& id = Integer::Handle();
42 id ^= id_obj.raw(); 42 id ^= id_obj.raw();
43 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); 43 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value());
44 return Bool::Get(PortMap::IsLocalPort(port_id)); 44 return Bool::Get(PortMap::IsLocalPort(port_id));
45 } 45 }
46 46
47 47
48 static RawInstance* CreateParameterMirrorList(const Function& func) { 48 static RawInstance* CreateParameterMirrorList(const Function& func,
49 const Instance& owner_mirror) {
49 HANDLESCOPE(Isolate::Current()); 50 HANDLESCOPE(Isolate::Current());
50 const intptr_t param_cnt = func.num_fixed_parameters() - 51 const intptr_t implicit_param_count = func.NumImplicitParameters();
51 func.NumImplicitParameters() + 52 const intptr_t non_implicit_param_count = func.NumParameters() -
52 func.NumOptionalParameters(); 53 implicit_param_count;
53 const Array& results = Array::Handle(Array::New(param_cnt)); 54 const intptr_t index_of_first_optional_param =
54 const Array& args = Array::Handle(Array::New(3)); 55 non_implicit_param_count - func.NumOptionalParameters();
56 const intptr_t index_of_first_named_param =
57 non_implicit_param_count - func.NumOptionalNamedParameters();
58 const Array& results = Array::Handle(Array::New(non_implicit_param_count));
59 const Array& args = Array::Handle(Array::New(6));
55 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 60 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
61 args.SetAt(2, owner_mirror);
56 Smi& pos = Smi::Handle(); 62 Smi& pos = Smi::Handle();
63 String& name = String::Handle();
57 Instance& param = Instance::Handle(); 64 Instance& param = Instance::Handle();
58 for (intptr_t i = 0; i < param_cnt; i++) { 65 for (intptr_t i = 0; i < non_implicit_param_count; i++) {
59 pos ^= Smi::New(i); 66 pos ^= Smi::New(i);
60 args.SetAt(1, pos); 67 name ^= func.ParameterNameAt(implicit_param_count + i);
61 args.SetAt(2, (i >= func.num_fixed_parameters()) ? 68 args.SetAt(1, name);
69 args.SetAt(3, pos);
70 args.SetAt(4, (i >= index_of_first_optional_param) ?
71 Bool::True() : Bool::False());
72 args.SetAt(5, (i >= index_of_first_named_param) ?
62 Bool::True() : Bool::False()); 73 Bool::True() : Bool::False());
63 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); 74 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args);
64 results.SetAt(i, param); 75 results.SetAt(i, param);
65 } 76 }
66 results.MakeImmutable(); 77 results.MakeImmutable();
67 return results.raw(); 78 return results.raw();
68 } 79 }
69 80
70 81
71 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, 82 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 owner_mirror, 382 owner_mirror,
372 arguments->NativeArgAt(0)); 383 arguments->NativeArgAt(0));
373 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 384 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
374 const Class& cls = Class::Handle(ref.GetClassReferent()); 385 const Class& cls = Class::Handle(ref.GetClassReferent());
375 const Function& func = Function::Handle(CallMethod(cls)); 386 const Function& func = Function::Handle(CallMethod(cls));
376 ASSERT(!func.IsNull()); 387 ASSERT(!func.IsNull());
377 return CreateMethodMirror(func, owner_mirror); 388 return CreateMethodMirror(func, owner_mirror);
378 } 389 }
379 390
380 391
381 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { 392 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) {
382 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 393 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
394 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
383 const Class& cls = Class::Handle(ref.GetClassReferent()); 395 const Class& cls = Class::Handle(ref.GetClassReferent());
384 const Function& func = Function::Handle(CallMethod(cls)); 396 const Function& func = Function::Handle(cls.signature_function());
385 ASSERT(!func.IsNull()); 397 return CreateParameterMirrorList(func, owner);
386 return CreateParameterMirrorList(func);
387 } 398 }
388 399
389 400
390 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { 401 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) {
391 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 402 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
392 const Class& cls = Class::Handle(ref.GetClassReferent()); 403 const Class& cls = Class::Handle(ref.GetClassReferent());
393 const Function& func = Function::Handle(CallMethod(cls)); 404 const Function& func = Function::Handle(CallMethod(cls));
394 ASSERT(!func.IsNull()); 405 ASSERT(!func.IsNull());
395 return func.result_type(); 406 return func.result_type();
396 } 407 }
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 const Class& owner = Class::Handle(func.Owner()); 1235 const Class& owner = Class::Handle(func.Owner());
1225 if (owner.IsTopLevel()) { 1236 if (owner.IsTopLevel()) {
1226 return CreateLibraryMirror(Library::Handle(owner.library())); 1237 return CreateLibraryMirror(Library::Handle(owner.library()));
1227 } 1238 }
1228 return CreateClassMirror(owner, 1239 return CreateClassMirror(owner,
1229 AbstractType::Handle(), 1240 AbstractType::Handle(),
1230 Object::null_instance()); 1241 Object::null_instance());
1231 } 1242 }
1232 1243
1233 1244
1234 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { 1245 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) {
1235 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1246 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
1247 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1236 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1248 const Function& func = Function::Handle(ref.GetFunctionReferent());
1237 return CreateParameterMirrorList(func); 1249 return CreateParameterMirrorList(func, owner);
1238 } 1250 }
1239 1251
1240 1252
1241 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { 1253 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
1242 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1254 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1243 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1255 const Function& func = Function::Handle(ref.GetFunctionReferent());
1244 // We handle constructors in Dart code. 1256 // We handle constructors in Dart code.
1245 ASSERT(!func.IsConstructor()); 1257 ASSERT(!func.IsConstructor());
1246 return func.result_type(); 1258 return func.result_type();
1247 } 1259 }
(...skipping 16 matching lines...) Expand all
1264 } 1276 }
1265 1277
1266 1278
1267 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1279 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1268 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1280 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1269 const Field& field = Field::Handle(ref.GetFieldReferent()); 1281 const Field& field = Field::Handle(ref.GetFieldReferent());
1270 return field.type(); 1282 return field.type();
1271 } 1283 }
1272 1284
1273 } // namespace dart 1285 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | tests/lib/mirrors/stringify.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698