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

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 10825431: More mirrors changes to bring vm mirrors more in line with the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
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 // VM-specific implementation of the dart:mirrors library. 5 // VM-specific implementation of the dart:mirrors library.
6 6
7 // These values are allowed to be passed directly over the wire. 7 // These values are allowed to be passed directly over the wire.
8 bool isSimpleValue(var value) { 8 bool isSimpleValue(var value) {
9 return (value === null || value is num || value is String || value is bool); 9 return (value === null || value is num || value is String || value is bool);
10 } 10 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl 255 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl
256 implements ClosureMirror { 256 implements ClosureMirror {
257 _LocalClosureMirrorImpl(ref, 257 _LocalClosureMirrorImpl(ref,
258 klass, 258 klass,
259 reflectee) : super(ref, klass, reflectee) {} 259 reflectee) : super(ref, klass, reflectee) {}
260 260
261 MethodMirror _function; 261 MethodMirror _function;
262 MethodMirror function() => _function; 262 MethodMirror function() => _function;
263 263
264 String source() { 264 String get source() {
265 throw new NotImplementedException('ClosureMirror.source() not implemented'); 265 throw new NotImplementedException('ClosureMirror.source not implemented');
266 } 266 }
267 267
268 Future<ObjectMirror> apply(List<Object> positionalArguments, 268 Future<ObjectMirror> apply(List<Object> positionalArguments,
269 [Map<String,Object> namedArguments]) { 269 [Map<String,Object> namedArguments]) {
270 if (namedArguments !== null) { 270 if (namedArguments !== null) {
271 throw new NotImplementedException('named arguments not implemented'); 271 throw new NotImplementedException('named arguments not implemented');
272 } 272 }
273 // Walk the arguments and make sure they are legal. 273 // Walk the arguments and make sure they are legal.
274 for (int i = 0; i < positionalArguments.length; i++) { 274 for (int i = 0; i < positionalArguments.length; i++) {
275 var arg = positionalArguments[i]; 275 var arg = positionalArguments[i];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 313
314 final String libraryName; 314 final String libraryName;
315 final String interfaceName; 315 final String interfaceName;
316 } 316 }
317 317
318 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 318 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
319 implements ClassMirror { 319 implements ClassMirror {
320 _LocalClassMirrorImpl(ref, 320 _LocalClassMirrorImpl(ref,
321 this.simpleName, 321 this.simpleName,
322 this.isClass, 322 this.isClass,
323 this._library, 323 this._owner,
324 this._superclass, 324 this._superclass,
325 this._superinterfaces, 325 this._superinterfaces,
326 this._defaultFactory, 326 this._defaultFactory,
327 this.members) : super(ref) {} 327 this.members) : super(ref) {}
328 328
329 final String simpleName; 329 final String simpleName;
330
331 String _qualifiedName = null;
332 String get qualifiedName() {
333 if (_qualifiedName === null) {
334 _qualifiedName = '${owner.qualifiedName}.${simpleName}';
335 }
336 return _qualifiedName;
337 }
338
339 var _owner;
340 DeclarationMirror get owner() {
341 if (_owner is! Mirror) {
342 _owner = _owner.resolve(mirrors);
343 }
344 return _owner;
345 }
346
347 bool get isPrivate() {
348 return simpleName.startsWith('_');
349 }
350
351 final bool isTopLevel = true;
352
353 SourceLocation get location() {
354 throw new NotImplementedException(
355 'ClassMirror.location not yet implemented');
356 }
357
330 final bool isClass; 358 final bool isClass;
331 359
332 var _library;
333 LibraryMirror get library() {
334 if (_library is _LazyLibraryMirror) {
335 _library = _library.resolve(mirrors);
336 }
337 return _library;
338 }
339
340 var _superclass; 360 var _superclass;
341 ClassMirror get superclass() { 361 ClassMirror get superclass() {
342 if (_superclass is _LazyClassMirror) { 362 if (_superclass is _LazyClassMirror) {
343 _superclass = _superclass.resolve(mirrors); 363 _superclass = _superclass.resolve(mirrors);
344 } 364 }
345 return _superclass; 365 return _superclass;
346 } 366 }
347 367
348 var _superinterfaces; 368 var _superinterfaces;
349 List<ClassMirror> get superinterfaces() { 369 List<ClassMirror> get superinterfaces() {
350 if (_superinterfaces.length > 0 && 370 if (_superinterfaces.length > 0 &&
351 _superinterfaces[0] is _LazyClassMirror) { 371 _superinterfaces[0] is _LazyClassMirror) {
352 List<ClassMirror> resolved = new List<ClassMirror>(); 372 List<ClassMirror> resolved = new List<ClassMirror>();
353 for (int i = 0; i < _superinterfaces.length; i++) { 373 for (int i = 0; i < _superinterfaces.length; i++) {
354 resolved.add(_superinterfaces[i].resolve(mirrors)); 374 resolved.add(_superinterfaces[i].resolve(mirrors));
355 } 375 }
356 _superinterfaces = resolved; 376 _superinterfaces = resolved;
357 } 377 }
358 return _superinterfaces; 378 return _superinterfaces;
359 } 379 }
360 380
361 var _defaultFactory; 381 var _defaultFactory;
362 ClassMirror get defaultFactory() { 382 ClassMirror get defaultFactory() {
363 if (_defaultFactory is _LazyClassMirror) { 383 if (_defaultFactory is _LazyClassMirror) {
364 _defaultFactory = _defaultFactory.resolve(mirrors); 384 _defaultFactory = _defaultFactory.resolve(mirrors);
365 } 385 }
366 return _defaultFactory; 386 return _defaultFactory;
367 } 387 }
368 388
369 final Map<String, ClassMirror> members; 389 final Map<String, Mirror> members;
370 390
371 Map<String, ClassMirror> _methods = null; 391 Map<String, MethodMirror> _methods = null;
372 Map<String, ClassMirror> _variables = null; 392 Map<String, MethodMirror> _constructors = null;
393 Map<String, MethodMirror> _getters = null;
394 Map<String, MethodMirror> _setters = null;
395 Map<String, VariableMirror> _variables = null;
373 396
374 Map<String, MethodMirror> get methods() { 397 Map<String, MethodMirror> get methods() {
375 if (_methods == null) { 398 if (_methods == null) {
376 _methods = filterMap(members, 399 _methods = filterMap(members,
377 (key, value) => (value is MethodMirror)); 400 (key, value) => (value is MethodMirror));
378 } 401 }
379 return _methods; 402 return _methods;
380 } 403 }
381 404
405 Map<String, MethodMirror> get constructors() {
406 if (_constructors == null) {
407 _constructors = filterMap(methods,
408 (key, value) => (value.isConstructor));
409 }
410 return _constructors;
411 }
412
413 Map<String, MethodMirror> get getters() {
414 if (_getters == null) {
415 _getters = filterMap(methods,
416 (key, value) => (value.isGetter));
417 }
418 return _getters;
419 }
420
421 Map<String, MethodMirror> get setters() {
422 if (_setters == null) {
423 _setters = filterMap(methods,
424 (key, value) => (value.isSetter));
425 }
426 return _setters;
427 }
428
382 Map<String, VariableMirror> get variables() { 429 Map<String, VariableMirror> get variables() {
383 if (_variables == null) { 430 if (_variables == null) {
384 _variables = filterMap(members, 431 _variables = filterMap(members,
385 (key, value) => (value is VariableMirror)); 432 (key, value) => (value is VariableMirror));
386 } 433 }
387 return _variables; 434 return _variables;
388 } 435 }
389 436
437 List<TypeVariableMirror> get typeVariables() {
438 throw new NotImplementedException(
439 'ClassMirror.typeVariables not yet implemented');
440 }
441
442 List<TypeMirror> get typeArguments() {
443 throw new NotImplementedException(
444 'ClassMirror.typeArguments not yet implemented');
445 }
446
447 bool isUnboundType() {
448 throw new NotImplementedException(
449 'ClassMirror.isUnboundType not yet implemented');
450 }
451
452 ClassMirror unboundType() {
453 throw new NotImplementedException(
454 'ClassMirror.unboundType not yet implemented');
455 }
456
390 String toString() { 457 String toString() {
391 return "ClassMirror on '$simpleName'"; 458 return "ClassMirror on '$simpleName'";
392 } 459 }
393 460
394 Future<InstanceMirror> newInstance(String constructorName, 461 Future<InstanceMirror> newInstance(String constructorName,
395 List positionalArguments, 462 List positionalArguments,
396 [Map<String,Dynamic> namedArguments]) { 463 [Map<String,Dynamic> namedArguments]) {
397 if (namedArguments !== null) { 464 if (namedArguments !== null) {
398 throw new NotImplementedException('named arguments not implemented'); 465 throw new NotImplementedException('named arguments not implemented');
399 } 466 }
400 // Walk the arguments and make sure they are legal. 467 // Walk the arguments and make sure they are legal.
401 for (int i = 0; i < positionalArguments.length; i++) { 468 for (int i = 0; i < positionalArguments.length; i++) {
402 var arg = positionalArguments[i]; 469 var arg = positionalArguments[i];
403 _LocalObjectMirrorImpl._validateArgument(i, arg); 470 _LocalObjectMirrorImpl._validateArgument(i, arg);
404 } 471 }
405 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); 472 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
406 try { 473 try {
(...skipping 20 matching lines...) Expand all
427 } 494 }
428 495
429 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl 496 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl
430 implements LibraryMirror { 497 implements LibraryMirror {
431 _LocalLibraryMirrorImpl(ref, 498 _LocalLibraryMirrorImpl(ref,
432 this.simpleName, 499 this.simpleName,
433 this.url, 500 this.url,
434 this.members) : super(ref) {} 501 this.members) : super(ref) {}
435 502
436 final String simpleName; 503 final String simpleName;
504
505 String get qualifiedName() {
cshapiro 2012/08/21 03:16:05 // The simple name and the qualified name are the
turnidge 2012/08/21 18:00:49 Switched all short functions (that can fit on one
506 // The simple name and the qualified name are the same for a library.
507 return simpleName;
508 }
509
510 // Always null for libraries.
511 final DeclarationMirror owner = null;
512
513 // Always false for libraries.
514 final bool isPrivate = false;
515
516 // Always false for libraries.
517 final bool isTopLevel = false;
518
519 SourceLocation get location() {
520 throw new NotImplementedException(
521 'LibraryMirror.location not yet implemented');
522 }
523
437 final String url; 524 final String url;
438 final Map<String, ClassMirror> members; 525 final Map<String, Mirror> members;
439 526
440 Map<String, ClassMirror> _classes = null; 527 Map<String, ClassMirror> _classes = null;
441 Map<String, ClassMirror> _functions = null; 528 Map<String, MethodMirror> _functions = null;
442 Map<String, ClassMirror> _variables = null; 529 Map<String, MethodMirror> _getters = null;
530 Map<String, MethodMirror> _setters = null;
531 Map<String, VariableMirror> _variables = null;
443 532
444 Map<String, ClassMirror> get classes() { 533 Map<String, ClassMirror> get classes() {
445 if (_classes == null) { 534 if (_classes == null) {
446 _classes = filterMap(members, 535 _classes = filterMap(members,
447 (key, value) => (value is ClassMirror)); 536 (key, value) => (value is ClassMirror));
448 } 537 }
449 return _classes; 538 return _classes;
450 } 539 }
451 540
452 Map<String, MethodMirror> get functions() { 541 Map<String, MethodMirror> get functions() {
453 if (_functions == null) { 542 if (_functions == null) {
454 _functions = filterMap(members, 543 _functions = filterMap(members,
455 (key, value) => (value is MethodMirror)); 544 (key, value) => (value is MethodMirror));
456 } 545 }
457 return _functions; 546 return _functions;
458 } 547 }
459 548
549 Map<String, MethodMirror> get getters() {
550 if (_getters == null) {
551 _getters = filterMap(functions,
552 (key, value) => (value.isGetter));
553 }
554 return _getters;
555 }
556
557 Map<String, MethodMirror> get setters() {
558 if (_setters == null) {
559 _setters = filterMap(functions,
560 (key, value) => (value.isSetter));
561 }
562 return _setters;
563 }
564
460 Map<String, VariableMirror> get variables() { 565 Map<String, VariableMirror> get variables() {
461 if (_variables == null) { 566 if (_variables == null) {
462 _variables = filterMap(members, 567 _variables = filterMap(members,
463 (key, value) => (value is VariableMirror)); 568 (key, value) => (value is VariableMirror));
464 } 569 }
465 return _variables; 570 return _variables;
466 } 571 }
467 572
468 String toString() { 573 String toString() {
469 return "LibraryMirror on '$simpleName'"; 574 return "LibraryMirror on '$simpleName'";
(...skipping 10 matching lines...) Expand all
480 this.isGetter, 585 this.isGetter,
481 this.isSetter, 586 this.isSetter,
482 this.isConstructor, 587 this.isConstructor,
483 this.isConstConstructor, 588 this.isConstConstructor,
484 this.isGenerativeConstructor, 589 this.isGenerativeConstructor,
485 this.isRedirectingConstructor, 590 this.isRedirectingConstructor,
486 this.isFactoryConstructor) {} 591 this.isFactoryConstructor) {}
487 592
488 final String simpleName; 593 final String simpleName;
489 594
595 String _qualifiedName = null;
596 String get qualifiedName() {
597 if (_qualifiedName === null) {
598 _qualifiedName = '${owner.qualifiedName}.${simpleName}';
599 }
600 return _qualifiedName;
601 }
602
490 var _owner; 603 var _owner;
491 Mirror get owner() { 604 DeclarationMirror get owner() {
492 if (_owner is! Mirror) { 605 if (_owner is! Mirror) {
493 _owner = _owner.resolve(mirrors); 606 _owner = _owner.resolve(mirrors);
494 } 607 }
495 return _owner; 608 return _owner;
496 } 609 }
497 610
498 final List<ParameterMirror> parameters; 611 bool get isPrivate() {
612 return simpleName.startsWith('_') || constructorName.startsWith('_');
613 }
499 614
500 bool get isTopLevel() { 615 bool get isTopLevel() {
501 return owner is LibraryMirror; 616 return owner is LibraryMirror;
502 } 617 }
503 618
619 SourceLocation get location() {
620 throw new NotImplementedException(
621 'MethodMirror.location not yet implemented');
622 }
623
624 TypeMirror get returnType() {
625 throw new NotImplementedException(
626 'MethodMirror.returnType not yet implemented');
627 }
628
629 final List<ParameterMirror> parameters;
630
504 final bool isStatic; 631 final bool isStatic;
632 final bool isAbstract;
505 633
506 bool get isMethod() { 634 bool get isRegularMethod() {
507 return !isGetter && !isSetter && !isConstructor; 635 return !isGetter && !isSetter && !isConstructor;
508 } 636 }
509 637
510 final bool isAbstract; 638 TypeMirror get isOperator() {
639 throw new NotImplementedException(
640 'MethodMirror.isOperator not yet implemented');
641 }
642
511 final bool isGetter; 643 final bool isGetter;
512 final bool isSetter; 644 final bool isSetter;
513 final bool isConstructor; 645 final bool isConstructor;
514 646
647 var _constructorName = null;
648 String get constructorName() {
649 if (_constructorName === null) {
650 if (!isConstructor) {
651 _constructorName = '';
652 } else {
653 var parts = simpleName.split('.');
654 if (parts.length > 2) {
655 throw new MirrorException(
656 'Internal error in MethodMirror.constructorName: '
657 'malformed name <$simpleName>');
658 } else if (parts.length == 2) {
659 _constructorName = parts[1];
660 } else {
661 _constructorName = '';
662 }
663 }
664 }
665 return _constructorName;
666 }
667
515 final bool isConstConstructor; 668 final bool isConstConstructor;
516 final bool isGenerativeConstructor; 669 final bool isGenerativeConstructor;
517 final bool isRedirectingConstructor; 670 final bool isRedirectingConstructor;
518 final bool isFactoryConstructor; 671 final bool isFactoryConstructor;
519 672
520 String toString() { 673 String toString() {
521 return "MethodMirror on '$simpleName'"; 674 return "MethodMirror on '$simpleName'";
522 } 675 }
523 } 676 }
524 677
525 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
526 implements ParameterMirror {
527 // TODO(rmacnak): Fill these mirrors will real information
528 _LocalParameterMirrorImpl(this.isOptional)
529 : super(null, null, false, false) {}
530
531 final bool isOptional;
532
533 TypeMirror get type() => null;
534 String get defaultValue() => null;
535 bool get hasDefaultValue() => null;
536 }
537
538 class _LocalVariableMirrorImpl extends _LocalMirrorImpl 678 class _LocalVariableMirrorImpl extends _LocalMirrorImpl
539 implements VariableMirror { 679 implements VariableMirror {
540 _LocalVariableMirrorImpl(this.simpleName, 680 _LocalVariableMirrorImpl(this.simpleName,
541 this._owner, 681 this._owner,
542 this.isStatic, 682 this.isStatic,
543 this.isFinal) {} 683 this.isFinal) {}
544 684
545 final String simpleName; 685 final String simpleName;
546 686
687 String _qualifiedName = null;
688 String get qualifiedName() {
689 if (_qualifiedName === null) {
690 _qualifiedName = '${owner.qualifiedName}.${simpleName}';
691 }
692 return _qualifiedName;
693 }
694
547 var _owner; 695 var _owner;
548 Mirror get owner() { 696 DeclarationMirror get owner() {
549 if (_owner is! Mirror) { 697 if (_owner is! Mirror) {
550 _owner = _owner.resolve(mirrors); 698 _owner = _owner.resolve(mirrors);
551 } 699 }
552 return _owner; 700 return _owner;
553 } 701 }
554 702
703 bool get isPrivate() {
704 return simpleName.startsWith('_');
705 }
706
555 bool get isTopLevel() { 707 bool get isTopLevel() {
556 return owner is LibraryMirror; 708 return owner is LibraryMirror;
557 } 709 }
558 710
711 SourceLocation get location() {
712 throw new NotImplementedException(
713 'MethodMirror.location not yet implemented');
714 }
715
716 TypeMirror get returnType() {
717 throw new NotImplementedException(
718 'MethodMirror.returnType not yet implemented');
719 }
720
559 final bool isStatic; 721 final bool isStatic;
560 final bool isFinal; 722 final bool isFinal;
561 723
562 String toString() { 724 String toString() {
563 return "VariableMirror on '$simpleName'"; 725 return "VariableMirror on '$simpleName'";
564 } 726 }
565 } 727 }
566 728
729 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
730 implements ParameterMirror {
731 // TODO(rmacnak): Fill these mirrors will real information
cshapiro 2012/08/21 03:16:05 Still relevant? Should this be a TODO(turnidge)?
turnidge 2012/08/21 18:00:49 Will change these unimplemented accessors to throw
732 _LocalParameterMirrorImpl(this.isOptional)
733 : super(null, null, false, false) {}
734
735 final bool isOptional;
736
737 TypeMirror get type() => null;
738 String get defaultValue() => null;
739 bool get hasDefaultValue() => null;
740 }
741
567 class _Mirrors { 742 class _Mirrors {
568 // Does a port refer to our local isolate? 743 // Does a port refer to our local isolate?
569 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; 744 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort';
570 745
571 static MirrorSystem _currentMirrorSystem = null; 746 static MirrorSystem _currentMirrorSystem = null;
572 747
573 // Creates a new local MirrorSystem. 748 // Creates a new local MirrorSystem.
574 static MirrorSystem makeLocalMirrorSystem() 749 static MirrorSystem makeLocalMirrorSystem()
575 native 'Mirrors_makeLocalMirrorSystem'; 750 native 'Mirrors_makeLocalMirrorSystem';
576 751
(...skipping 23 matching lines...) Expand all
600 775
601 // Creates a new local InstanceMirror 776 // Creates a new local InstanceMirror
602 static InstanceMirror makeLocalInstanceMirror(Object reflectee) 777 static InstanceMirror makeLocalInstanceMirror(Object reflectee)
603 native 'Mirrors_makeLocalInstanceMirror'; 778 native 'Mirrors_makeLocalInstanceMirror';
604 779
605 // Creates a new local mirror for some Object. 780 // Creates a new local mirror for some Object.
606 static InstanceMirror reflect(Object reflectee) { 781 static InstanceMirror reflect(Object reflectee) {
607 return makeLocalInstanceMirror(reflectee); 782 return makeLocalInstanceMirror(reflectee);
608 } 783 }
609 } 784 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698