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

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

Issue 20216002: Make ClassMirror.typeVariables lazy and convert dependencies to native code. (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
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 import "dart:collection";
8
7 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
8 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
9 return (value == null || value is num || value is String || value is bool); 11 return (value == null || value is num || value is String || value is bool);
10 } 12 }
11 13
12 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { 14 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) {
13 Map new_map = new Map<Symbol, dynamic>(); 15 Map new_map = new Map<Symbol, dynamic>();
14 old_map.forEach((key, value) { 16 old_map.forEach((key, value) {
15 if (filter(key, value)) { 17 if (filter(key, value)) {
16 new_map[key] = value; 18 new_map[key] = value;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return resolved; 391 return resolved;
390 } 392 }
391 393
392 final String libraryUrl; 394 final String libraryUrl;
393 final Symbol typeName; 395 final Symbol typeName;
394 } 396 }
395 397
396 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 398 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
397 implements ClassMirror { 399 implements ClassMirror {
398 _LocalClassMirrorImpl(reflectee, 400 _LocalClassMirrorImpl(reflectee,
399 String simpleName, 401 String simpleName)
400 Map<String, Mirror> typeVariables)
401 : this._simpleName = _s(simpleName), 402 : this._simpleName = _s(simpleName),
402 this.typeVariables = _convertStringToSymbolMap(typeVariables),
403 super(reflectee); 403 super(reflectee);
404 404
405 Symbol _simpleName; 405 Symbol _simpleName;
406 Symbol get simpleName { 406 Symbol get simpleName {
407 // dynamic, void and the function types have their names set eagerly in the 407 // dynamic, void and the function types have their names set eagerly in the
408 // constructor. 408 // constructor.
409 if(_simpleName == null) { 409 if(_simpleName == null) {
410 _simpleName = _s(_name(_reflectee)); 410 _simpleName = _s(_name(_reflectee));
411 } 411 }
412 return _simpleName; 412 return _simpleName;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 519
520 Map<Symbol, MethodMirror> _constructors; 520 Map<Symbol, MethodMirror> _constructors;
521 521
522 Map<Symbol, MethodMirror> get constructors { 522 Map<Symbol, MethodMirror> get constructors {
523 if (_constructors == null) { 523 if (_constructors == null) {
524 _constructors = _makeMemberMap(_computeConstructors(_reflectee)); 524 _constructors = _makeMemberMap(_computeConstructors(_reflectee));
525 } 525 }
526 return _constructors; 526 return _constructors;
527 } 527 }
528 528
529 Map<Symbol, TypeVariableMirror> typeVariables; 529 Map<Symbol, TypeVariableMirror> _typeVariables = null;
530
531 Map<Symbol, TypeVariableMirror> get typeVariables {
532 if (_typeVariables == null) {
533 List params = _ClassMirror_type_variables(_reflectee);
534 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>();
535 var mirror;
536 for (var i = 0; i < params.length; i += 2) {
537 mirror = new _LocalTypeVariableMirrorImpl(
538 params[i + 1], params[i], this);
539 _typeVariables[mirror.simpleName] = mirror;
540 }
541 }
542 return _typeVariables;
543 }
530 544
531 Map<Symbol, TypeMirror> get typeArguments { 545 Map<Symbol, TypeMirror> get typeArguments {
532 throw new UnimplementedError( 546 throw new UnimplementedError(
533 'ClassMirror.typeArguments is not implemented'); 547 'ClassMirror.typeArguments is not implemented');
534 } 548 }
535 549
536 bool get isOriginalDeclaration { 550 bool get isOriginalDeclaration {
537 throw new UnimplementedError( 551 throw new UnimplementedError(
538 'ClassMirror.isOriginalDeclaration is not implemented'); 552 'ClassMirror.isOriginalDeclaration is not implemented');
539 } 553 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 native 'ClassMirror_invoke'; 619 native 'ClassMirror_invoke';
606 620
607 _invokeGetter(reflectee, getterName) 621 _invokeGetter(reflectee, getterName)
608 native 'ClassMirror_invokeGetter'; 622 native 'ClassMirror_invokeGetter';
609 623
610 _invokeSetter(reflectee, setterName, value) 624 _invokeSetter(reflectee, setterName, value)
611 native 'ClassMirror_invokeSetter'; 625 native 'ClassMirror_invokeSetter';
612 626
613 static _invokeConstructor(reflectee, constructorName, positionalArguments) 627 static _invokeConstructor(reflectee, constructorName, positionalArguments)
614 native 'ClassMirror_invokeConstructor'; 628 native 'ClassMirror_invokeConstructor';
629
630 static _ClassMirror_type_variables(reflectee)
631 native "ClassMirror_type_variables";
615 } 632 }
616 633
617 class _LazyFunctionTypeMirror { 634 class _LazyFunctionTypeMirror {
618 _LazyFunctionTypeMirror(this.reflectee, this.returnType, this.parameters) {} 635 _LazyFunctionTypeMirror(this.reflectee, this.returnType, this.parameters) {}
619 636
620 ClassMirror resolve(MirrorSystem mirrors) { 637 ClassMirror resolve(MirrorSystem mirrors) {
621 return mirrors._lookupFunctionTypeMirror(reflectee, 638 return mirrors._lookupFunctionTypeMirror(reflectee,
622 returnType.resolve(mirrors), 639 returnType.resolve(mirrors),
623 parameters); 640 parameters);
624 } 641 }
625 642
626 final reflectee; 643 final reflectee;
627 final returnType; 644 final returnType;
628 final List<ParameterMirror> parameters; 645 final List<ParameterMirror> parameters;
629 } 646 }
630 647
631 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl 648 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
632 implements FunctionTypeMirror { 649 implements FunctionTypeMirror {
633 _LocalFunctionTypeMirrorImpl(reflectee, 650 _LocalFunctionTypeMirrorImpl(reflectee,
634 simpleName, 651 simpleName,
635 this._returnType, 652 this._returnType,
636 this.parameters) 653 this.parameters)
637 : super(reflectee, 654 : super(reflectee,
638 simpleName, 655 simpleName);
639 const {});
640 656
641 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>(); 657 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>();
642 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>(); 658 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>();
643 659
644 var _returnType; 660 var _returnType;
645 TypeMirror get returnType { 661 TypeMirror get returnType {
646 if (_returnType is! Mirror) { 662 if (_returnType is! Mirror) {
647 _returnType = _returnType.resolve(mirrors); 663 _returnType = _returnType.resolve(mirrors);
648 } 664 }
649 return _returnType; 665 return _returnType;
650 } 666 }
651 667
652 final List<ParameterMirror> parameters; 668 final List<ParameterMirror> parameters;
669 final Map<Symbol, TypeVariableMirror> typeVariables = const {};
653 670
654 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; 671 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'";
655 } 672 }
656 673
657 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl 674 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl
658 implements DeclarationMirror { 675 implements DeclarationMirror {
659 _LocalDeclarationMirrorImpl(this._reflectee); 676 _LocalDeclarationMirrorImpl(this._reflectee);
660 final _MirrorReference _reflectee; 677 final _reflectee;
661 678
662 List<InstanceMirror> get metadata { 679 List<InstanceMirror> get metadata {
663 // Get the metadata objects, convert them into InstanceMirrors using 680 // Get the metadata objects, convert them into InstanceMirrors using
664 // reflect() and then make them into a Dart list. 681 // reflect() and then make them into a Dart list.
665 return _metadata(_reflectee).map(reflect).toList(growable:false); 682 return _metadata(_reflectee).map(reflect).toList(growable:false);
666 } 683 }
667 } 684 }
668 685
669 class _LazyTypeVariableMirror { 686 class _LazyTypeVariableMirror {
670 _LazyTypeVariableMirror(String variableName, this._owner) 687 _LazyTypeVariableMirror(String variableName, this._owner)
671 : this._variableName = _s(variableName); 688 : this._variableName = _s(variableName);
672 689
673 TypeVariableMirror resolve(MirrorSystem mirrors) { 690 TypeVariableMirror resolve(MirrorSystem mirrors) {
674 ClassMirror owner = _owner.resolve(mirrors); 691 ClassMirror owner = _owner.resolve(mirrors);
675 return owner.typeVariables[_variableName]; 692 return owner.typeVariables[_variableName];
676 } 693 }
677 694
678 final Symbol _variableName; 695 final Symbol _variableName;
679 final _LazyTypeMirror _owner; 696 final _LazyTypeMirror _owner;
680 } 697 }
681 698
682 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl 699 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
683 implements TypeVariableMirror { 700 implements TypeVariableMirror {
684 _LocalTypeVariableMirrorImpl(reflectee, 701 _LocalTypeVariableMirrorImpl(reflectee,
685 String simpleName, 702 String simpleName,
686 this._owner, 703 this._owner)
687 this._upperBound)
688 : this.simpleName = _s(simpleName), 704 : this.simpleName = _s(simpleName),
689 super(reflectee); 705 super(reflectee);
690 706
691 final Symbol simpleName; 707 final Symbol simpleName;
692 708
693 Symbol _qualifiedName = null; 709 Symbol _qualifiedName = null;
694 Symbol get qualifiedName { 710 Symbol get qualifiedName {
695 if (_qualifiedName == null) { 711 if (_qualifiedName == null) {
696 _qualifiedName = _computeQualifiedName(owner, simpleName); 712 _qualifiedName = _computeQualifiedName(owner, simpleName);
697 } 713 }
698 return _qualifiedName; 714 return _qualifiedName;
699 } 715 }
700 716
701 var _owner; 717 var _owner;
702 DeclarationMirror get owner { 718 DeclarationMirror get owner {
719 if (_owner == null) {
720 _owner = _LocalTypeVariableMirror_owner(_reflectee);
721 }
722 // TODO(11897): This will go away, as soon as lazy mirrors go away.
703 if (_owner is! Mirror) { 723 if (_owner is! Mirror) {
704 _owner = _owner.resolve(mirrors); 724 _owner = _owner.resolve(mirrors);
705 } 725 }
706 return _owner; 726 return _owner;
707 } 727 }
708 728
709 bool get isPrivate => false; 729 bool get isPrivate => false;
710 730
711 final bool isTopLevel = false; 731 final bool isTopLevel = false;
712 732
713 SourceLocation get location { 733 SourceLocation get location {
714 throw new UnimplementedError( 734 throw new UnimplementedError(
715 'TypeVariableMirror.location is not implemented'); 735 'TypeVariableMirror.location is not implemented');
716 } 736 }
717 737
718 var _upperBound; 738 TypeMirror _upperBound = null;
719 TypeMirror get upperBound { 739 TypeMirror get upperBound {
720 if (_upperBound is! Mirror) { 740 if (_upperBound == null) {
721 _upperBound = _upperBound.resolve(mirrors); 741 _upperBound = _LocalTypeVariableMirror_upper_bound(_reflectee);
722 } 742 }
723 return _upperBound; 743 return _upperBound;
724 } 744 }
725 745
726 List<InstanceMirror> get metadata { 746 List<InstanceMirror> get metadata {
727 throw new UnimplementedError( 747 throw new UnimplementedError(
728 'TypeVariableMirror.metadata is not implemented'); 748 'TypeVariableMirror.metadata is not implemented');
729 } 749 }
730 750
731 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; 751 String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
752
753 static DeclarationMirror _LocalTypeVariableMirror_owner(reflectee)
754 native "LocalTypeVariableMirror_owner";
755
756 static TypeMirror _LocalTypeVariableMirror_upper_bound(reflectee)
757 native "LocalTypeVariableMirror_upper_bound";
732 } 758 }
733 759
734 760
735 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 761 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
736 implements TypedefMirror { 762 implements TypedefMirror {
737 _LocalTypedefMirrorImpl(reflectee, 763 _LocalTypedefMirrorImpl(reflectee,
738 String simpleName, 764 String simpleName,
739 this._owner, 765 this._owner,
740 this._referent) 766 this._referent)
741 : this.simpleName = _s(simpleName), 767 : this.simpleName = _s(simpleName),
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1240 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1215 static ClassMirror reflectClass(Type key) { 1241 static ClassMirror reflectClass(Type key) {
1216 var classMirror = _classMirrorCache[key]; 1242 var classMirror = _classMirrorCache[key];
1217 if (classMirror == null) { 1243 if (classMirror == null) {
1218 classMirror = makeLocalClassMirror(key); 1244 classMirror = makeLocalClassMirror(key);
1219 _classMirrorCache[key] = classMirror; 1245 _classMirrorCache[key] = classMirror;
1220 } 1246 }
1221 return classMirror; 1247 return classMirror;
1222 } 1248 }
1223 } 1249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698