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

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

Issue 63393003: Drop "Impl" suffix from local mirror class names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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') | 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 "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/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See 196 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See
197 // above. 197 // above.
198 args.SetAt(1, name); 198 args.SetAt(1, name);
199 args.SetAt(3, pos); 199 args.SetAt(3, pos);
200 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param)); 200 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param));
201 args.SetAt(5, Bool::Get(i >= index_of_first_named_param)); 201 args.SetAt(5, Bool::Get(i >= index_of_first_named_param));
202 args.SetAt(6, is_final); 202 args.SetAt(6, is_final);
203 args.SetAt(7, default_value); 203 args.SetAt(7, default_value);
204 args.SetAt(8, metadata); 204 args.SetAt(8, metadata);
205 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); 205 param ^= CreateMirror(Symbols::_LocalParameterMirror(), args);
206 results.SetAt(i, param); 206 results.SetAt(i, param);
207 } 207 }
208 results.MakeImmutable(); 208 results.MakeImmutable();
209 return results.raw(); 209 return results.raw();
210 } 210 }
211 211
212 212
213 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, 213 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param,
214 const Instance& owner_mirror) { 214 const Instance& owner_mirror) {
215 const Array& args = Array::Handle(Array::New(3)); 215 const Array& args = Array::Handle(Array::New(3));
216 args.SetAt(0, param); 216 args.SetAt(0, param);
217 args.SetAt(1, String::Handle(param.name())); 217 args.SetAt(1, String::Handle(param.name()));
218 args.SetAt(2, owner_mirror); 218 args.SetAt(2, owner_mirror);
219 return CreateMirror(Symbols::_LocalTypeVariableMirrorImpl(), args); 219 return CreateMirror(Symbols::_LocalTypeVariableMirror(), args);
220 } 220 }
221 221
222 222
223 // We create a list in native code and let Dart code create the type mirror 223 // We create a list in native code and let Dart code create the type mirror
224 // object and the ordered map. 224 // object and the ordered map.
225 static RawInstance* CreateTypeVariableList(const Class& cls) { 225 static RawInstance* CreateTypeVariableList(const Class& cls) {
226 const TypeArguments& args = TypeArguments::Handle(cls.type_parameters()); 226 const TypeArguments& args = TypeArguments::Handle(cls.type_parameters());
227 if (args.IsNull()) { 227 if (args.IsNull()) {
228 return Object::empty_array().raw(); 228 return Object::empty_array().raw();
229 } 229 }
(...skipping 17 matching lines...) Expand all
247 const AbstractType& type, 247 const AbstractType& type,
248 const Bool& is_declaration, 248 const Bool& is_declaration,
249 const Instance& owner_mirror) { 249 const Instance& owner_mirror) {
250 const Array& args = Array::Handle(Array::New(6)); 250 const Array& args = Array::Handle(Array::New(6));
251 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 251 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
252 args.SetAt(1, type); 252 args.SetAt(1, type);
253 args.SetAt(2, String::Handle(cls.UserVisibleName())); 253 args.SetAt(2, String::Handle(cls.UserVisibleName()));
254 args.SetAt(3, Bool::Get(cls.NumTypeParameters() != 0)); 254 args.SetAt(3, Bool::Get(cls.NumTypeParameters() != 0));
255 args.SetAt(4, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); 255 args.SetAt(4, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration);
256 args.SetAt(5, owner_mirror); 256 args.SetAt(5, owner_mirror);
257 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); 257 return CreateMirror(Symbols::_LocalTypedefMirror(), args);
258 } 258 }
259 259
260 260
261 static RawInstance* CreateFunctionTypeMirror(const Class& cls, 261 static RawInstance* CreateFunctionTypeMirror(const Class& cls,
262 const AbstractType& type) { 262 const AbstractType& type) {
263 const Array& args = Array::Handle(Array::New(2)); 263 const Array& args = Array::Handle(Array::New(2));
264 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 264 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
265 args.SetAt(1, type); 265 args.SetAt(1, type);
266 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); 266 return CreateMirror(Symbols::_LocalFunctionTypeMirror(), args);
267 } 267 }
268 268
269 269
270 static RawInstance* CreateMethodMirror(const Function& func, 270 static RawInstance* CreateMethodMirror(const Function& func,
271 const Instance& owner_mirror) { 271 const Instance& owner_mirror) {
272 const Array& args = Array::Handle(Array::New(12)); 272 const Array& args = Array::Handle(Array::New(12));
273 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 273 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
274 274
275 String& name = String::Handle(func.name()); 275 String& name = String::Handle(func.name());
276 name = String::IdentifierPrettyNameRetainPrivate(name); 276 name = String::IdentifierPrettyNameRetainPrivate(name);
277 args.SetAt(1, name); 277 args.SetAt(1, name);
278 278
279 args.SetAt(2, owner_mirror); 279 args.SetAt(2, owner_mirror);
280 args.SetAt(3, Bool::Get(func.is_static())); 280 args.SetAt(3, Bool::Get(func.is_static()));
281 args.SetAt(4, Bool::Get(func.is_abstract())); 281 args.SetAt(4, Bool::Get(func.is_abstract()));
282 args.SetAt(5, Bool::Get(func.IsGetterFunction())); 282 args.SetAt(5, Bool::Get(func.IsGetterFunction()));
283 args.SetAt(6, Bool::Get(func.IsSetterFunction())); 283 args.SetAt(6, Bool::Get(func.IsSetterFunction()));
284 284
285 bool isConstructor = (func.kind() == RawFunction::kConstructor); 285 bool isConstructor = (func.kind() == RawFunction::kConstructor);
286 args.SetAt(7, Bool::Get(isConstructor)); 286 args.SetAt(7, Bool::Get(isConstructor));
287 args.SetAt(8, Bool::Get(isConstructor && func.is_const())); 287 args.SetAt(8, Bool::Get(isConstructor && func.is_const()));
288 args.SetAt(9, Bool::Get(isConstructor && func.IsConstructor())); 288 args.SetAt(9, Bool::Get(isConstructor && func.IsConstructor()));
289 args.SetAt(10, Bool::Get(isConstructor && func.is_redirecting())); 289 args.SetAt(10, Bool::Get(isConstructor && func.is_redirecting()));
290 args.SetAt(11, Bool::Get(isConstructor && func.IsFactory())); 290 args.SetAt(11, Bool::Get(isConstructor && func.IsFactory()));
291 291
292 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); 292 return CreateMirror(Symbols::_LocalMethodMirror(), args);
293 } 293 }
294 294
295 295
296 static RawInstance* CreateVariableMirror(const Field& field, 296 static RawInstance* CreateVariableMirror(const Field& field,
297 const Instance& owner_mirror) { 297 const Instance& owner_mirror) {
298 const MirrorReference& field_ref = 298 const MirrorReference& field_ref =
299 MirrorReference::Handle(MirrorReference::New(field)); 299 MirrorReference::Handle(MirrorReference::New(field));
300 300
301 const String& name = String::Handle(field.name()); 301 const String& name = String::Handle(field.name());
302 302
303 const Array& args = Array::Handle(Array::New(7)); 303 const Array& args = Array::Handle(Array::New(7));
304 args.SetAt(0, field_ref); 304 args.SetAt(0, field_ref);
305 args.SetAt(1, name); 305 args.SetAt(1, name);
306 args.SetAt(2, owner_mirror); 306 args.SetAt(2, owner_mirror);
307 args.SetAt(3, Object::null_instance()); // Null for type. 307 args.SetAt(3, Object::null_instance()); // Null for type.
308 args.SetAt(4, Bool::Get(field.is_static())); 308 args.SetAt(4, Bool::Get(field.is_static()));
309 args.SetAt(5, Bool::Get(field.is_final())); 309 args.SetAt(5, Bool::Get(field.is_final()));
310 args.SetAt(6, Bool::Get(field.is_const())); 310 args.SetAt(6, Bool::Get(field.is_const()));
311 311
312 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); 312 return CreateMirror(Symbols::_LocalVariableMirror(), args);
313 } 313 }
314 314
315 static RawFunction* CallMethod(const Class& cls) { 315 static RawFunction* CallMethod(const Class& cls) {
316 if (cls.IsSignatureClass()) { 316 if (cls.IsSignatureClass()) {
317 return cls.signature_function(); 317 return cls.signature_function();
318 } 318 }
319 319
320 Class& lookup_cls = Class::Handle(cls.raw()); 320 Class& lookup_cls = Class::Handle(cls.raw());
321 Function& call_function = Function::Handle(); 321 Function& call_function = Function::Handle();
322 do { 322 do {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // We do not set the names of anonymous mixin applications because the mirrors 356 // We do not set the names of anonymous mixin applications because the mirrors
357 // use a different naming convention than the VM (lib.S with lib.M and S&M 357 // use a different naming convention than the VM (lib.S with lib.M and S&M
358 // respectively). 358 // respectively).
359 if (!cls.IsAnonymousMixinApplication()) { 359 if (!cls.IsAnonymousMixinApplication()) {
360 args.SetAt(2, String::Handle(cls.Name())); 360 args.SetAt(2, String::Handle(cls.Name()));
361 } 361 }
362 args.SetAt(3, owner_mirror); 362 args.SetAt(3, owner_mirror);
363 args.SetAt(4, is_generic); 363 args.SetAt(4, is_generic);
364 args.SetAt(5, is_mixin_app_alias); 364 args.SetAt(5, is_mixin_app_alias);
365 args.SetAt(6, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); 365 args.SetAt(6, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration);
366 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); 366 return CreateMirror(Symbols::_LocalClassMirror(), args);
367 } 367 }
368 368
369 369
370 static RawInstance* CreateLibraryMirror(const Library& lib) { 370 static RawInstance* CreateLibraryMirror(const Library& lib) {
371 const Array& args = Array::Handle(Array::New(3)); 371 const Array& args = Array::Handle(Array::New(3));
372 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); 372 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib)));
373 String& str = String::Handle(); 373 String& str = String::Handle();
374 str = lib.name(); 374 str = lib.name();
375 args.SetAt(1, str); 375 args.SetAt(1, str);
376 str = lib.url(); 376 str = lib.url();
377 args.SetAt(2, str); 377 args.SetAt(2, str);
378 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); 378 return CreateMirror(Symbols::_LocalLibraryMirror(), args);
379 } 379 }
380 380
381 381
382 static RawInstance* CreateTypeMirror(const AbstractType& type) { 382 static RawInstance* CreateTypeMirror(const AbstractType& type) {
383 ASSERT(type.IsFinalized()); 383 ASSERT(type.IsFinalized());
384 ASSERT(!type.IsMalformed()); 384 ASSERT(!type.IsMalformed());
385 if (type.HasResolvedTypeClass()) { 385 if (type.HasResolvedTypeClass()) {
386 const Class& cls = Class::Handle(type.type_class()); 386 const Class& cls = Class::Handle(type.type_class());
387 // Handle void and dynamic types. 387 // Handle void and dynamic types.
388 if (cls.IsVoidClass()) { 388 if (cls.IsVoidClass()) {
389 Array& args = Array::Handle(Array::New(1)); 389 Array& args = Array::Handle(Array::New(1));
390 args.SetAt(0, Symbols::Void()); 390 args.SetAt(0, Symbols::Void());
391 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. 391 // TODO(mlippautz): Create once in the VM isolate and retrieve from there.
392 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); 392 return CreateMirror(Symbols::_SpecialTypeMirror(), args);
393 } else if (cls.IsDynamicClass()) { 393 } else if (cls.IsDynamicClass()) {
394 Array& args = Array::Handle(Array::New(1)); 394 Array& args = Array::Handle(Array::New(1));
395 args.SetAt(0, Symbols::Dynamic()); 395 args.SetAt(0, Symbols::Dynamic());
396 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. 396 // TODO(mlippautz): Create once in the VM isolate and retrieve from there.
397 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); 397 return CreateMirror(Symbols::_SpecialTypeMirror(), args);
398 } 398 }
399 return CreateClassMirror(cls, type, Bool::False(), Object::null_instance()); 399 return CreateClassMirror(cls, type, Bool::False(), Object::null_instance());
400 } else if (type.IsTypeParameter()) { 400 } else if (type.IsTypeParameter()) {
401 return CreateTypeVariableMirror(TypeParameter::Cast(type), 401 return CreateTypeVariableMirror(TypeParameter::Cast(type),
402 Object::null_instance()); 402 Object::null_instance());
403 } else if (type.IsBoundedType()) { 403 } else if (type.IsBoundedType()) {
404 AbstractType& actual_type = 404 AbstractType& actual_type =
405 AbstractType::Handle(BoundedType::Cast(type).type()); 405 AbstractType::Handle(BoundedType::Cast(type).type());
406 return CreateTypeMirror(actual_type); 406 return CreateTypeMirror(actual_type);
407 } 407 }
408 UNREACHABLE(); 408 UNREACHABLE();
409 return Instance::null(); 409 return Instance::null();
410 } 410 }
411 411
412 412
413 static RawInstance* CreateIsolateMirror() { 413 static RawInstance* CreateIsolateMirror() {
414 Isolate* isolate = Isolate::Current(); 414 Isolate* isolate = Isolate::Current();
415 const String& debug_name = String::Handle(String::New(isolate->name())); 415 const String& debug_name = String::Handle(String::New(isolate->name()));
416 const Library& root_library = 416 const Library& root_library =
417 Library::Handle(isolate, isolate->object_store()->root_library()); 417 Library::Handle(isolate, isolate->object_store()->root_library());
418 const Instance& root_library_mirror = 418 const Instance& root_library_mirror =
419 Instance::Handle(CreateLibraryMirror(root_library)); 419 Instance::Handle(CreateLibraryMirror(root_library));
420 420
421 const Array& args = Array::Handle(Array::New(2)); 421 const Array& args = Array::Handle(Array::New(2));
422 args.SetAt(0, debug_name); 422 args.SetAt(0, debug_name);
423 args.SetAt(1, root_library_mirror); 423 args.SetAt(1, root_library_mirror);
424 return CreateMirror(Symbols::_LocalIsolateMirrorImpl(), args); 424 return CreateMirror(Symbols::_LocalIsolateMirror(), args);
425 } 425 }
426 426
427 427
428 static RawInstance* CreateMirrorSystem() { 428 static RawInstance* CreateMirrorSystem() {
429 Isolate* isolate = Isolate::Current(); 429 Isolate* isolate = Isolate::Current();
430 const GrowableObjectArray& libraries = 430 const GrowableObjectArray& libraries =
431 GrowableObjectArray::Handle(isolate->object_store()->libraries()); 431 GrowableObjectArray::Handle(isolate->object_store()->libraries());
432 432
433 const int num_libraries = libraries.Length(); 433 const int num_libraries = libraries.Length();
434 const Array& library_mirrors = Array::Handle(Array::New(num_libraries)); 434 const Array& library_mirrors = Array::Handle(Array::New(num_libraries));
435 Library& library = Library::Handle(); 435 Library& library = Library::Handle();
436 Instance& library_mirror = Instance::Handle(); 436 Instance& library_mirror = Instance::Handle();
437 437
438 for (int i = 0; i < num_libraries; i++) { 438 for (int i = 0; i < num_libraries; i++) {
439 library ^= libraries.At(i); 439 library ^= libraries.At(i);
440 library_mirror = CreateLibraryMirror(library); 440 library_mirror = CreateLibraryMirror(library);
441 library_mirrors.SetAt(i, library_mirror); 441 library_mirrors.SetAt(i, library_mirror);
442 } 442 }
443 443
444 const Instance& isolate_mirror = Instance::Handle(CreateIsolateMirror()); 444 const Instance& isolate_mirror = Instance::Handle(CreateIsolateMirror());
445 445
446 const Array& args = Array::Handle(Array::New(2)); 446 const Array& args = Array::Handle(Array::New(2));
447 args.SetAt(0, library_mirrors); 447 args.SetAt(0, library_mirrors);
448 args.SetAt(1, isolate_mirror); 448 args.SetAt(1, isolate_mirror);
449 return CreateMirror(Symbols::_LocalMirrorSystemImpl(), args); 449 return CreateMirror(Symbols::_LocalMirrorSystem(), args);
450 } 450 }
451 451
452 452
453 static RawInstance* ReturnResult(const Object& result) { 453 static RawInstance* ReturnResult(const Object& result) {
454 if (result.IsError()) { 454 if (result.IsError()) {
455 ThrowInvokeError(Error::Cast(result)); 455 ThrowInvokeError(Error::Cast(result));
456 UNREACHABLE(); 456 UNREACHABLE();
457 } 457 }
458 if (result.IsInstance()) { 458 if (result.IsInstance()) {
459 return Instance::Cast(result).raw(); 459 return Instance::Cast(result).raw();
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 1945
1946 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { 1946 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) {
1947 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1947 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1948 const Field& field = Field::Handle(ref.GetFieldReferent()); 1948 const Field& field = Field::Handle(ref.GetFieldReferent());
1949 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); 1949 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1950 const AbstractType& type = AbstractType::Handle(field.type()); 1950 const AbstractType& type = AbstractType::Handle(field.type());
1951 return InstantiateType(type, instantiator); 1951 return InstantiateType(type, instantiator);
1952 } 1952 }
1953 1953
1954 } // namespace dart 1954 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698