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

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

Issue 24005002: Make TypedefMirror a direct descendant of TypeMirror. (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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // TODO(ahe): This is a hack, see delegate below. 262 // TODO(ahe): This is a hack, see delegate below.
263 static Function _invokeOnClosure; 263 static Function _invokeOnClosure;
264 264
265 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); 265 _LocalInstanceMirrorImpl(reflectee) : super(reflectee);
266 266
267 ClassMirror _type; 267 ClassMirror _type;
268 ClassMirror get type { 268 ClassMirror get type {
269 if (_type == null) { 269 if (_type == null) {
270 // Note it not safe to use reflectee.runtimeType because runtimeType may 270 // Note it not safe to use reflectee.runtimeType because runtimeType may
271 // be overridden. 271 // be overridden.
272 _type = _Mirrors._reflectType(_computeType(reflectee)); 272 _type = reflectType(_computeType(reflectee));
273 } 273 }
274 return _type; 274 return _type;
275 } 275 }
276 276
277 // LocalInstanceMirrors always reflect local instances 277 // LocalInstanceMirrors always reflect local instances
278 bool hasReflectee = true; 278 bool hasReflectee = true;
279 279
280 get reflectee => _reflectee; 280 get reflectee => _reflectee;
281 281
282 delegate(Invocation invocation) { 282 delegate(Invocation invocation) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 ClassMirror _trueSuperclassField; 485 ClassMirror _trueSuperclassField;
486 ClassMirror get _trueSuperclass { 486 ClassMirror get _trueSuperclass {
487 if (_trueSuperclassField == null) { 487 if (_trueSuperclassField == null) {
488 Type supertype = isOriginalDeclaration 488 Type supertype = isOriginalDeclaration
489 ? _supertype(_reflectedType) 489 ? _supertype(_reflectedType)
490 : _supertypeInstantiated(_reflectedType); 490 : _supertypeInstantiated(_reflectedType);
491 if (supertype == null) { 491 if (supertype == null) {
492 // Object has no superclass. 492 // Object has no superclass.
493 return null; 493 return null;
494 } 494 }
495 _trueSuperclassField = _Mirrors._reflectType(supertype); 495 _trueSuperclassField = reflectType(supertype);
496 } 496 }
497 return _trueSuperclassField; 497 return _trueSuperclassField;
498 } 498 }
499 ClassMirror get superclass { 499 ClassMirror get superclass {
500 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; 500 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass;
501 } 501 }
502 502
503 var _superinterfaces; 503 var _superinterfaces;
504 List<ClassMirror> get superinterfaces { 504 List<ClassMirror> get superinterfaces {
505 if (_superinterfaces == null) { 505 if (_superinterfaces == null) {
506 _superinterfaces = _interfaces(_reflectee) 506 _superinterfaces = _interfaces(_reflectee)
507 .map((i) => _Mirrors._reflectType(i)).toList(growable:false); 507 .map((i) => reflectType(i)).toList(growable:false);
508 } 508 }
509 return _superinterfaces; 509 return _superinterfaces;
510 } 510 }
511 511
512 get _mixinApplicationName { 512 get _mixinApplicationName {
513 var mixins = new List<ClassMirror>(); 513 var mixins = new List<ClassMirror>();
514 var klass = this; 514 var klass = this;
515 while (_computeMixin(klass._reflectee) != null) { 515 while (_computeMixin(klass._reflectee) != null) {
516 mixins.add(klass.mixin); 516 mixins.add(klass.mixin);
517 klass = klass.superclass; 517 klass = klass.superclass;
518 } 518 }
519 return _s( 519 return _s(
520 _n(klass.qualifiedName) 520 _n(klass.qualifiedName)
521 + ' with ' 521 + ' with '
522 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); 522 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', '));
523 } 523 }
524 524
525 var _mixin; 525 var _mixin;
526 ClassMirror get mixin { 526 ClassMirror get mixin {
527 if (_mixin == null) { 527 if (_mixin == null) {
528 if (_isMixinTypedef) { 528 if (_isMixinTypedef) {
529 _mixin = _trueSuperclass.mixin; 529 _mixin = _trueSuperclass.mixin;
530 } else { 530 } else {
531 var mixinType = _computeMixin(_reflectee); 531 var mixinType = _computeMixin(_reflectee);
532 if (mixinType == null) { 532 if (mixinType == null) {
533 // The reflectee is not a mixin application. 533 // The reflectee is not a mixin application.
534 _mixin = this; 534 _mixin = this;
535 } else { 535 } else {
536 _mixin = _Mirrors._reflectType(mixinType); 536 _mixin = reflectType(mixinType);
537 } 537 }
538 } 538 }
539 } 539 }
540 return _mixin; 540 return _mixin;
541 } 541 }
542 542
543 Map<Symbol, Mirror> _members; 543 Map<Symbol, Mirror> _members;
544 Map<Symbol, Mirror> get members { 544 Map<Symbol, Mirror> get members {
545 if (_members == null) { 545 if (_members == null) {
546 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this; 546 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 if (_callMethod == null) { 759 if (_callMethod == null) {
760 _callMethod = this._FunctionTypeMirror_call_method(_reflectee); 760 _callMethod = this._FunctionTypeMirror_call_method(_reflectee);
761 } 761 }
762 return _callMethod; 762 return _callMethod;
763 } 763 }
764 764
765 TypeMirror _returnType = null; 765 TypeMirror _returnType = null;
766 TypeMirror get returnType { 766 TypeMirror get returnType {
767 if (_returnType == null) { 767 if (_returnType == null) {
768 _returnType = 768 _returnType =
769 _Mirrors._reflectType(_FunctionTypeMirror_return_type(_reflectee)); 769 reflectType(_FunctionTypeMirror_return_type(_reflectee));
770 } 770 }
771 return _returnType; 771 return _returnType;
772 } 772 }
773 773
774 List<ParameterMirror> _parameters = null; 774 List<ParameterMirror> _parameters = null;
775 List<ParameterMirror> get parameters { 775 List<ParameterMirror> get parameters {
776 if (_parameters == null) { 776 if (_parameters == null) {
777 _parameters = _FunctionTypeMirror_parameters(_reflectee); 777 _parameters = _FunctionTypeMirror_parameters(_reflectee);
778 } 778 }
779 return _parameters; 779 return _parameters;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 final bool isTopLevel = false; 845 final bool isTopLevel = false;
846 846
847 SourceLocation get location { 847 SourceLocation get location {
848 throw new UnimplementedError( 848 throw new UnimplementedError(
849 'TypeVariableMirror.location is not implemented'); 849 'TypeVariableMirror.location is not implemented');
850 } 850 }
851 851
852 TypeMirror _upperBound = null; 852 TypeMirror _upperBound = null;
853 TypeMirror get upperBound { 853 TypeMirror get upperBound {
854 if (_upperBound == null) { 854 if (_upperBound == null) {
855 _upperBound = 855 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee));
856 _Mirrors._reflectType(_TypeVariableMirror_upper_bound(_reflectee));
857 } 856 }
858 return _upperBound; 857 return _upperBound;
859 } 858 }
860 859
861 bool get hasReflectedType => false; 860 bool get hasReflectedType => false;
862 Type get reflectedType => throw new UnsupportedError() ; 861 Type get reflectedType => throw new UnsupportedError() ;
863 862
864 List<TypeVariableMirror> get typeVariables => new UnmodifiableListView<TypeVar iableMirror>(); 863 List<TypeVariableMirror> get typeVariables => new UnmodifiableListView<TypeVar iableMirror>();
865 List<TypeMirror> get typeArguments => new UnmodifiableListView<TypeMirror>(); 864 List<TypeMirror> get typeArguments => new UnmodifiableListView<TypeMirror>();
866 865
(...skipping 11 matching lines...) Expand all
878 static Type _TypeVariableMirror_instantiate_from(reflectee, instantiator) 877 static Type _TypeVariableMirror_instantiate_from(reflectee, instantiator)
879 native "TypeVariableMirror_instantiate_from"; 878 native "TypeVariableMirror_instantiate_from";
880 879
881 TypeMirror _instantiateInContextOf(declaration) { 880 TypeMirror _instantiateInContextOf(declaration) {
882 var instantiator = declaration; 881 var instantiator = declaration;
883 while (instantiator is MethodMirror) instantiator = instantiator.owner; 882 while (instantiator is MethodMirror) instantiator = instantiator.owner;
884 if (instantiator is LibraryMirror) return this; 883 if (instantiator is LibraryMirror) return this;
885 if (instantiator is! ClassMirror) throw "UNREACHABLE"; 884 if (instantiator is! ClassMirror) throw "UNREACHABLE";
886 if (instantiator.isOriginalDeclaration) return this; 885 if (instantiator.isOriginalDeclaration) return this;
887 886
888 return _Mirrors._reflectType( 887 return reflectType(
889 _TypeVariableMirror_instantiate_from( 888 _TypeVariableMirror_instantiate_from(_reflectee,
890 _reflectee, 889 instantiator._reflectedType));
891 instantiator._reflectedType));
892 } 890 }
893 } 891 }
894 892
895 893
896 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 894 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
897 implements TypedefMirror { 895 implements TypedefMirror {
898 _LocalTypedefMirrorImpl(reflectee, 896 _LocalTypedefMirrorImpl(reflectee,
899 String simpleName, 897 String simpleName,
900 this._owner) 898 this._owner)
901 : super(reflectee, _s(simpleName)); 899 : super(reflectee, _s(simpleName));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 final Uri uri; 966 final Uri uri;
969 967
970 Map<Symbol, Mirror> _members; 968 Map<Symbol, Mirror> _members;
971 Map<Symbol, Mirror> get members { 969 Map<Symbol, Mirror> get members {
972 if (_members == null) { 970 if (_members == null) {
973 _members = _makeMemberMap(_computeMembers(_reflectee)); 971 _members = _makeMemberMap(_computeMembers(_reflectee));
974 } 972 }
975 return _members; 973 return _members;
976 } 974 }
977 975
976 Map<Symbol, ClassMirror> _types;
977 Map<Symbol, TypeMirror> get types {
978 if (_types == null) {
979 _types = _filterMap(members, (key, value) => (value is TypeMirror));
980 }
981 return _types;
982 }
983
978 Map<Symbol, ClassMirror> _classes; 984 Map<Symbol, ClassMirror> _classes;
979 Map<Symbol, ClassMirror> get classes { 985 Map<Symbol, ClassMirror> get classes {
980 if (_classes == null) { 986 if (_classes == null) {
981 _classes = _filterMap(members, 987 _classes = _filterMap(members,
982 (key, value) => (value is ClassMirror)); 988 (key, value) => (value is ClassMirror));
983 } 989 }
984 return _classes; 990 return _classes;
985 } 991 }
986 992
987 Map<Symbol, MethodMirror> _functions; 993 Map<Symbol, MethodMirror> _functions;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 SourceLocation get location { 1100 SourceLocation get location {
1095 throw new UnimplementedError('MethodMirror.location is not implemented'); 1101 throw new UnimplementedError('MethodMirror.location is not implemented');
1096 } 1102 }
1097 1103
1098 TypeMirror _returnType = null; 1104 TypeMirror _returnType = null;
1099 TypeMirror get returnType { 1105 TypeMirror get returnType {
1100 if (_returnType == null) { 1106 if (_returnType == null) {
1101 if (isConstructor) { 1107 if (isConstructor) {
1102 _returnType = owner; 1108 _returnType = owner;
1103 } else { 1109 } else {
1104 _returnType = 1110 _returnType = reflectType(_MethodMirror_return_type(_reflectee));
1105 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee));
1106 } 1111 }
1107 _returnType = _returnType._instantiateInContextOf(owner); 1112 _returnType = _returnType._instantiateInContextOf(owner);
1108 } 1113 }
1109 return _returnType; 1114 return _returnType;
1110 } 1115 }
1111 1116
1112 List<ParameterMirror> _parameters = null; 1117 List<ParameterMirror> _parameters = null;
1113 List<ParameterMirror> get parameters { 1118 List<ParameterMirror> get parameters {
1114 if (_parameters == null) { 1119 if (_parameters == null) {
1115 _parameters = _MethodMirror_parameters(_reflectee); 1120 _parameters = _MethodMirror_parameters(_reflectee);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 1196
1192 bool get isTopLevel => owner is LibraryMirror; 1197 bool get isTopLevel => owner is LibraryMirror;
1193 1198
1194 SourceLocation get location { 1199 SourceLocation get location {
1195 throw new UnimplementedError('VariableMirror.location is not implemented'); 1200 throw new UnimplementedError('VariableMirror.location is not implemented');
1196 } 1201 }
1197 1202
1198 TypeMirror _type; 1203 TypeMirror _type;
1199 TypeMirror get type { 1204 TypeMirror get type {
1200 if (_type == null) { 1205 if (_type == null) {
1201 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); 1206 _type = reflectType(_VariableMirror_type(_reflectee));
1202 _type = _type._instantiateInContextOf(owner); 1207 _type = _type._instantiateInContextOf(owner);
1203 } 1208 }
1204 return _type; 1209 return _type;
1205 } 1210 }
1206 1211
1207 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'" ; 1212 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'" ;
1208 1213
1209 static _VariableMirror_type(reflectee) 1214 static _VariableMirror_type(reflectee)
1210 native "VariableMirror_type"; 1215 native "VariableMirror_type";
1211 } 1216 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 bool get hasDefaultValue => _defaultValueReflectee != null; 1253 bool get hasDefaultValue => _defaultValueReflectee != null;
1249 1254
1250 List<InstanceMirror> get metadata { 1255 List<InstanceMirror> get metadata {
1251 if ( _unmirroredMetadata == null) return const []; 1256 if ( _unmirroredMetadata == null) return const [];
1252 return _unmirroredMetadata.map(reflect).toList(growable:false); 1257 return _unmirroredMetadata.map(reflect).toList(growable:false);
1253 } 1258 }
1254 1259
1255 TypeMirror _type = null; 1260 TypeMirror _type = null;
1256 TypeMirror get type { 1261 TypeMirror get type {
1257 if (_type == null) { 1262 if (_type == null) {
1258 _type = 1263 _type = reflectType(_ParameterMirror_type(_reflectee, _position));
1259 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position));
1260 _type = _type._instantiateInContextOf(owner); 1264 _type = _type._instantiateInContextOf(owner);
1261 } 1265 }
1262 return _type; 1266 return _type;
1263 } 1267 }
1264 1268
1265 String toString() => "ParameterMirror on '${_n(simpleName)}'"; 1269 String toString() => "ParameterMirror on '${_n(simpleName)}'";
1266 1270
1267 static Type _ParameterMirror_type(_reflectee, _position) 1271 static Type _ParameterMirror_type(_reflectee, _position)
1268 native "ParameterMirror_type"; 1272 native "ParameterMirror_type";
1269 } 1273 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 ? new _LocalClosureMirrorImpl(reflectee) 1344 ? new _LocalClosureMirrorImpl(reflectee)
1341 : new _LocalInstanceMirrorImpl(reflectee); 1345 : new _LocalInstanceMirrorImpl(reflectee);
1342 } 1346 }
1343 1347
1344 static ClassMirror makeLocalClassMirror(Type key) 1348 static ClassMirror makeLocalClassMirror(Type key)
1345 native "Mirrors_makeLocalClassMirror"; 1349 native "Mirrors_makeLocalClassMirror";
1346 static TypeMirror makeLocalTypeMirror(Type key) 1350 static TypeMirror makeLocalTypeMirror(Type key)
1347 native "Mirrors_makeLocalTypeMirror"; 1351 native "Mirrors_makeLocalTypeMirror";
1348 1352
1349 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); 1353 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror");
1350 static Expando<ClassMirror> _instanitationCache = new Expando("TypeMirror"); 1354 static Expando<TypeMirror> _instanitationCache = new Expando("TypeMirror");
1351 1355
1352 static ClassMirror reflectClass(Type key) { 1356 static ClassMirror reflectClass(Type key) {
1353 var classMirror = _declarationCache[key]; 1357 var classMirror = _declarationCache[key];
1354 if (classMirror == null) { 1358 if (classMirror == null) {
1355 classMirror = makeLocalClassMirror(key); 1359 classMirror = makeLocalClassMirror(key);
1356 _declarationCache[key] = classMirror; 1360 _declarationCache[key] = classMirror;
1357 if (!classMirror._isGeneric) { 1361 if (!classMirror._isGeneric) {
1358 _instanitationCache[key] = classMirror; 1362 _instanitationCache[key] = classMirror;
1359 } 1363 }
1360 } 1364 }
1361 return classMirror; 1365 return classMirror;
1362 } 1366 }
1363 1367
1364 static TypeMirror _reflectType(Type key) { 1368 static TypeMirror reflectType(Type key) {
1365 var typeMirror = _instanitationCache[key]; 1369 var typeMirror = _instanitationCache[key];
1366 if (typeMirror == null) { 1370 if (typeMirror == null) {
1367 typeMirror = makeLocalTypeMirror(key); 1371 typeMirror = makeLocalTypeMirror(key);
1368 _instanitationCache[key] = typeMirror; 1372 _instanitationCache[key] = typeMirror;
1369 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1373 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1370 _declarationCache[key] = typeMirror; 1374 _declarationCache[key] = typeMirror;
1371 } 1375 }
1372 } 1376 }
1373 return typeMirror; 1377 return typeMirror;
1374 } 1378 }
1375 } 1379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698