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

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: rebase 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 ClassMirror get defaultFactory => null; 491 ClassMirror get defaultFactory => null;
492 492
493 ClassMirror _trueSuperclassField; 493 ClassMirror _trueSuperclassField;
494 ClassMirror get _trueSuperclass { 494 ClassMirror get _trueSuperclass {
495 if (_trueSuperclassField == null) { 495 if (_trueSuperclassField == null) {
496 Type supertype = _supertype(_reflectee); 496 Type supertype = _supertype(_reflectee);
497 if (supertype == null) { 497 if (supertype == null) {
498 // Object has no superclass. 498 // Object has no superclass.
499 return null; 499 return null;
500 } 500 }
501 _trueSuperclassField = _Mirrors._reflectType(supertype); 501 _trueSuperclassField = reflectType(supertype);
502 } 502 }
503 return _trueSuperclassField; 503 return _trueSuperclassField;
504 } 504 }
505 ClassMirror get superclass { 505 ClassMirror get superclass {
506 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; 506 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass;
507 } 507 }
508 508
509 var _superinterfaces; 509 var _superinterfaces;
510 List<ClassMirror> get superinterfaces { 510 List<ClassMirror> get superinterfaces {
511 if (_superinterfaces == null) { 511 if (_superinterfaces == null) {
512 _superinterfaces = _interfaces(_reflectee) 512 _superinterfaces = _interfaces(_reflectee)
513 .map((i) => _Mirrors._reflectType(i)).toList(growable:false); 513 .map((i) => reflectType(i)).toList(growable:false);
514 } 514 }
515 return _superinterfaces; 515 return _superinterfaces;
516 } 516 }
517 517
518 get _mixinApplicationName { 518 get _mixinApplicationName {
519 var mixins = new List<ClassMirror>(); 519 var mixins = new List<ClassMirror>();
520 var klass = this; 520 var klass = this;
521 while (_computeMixin(klass._reflectee) != null) { 521 while (_computeMixin(klass._reflectee) != null) {
522 mixins.add(klass.mixin); 522 mixins.add(klass.mixin);
523 klass = klass.superclass; 523 klass = klass.superclass;
524 } 524 }
525 return _s( 525 return _s(
526 _n(klass.qualifiedName) 526 _n(klass.qualifiedName)
527 + ' with ' 527 + ' with '
528 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); 528 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', '));
529 } 529 }
530 530
531 var _mixin; 531 var _mixin;
532 ClassMirror get mixin { 532 ClassMirror get mixin {
533 if (_mixin == null) { 533 if (_mixin == null) {
534 if (_isMixinTypedef) { 534 if (_isMixinTypedef) {
535 _mixin = _trueSuperclass.mixin; 535 _mixin = _trueSuperclass.mixin;
536 } else { 536 } else {
537 var mixinType = _computeMixin(_reflectee); 537 var mixinType = _computeMixin(_reflectee);
538 if (mixinType == null) { 538 if (mixinType == null) {
539 // The reflectee is not a mixin application. 539 // The reflectee is not a mixin application.
540 _mixin = this; 540 _mixin = this;
541 } else { 541 } else {
542 _mixin = _Mirrors._reflectType(mixinType); 542 _mixin = reflectType(mixinType);
543 } 543 }
544 } 544 }
545 } 545 }
546 return _mixin; 546 return _mixin;
547 } 547 }
548 548
549 Map<Symbol, Mirror> _members; 549 Map<Symbol, Mirror> _members;
550 Map<Symbol, Mirror> get members { 550 Map<Symbol, Mirror> get members {
551 if (_members == null) { 551 if (_members == null) {
552 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this; 552 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 if (_callMethod == null) { 754 if (_callMethod == null) {
755 _callMethod = this._FunctionTypeMirror_call_method(_reflectee); 755 _callMethod = this._FunctionTypeMirror_call_method(_reflectee);
756 } 756 }
757 return _callMethod; 757 return _callMethod;
758 } 758 }
759 759
760 TypeMirror _returnType = null; 760 TypeMirror _returnType = null;
761 TypeMirror get returnType { 761 TypeMirror get returnType {
762 if (_returnType == null) { 762 if (_returnType == null) {
763 _returnType = 763 _returnType =
764 _Mirrors._reflectType(_FunctionTypeMirror_return_type(_reflectee)); 764 reflectType(_FunctionTypeMirror_return_type(_reflectee));
765 } 765 }
766 return _returnType; 766 return _returnType;
767 } 767 }
768 768
769 List<ParameterMirror> _parameters = null; 769 List<ParameterMirror> _parameters = null;
770 List<ParameterMirror> get parameters { 770 List<ParameterMirror> get parameters {
771 if (_parameters == null) { 771 if (_parameters == null) {
772 _parameters = _FunctionTypeMirror_parameters(_reflectee); 772 _parameters = _FunctionTypeMirror_parameters(_reflectee);
773 } 773 }
774 return _parameters; 774 return _parameters;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 final bool isTopLevel = false; 840 final bool isTopLevel = false;
841 841
842 SourceLocation get location { 842 SourceLocation get location {
843 throw new UnimplementedError( 843 throw new UnimplementedError(
844 'TypeVariableMirror.location is not implemented'); 844 'TypeVariableMirror.location is not implemented');
845 } 845 }
846 846
847 TypeMirror _upperBound = null; 847 TypeMirror _upperBound = null;
848 TypeMirror get upperBound { 848 TypeMirror get upperBound {
849 if (_upperBound == null) { 849 if (_upperBound == null) {
850 _upperBound = 850 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee));
851 _Mirrors._reflectType(_TypeVariableMirror_upper_bound(_reflectee));
852 } 851 }
853 return _upperBound; 852 return _upperBound;
854 } 853 }
855 854
856 bool get isOriginalDeclaration => true; 855 bool get isOriginalDeclaration => true;
857 ClassMirror get originalDeclaration => this; 856 ClassMirror get originalDeclaration => this;
858 857
859 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; 858 String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
860 859
861 static DeclarationMirror _TypeVariableMirror_owner(reflectee) 860 static DeclarationMirror _TypeVariableMirror_owner(reflectee)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 final Uri uri; 937 final Uri uri;
939 938
940 Map<Symbol, Mirror> _members; 939 Map<Symbol, Mirror> _members;
941 Map<Symbol, Mirror> get members { 940 Map<Symbol, Mirror> get members {
942 if (_members == null) { 941 if (_members == null) {
943 _members = _makeMemberMap(_computeMembers(_reflectee)); 942 _members = _makeMemberMap(_computeMembers(_reflectee));
944 } 943 }
945 return _members; 944 return _members;
946 } 945 }
947 946
947 Map<Symbol, ClassMirror> _types;
948 Map<Symbol, TypeMirror> get types {
949 if (_types == null) {
950 _types = _filterMap(members, (key, value) => (value is TypeMirror));
951 }
952 return _types;
953 }
954
948 Map<Symbol, ClassMirror> _classes; 955 Map<Symbol, ClassMirror> _classes;
949 Map<Symbol, ClassMirror> get classes { 956 Map<Symbol, ClassMirror> get classes {
950 if (_classes == null) { 957 if (_classes == null) {
951 _classes = _filterMap(members, 958 _classes = _filterMap(members,
952 (key, value) => (value is ClassMirror)); 959 (key, value) => (value is ClassMirror));
953 } 960 }
954 return _classes; 961 return _classes;
955 } 962 }
956 963
957 Map<Symbol, MethodMirror> _functions; 964 Map<Symbol, MethodMirror> _functions;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 SourceLocation get location { 1071 SourceLocation get location {
1065 throw new UnimplementedError('MethodMirror.location is not implemented'); 1072 throw new UnimplementedError('MethodMirror.location is not implemented');
1066 } 1073 }
1067 1074
1068 TypeMirror _returnType = null; 1075 TypeMirror _returnType = null;
1069 TypeMirror get returnType { 1076 TypeMirror get returnType {
1070 if (_returnType == null) { 1077 if (_returnType == null) {
1071 if (isConstructor) { 1078 if (isConstructor) {
1072 _returnType = owner; 1079 _returnType = owner;
1073 } else { 1080 } else {
1074 _returnType = 1081 _returnType = reflectType(_MethodMirror_return_type(_reflectee));
1075 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee));
1076 } 1082 }
1077 } 1083 }
1078 return _returnType; 1084 return _returnType;
1079 } 1085 }
1080 1086
1081 List<ParameterMirror> _parameters = null; 1087 List<ParameterMirror> _parameters = null;
1082 List<ParameterMirror> get parameters { 1088 List<ParameterMirror> get parameters {
1083 if (_parameters == null) { 1089 if (_parameters == null) {
1084 _parameters = _MethodMirror_parameters(_reflectee); 1090 _parameters = _MethodMirror_parameters(_reflectee);
1085 } 1091 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 1166
1161 bool get isTopLevel => owner is LibraryMirror; 1167 bool get isTopLevel => owner is LibraryMirror;
1162 1168
1163 SourceLocation get location { 1169 SourceLocation get location {
1164 throw new UnimplementedError('VariableMirror.location is not implemented'); 1170 throw new UnimplementedError('VariableMirror.location is not implemented');
1165 } 1171 }
1166 1172
1167 TypeMirror _type; 1173 TypeMirror _type;
1168 TypeMirror get type { 1174 TypeMirror get type {
1169 if (_type == null) { 1175 if (_type == null) {
1170 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); 1176 _type = reflectType(_VariableMirror_type(_reflectee));
1171 } 1177 }
1172 return _type; 1178 return _type;
1173 } 1179 }
1174 1180
1175 String toString() => "VariableMirror on '${_n(simpleName)}'"; 1181 String toString() => "VariableMirror on '${_n(simpleName)}'";
1176 1182
1177 static _VariableMirror_type(reflectee) 1183 static _VariableMirror_type(reflectee)
1178 native "VariableMirror_type"; 1184 native "VariableMirror_type";
1179 } 1185 }
1180 1186
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 bool get hasDefaultValue => _defaultValueReflectee != null; 1222 bool get hasDefaultValue => _defaultValueReflectee != null;
1217 1223
1218 List<InstanceMirror> get metadata { 1224 List<InstanceMirror> get metadata {
1219 if ( _unmirroredMetadata == null) return const []; 1225 if ( _unmirroredMetadata == null) return const [];
1220 return _unmirroredMetadata.map(reflect).toList(growable:false); 1226 return _unmirroredMetadata.map(reflect).toList(growable:false);
1221 } 1227 }
1222 1228
1223 TypeMirror _type = null; 1229 TypeMirror _type = null;
1224 TypeMirror get type { 1230 TypeMirror get type {
1225 if (_type == null) { 1231 if (_type == null) {
1226 _type = 1232 _type = reflectType(_ParameterMirror_type(_reflectee, _position));
1227 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position));
1228 } 1233 }
1229 return _type; 1234 return _type;
1230 } 1235 }
1231 1236
1232 String toString() => "ParameterMirror on '${_n(simpleName)}'"; 1237 String toString() => "ParameterMirror on '${_n(simpleName)}'";
1233 1238
1234 static Type _ParameterMirror_type(_reflectee, _position) 1239 static Type _ParameterMirror_type(_reflectee, _position)
1235 native "ParameterMirror_type"; 1240 native "ParameterMirror_type";
1236 } 1241 }
1237 1242
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 ? new _LocalClosureMirrorImpl(reflectee) 1310 ? new _LocalClosureMirrorImpl(reflectee)
1306 : new _LocalInstanceMirrorImpl(reflectee); 1311 : new _LocalInstanceMirrorImpl(reflectee);
1307 } 1312 }
1308 1313
1309 static ClassMirror makeLocalClassMirror(Type key) 1314 static ClassMirror makeLocalClassMirror(Type key)
1310 native "Mirrors_makeLocalClassMirror"; 1315 native "Mirrors_makeLocalClassMirror";
1311 static TypeMirror makeLocalTypeMirror(Type key) 1316 static TypeMirror makeLocalTypeMirror(Type key)
1312 native "Mirrors_makeLocalTypeMirror"; 1317 native "Mirrors_makeLocalTypeMirror";
1313 1318
1314 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); 1319 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror");
1315 static Expando<ClassMirror> _instanitationCache = new Expando("TypeMirror"); 1320 static Expando<TypeMirror> _instanitationCache = new Expando("TypeMirror");
1316 1321
1317 static ClassMirror reflectClass(Type key) { 1322 static ClassMirror reflectClass(Type key) {
1318 var classMirror = _declarationCache[key]; 1323 var classMirror = _declarationCache[key];
1319 if (classMirror == null) { 1324 if (classMirror == null) {
1320 classMirror = makeLocalClassMirror(key); 1325 classMirror = makeLocalClassMirror(key);
1321 _declarationCache[key] = classMirror; 1326 _declarationCache[key] = classMirror;
1322 if (!classMirror._isGeneric) { 1327 if (!classMirror._isGeneric) {
1323 _instanitationCache[key] = classMirror; 1328 _instanitationCache[key] = classMirror;
1324 } 1329 }
1325 } 1330 }
1326 return classMirror; 1331 return classMirror;
1327 } 1332 }
1328 1333
1329 static TypeMirror _reflectType(Type key) { 1334 static TypeMirror reflectType(Type key) {
1330 var typeMirror = _instanitationCache[key]; 1335 var typeMirror = _instanitationCache[key];
1331 if (typeMirror == null) { 1336 if (typeMirror == null) {
1332 typeMirror = makeLocalTypeMirror(key); 1337 typeMirror = makeLocalTypeMirror(key);
1333 _instanitationCache[key] = typeMirror; 1338 _instanitationCache[key] = typeMirror;
1334 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1339 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1335 _declarationCache[key] = typeMirror; 1340 _declarationCache[key] = typeMirror;
1336 } 1341 }
1337 } 1342 }
1338 return typeMirror; 1343 return typeMirror;
1339 } 1344 }
1340 } 1345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698