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

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, 3 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
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/lib/mirrors_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // TODO(ahe): This is a hack, see delegate below. 278 // TODO(ahe): This is a hack, see delegate below.
279 static Function _invokeOnClosure; 279 static Function _invokeOnClosure;
280 280
281 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); 281 _LocalInstanceMirrorImpl(reflectee) : super(reflectee);
282 282
283 ClassMirror _type; 283 ClassMirror _type;
284 ClassMirror get type { 284 ClassMirror get type {
285 if (_type == null) { 285 if (_type == null) {
286 // Note it not safe to use reflectee.runtimeType because runtimeType may 286 // Note it not safe to use reflectee.runtimeType because runtimeType may
287 // be overridden. 287 // be overridden.
288 _type = _Mirrors._reflectType(_computeType(reflectee)); 288 _type = reflectType(_computeType(reflectee));
289 } 289 }
290 return _type; 290 return _type;
291 } 291 }
292 292
293 // LocalInstanceMirrors always reflect local instances 293 // LocalInstanceMirrors always reflect local instances
294 bool hasReflectee = true; 294 bool hasReflectee = true;
295 295
296 get reflectee => _reflectee; 296 get reflectee => _reflectee;
297 297
298 delegate(Invocation invocation) { 298 delegate(Invocation invocation) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 ClassMirror get defaultFactory => null; 509 ClassMirror get defaultFactory => null;
510 510
511 ClassMirror _trueSuperclassField; 511 ClassMirror _trueSuperclassField;
512 ClassMirror get _trueSuperclass { 512 ClassMirror get _trueSuperclass {
513 if (_trueSuperclassField == null) { 513 if (_trueSuperclassField == null) {
514 Type supertype = _supertype(_reflectee); 514 Type supertype = _supertype(_reflectee);
515 if (supertype == null) { 515 if (supertype == null) {
516 // Object has no superclass. 516 // Object has no superclass.
517 return null; 517 return null;
518 } 518 }
519 _trueSuperclassField = _Mirrors._reflectType(supertype); 519 _trueSuperclassField = reflectType(supertype);
520 } 520 }
521 return _trueSuperclassField; 521 return _trueSuperclassField;
522 } 522 }
523 ClassMirror get superclass { 523 ClassMirror get superclass {
524 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; 524 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass;
525 } 525 }
526 526
527 var _superinterfaces; 527 var _superinterfaces;
528 List<ClassMirror> get superinterfaces { 528 List<ClassMirror> get superinterfaces {
529 if (_superinterfaces == null) { 529 if (_superinterfaces == null) {
530 _superinterfaces = _interfaces(_reflectee) 530 _superinterfaces = _interfaces(_reflectee)
531 .map((i) => _Mirrors._reflectType(i)).toList(growable:false); 531 .map((i) => reflectType(i)).toList(growable:false);
532 } 532 }
533 return _superinterfaces; 533 return _superinterfaces;
534 } 534 }
535 535
536 get _mixinApplicationName { 536 get _mixinApplicationName {
537 var mixins = new List<ClassMirror>(); 537 var mixins = new List<ClassMirror>();
538 var klass = this; 538 var klass = this;
539 while (_computeMixin(klass._reflectee) != null) { 539 while (_computeMixin(klass._reflectee) != null) {
540 mixins.add(klass.mixin); 540 mixins.add(klass.mixin);
541 klass = klass.superclass; 541 klass = klass.superclass;
542 } 542 }
543 return _s( 543 return _s(
544 _n(klass.qualifiedName) 544 _n(klass.qualifiedName)
545 + ' with ' 545 + ' with '
546 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', ')); 546 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', '));
547 } 547 }
548 548
549 var _mixin; 549 var _mixin;
550 ClassMirror get mixin { 550 ClassMirror get mixin {
551 if (_mixin == null) { 551 if (_mixin == null) {
552 if (_isMixinTypedef) { 552 if (_isMixinTypedef) {
553 _mixin = _trueSuperclass.mixin; 553 _mixin = _trueSuperclass.mixin;
554 } else { 554 } else {
555 var mixinType = _computeMixin(_reflectee); 555 var mixinType = _computeMixin(_reflectee);
556 if (mixinType == null) { 556 if (mixinType == null) {
557 // The reflectee is not a mixin application. 557 // The reflectee is not a mixin application.
558 _mixin = this; 558 _mixin = this;
559 } else { 559 } else {
560 _mixin = _Mirrors._reflectType(mixinType); 560 _mixin = reflectType(mixinType);
561 } 561 }
562 } 562 }
563 } 563 }
564 return _mixin; 564 return _mixin;
565 } 565 }
566 566
567 Map<Symbol, Mirror> _members; 567 Map<Symbol, Mirror> _members;
568 568
569 Map<Symbol, Mirror> get members { 569 Map<Symbol, Mirror> get members {
570 if (_members == null) { 570 if (_members == null) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 if (_callMethod == null) { 782 if (_callMethod == null) {
783 _callMethod = this._FunctionTypeMirror_call_method(_reflectee); 783 _callMethod = this._FunctionTypeMirror_call_method(_reflectee);
784 } 784 }
785 return _callMethod; 785 return _callMethod;
786 } 786 }
787 787
788 TypeMirror _returnType = null; 788 TypeMirror _returnType = null;
789 TypeMirror get returnType { 789 TypeMirror get returnType {
790 if (_returnType == null) { 790 if (_returnType == null) {
791 _returnType = 791 _returnType =
792 _Mirrors._reflectType(_FunctionTypeMirror_return_type(_reflectee)); 792 reflectType(_FunctionTypeMirror_return_type(_reflectee));
793 } 793 }
794 return _returnType; 794 return _returnType;
795 } 795 }
796 796
797 List<ParameterMirror> _parameters = null; 797 List<ParameterMirror> _parameters = null;
798 List<ParameterMirror> get parameters { 798 List<ParameterMirror> get parameters {
799 if (_parameters == null) { 799 if (_parameters == null) {
800 _parameters = _FunctionTypeMirror_parameters(_reflectee); 800 _parameters = _FunctionTypeMirror_parameters(_reflectee);
801 } 801 }
802 return _parameters; 802 return _parameters;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 870
871 SourceLocation get location { 871 SourceLocation get location {
872 throw new UnimplementedError( 872 throw new UnimplementedError(
873 'TypeVariableMirror.location is not implemented'); 873 'TypeVariableMirror.location is not implemented');
874 } 874 }
875 875
876 TypeMirror _upperBound = null; 876 TypeMirror _upperBound = null;
877 TypeMirror get upperBound { 877 TypeMirror get upperBound {
878 if (_upperBound == null) { 878 if (_upperBound == null) {
879 _upperBound = 879 _upperBound =
880 _Mirrors._reflectType(_TypeVariableMirror_upper_bound(_reflectee)); 880 reflectType(_TypeVariableMirror_upper_bound(_reflectee));
881 } 881 }
882 return _upperBound; 882 return _upperBound;
883 } 883 }
884 884
885 List<InstanceMirror> get metadata { 885 List<InstanceMirror> get metadata {
886 throw new UnimplementedError( 886 throw new UnimplementedError(
887 'TypeVariableMirror.metadata is not implemented'); 887 'TypeVariableMirror.metadata is not implemented');
888 } 888 }
889 889
890 bool get isOriginalDeclaration => true; 890 bool get isOriginalDeclaration => true;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 975
976 Map<Symbol, Mirror> _members; 976 Map<Symbol, Mirror> _members;
977 977
978 Map<Symbol, Mirror> get members { 978 Map<Symbol, Mirror> get members {
979 if (_members == null) { 979 if (_members == null) {
980 _members = _makeMemberMap(_computeMembers(_reflectee)); 980 _members = _makeMemberMap(_computeMembers(_reflectee));
981 } 981 }
982 return _members; 982 return _members;
983 } 983 }
984 984
985 Map<Symbol, ClassMirror> _types = null;
985 Map<Symbol, ClassMirror> _classes = null; 986 Map<Symbol, ClassMirror> _classes = null;
986 Map<Symbol, MethodMirror> _functions = null; 987 Map<Symbol, MethodMirror> _functions = null;
987 Map<Symbol, MethodMirror> _getters = null; 988 Map<Symbol, MethodMirror> _getters = null;
988 Map<Symbol, MethodMirror> _setters = null; 989 Map<Symbol, MethodMirror> _setters = null;
989 Map<Symbol, VariableMirror> _variables = null; 990 Map<Symbol, VariableMirror> _variables = null;
990 991
992 Map<Symbol, TypeMirror> get types {
993 if (_types == null) {
994 _types = _filterMap(members,
Michael Lippautz (Google) 2013/09/06 16:58:40 weird alignment
995 (key, value) => (value is TypeMirror));
996 }
997 return _types;
998 }
999
991 Map<Symbol, ClassMirror> get classes { 1000 Map<Symbol, ClassMirror> get classes {
992 if (_classes == null) { 1001 if (_classes == null) {
993 _classes = _filterMap(members, 1002 _classes = _filterMap(members,
994 (key, value) => (value is ClassMirror)); 1003 (key, value) => (value is ClassMirror));
995 } 1004 }
996 return _classes; 1005 return _classes;
997 } 1006 }
998 1007
999 Map<Symbol, MethodMirror> get functions { 1008 Map<Symbol, MethodMirror> get functions {
1000 if (_functions == null) { 1009 if (_functions == null) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 throw new UnimplementedError( 1117 throw new UnimplementedError(
1109 'MethodMirror.location is not implemented'); 1118 'MethodMirror.location is not implemented');
1110 } 1119 }
1111 1120
1112 TypeMirror _returnType = null; 1121 TypeMirror _returnType = null;
1113 TypeMirror get returnType { 1122 TypeMirror get returnType {
1114 if (_returnType == null) { 1123 if (_returnType == null) {
1115 if (isConstructor) { 1124 if (isConstructor) {
1116 _returnType = owner; 1125 _returnType = owner;
1117 } else { 1126 } else {
1118 _returnType = 1127 _returnType =
Michael Lippautz (Google) 2013/09/06 16:58:40 fits on prev line?
1119 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee)); 1128 reflectType(_MethodMirror_return_type(_reflectee));
1120 } 1129 }
1121 } 1130 }
1122 return _returnType; 1131 return _returnType;
1123 } 1132 }
1124 1133
1125 List<ParameterMirror> _parameters = null; 1134 List<ParameterMirror> _parameters = null;
1126 List<ParameterMirror> get parameters { 1135 List<ParameterMirror> get parameters {
1127 if (_parameters == null) { 1136 if (_parameters == null) {
1128 _parameters = _MethodMirror_parameters(_reflectee); 1137 _parameters = _MethodMirror_parameters(_reflectee);
1129 } 1138 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 } 1216 }
1208 1217
1209 SourceLocation get location { 1218 SourceLocation get location {
1210 throw new UnimplementedError( 1219 throw new UnimplementedError(
1211 'VariableMirror.location is not implemented'); 1220 'VariableMirror.location is not implemented');
1212 } 1221 }
1213 1222
1214 TypeMirror _type; 1223 TypeMirror _type;
1215 TypeMirror get type { 1224 TypeMirror get type {
1216 if (_type == null) { 1225 if (_type == null) {
1217 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); 1226 _type = reflectType(_VariableMirror_type(_reflectee));
1218 } 1227 }
1219 return _type; 1228 return _type;
1220 } 1229 }
1221 1230
1222 final bool isStatic; 1231 final bool isStatic;
1223 final bool isFinal; 1232 final bool isFinal;
1224 1233
1225 String toString() => "VariableMirror on '${_n(simpleName)}'"; 1234 String toString() => "VariableMirror on '${_n(simpleName)}'";
1226 1235
1227 static _VariableMirror_type(reflectee) 1236 static _VariableMirror_type(reflectee)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 bool get hasDefaultValue => _defaultValueReflectee != null; 1275 bool get hasDefaultValue => _defaultValueReflectee != null;
1267 1276
1268 List<InstanceMirror> get metadata { 1277 List<InstanceMirror> get metadata {
1269 if ( _unmirroredMetadata == null) return const []; 1278 if ( _unmirroredMetadata == null) return const [];
1270 return _unmirroredMetadata.map(reflect).toList(growable:false); 1279 return _unmirroredMetadata.map(reflect).toList(growable:false);
1271 } 1280 }
1272 1281
1273 TypeMirror _type = null; 1282 TypeMirror _type = null;
1274 TypeMirror get type { 1283 TypeMirror get type {
1275 if (_type == null) { 1284 if (_type == null) {
1276 _type = 1285 _type =
Michael Lippautz (Google) 2013/09/06 16:58:40 ditto
1277 _Mirrors._reflectType(_ParameterMirror_type(_reflectee, _position)); 1286 reflectType(_ParameterMirror_type(_reflectee, _position));
1278 } 1287 }
1279 return _type; 1288 return _type;
1280 } 1289 }
1281 1290
1282 String toString() => "ParameterMirror on '${_n(simpleName)}'"; 1291 String toString() => "ParameterMirror on '${_n(simpleName)}'";
1283 1292
1284 static Type _ParameterMirror_type(_reflectee, _position) 1293 static Type _ParameterMirror_type(_reflectee, _position)
1285 native "ParameterMirror_type"; 1294 native "ParameterMirror_type";
1286 } 1295 }
1287 1296
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 ? new _LocalClosureMirrorImpl(reflectee) 1369 ? new _LocalClosureMirrorImpl(reflectee)
1361 : new _LocalInstanceMirrorImpl(reflectee); 1370 : new _LocalInstanceMirrorImpl(reflectee);
1362 } 1371 }
1363 1372
1364 static ClassMirror makeLocalClassMirror(Type key) 1373 static ClassMirror makeLocalClassMirror(Type key)
1365 native "Mirrors_makeLocalClassMirror"; 1374 native "Mirrors_makeLocalClassMirror";
1366 static TypeMirror makeLocalTypeMirror(Type key) 1375 static TypeMirror makeLocalTypeMirror(Type key)
1367 native "Mirrors_makeLocalTypeMirror"; 1376 native "Mirrors_makeLocalTypeMirror";
1368 1377
1369 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); 1378 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror");
1370 static Expando<ClassMirror> _instanitationCache = new Expando("TypeMirror"); 1379 static Expando<TypeMirror> _instanitationCache = new Expando("TypeMirror");
1371 1380
1372 static ClassMirror reflectClass(Type key) { 1381 static ClassMirror reflectClass(Type key) {
1373 var classMirror = _declarationCache[key]; 1382 var classMirror = _declarationCache[key];
1374 if (classMirror == null) { 1383 if (classMirror == null) {
1375 classMirror = makeLocalClassMirror(key); 1384 classMirror = makeLocalClassMirror(key);
1376 _declarationCache[key] = classMirror; 1385 _declarationCache[key] = classMirror;
1377 if (!classMirror._isGeneric) { 1386 if (!classMirror._isGeneric) {
1378 _instanitationCache[key] = classMirror; 1387 _instanitationCache[key] = classMirror;
1379 } 1388 }
1380 } 1389 }
1381 return classMirror; 1390 return classMirror;
1382 } 1391 }
1383 1392
1384 static TypeMirror _reflectType(Type key) { 1393 static TypeMirror reflectType(Type key) {
1385 var typeMirror = _instanitationCache[key]; 1394 var typeMirror = _instanitationCache[key];
1386 if (typeMirror == null) { 1395 if (typeMirror == null) {
1387 typeMirror = makeLocalTypeMirror(key); 1396 typeMirror = makeLocalTypeMirror(key);
1388 _instanitationCache[key] = typeMirror; 1397 _instanitationCache[key] = typeMirror;
1389 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1398 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1390 _declarationCache[key] = typeMirror; 1399 _declarationCache[key] = typeMirror;
1391 } 1400 }
1392 } 1401 }
1393 return typeMirror; 1402 return typeMirror;
1394 } 1403 }
1395 } 1404 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/lib/mirrors_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698