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

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

Issue 22292002: Reflection on generics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address generic equality 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 "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/dart_entry.h" 8 #include "vm/dart_entry.h"
8 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
9 #include "vm/object_store.h" 10 #include "vm/object_store.h"
10 #include "vm/port.h" 11 #include "vm/port.h"
11 #include "vm/symbols.h" 12 #include "vm/symbols.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 static RawInstance* CreateMirror(const String& mirror_class_name, 16 static RawInstance* CreateMirror(const String& mirror_class_name,
16 const Array& constructor_arguments) { 17 const Array& constructor_arguments) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ASSERT(type.IsTypeParameter()); 93 ASSERT(type.IsTypeParameter());
93 name ^= type.name(); 94 name ^= type.name();
94 result.SetAt(2 * i, name); 95 result.SetAt(2 * i, name);
95 result.SetAt(2 * i + 1, type); 96 result.SetAt(2 * i + 1, type);
96 } 97 }
97 return result.raw(); 98 return result.raw();
98 } 99 }
99 100
100 101
101 static RawInstance* CreateTypedefMirror(const Class& cls, 102 static RawInstance* CreateTypedefMirror(const Class& cls,
103 const AbstractType& type,
regis 2013/08/08 17:06:34 Parameter 'type' added but not used? If it is for
rmacnak 2013/08/08 20:04:06 Leftover from intermediate implementation that com
102 const Instance& owner_mirror) { 104 const Instance& owner_mirror) {
103 const Array& args = Array::Handle(Array::New(3)); 105 const Array& args = Array::Handle(Array::New(3));
104 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 106 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
105 args.SetAt(1, String::Handle(cls.UserVisibleName())); 107 args.SetAt(1, String::Handle(cls.UserVisibleName()));
106 args.SetAt(2, owner_mirror); 108 args.SetAt(2, owner_mirror);
107 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); 109 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args);
108 } 110 }
109 111
110 112
111 static RawInstance* CreateFunctionTypeMirror(const Class& cls) { 113 static RawInstance* CreateFunctionTypeMirror(const Class& cls,
112 const Array& args = Array::Handle(Array::New(1)); 114 const AbstractType& type) {
115 const Array& args = Array::Handle(Array::New(2));
113 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 116 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
117 args.SetAt(1, type);
114 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); 118 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args);
115 } 119 }
116 120
117 121
118 static RawInstance* CreateMethodMirror(const Function& func, 122 static RawInstance* CreateMethodMirror(const Function& func,
119 const Instance& owner_mirror) { 123 const Instance& owner_mirror) {
120 const Array& args = Array::Handle(Array::New(12)); 124 const Array& args = Array::Handle(Array::New(12));
121 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 125 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
122 args.SetAt(1, String::Handle(func.UserVisibleName())); 126 args.SetAt(1, String::Handle(func.UserVisibleName()));
123 args.SetAt(2, owner_mirror); 127 args.SetAt(2, owner_mirror);
(...skipping 24 matching lines...) Expand all
148 args.SetAt(2, owner_mirror); 152 args.SetAt(2, owner_mirror);
149 args.SetAt(3, Instance::Handle()); // Null for type. 153 args.SetAt(3, Instance::Handle()); // Null for type.
150 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); 154 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False());
151 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); 155 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False());
152 156
153 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); 157 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args);
154 } 158 }
155 159
156 160
157 static RawInstance* CreateClassMirror(const Class& cls, 161 static RawInstance* CreateClassMirror(const Class& cls,
162 const AbstractType& type,
158 const Instance& owner_mirror) { 163 const Instance& owner_mirror) {
159 if (cls.IsSignatureClass()) { 164 if (cls.IsSignatureClass()) {
160 if (cls.IsCanonicalSignatureClass()) { 165 if (cls.IsCanonicalSignatureClass()) {
161 // We represent function types as canonical signature classes. 166 // We represent function types as canonical signature classes.
162 return CreateFunctionTypeMirror(cls); 167 return CreateFunctionTypeMirror(cls, type);
163 } else { 168 } else {
164 // We represent typedefs as non-canonical signature classes. 169 // We represent typedefs as non-canonical signature classes.
165 return CreateTypedefMirror(cls, owner_mirror); 170 return CreateTypedefMirror(cls, type, owner_mirror);
166 } 171 }
167 } 172 }
168 173
169 const Array& args = Array::Handle(Array::New(2)); 174 AbstractTypeArguments& type_parameters =
175 AbstractTypeArguments::Handle(cls.type_parameters());
176 const Bool& is_generic =
177 type_parameters.IsNull() || type_parameters.Length() == 0
regis 2013/08/08 17:06:34 We like parenthesis (a lot!). In any case, this wo
rmacnak 2013/08/08 20:04:06 Done.
178 ? Bool::False()
179 : Bool::True();
180
181 const Array& args = Array::Handle(Array::New(4));
170 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 182 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
171 args.SetAt(1, String::Handle(cls.UserVisibleName())); 183 args.SetAt(1, type);
184 args.SetAt(2, String::Handle(cls.UserVisibleName()));
185 args.SetAt(3, is_generic);
172 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); 186 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args);
173 } 187 }
174 188
175 189
190 // Note a "raw type" is not the same as a RawType.
191 static RawAbstractType* RawTypeOfClass(const Class& klass) {
regis 2013/08/08 17:06:34 Why 'klass' and 'cls' elsewhere? I think 'cls' is
rmacnak 2013/08/08 20:04:06 Different authors. Switched to cls, as its use is
192 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
regis 2013/08/08 17:06:34 You can save a handle and pass directly Object::nu
rmacnak 2013/08/08 20:04:06 Done.
193 Type& type =
194 Type::Handle(Type::New(klass, type_arguments, Scanner::kDummyTokenIndex));
195 return ClassFinalizer::FinalizeType(klass,
196 type,
197 ClassFinalizer::kCanonicalize);
198 }
199
200
176 static RawInstance* CreateLibraryMirror(const Library& lib) { 201 static RawInstance* CreateLibraryMirror(const Library& lib) {
177 const Array& args = Array::Handle(Array::New(3)); 202 const Array& args = Array::Handle(Array::New(3));
178 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); 203 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib)));
179 String& str = String::Handle(); 204 String& str = String::Handle();
180 str = lib.name(); 205 str = lib.name();
181 args.SetAt(1, str); 206 args.SetAt(1, str);
182 str = lib.url(); 207 str = lib.url();
183 args.SetAt(2, str); 208 args.SetAt(2, str);
184 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); 209 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args);
185 } 210 }
186 211
187 212
188 static RawInstance* CreateTypeMirror(const AbstractType& type) { 213 static RawInstance* CreateTypeMirror(const AbstractType& type) {
189 ASSERT(!type.IsMalformed()); 214 ASSERT(!type.IsMalformed());
190 if (type.HasResolvedTypeClass()) { 215 if (type.HasResolvedTypeClass()) {
191 const Class& cls = Class::Handle(type.type_class()); 216 const Class& cls = Class::Handle(type.type_class());
192 // Handle void and dynamic types. 217 // Handle void and dynamic types.
193 if (cls.IsVoidClass()) { 218 if (cls.IsVoidClass()) {
194 Array& args = Array::Handle(Array::New(1)); 219 Array& args = Array::Handle(Array::New(1));
195 args.SetAt(0, Symbols::Void()); 220 args.SetAt(0, Symbols::Void());
196 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. 221 // TODO(mlippautz): Create once in the VM isolate and retrieve from there.
197 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); 222 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args);
198 } else if (cls.IsDynamicClass()) { 223 } else if (cls.IsDynamicClass()) {
199 Array& args = Array::Handle(Array::New(1)); 224 Array& args = Array::Handle(Array::New(1));
200 args.SetAt(0, Symbols::Dynamic()); 225 args.SetAt(0, Symbols::Dynamic());
201 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. 226 // TODO(mlippautz): Create once in the VM isolate and retrieve from there.
202 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); 227 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args);
203 } 228 }
204 return CreateClassMirror(cls, Object::null_instance()); 229 return CreateClassMirror(cls, type, Object::null_instance());
205 } else if (type.IsTypeParameter()) { 230 } else if (type.IsTypeParameter()) {
206 return CreateTypeVariableMirror(TypeParameter::Cast(type), 231 return CreateTypeVariableMirror(TypeParameter::Cast(type),
207 Object::null_instance()); 232 Object::null_instance());
208 } 233 }
209 UNREACHABLE(); 234 UNREACHABLE();
210 return Instance::null(); 235 return Instance::null();
211 } 236 }
212 237
213 238
214 static RawInstance* CreateIsolateMirror() { 239 static RawInstance* CreateIsolateMirror() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 277
253 278
254 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { 279 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) {
255 return CreateMirrorSystem(); 280 return CreateMirrorSystem();
256 } 281 }
257 282
258 283
259 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { 284 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) {
260 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); 285 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
261 const Class& cls = Class::Handle(type.type_class()); 286 const Class& cls = Class::Handle(type.type_class());
262 return CreateClassMirror(cls, Object::null_instance()); 287 ASSERT(!cls.IsNull());
288 return CreateClassMirror(cls,
289 AbstractType::Handle(),
290 Instance::null_instance());
263 } 291 }
264 292
265 293
294 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) {
295 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
296 return CreateTypeMirror(type);
297 }
298
299
266 static void ThrowMirroredCompilationError(const String& message) { 300 static void ThrowMirroredCompilationError(const String& message) {
267 Array& args = Array::Handle(Array::New(1)); 301 Array& args = Array::Handle(Array::New(1));
268 args.SetAt(0, message); 302 args.SetAt(0, message);
269 303
270 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); 304 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args);
271 UNREACHABLE(); 305 UNREACHABLE();
272 } 306 }
273 307
274 308
275 static void ThrowInvokeError(const Error& error) { 309 static void ThrowInvokeError(const Error& error) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 const Class& cls = Class::Handle(ref.GetClassReferent()); 362 const Class& cls = Class::Handle(ref.GetClassReferent());
329 const Function& func = Function::Handle(cls.signature_function()); 363 const Function& func = Function::Handle(cls.signature_function());
330 return CreateParameterMirrorList(func); 364 return CreateParameterMirrorList(func);
331 } 365 }
332 366
333 367
334 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { 368 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) {
335 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 369 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
336 const Class& cls = Class::Handle(ref.GetClassReferent()); 370 const Class& cls = Class::Handle(ref.GetClassReferent());
337 const Function& func = Function::Handle(cls.signature_function()); 371 const Function& func = Function::Handle(cls.signature_function());
338 const AbstractType& return_type = AbstractType::Handle(func.result_type()); 372 return func.result_type();
339 return CreateTypeMirror(return_type);
340 } 373 }
341 374
342 375
343 static bool FieldIsUninitialized(const Field& field) { 376 static bool FieldIsUninitialized(const Field& field) {
344 ASSERT(!field.IsNull()); 377 ASSERT(!field.IsNull());
345 378
346 // Return getter method for uninitialized fields, rather than the 379 // Return getter method for uninitialized fields, rather than the
347 // field object, since the value in the field object will not be 380 // field object, since the value in the field object will not be
348 // initialized until the first time the getter is invoked. 381 // initialized until the first time the getter is invoked.
349 const Instance& value = Instance::Handle(field.value()); 382 const Instance& value = Instance::Handle(field.value());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 DictionaryIterator entries(library); 525 DictionaryIterator entries(library);
493 526
494 while (entries.HasNext()) { 527 while (entries.HasNext()) {
495 entry = entries.GetNext(); 528 entry = entries.GetNext();
496 if (entry.IsClass()) { 529 if (entry.IsClass()) {
497 const Class& klass = Class::Cast(entry); 530 const Class& klass = Class::Cast(entry);
498 if (!klass.IsCanonicalSignatureClass()) { 531 if (!klass.IsCanonicalSignatureClass()) {
499 // The various implementations of public classes don't always have the 532 // The various implementations of public classes don't always have the
500 // expected superinterfaces or other properties, so we filter them out. 533 // expected superinterfaces or other properties, so we filter them out.
501 if (!RawObject::IsImplementationClassId(klass.id())) { 534 if (!RawObject::IsImplementationClassId(klass.id())) {
502 member_mirror = CreateClassMirror(klass, owner_mirror); 535 member_mirror = CreateClassMirror(klass,
536 AbstractType::Handle(),
537 owner_mirror);
503 member_mirrors.Add(member_mirror); 538 member_mirrors.Add(member_mirror);
504 } 539 }
505 } 540 }
506 } else if (entry.IsField()) { 541 } else if (entry.IsField()) {
507 const Field& field = Field::Cast(entry); 542 const Field& field = Field::Cast(entry);
508 member_mirror = CreateVariableMirror(field, owner_mirror); 543 member_mirror = CreateVariableMirror(field, owner_mirror);
509 member_mirrors.Add(member_mirror); 544 member_mirrors.Add(member_mirror);
510 } else if (entry.IsFunction()) { 545 } else if (entry.IsFunction()) {
511 const Function& func = Function::Cast(entry); 546 const Function& func = Function::Cast(entry);
512 if (func.kind() == RawFunction::kRegularFunction || 547 if (func.kind() == RawFunction::kRegularFunction ||
513 func.kind() == RawFunction::kGetterFunction || 548 func.kind() == RawFunction::kGetterFunction ||
514 func.kind() == RawFunction::kSetterFunction) { 549 func.kind() == RawFunction::kSetterFunction) {
515 member_mirror = CreateMethodMirror(func, owner_mirror); 550 member_mirror = CreateMethodMirror(func, owner_mirror);
516 member_mirrors.Add(member_mirror); 551 member_mirrors.Add(member_mirror);
517 } 552 }
518 } 553 }
519 } 554 }
520 555
521 return member_mirrors.raw(); 556 return member_mirrors.raw();
522 } 557 }
523 558
524 559
525 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { 560 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) {
526 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 561 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
527 const Class& klass = Class::Handle(ref.GetClassReferent()); 562 const Class& klass = Class::Handle(ref.GetClassReferent());
528 return CreateTypeVariableList(klass); 563 return CreateTypeVariableList(klass);
529 } 564 }
530 565
531 566
532 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_owner, 1) { 567 DEFINE_NATIVE_ENTRY(ClassMirror_type_arguments, 1) {
568 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
569
570 const AbstractTypeArguments& args =
571 AbstractTypeArguments::Handle(type.arguments());
572 if (args.IsNull()) {
573 return Object::empty_array().raw();
574 }
575
576 const Class& klass = Class::Handle(type.type_class());
577 const TypeArguments& params = TypeArguments::Handle(klass.type_parameters());
578 intptr_t num_params = 0;
579 if (!params.IsNull()) {
580 num_params = params.Length();
581 }
regis 2013/08/08 17:06:34 You can replace the above 5 lines with const intpt
rmacnak 2013/08/08 20:04:06 Done.
582 const intptr_t num_inherited_args = args.Length() - num_params;
583
584 const Array& result = Array::Handle(Array::New(num_params));
585 AbstractType& arg_type = AbstractType::Handle();
586 Instance& type_mirror = Instance::Handle();
587 for (intptr_t i = 0; i < num_params; i++) {
588 arg_type ^= args.TypeAt(i + num_inherited_args);
589 type_mirror = CreateTypeMirror(arg_type);
590 result.SetAt(i, type_mirror);
591 }
592 return result.raw();
593 }
594
595
596 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) {
533 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); 597 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
534 return CreateClassMirror(Class::Handle(param.parameterized_class()), 598 return CreateClassMirror(Class::Handle(param.parameterized_class()),
599 AbstractType::Handle(),
535 Instance::null_instance()); 600 Instance::null_instance());
536 } 601 }
537 602
538 603
539 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_upper_bound, 1) { 604 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) {
540 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); 605 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
541 return CreateTypeMirror(AbstractType::Handle(param.bound())); 606 return param.bound();
542 } 607 }
543 608
544 609
545 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled 610 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled
546 // exceptions. Wrap and propagate any compilation errors. 611 // exceptions. Wrap and propagate any compilation errors.
547 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, 612 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver,
548 const Function& function, 613 const Function& function,
549 const String& target_name, 614 const String& target_name,
550 const Array& arguments) { 615 const Array& arguments) {
551 // Note "arguments" is already the internal arguments with the receiver as 616 // Note "arguments" is already the internal arguments with the receiver as
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); 821 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args);
757 UNREACHABLE(); 822 UNREACHABLE();
758 } 823 }
759 824
760 825
761 static void ThrowNoSuchMethod(const Class& klass, 826 static void ThrowNoSuchMethod(const Class& klass,
762 const String& function_name, 827 const String& function_name,
763 const Function& function, 828 const Function& function,
764 const InvocationMirror::Call call, 829 const InvocationMirror::Call call,
765 const InvocationMirror::Type type) { 830 const InvocationMirror::Type type) {
766 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 831 AbstractType& runtime_type = AbstractType::Handle(RawTypeOfClass(klass));
767 Type& pre_type = Type::Handle(
768 Type::New(klass, type_arguments, Scanner::kDummyTokenIndex));
769 pre_type.SetIsFinalized();
770 AbstractType& runtime_type = AbstractType::Handle(pre_type.Canonicalize());
771 832
772 ThrowNoSuchMethod(runtime_type, 833 ThrowNoSuchMethod(runtime_type,
773 function_name, 834 function_name,
774 function, 835 function,
775 call, 836 call,
776 type); 837 type);
777 UNREACHABLE(); 838 UNREACHABLE();
778 } 839 }
779 840
780 841
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1205 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1145 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1206 const Function& func = Function::Handle(ref.GetFunctionReferent());
1146 if (func.IsNonImplicitClosureFunction()) { 1207 if (func.IsNonImplicitClosureFunction()) {
1147 return CreateMethodMirror(Function::Handle( 1208 return CreateMethodMirror(Function::Handle(
1148 func.parent_function()), Object::null_instance()); 1209 func.parent_function()), Object::null_instance());
1149 } 1210 }
1150 const Class& owner = Class::Handle(func.Owner()); 1211 const Class& owner = Class::Handle(func.Owner());
1151 if (owner.IsTopLevel()) { 1212 if (owner.IsTopLevel()) {
1152 return CreateLibraryMirror(Library::Handle(owner.library())); 1213 return CreateLibraryMirror(Library::Handle(owner.library()));
1153 } 1214 }
1154 return CreateClassMirror(owner, Object::null_instance()); 1215 return CreateClassMirror(owner,
1216 AbstractType::Handle(),
1217 Object::null_instance());
1155 } 1218 }
1156 1219
1157 1220
1158 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { 1221 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) {
1159 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1222 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1160 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1223 const Function& func = Function::Handle(ref.GetFunctionReferent());
1161 return CreateParameterMirrorList(func); 1224 return CreateParameterMirrorList(func);
1162 } 1225 }
1163 1226
1164 1227
1165 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { 1228 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
1166 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1229 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1167 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1230 const Function& func = Function::Handle(ref.GetFunctionReferent());
1168 // We handle constructors in Dart code. 1231 // We handle constructors in Dart code.
1169 ASSERT(!func.IsConstructor()); 1232 ASSERT(!func.IsConstructor());
1170 const AbstractType& return_type = AbstractType::Handle(func.result_type()); 1233 return func.result_type();
1171 return CreateTypeMirror(return_type);
1172 } 1234 }
1173 1235
1174 1236
1175 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { 1237 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) {
1176 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1238 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1177 const Class& cls = Class::Handle(ref.GetClassReferent()); 1239 const Class& cls = Class::Handle(ref.GetClassReferent());
1178 const Function& sig_func = Function::Handle(cls.signature_function()); 1240 const Function& sig_func = Function::Handle(cls.signature_function());
1179 const Class& sig_cls = Class::Handle(sig_func.signature_class()); 1241 const Class& sig_cls = Class::Handle(sig_func.signature_class());
1180 return MirrorReference::New(sig_cls); 1242 return MirrorReference::New(sig_cls);
1181 } 1243 }
1182 1244
1183 1245
1184 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { 1246 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) {
1185 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1247 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1186 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); 1248 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1));
1187 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1249 const Function& func = Function::Handle(ref.GetFunctionReferent());
1188 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( 1250 return func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value());
1189 func.NumImplicitParameters() + pos.Value()));
1190 return CreateTypeMirror(param_type);
1191 } 1251 }
1192 1252
1193 1253
1194 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1254 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1195 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1255 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1196 const Field& field = Field::Handle(ref.GetFieldReferent()); 1256 const Field& field = Field::Handle(ref.GetFieldReferent());
1197 1257 return field.type();
1198 const AbstractType& type = AbstractType::Handle(field.type());
1199 return CreateTypeMirror(type);
1200 } 1258 }
1201 1259
1202 } // namespace dart 1260 } // 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