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

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: Get rid of TypeVariableMirror dependency 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 396
395 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 397 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
396 implements ClassMirror { 398 implements ClassMirror {
397 _LocalClassMirrorImpl(reflectee, 399 _LocalClassMirrorImpl(reflectee,
398 String simpleName, 400 String simpleName,
399 this.isClass, 401 this.isClass,
400 this._owner, 402 this._owner,
401 this._superclass, 403 this._superclass,
402 this._superinterfaces, 404 this._superinterfaces,
403 this._defaultFactory, 405 this._defaultFactory,
404 Map<String, Mirror> constructors, 406 Map<String, Mirror> constructors)
405 Map<String, Mirror> typeVariables)
406 : this._simpleName = _s(simpleName), 407 : this._simpleName = _s(simpleName),
407 this.constructors = _convertStringToSymbolMap(constructors), 408 this.constructors = _convertStringToSymbolMap(constructors),
408 this.typeVariables = _convertStringToSymbolMap(typeVariables),
409 super(reflectee); 409 super(reflectee);
410 410
411 Symbol _simpleName; 411 Symbol _simpleName;
412 Symbol get simpleName { 412 Symbol get simpleName {
413 // dynamic, void and the function types have their names set eagerly in the 413 // dynamic, void and the function types have their names set eagerly in the
414 // constructor. 414 // constructor.
415 if(_simpleName == null) { 415 if(_simpleName == null) {
416 _simpleName = _s(_name(_reflectee)); 416 _simpleName = _s(_name(_reflectee));
417 } 417 }
418 return _simpleName; 418 return _simpleName;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 Map<Symbol, VariableMirror> get variables { 521 Map<Symbol, VariableMirror> get variables {
522 if (_variables == null) { 522 if (_variables == null) {
523 _variables = _filterMap( 523 _variables = _filterMap(
524 members, 524 members,
525 (key, value) => (value is VariableMirror)); 525 (key, value) => (value is VariableMirror));
526 } 526 }
527 return _variables; 527 return _variables;
528 } 528 }
529 529
530 Map<Symbol, MethodMirror> constructors; 530 Map<Symbol, MethodMirror> constructors;
531 Map<Symbol, TypeVariableMirror> typeVariables; 531
532 Map<Symbol, TypeVariableMirror> _typeVariables = null;
533 Map<Symbol, TypeVariableMirror> get typeVariables {
Michael Lippautz (Google) 2013/07/25 20:17:57 Future API may return a List here. We already get
534 if (_typeVariables == null) {
535 List<TypeVariableMirror> result = _ClassMirror_type_variables(
536 _reflectee, this);
537 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>
538 .fromIterable(result, key: (e) => e.simpleName);
539 }
540 return _typeVariables;
541 }
532 542
533 Map<Symbol, TypeMirror> get typeArguments { 543 Map<Symbol, TypeMirror> get typeArguments {
534 throw new UnimplementedError( 544 throw new UnimplementedError(
535 'ClassMirror.typeArguments is not implemented'); 545 'ClassMirror.typeArguments is not implemented');
536 } 546 }
537 547
538 bool get isOriginalDeclaration { 548 bool get isOriginalDeclaration {
539 throw new UnimplementedError( 549 throw new UnimplementedError(
540 'ClassMirror.isOriginalDeclaration is not implemented'); 550 'ClassMirror.isOriginalDeclaration is not implemented');
541 } 551 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 native 'ClassMirror_invoke'; 609 native 'ClassMirror_invoke';
600 610
601 _invokeGetter(reflectee, getterName) 611 _invokeGetter(reflectee, getterName)
602 native 'ClassMirror_invokeGetter'; 612 native 'ClassMirror_invokeGetter';
603 613
604 _invokeSetter(reflectee, setterName, value) 614 _invokeSetter(reflectee, setterName, value)
605 native 'ClassMirror_invokeSetter'; 615 native 'ClassMirror_invokeSetter';
606 616
607 static _invokeConstructor(reflectee, constructorName, positionalArguments) 617 static _invokeConstructor(reflectee, constructorName, positionalArguments)
608 native 'ClassMirror_invokeConstructor'; 618 native 'ClassMirror_invokeConstructor';
619
620 static _ClassMirror_type_variables(reflectee, mirror)
621 native "ClassMirror_type_variables";
609 } 622 }
610 623
611 class _LazyFunctionTypeMirror { 624 class _LazyFunctionTypeMirror {
612 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} 625 _LazyFunctionTypeMirror(this.returnType, this.parameters) {}
613 626
614 ClassMirror resolve(MirrorSystem mirrors) { 627 ClassMirror resolve(MirrorSystem mirrors) {
615 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), 628 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors),
616 parameters); 629 parameters);
617 } 630 }
618 631
619 final returnType; 632 final returnType;
620 final List<ParameterMirror> parameters; 633 final List<ParameterMirror> parameters;
621 } 634 }
622 635
623 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl 636 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
624 implements FunctionTypeMirror { 637 implements FunctionTypeMirror {
625 _LocalFunctionTypeMirrorImpl(reflectee, 638 _LocalFunctionTypeMirrorImpl(reflectee,
626 simpleName, 639 simpleName,
627 this._returnType, 640 this._returnType,
628 this.parameters) 641 this.parameters)
629 : super(reflectee, 642 : super(reflectee,
630 simpleName, 643 simpleName,
631 true, 644 true,
632 null, 645 null,
633 new _LazyTypeMirror('dart:core', 'Object'), 646 new _LazyTypeMirror('dart:core', 'Object'),
634 [ new _LazyTypeMirror('dart:core', 'Function') ], 647 [ new _LazyTypeMirror('dart:core', 'Function') ],
635 null, 648 null,
636 const {},
637 const {}); 649 const {});
638 650
639 Map<Symbol, Mirror> get members => const {}; 651 Map<Symbol, Mirror> get members => const {};
640 652
641 var _returnType; 653 var _returnType;
642 TypeMirror get returnType { 654 TypeMirror get returnType {
643 if (_returnType is! Mirror) { 655 if (_returnType is! Mirror) {
644 _returnType = _returnType.resolve(mirrors); 656 _returnType = _returnType.resolve(mirrors);
645 } 657 }
646 return _returnType; 658 return _returnType;
647 } 659 }
648 660
649 final List<ParameterMirror> parameters; 661 final List<ParameterMirror> parameters;
662 final Map<Symbol, TypeVariableMirror> typeVariables = const {};
650 663
651 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; 664 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'";
652 } 665 }
653 666
654 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl 667 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl
655 implements DeclarationMirror { 668 implements DeclarationMirror {
656 _LocalDeclarationMirrorImpl(this._reflectee); 669 _LocalDeclarationMirrorImpl(this._reflectee);
657 final _MirrorReference _reflectee; 670 final _MirrorReference _reflectee;
658 671
659 List<InstanceMirror> get metadata { 672 List<InstanceMirror> get metadata {
(...skipping 13 matching lines...) Expand all
673 } 686 }
674 687
675 final Symbol _variableName; 688 final Symbol _variableName;
676 final _LazyTypeMirror _owner; 689 final _LazyTypeMirror _owner;
677 } 690 }
678 691
679 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl 692 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
680 implements TypeVariableMirror { 693 implements TypeVariableMirror {
681 _LocalTypeVariableMirrorImpl(reflectee, 694 _LocalTypeVariableMirrorImpl(reflectee,
682 String simpleName, 695 String simpleName,
683 this._owner, 696 this._owner)
684 this._upperBound)
685 : this.simpleName = _s(simpleName), 697 : this.simpleName = _s(simpleName),
686 super(reflectee); 698 super(reflectee);
687 699
688 final Symbol simpleName; 700 final Symbol simpleName;
689 701
690 Symbol _qualifiedName = null; 702 Symbol _qualifiedName = null;
691 Symbol get qualifiedName { 703 Symbol get qualifiedName {
692 if (_qualifiedName == null) { 704 if (_qualifiedName == null) {
693 _qualifiedName = _computeQualifiedName(owner, simpleName); 705 _qualifiedName = _computeQualifiedName(owner, simpleName);
694 } 706 }
695 return _qualifiedName; 707 return _qualifiedName;
696 } 708 }
697 709
698 var _owner; 710 var _owner;
699 DeclarationMirror get owner { 711 DeclarationMirror get owner {
712 if (_owner == null) {
713 _owner = _LocalTypeVariableMirror_owner(_reflectee);
714 }
715 // TODO(11897): This will go away, as soon as lazy mirrors go away.
700 if (_owner is! Mirror) { 716 if (_owner is! Mirror) {
701 _owner = _owner.resolve(mirrors); 717 _owner = _owner.resolve(mirrors);
702 } 718 }
703 return _owner; 719 return _owner;
704 } 720 }
705 721
706 bool get isPrivate => false; 722 bool get isPrivate => false;
707 723
708 final bool isTopLevel = false; 724 final bool isTopLevel = false;
709 725
710 SourceLocation get location { 726 SourceLocation get location {
711 throw new UnimplementedError( 727 throw new UnimplementedError(
712 'TypeVariableMirror.location is not implemented'); 728 'TypeVariableMirror.location is not implemented');
713 } 729 }
714 730
715 var _upperBound; 731 TypeMirror _upperBound = null;
716 TypeMirror get upperBound { 732 TypeMirror get upperBound {
717 if (_upperBound is! Mirror) { 733 if (_upperBound == null) {
718 _upperBound = _upperBound.resolve(mirrors); 734 _upperBound = _LocalTypeVariableMirror_upper_bound(_reflectee);
719 } 735 }
720 return _upperBound; 736 return _upperBound;
721 } 737 }
722 738
723 List<InstanceMirror> get metadata { 739 List<InstanceMirror> get metadata {
724 throw new UnimplementedError( 740 throw new UnimplementedError(
725 'TypeVariableMirror.metadata is not implemented'); 741 'TypeVariableMirror.metadata is not implemented');
726 } 742 }
727 743
728 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; 744 String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
745
746 static DeclarationMirror _LocalTypeVariableMirror_owner(reflectee)
747 native "LocalTypeVariableMirror_owner";
748
749 static TypeMirror _LocalTypeVariableMirror_upper_bound(reflectee)
750 native "LocalTypeVariableMirror_upper_bound";
729 } 751 }
730 752
731 753
732 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 754 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
733 implements TypedefMirror { 755 implements TypedefMirror {
734 _LocalTypedefMirrorImpl(reflectee, 756 _LocalTypedefMirrorImpl(reflectee,
735 String simpleName, 757 String simpleName,
736 this._owner, 758 this._owner,
737 this._referent) 759 this._referent)
738 : this.simpleName = _s(simpleName), 760 : this.simpleName = _s(simpleName),
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1225 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1204 static ClassMirror reflectClass(Type key) { 1226 static ClassMirror reflectClass(Type key) {
1205 var classMirror = _classMirrorCache[key]; 1227 var classMirror = _classMirrorCache[key];
1206 if (classMirror == null) { 1228 if (classMirror == null) {
1207 classMirror = makeLocalClassMirror(key); 1229 classMirror = makeLocalClassMirror(key);
1208 _classMirrorCache[key] = classMirror; 1230 _classMirrorCache[key] = classMirror;
1209 } 1231 }
1210 return classMirror; 1232 return classMirror;
1211 } 1233 }
1212 } 1234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698