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

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

Issue 26344006: Substitution for type variables in mirrors on instantiated generics. (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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 this._isMixinTypedef, 426 this._isMixinTypedef,
427 this._isGenericDeclaration) 427 this._isGenericDeclaration)
428 : this._simpleName = _s(simpleName), 428 : this._simpleName = _s(simpleName),
429 super(reflectee); 429 super(reflectee);
430 430
431 final Type _reflectedType; 431 final Type _reflectedType;
432 final bool _isGeneric; 432 final bool _isGeneric;
433 final bool _isMixinTypedef; 433 final bool _isMixinTypedef;
434 final bool _isGenericDeclaration; 434 final bool _isGenericDeclaration;
435 435
436 TypeMirror _instantiateInContextOf(declaration) => this;
437
436 bool get hasReflectedType => !_isGenericDeclaration; 438 bool get hasReflectedType => !_isGenericDeclaration;
437 Type get reflectedType { 439 Type get reflectedType {
438 if (!hasReflectedType) { 440 if (!hasReflectedType) {
439 throw new UnsupportedError( 441 throw new UnsupportedError(
440 "Declarations of generics have no reflected type"); 442 "Declarations of generics have no reflected type");
441 } 443 }
442 return _reflectedType; 444 return _reflectedType;
443 } 445 }
444 446
445 Symbol _simpleName; 447 Symbol _simpleName;
(...skipping 30 matching lines...) Expand all
476 } 478 }
477 479
478 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces 480 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces
479 // once we send out a breaking change. 481 // once we send out a breaking change.
480 bool get isClass => true; 482 bool get isClass => true;
481 ClassMirror get defaultFactory => null; 483 ClassMirror get defaultFactory => null;
482 484
483 ClassMirror _trueSuperclassField; 485 ClassMirror _trueSuperclassField;
484 ClassMirror get _trueSuperclass { 486 ClassMirror get _trueSuperclass {
485 if (_trueSuperclassField == null) { 487 if (_trueSuperclassField == null) {
486 Type supertype = _supertype(_reflectee); 488 Type supertype = isOriginalDeclaration
489 ? _supertype(_reflectedType)
490 : _supertypeInstantiated(_reflectedType);
487 if (supertype == null) { 491 if (supertype == null) {
488 // Object has no superclass. 492 // Object has no superclass.
489 return null; 493 return null;
490 } 494 }
491 _trueSuperclassField = _Mirrors._reflectType(supertype); 495 _trueSuperclassField = _Mirrors._reflectType(supertype);
492 } 496 }
493 return _trueSuperclassField; 497 return _trueSuperclassField;
494 } 498 }
495 ClassMirror get superclass { 499 ClassMirror get superclass {
496 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; 500 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 Map<Symbol, MethodMirror> get constructors { 593 Map<Symbol, MethodMirror> get constructors {
590 if (_constructors == null) { 594 if (_constructors == null) {
591 var constructorsList = _computeConstructors(_reflectee); 595 var constructorsList = _computeConstructors(_reflectee);
592 var stringName = _n(simpleName); 596 var stringName = _n(simpleName);
593 constructorsList.forEach((c) => c._patchConstructorName(stringName)); 597 constructorsList.forEach((c) => c._patchConstructorName(stringName));
594 _constructors = _makeMemberMap(constructorsList); 598 _constructors = _makeMemberMap(constructorsList);
595 } 599 }
596 return _constructors; 600 return _constructors;
597 } 601 }
598 602
603 bool get _isAnonymousMixinApplication {
604 if (_isMixinTypedef) return false; // Named mixin application.
605 if (mixin == this) return false; // Not a mixin application.
606 return true;
607 }
608
599 List<TypeVariableMirror> _typeVariables = null; 609 List<TypeVariableMirror> _typeVariables = null;
600 List<TypeVariableMirror> get typeVariables { 610 List<TypeVariableMirror> get typeVariables {
601 if (_typeVariables == null) { 611 if (_typeVariables == null) {
612 _typeVariables = new List<TypeVariableMirror>();
613 if (_isAnonymousMixinApplication) return _typeVariables;
614
602 List params = _ClassMirror_type_variables(_reflectee); 615 List params = _ClassMirror_type_variables(_reflectee);
603 _typeVariables = new List<TypeVariableMirror>();
604 var mirror; 616 var mirror;
605 for (var i = 0; i < params.length; i += 2) { 617 for (var i = 0; i < params.length; i += 2) {
606 mirror = new _LocalTypeVariableMirrorImpl( 618 mirror = new _LocalTypeVariableMirrorImpl(
607 params[i + 1], params[i], this); 619 params[i + 1], params[i], this);
608 _typeVariables.add(mirror); 620 _typeVariables.add(mirror);
609 } 621 }
610 } 622 }
611 return _typeVariables; 623 return _typeVariables;
612 } 624 }
613 625
614 List<TypeMirror> _typeArguments = null; 626 List<TypeMirror> _typeArguments = null;
615 List<TypeMirror> get typeArguments { 627 List<TypeMirror> get typeArguments {
616 if(_typeArguments == null) { 628 if(_typeArguments == null) {
617 if(_isGenericDeclaration) { 629 if(_isGenericDeclaration || _isAnonymousMixinApplication) {
618 _typeArguments = new List<TypeMirror>(); 630 _typeArguments = new List<TypeMirror>();
619 } else { 631 } else {
620 _typeArguments = 632 _typeArguments =
621 new List<TypeMirror>.from(_computeTypeArguments(_reflectedType)); 633 new List<TypeMirror>.from(_computeTypeArguments(_reflectedType));
622 } 634 }
623 } 635 }
624 return _typeArguments; 636 return _typeArguments;
625 } 637 }
626 638
627 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration; 639 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 this._reflectee == other._reflectee && 696 this._reflectee == other._reflectee &&
685 this._reflectedType == other._reflectedType && 697 this._reflectedType == other._reflectedType &&
686 this._isGenericDeclaration == other._isGenericDeclaration; 698 this._isGenericDeclaration == other._isGenericDeclaration;
687 } 699 }
688 700
689 int get hashCode => simpleName.hashCode; 701 int get hashCode => simpleName.hashCode;
690 702
691 static _library(reflectee) 703 static _library(reflectee)
692 native "ClassMirror_library"; 704 native "ClassMirror_library";
693 705
694 static _supertype(reflectee) 706 static _supertype(reflectedType)
695 native "ClassMirror_supertype"; 707 native "ClassMirror_supertype";
696 708
709 static _supertypeInstantiated(reflectedType)
710 native "ClassMirror_supertype_instantiated";
711
697 static _interfaces(reflectee) 712 static _interfaces(reflectee)
698 native "ClassMirror_interfaces"; 713 native "ClassMirror_interfaces";
699 714
700 static _computeMixin(reflectee) 715 static _computeMixin(reflectee)
701 native "ClassMirror_mixin"; 716 native "ClassMirror_mixin";
702 717
703 _computeMembers(reflectee) 718 _computeMembers(reflectee)
704 native "ClassMirror_members"; 719 native "ClassMirror_members";
705 720
706 _computeConstructors(reflectee) 721 _computeConstructors(reflectee)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 bool get isOriginalDeclaration => true; 861 bool get isOriginalDeclaration => true;
847 ClassMirror get originalDeclaration => this; 862 ClassMirror get originalDeclaration => this;
848 863
849 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; 864 String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
850 865
851 static DeclarationMirror _TypeVariableMirror_owner(reflectee) 866 static DeclarationMirror _TypeVariableMirror_owner(reflectee)
852 native "TypeVariableMirror_owner"; 867 native "TypeVariableMirror_owner";
853 868
854 static Type _TypeVariableMirror_upper_bound(reflectee) 869 static Type _TypeVariableMirror_upper_bound(reflectee)
855 native "TypeVariableMirror_upper_bound"; 870 native "TypeVariableMirror_upper_bound";
871
872 static Type _TypeVariableMirror_instantiate_from(reflectee, instantiator)
873 native "TypeVariableMirror_instantiate_from";
874
875 TypeMirror _instantiateInContextOf(declaration) {
876 var instantiator = declaration;
877 while (instantiator is MethodMirror) instantiator = instantiator.owner;
878 if (instantiator is LibraryMirror) return this;
879 if (instantiator is! ClassMirror) throw "UNREACHABLE";
880 if (instantiator.isOriginalDeclaration) return this;
881
882 return _Mirrors._reflectType(
883 _TypeVariableMirror_instantiate_from(
884 _reflectee,
885 instantiator._reflectedType));
886 }
856 } 887 }
857 888
858 889
859 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 890 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
860 implements TypedefMirror { 891 implements TypedefMirror {
861 _LocalTypedefMirrorImpl(reflectee, 892 _LocalTypedefMirrorImpl(reflectee,
862 String simpleName, 893 String simpleName,
863 this._owner) 894 this._owner)
864 : super(reflectee, _s(simpleName)); 895 : super(reflectee, _s(simpleName));
865 896
(...skipping 23 matching lines...) Expand all
889 return new _LocalFunctionTypeMirrorImpl( 920 return new _LocalFunctionTypeMirrorImpl(
890 _TypedefMirror_referent(_reflectee), null); 921 _TypedefMirror_referent(_reflectee), null);
891 } 922 }
892 return _referent; 923 return _referent;
893 } 924 }
894 925
895 String toString() => "TypedefMirror on '${_n(simpleName)}'"; 926 String toString() => "TypedefMirror on '${_n(simpleName)}'";
896 927
897 static _TypedefMirror_referent(_reflectee) 928 static _TypedefMirror_referent(_reflectee)
898 native "TypedefMirror_referent"; 929 native "TypedefMirror_referent";
930
931 // TODO(12282): This is wrong.
932 TypeMirror _instantiateInContextOf(declaration) => this;
899 } 933 }
900 934
901 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl 935 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl
902 implements LibraryMirror { 936 implements LibraryMirror {
903 _LocalLibraryMirrorImpl(reflectee, 937 _LocalLibraryMirrorImpl(reflectee,
904 String simpleName, 938 String simpleName,
905 String url) 939 String url)
906 : this.simpleName = _s(simpleName), 940 : this.simpleName = _s(simpleName),
907 this.uri = Uri.parse(url), 941 this.uri = Uri.parse(url),
908 super(reflectee); 942 super(reflectee);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 1091
1058 TypeMirror _returnType = null; 1092 TypeMirror _returnType = null;
1059 TypeMirror get returnType { 1093 TypeMirror get returnType {
1060 if (_returnType == null) { 1094 if (_returnType == null) {
1061 if (isConstructor) { 1095 if (isConstructor) {
1062 _returnType = owner; 1096 _returnType = owner;
1063 } else { 1097 } else {
1064 _returnType = 1098 _returnType =
1065 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee)); 1099 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee));
1066 } 1100 }
1101 _returnType = _returnType._instantiateInContextOf(owner);
1067 } 1102 }
1068 return _returnType; 1103 return _returnType;
1069 } 1104 }
1070 1105
1071 List<ParameterMirror> _parameters = null; 1106 List<ParameterMirror> _parameters = null;
1072 List<ParameterMirror> get parameters { 1107 List<ParameterMirror> get parameters {
1073 if (_parameters == null) { 1108 if (_parameters == null) {
1074 _parameters = _MethodMirror_parameters(_reflectee); 1109 _parameters = _MethodMirror_parameters(_reflectee);
1075 } 1110 }
1076 return _parameters; 1111 return _parameters;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 bool get isTopLevel => owner is LibraryMirror; 1186 bool get isTopLevel => owner is LibraryMirror;
1152 1187
1153 SourceLocation get location { 1188 SourceLocation get location {
1154 throw new UnimplementedError('VariableMirror.location is not implemented'); 1189 throw new UnimplementedError('VariableMirror.location is not implemented');
1155 } 1190 }
1156 1191
1157 TypeMirror _type; 1192 TypeMirror _type;
1158 TypeMirror get type { 1193 TypeMirror get type {
1159 if (_type == null) { 1194 if (_type == null) {
1160 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); 1195 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee));
1196 _type = _type._instantiateInContextOf(owner);
1161 } 1197 }
1162 return _type; 1198 return _type;
1163 } 1199 }
1164 1200
1165 String toString() => "VariableMirror on '${_n(simpleName)}'"; 1201 String toString() => "VariableMirror on '${_n(simpleName)}'";
1166 1202
1167 static _VariableMirror_type(reflectee) 1203 static _VariableMirror_type(reflectee)
1168 native "VariableMirror_type"; 1204 native "VariableMirror_type";
1169 } 1205 }
1170 1206
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 List<InstanceMirror> get metadata { 1244 List<InstanceMirror> get metadata {
1209 if ( _unmirroredMetadata == null) return const []; 1245 if ( _unmirroredMetadata == null) return const [];
1210 return _unmirroredMetadata.map(reflect).toList(growable:false); 1246 return _unmirroredMetadata.map(reflect).toList(growable:false);
1211 } 1247 }
1212 1248
1213 TypeMirror _type = null; 1249 TypeMirror _type = null;
1214 TypeMirror get type { 1250 TypeMirror get type {
1215 if (_type == null) { 1251 if (_type == null) {
1216 _type = 1252 _type =
1217 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position)); 1253 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position));
1254 _type = _type._instantiateInContextOf(owner);
1218 } 1255 }
1219 return _type; 1256 return _type;
1220 } 1257 }
1221 1258
1222 String toString() => "ParameterMirror on '${_n(simpleName)}'"; 1259 String toString() => "ParameterMirror on '${_n(simpleName)}'";
1223 1260
1224 static Type _ParameterMirror_type(_reflectee, _position) 1261 static Type _ParameterMirror_type(_reflectee, _position)
1225 native "ParameterMirror_type"; 1262 native "ParameterMirror_type";
1226 } 1263 }
1227 1264
(...skipping 19 matching lines...) Expand all
1247 bool operator ==(other) { 1284 bool operator ==(other) {
1248 if (other is! _SpecialTypeMirrorImpl) { 1285 if (other is! _SpecialTypeMirrorImpl) {
1249 return false; 1286 return false;
1250 } 1287 }
1251 return this.simpleName == other.simpleName; 1288 return this.simpleName == other.simpleName;
1252 } 1289 }
1253 1290
1254 int get hashCode => simpleName.hashCode; 1291 int get hashCode => simpleName.hashCode;
1255 1292
1256 String toString() => "TypeMirror on '${_n(simpleName)}'"; 1293 String toString() => "TypeMirror on '${_n(simpleName)}'";
1294
1295 TypeMirror _instantiateInContextOf(declaration) => this;
1257 } 1296 }
1258 1297
1259 class _Mirrors { 1298 class _Mirrors {
1260 // Does a port refer to our local isolate? 1299 // Does a port refer to our local isolate?
1261 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; 1300 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort';
1262 1301
1263 static MirrorSystem _currentMirrorSystem = null; 1302 static MirrorSystem _currentMirrorSystem = null;
1264 1303
1265 // Creates a new local MirrorSystem. 1304 // Creates a new local MirrorSystem.
1266 static MirrorSystem makeLocalMirrorSystem() 1305 static MirrorSystem makeLocalMirrorSystem()
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 if (typeMirror == null) { 1360 if (typeMirror == null) {
1322 typeMirror = makeLocalTypeMirror(key); 1361 typeMirror = makeLocalTypeMirror(key);
1323 _instanitationCache[key] = typeMirror; 1362 _instanitationCache[key] = typeMirror;
1324 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1363 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1325 _declarationCache[key] = typeMirror; 1364 _declarationCache[key] = typeMirror;
1326 } 1365 }
1327 } 1366 }
1328 return typeMirror; 1367 return typeMirror;
1329 } 1368 }
1330 } 1369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698