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

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
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('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 // 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, this.simpleName); 676 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName);
660 677
661 final _MirrorReference _reflectee; 678 final _reflectee;
662 679
663 final Symbol simpleName; 680 final Symbol simpleName;
664 681
665 Symbol _qualifiedName = null; 682 Symbol _qualifiedName = null;
666 Symbol get qualifiedName { 683 Symbol get qualifiedName {
667 if (_qualifiedName == null) { 684 if (_qualifiedName == null) {
668 _qualifiedName = _computeQualifiedName(owner, simpleName); 685 _qualifiedName = _computeQualifiedName(owner, simpleName);
669 } 686 }
670 return _qualifiedName; 687 return _qualifiedName;
671 } 688 }
(...skipping 15 matching lines...) Expand all
687 } 704 }
688 705
689 final Symbol _variableName; 706 final Symbol _variableName;
690 final _LazyTypeMirror _owner; 707 final _LazyTypeMirror _owner;
691 } 708 }
692 709
693 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl 710 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
694 implements TypeVariableMirror { 711 implements TypeVariableMirror {
695 _LocalTypeVariableMirrorImpl(reflectee, 712 _LocalTypeVariableMirrorImpl(reflectee,
696 String simpleName, 713 String simpleName,
697 this._owner, 714 this._owner)
698 this._upperBound)
699 : super(reflectee, _s(simpleName)); 715 : super(reflectee, _s(simpleName));
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 : super(reflectee, _s(simpleName)); 767 : super(reflectee, _s(simpleName));
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1201 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1176 static ClassMirror reflectClass(Type key) { 1202 static ClassMirror reflectClass(Type key) {
1177 var classMirror = _classMirrorCache[key]; 1203 var classMirror = _classMirrorCache[key];
1178 if (classMirror == null) { 1204 if (classMirror == null) {
1179 classMirror = makeLocalClassMirror(key); 1205 classMirror = makeLocalClassMirror(key);
1180 _classMirrorCache[key] = classMirror; 1206 _classMirrorCache[key] = classMirror;
1181 } 1207 }
1182 return classMirror; 1208 return classMirror;
1183 } 1209 }
1184 } 1210 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698