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

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

Issue 21124011: Inline CreateTypedefMirror and get rid of LazyXXXMirror (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"; 7 import "dart:collection";
8 8
9 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
10 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 TypeMirror _voidType = null; 117 TypeMirror _voidType = null;
118 118
119 TypeMirror get voidType { 119 TypeMirror get voidType {
120 if (_voidType == null) { 120 if (_voidType == null) {
121 _voidType = new _SpecialTypeMirrorImpl('void'); 121 _voidType = new _SpecialTypeMirrorImpl('void');
122 } 122 }
123 return _voidType; 123 return _voidType;
124 } 124 }
125 125
126 final Map<String, FunctionTypeMirror> _functionTypes; 126 final Map<String, FunctionTypeMirror> _functionTypes;
127 FunctionTypeMirror _lookupFunctionTypeMirror( 127 FunctionTypeMirror _lookupFunctionTypeMirror(
rmacnak 2013/07/31 20:24:37 Dead code.
Michael Lippautz (Google) 2013/07/31 20:33:25 Done.
128 reflectee, 128 reflectee) {
129 TypeMirror returnType, 129 return new _LocalFunctionTypeMirrorImpl(reflectee);
130 List<ParameterMirror> parameters) {
131 var sigString = _makeSignatureString(returnType, parameters);
132 var mirror = _functionTypes[sigString];
133 if (mirror == null) {
134 mirror = new _LocalFunctionTypeMirrorImpl(reflectee,
135 sigString,
136 returnType,
137 parameters);
138 _functionTypes[sigString] = mirror;
139 }
140 return mirror;
141 } 130 }
142 131
143 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; 132 String toString() => "MirrorSystem for isolate '${isolate.debugName}'";
144 } 133 }
145 134
146 abstract class _LocalMirrorImpl implements Mirror { 135 abstract class _LocalMirrorImpl implements Mirror {
147 int get hashCode { 136 int get hashCode {
148 throw new UnimplementedError('Mirror.hashCode is not implemented'); 137 throw new UnimplementedError('Mirror.hashCode is not implemented');
149 } 138 }
150 139
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 350
362 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'"; 351 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'";
363 352
364 static _apply(reflectee, positionalArguments) 353 static _apply(reflectee, positionalArguments)
365 native 'ClosureMirror_apply'; 354 native 'ClosureMirror_apply';
366 355
367 static _computeFunction(reflectee) 356 static _computeFunction(reflectee)
368 native 'ClosureMirror_function'; 357 native 'ClosureMirror_function';
369 } 358 }
370 359
371 class _LazyTypeMirror {
372 _LazyTypeMirror(String this.libraryUrl, String typeName)
373 : this.typeName = _s(typeName);
374
375 TypeMirror resolve(MirrorSystem mirrors) {
376 if (libraryUrl == null) {
377 if (typeName == const Symbol('dynamic')) {
378 return mirrors.dynamicType;
379 } else if (typeName == const Symbol('void')) {
380 return mirrors.voidType;
381 } else {
382 throw new UnimplementedError(
383 "Mirror for type '$typeName' is not implemented");
384 }
385 }
386 var resolved = mirrors.libraries[Uri.parse(libraryUrl)].members[typeName];
387 if (resolved == null) {
388 throw new UnimplementedError(
389 "Mirror for type '$typeName' is not implemented");
390 }
391 return resolved;
392 }
393
394 final String libraryUrl;
395 final Symbol typeName;
396 }
397
398 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 360 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
399 implements ClassMirror { 361 implements ClassMirror {
400 _LocalClassMirrorImpl(reflectee, 362 _LocalClassMirrorImpl(reflectee,
401 String simpleName) 363 String simpleName)
402 : this._simpleName = _s(simpleName), 364 : this._simpleName = _s(simpleName),
403 super(reflectee); 365 super(reflectee);
404 366
405 Symbol _simpleName; 367 Symbol _simpleName;
406 Symbol get simpleName { 368 Symbol get simpleName {
407 // dynamic, void and the function types have their names set eagerly in the 369 // dynamic, void and the function types have their names set eagerly in the
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 _invokeSetter(reflectee, setterName, value) 586 _invokeSetter(reflectee, setterName, value)
625 native 'ClassMirror_invokeSetter'; 587 native 'ClassMirror_invokeSetter';
626 588
627 static _invokeConstructor(reflectee, constructorName, positionalArguments) 589 static _invokeConstructor(reflectee, constructorName, positionalArguments)
628 native 'ClassMirror_invokeConstructor'; 590 native 'ClassMirror_invokeConstructor';
629 591
630 static _ClassMirror_type_variables(reflectee) 592 static _ClassMirror_type_variables(reflectee)
631 native "ClassMirror_type_variables"; 593 native "ClassMirror_type_variables";
632 } 594 }
633 595
634 class _LazyFunctionTypeMirror {
635 _LazyFunctionTypeMirror(this.reflectee, this.returnType, this.parameters) {}
636
637 ClassMirror resolve(MirrorSystem mirrors) {
638 return mirrors._lookupFunctionTypeMirror(reflectee,
639 returnType.resolve(mirrors),
640 parameters);
641 }
642
643 final reflectee;
644 final returnType;
645 final List<ParameterMirror> parameters;
646 }
647
648 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl 596 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
649 implements FunctionTypeMirror { 597 implements FunctionTypeMirror {
650 _LocalFunctionTypeMirrorImpl(reflectee, 598 _LocalFunctionTypeMirrorImpl(reflectee) : super(reflectee, null);
651 simpleName,
652 this._returnType,
653 this.parameters)
654 : super(reflectee,
655 simpleName);
656 599
657 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>(); 600 // FunctionTypeMirrors have a simpleName generated from their signature.
658 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>(); 601 Symbol _simpleName = null;
602 Symbol get simpleName {
603 if (_simpleName == null) {
604 _simpleName = _s(_makeSignatureString(returnType, parameters));
605 }
606 return _simpleName;
607 }
659 608
660 var _returnType; 609 TypeMirror _returnType = null;
661 TypeMirror get returnType { 610 TypeMirror get returnType {
662 if (_returnType is! Mirror) { 611 if (_returnType == null) {
663 _returnType = _returnType.resolve(mirrors); 612 _returnType = _FunctionTypeMirror_return_type(_reflectee);
664 } 613 }
665 return _returnType; 614 return _returnType;
666 } 615 }
667 616
668 final List<ParameterMirror> parameters; 617 List<ParameterMirror> _parameters = null;
618 List<ParameterMirror> get parameters {
619 if (_parameters == null) {
620 _parameters = _FunctionTypeMirror_parameters(_reflectee);
621 }
622 return _parameters;
623 }
624
625 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>();
626 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>();
669 final Map<Symbol, TypeVariableMirror> typeVariables = const {}; 627 final Map<Symbol, TypeVariableMirror> typeVariables = const {};
670 628
671 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; 629 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'";
630
631 static TypeMirror _FunctionTypeMirror_return_type(reflectee)
632 native "FunctionTypeMirror_return_type";
633
634 static List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee)
635 native "FunctionTypeMirror_parameters";
672 } 636 }
673 637
674 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl 638 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl
675 implements DeclarationMirror { 639 implements DeclarationMirror {
676 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName); 640 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName);
677 641
678 final _reflectee; 642 final _reflectee;
679 643
680 final Symbol simpleName; 644 final Symbol simpleName;
681 645
682 Symbol _qualifiedName = null; 646 Symbol _qualifiedName = null;
683 Symbol get qualifiedName { 647 Symbol get qualifiedName {
684 if (_qualifiedName == null) { 648 if (_qualifiedName == null) {
685 _qualifiedName = _computeQualifiedName(owner, simpleName); 649 _qualifiedName = _computeQualifiedName(owner, simpleName);
686 } 650 }
687 return _qualifiedName; 651 return _qualifiedName;
688 } 652 }
689 653
690 List<InstanceMirror> get metadata { 654 List<InstanceMirror> get metadata {
691 // Get the metadata objects, convert them into InstanceMirrors using 655 // Get the metadata objects, convert them into InstanceMirrors using
692 // reflect() and then make them into a Dart list. 656 // reflect() and then make them into a Dart list.
693 return _metadata(_reflectee).map(reflect).toList(growable:false); 657 return _metadata(_reflectee).map(reflect).toList(growable:false);
694 } 658 }
695 } 659 }
696 660
697 class _LazyTypeVariableMirror {
698 _LazyTypeVariableMirror(String variableName, this._owner)
699 : this._variableName = _s(variableName);
700
701 TypeVariableMirror resolve(MirrorSystem mirrors) {
702 ClassMirror owner = _owner.resolve(mirrors);
703 return owner.typeVariables[_variableName];
704 }
705
706 final Symbol _variableName;
707 final _LazyTypeMirror _owner;
708 }
709
710 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl 661 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
711 implements TypeVariableMirror { 662 implements TypeVariableMirror {
712 _LocalTypeVariableMirrorImpl(reflectee, 663 _LocalTypeVariableMirrorImpl(reflectee,
713 String simpleName, 664 String simpleName,
714 this._owner) 665 this._owner)
715 : super(reflectee, _s(simpleName)); 666 : super(reflectee, _s(simpleName));
716 667
717 var _owner; 668 var _owner;
718 DeclarationMirror get owner { 669 DeclarationMirror get owner {
719 if (_owner == null) { 670 if (_owner == null) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 706
756 static TypeMirror _LocalTypeVariableMirror_upper_bound(reflectee) 707 static TypeMirror _LocalTypeVariableMirror_upper_bound(reflectee)
757 native "LocalTypeVariableMirror_upper_bound"; 708 native "LocalTypeVariableMirror_upper_bound";
758 } 709 }
759 710
760 711
761 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 712 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
762 implements TypedefMirror { 713 implements TypedefMirror {
763 _LocalTypedefMirrorImpl(reflectee, 714 _LocalTypedefMirrorImpl(reflectee,
764 String simpleName, 715 String simpleName,
765 this._owner, 716 this._owner)
766 this._referent)
767 : super(reflectee, _s(simpleName)); 717 : super(reflectee, _s(simpleName));
768 718
769 var _owner; 719 var _owner;
770 DeclarationMirror get owner { 720 DeclarationMirror get owner {
771 if (_owner == null) { 721 if (_owner == null) {
772 _owner = _LocalClassMirrorImpl._library(_reflectee); 722 _owner = _LocalClassMirrorImpl._library(_reflectee);
773 } 723 }
774 if (_owner is! Mirror) { 724 if (_owner is! Mirror) {
775 _owner = _owner.resolve(mirrors); 725 _owner = _owner.resolve(mirrors);
776 } 726 }
777 return _owner; 727 return _owner;
778 } 728 }
779 729
780 bool get isPrivate => false; 730 bool get isPrivate => false;
781 731
782 final bool isTopLevel = true; 732 final bool isTopLevel = true;
783 733
784 SourceLocation get location { 734 SourceLocation get location {
785 throw new UnimplementedError( 735 throw new UnimplementedError(
786 'TypedefMirror.location is not implemented'); 736 'TypedefMirror.location is not implemented');
787 } 737 }
788 738
789 var _referent; 739 TypeMirror _referent = null;
790 TypeMirror get referent { 740 TypeMirror get referent {
791 if (_referent is! Mirror) { 741 if (_referent == null) {
792 _referent = _referent.resolve(mirrors); 742 return new _LocalFunctionTypeMirrorImpl(
743 _TypedefMirror_referent(_reflectee));
793 } 744 }
794 return _referent; 745 return _referent;
795 } 746 }
796 747
797 String toString() => "TypedefMirror on '${_n(simpleName)}'"; 748 String toString() => "TypedefMirror on '${_n(simpleName)}'";
798 }
799 749
800 750 static _TypedefMirror_referent(_reflectee)
801 class _LazyLibraryMirror { 751 native "TypedefMirror_referent";
802 _LazyLibraryMirror(String this.libraryUrl);
803
804 LibraryMirror resolve(MirrorSystem mirrors) {
805 return mirrors.libraries[Uri.parse(libraryUrl)];
806 }
807
808 final String libraryUrl;
809 } 752 }
810 753
811 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl 754 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl
812 implements LibraryMirror { 755 implements LibraryMirror {
813 _LocalLibraryMirrorImpl(reflectee, 756 _LocalLibraryMirrorImpl(reflectee,
814 String simpleName, 757 String simpleName,
815 String url) 758 String url)
816 : this.simpleName = _s(simpleName), 759 : this.simpleName = _s(simpleName),
817 this.uri = Uri.parse(url), 760 this.uri = Uri.parse(url),
818 super(reflectee); 761 super(reflectee);
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1144 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1202 static ClassMirror reflectClass(Type key) { 1145 static ClassMirror reflectClass(Type key) {
1203 var classMirror = _classMirrorCache[key]; 1146 var classMirror = _classMirrorCache[key];
1204 if (classMirror == null) { 1147 if (classMirror == null) {
1205 classMirror = makeLocalClassMirror(key); 1148 classMirror = makeLocalClassMirror(key);
1206 _classMirrorCache[key] = classMirror; 1149 _classMirrorCache[key] = classMirror;
1207 } 1150 }
1208 return classMirror; 1151 return classMirror;
1209 } 1152 }
1210 } 1153 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | tests/lib/lib.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698