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

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

Issue 27728004: Generic typedefs and their referents. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 MethodMirror get callMethod { 778 MethodMirror get callMethod {
779 if (_callMethod == null) { 779 if (_callMethod == null) {
780 _callMethod = this._FunctionTypeMirror_call_method(_reflectee); 780 _callMethod = this._FunctionTypeMirror_call_method(_reflectee);
781 } 781 }
782 return _callMethod; 782 return _callMethod;
783 } 783 }
784 784
785 TypeMirror _returnType = null; 785 TypeMirror _returnType = null;
786 TypeMirror get returnType { 786 TypeMirror get returnType {
787 if (_returnType == null) { 787 if (_returnType == null) {
788 _returnType = 788 _returnType = reflectType(_FunctionTypeMirror_return_type(_reflectee));
789 reflectType(_FunctionTypeMirror_return_type(_reflectee)); 789 _returnType = _returnType._instantiateInContextOf(reflectType(_instantiato r));
790 } 790 }
791 return _returnType; 791 return _returnType;
792 } 792 }
793 793
794 List<ParameterMirror> _parameters = null; 794 List<ParameterMirror> _parameters = null;
795 List<ParameterMirror> get parameters { 795 List<ParameterMirror> get parameters {
796 if (_parameters == null) { 796 if (_parameters == null) {
797 _parameters = _FunctionTypeMirror_parameters(_reflectee); 797 _parameters = _FunctionTypeMirror_parameters(_reflectee);
798 _parameters.forEach((p) {
799 p._type = p.type._instantiateInContextOf(reflectType(_instantiator));
800 });
798 } 801 }
799 return _parameters; 802 return _parameters;
800 } 803 }
801 804
805 bool get isOriginalDeclaration => true;
806 get originalDeclaration => this;
807 get typeVariables => [];
808 get typeArguments => [];
809 get metadata => [];
810
802 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>(); 811 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>();
803 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>(); 812 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>();
804 813
805 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; 814 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'";
806 815
807 MethodMirror _FunctionTypeMirror_call_method(reflectee) 816 MethodMirror _FunctionTypeMirror_call_method(reflectee)
808 native "FunctionTypeMirror_call_method"; 817 native "FunctionTypeMirror_call_method";
809 818
810 static Type _FunctionTypeMirror_return_type(reflectee) 819 static Type _FunctionTypeMirror_return_type(reflectee)
811 native "FunctionTypeMirror_return_type"; 820 native "FunctionTypeMirror_return_type";
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 static Type _TypeVariableMirror_upper_bound(reflectee) 910 static Type _TypeVariableMirror_upper_bound(reflectee)
902 native "TypeVariableMirror_upper_bound"; 911 native "TypeVariableMirror_upper_bound";
903 912
904 static Type _TypeVariableMirror_instantiate_from(reflectee, instantiator) 913 static Type _TypeVariableMirror_instantiate_from(reflectee, instantiator)
905 native "TypeVariableMirror_instantiate_from"; 914 native "TypeVariableMirror_instantiate_from";
906 915
907 TypeMirror _instantiateInContextOf(declaration) { 916 TypeMirror _instantiateInContextOf(declaration) {
908 var instantiator = declaration; 917 var instantiator = declaration;
909 while (instantiator is MethodMirror) instantiator = instantiator.owner; 918 while (instantiator is MethodMirror) instantiator = instantiator.owner;
910 if (instantiator is LibraryMirror) return this; 919 if (instantiator is LibraryMirror) return this;
911 if (instantiator is! ClassMirror) throw "UNREACHABLE"; 920 if (!(instantiator is ClassMirror || instantiator is TypedefMirror))
921 throw "UNREACHABLE";
912 if (instantiator.isOriginalDeclaration) return this; 922 if (instantiator.isOriginalDeclaration) return this;
913 923
914 return reflectType( 924 return reflectType(
915 _TypeVariableMirror_instantiate_from(_reflectee, 925 _TypeVariableMirror_instantiate_from(_reflectee,
916 instantiator._reflectedType)); 926 instantiator._reflectedType));
917 } 927 }
918 } 928 }
919 929
920 930
921 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 931 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
922 implements TypedefMirror { 932 implements TypedefMirror {
923 _LocalTypedefMirrorImpl(reflectee, 933 _LocalTypedefMirrorImpl(reflectee,
934 this._reflectedType,
924 String simpleName, 935 String simpleName,
936 this._isGeneric,
937 this._isGenericDeclaration,
925 this._owner) 938 this._owner)
926 : super(reflectee, _s(simpleName)); 939 : super(reflectee, _s(simpleName));
927 940
928 final bool isTopLevel = true; 941 final Type _reflectedType;
942 final bool _isGeneric;
943 final bool _isGenericDeclaration;
929 944
930 // TODO(12282): Deal with generic typedefs. 945 bool get isTopLevel => true;
931 bool get _isGeneric => false;
932
933 bool get isPrivate => false; 946 bool get isPrivate => false;
934 947
935 DeclarationMirror _owner; 948 DeclarationMirror _owner;
936 DeclarationMirror get owner { 949 DeclarationMirror get owner {
937 if (_owner == null) { 950 if (_owner == null) {
938 _owner = _LocalClassMirrorImpl._library(_reflectee); 951 _owner = _LocalClassMirrorImpl._library(_reflectee);
939 } 952 }
940 return _owner; 953 return _owner;
941 } 954 }
942 955
943 SourceLocation get location { 956 SourceLocation get location {
944 throw new UnimplementedError('TypedefMirror.location is not implemented'); 957 throw new UnimplementedError('TypedefMirror.location is not implemented');
945 } 958 }
946 959
947 TypeMirror _referent = null; 960 TypeMirror _referent = null;
948 TypeMirror get referent { 961 TypeMirror get referent {
949 if (_referent == null) { 962 if (_referent == null) {
950 // TODO(12282): Deal with generic typedef. 963 _referent = _nativeReferent(_reflectedType);
951 return new _LocalFunctionTypeMirrorImpl( 964 _referent._instantiator = _reflectedType;
952 _TypedefMirror_referent(_reflectee), null);
953 } 965 }
954 return _referent; 966 return _referent;
955 } 967 }
956 968
969 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration;
970
971 TypedefMirror get originalDeclaration {
972 if (isOriginalDeclaration) {
973 return this;
974 } else {
975 return _nativeDeclaration(_reflectedType);
976 }
977 }
978
979 List<TypeVariableMirror> _typeVariables = null;
980 List<TypeVariableMirror> get typeVariables {
981 if (_typeVariables == null) {
982 _typeVariables = new List<TypeVariableMirror>();
983 List params = _LocalClassMirrorImpl._ClassMirror_type_variables(_reflectee );
984 var mirror;
985 for (var i = 0; i < params.length; i += 2) {
986 mirror = new _LocalTypeVariableMirrorImpl(
987 params[i + 1], params[i], this);
988 _typeVariables.add(mirror);
989 }
990 }
991 return _typeVariables;
992 }
993
994 List<TypeMirror> _typeArguments = null;
995 List<TypeMirror> get typeArguments {
996 if(_typeArguments == null) {
997 if(_isGenericDeclaration) {
998 _typeArguments = new List<TypeMirror>();
999 } else {
1000 _typeArguments =
1001 new List<TypeMirror>.from(_LocalClassMirrorImpl._computeTypeArgument s(_reflectedType));
1002 }
1003 }
1004 return _typeArguments;
1005 }
1006
1007 TypeMirror _instantiateInContextOf(declaration) {
1008 var instantiator = declaration;
1009 while (instantiator is MethodMirror) instantiator = instantiator.owner;
1010 if (instantiator is LibraryMirror) return this;
1011 if (!(instantiator is ClassMirror || instantiator is TypedefMirror))
1012 throw "UNREACHABLE";
1013
1014 return reflectType(
1015 _nativeInstatniateFrom(_reflectedType, instantiator._reflectedType));
1016 }
1017
957 String toString() => "TypedefMirror on '${_n(simpleName)}'"; 1018 String toString() => "TypedefMirror on '${_n(simpleName)}'";
958 1019
959 static _TypedefMirror_referent(_reflectee) 1020 static _nativeReferent(reflectedType)
960 native "TypedefMirror_referent"; 1021 native "TypedefMirror_referent";
961 1022
962 // TODO(12282): This is wrong. 1023 static _nativeInstatniateFrom(reflectedType, instantiator)
963 TypeMirror _instantiateInContextOf(declaration) => this; 1024 native "TypedefMirror_instantiate_from";
1025
1026 static _nativeDeclaration(reflectedType)
1027 native "TypedefMirror_declaration";
964 } 1028 }
965 1029
966 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl 1030 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl
967 implements LibraryMirror { 1031 implements LibraryMirror {
968 _LocalLibraryMirrorImpl(reflectee, 1032 _LocalLibraryMirrorImpl(reflectee,
969 String simpleName, 1033 String simpleName,
970 String url) 1034 String url)
971 : this.simpleName = _s(simpleName), 1035 : this.simpleName = _s(simpleName),
972 this.uri = Uri.parse(url), 1036 this.uri = Uri.parse(url),
973 super(reflectee); 1037 super(reflectee);
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 if (typeMirror == null) { 1461 if (typeMirror == null) {
1398 typeMirror = makeLocalTypeMirror(key); 1462 typeMirror = makeLocalTypeMirror(key);
1399 _instanitationCache[key] = typeMirror; 1463 _instanitationCache[key] = typeMirror;
1400 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1464 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1401 _declarationCache[key] = typeMirror; 1465 _declarationCache[key] = typeMirror;
1402 } 1466 }
1403 } 1467 }
1404 return typeMirror; 1468 return typeMirror;
1405 } 1469 }
1406 } 1470 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698