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

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

Issue 85753008: Remove old mirror API from the VM. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | « no previous file | tests/lib/lib.status » ('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 final emptyList = new UnmodifiableListView([]); 9 final emptyList = new UnmodifiableListView([]);
10 final emptyMap = new _UnmodifiableMapView({}); 10 final emptyMap = new _UnmodifiableMapView({});
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 int get hashCode { 242 int get hashCode {
243 // Avoid hash collisions with the reflectee. This constant is in Smi range 243 // Avoid hash collisions with the reflectee. This constant is in Smi range
244 // and happens to be the inner padding from RFC 2104. 244 // and happens to be the inner padding from RFC 2104.
245 return identityHashCode(_reflectee) ^ 0x36363636; 245 return identityHashCode(_reflectee) ^ 0x36363636;
246 } 246 }
247 247
248 Function operator [](Symbol selector) { 248 Function operator [](Symbol selector) {
249 bool found = false; 249 bool found = false;
250 for (ClassMirror c = type; c != null; c = c.superclass) { 250 for (ClassMirror c = type; c != null; c = c.superclass) {
251 var target = c.methods[selector]; 251 var target = c._methods[selector];
252 if (target != null && !target.isStatic && target.isRegularMethod) { 252 if (target != null && !target.isStatic && target.isRegularMethod) {
253 found = true; 253 found = true;
254 break; 254 break;
255 } 255 }
256 } 256 }
257 if (!found) { 257 if (!found) {
258 throw new ArgumentError( 258 throw new ArgumentError(
259 "${MirrorSystem.getName(type.simpleName)} has no instance method " 259 "${MirrorSystem.getName(type.simpleName)} has no instance method "
260 "${MirrorSystem.getName(selector)}"); 260 "${MirrorSystem.getName(selector)}");
261 } 261 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 arguments[argumentIndex++] = value; 330 arguments[argumentIndex++] = value;
331 names[nameIndex++] = _n(name); 331 names[nameIndex++] = _n(name);
332 }); 332 });
333 } 333 }
334 334
335 // It is tempting to implement this in terms of Function.apply, but then 335 // It is tempting to implement this in terms of Function.apply, but then
336 // lazy compilation errors would be fatal. 336 // lazy compilation errors would be fatal.
337 return reflect(_apply(arguments, names)); 337 return reflect(_apply(arguments, names));
338 } 338 }
339 339
340 Future<InstanceMirror> applyAsync(List positionalArguments,
341 [Map<Symbol, dynamic> namedArguments]) {
342 return new Future(() {
343 return this.apply(_unwrapAsyncPositionals(positionalArguments),
344 _unwrapAsyncNamed(namedArguments));
345 });
346 }
347
348 InstanceMirror findInContext(Symbol name, {ifAbsent: null}) { 340 InstanceMirror findInContext(Symbol name, {ifAbsent: null}) {
349 List<String> parts = _n(name).split(".").toList(growable: false); 341 List<String> parts = _n(name).split(".").toList(growable: false);
350 if (parts.length > 3) { 342 if (parts.length > 3) {
351 throw new ArgumentError("Invalid symbol: ${name}"); 343 throw new ArgumentError("Invalid symbol: ${name}");
352 } 344 }
353 List tuple = _computeFindInContext(_reflectee, parts); 345 List tuple = _computeFindInContext(_reflectee, parts);
354 if (tuple.length == 0) { 346 if (tuple.length == 0) {
355 throw new UnsupportedError( 347 throw new UnsupportedError(
356 "ClosureMirror.findInContext not yet supported"); 348 "ClosureMirror.findInContext not yet supported");
357 } 349 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 489 }
498 } 490 }
499 } 491 }
500 return _mixin; 492 return _mixin;
501 } 493 }
502 494
503 Map<Symbol, DeclarationMirror> _declarations; 495 Map<Symbol, DeclarationMirror> _declarations;
504 Map<Symbol, DeclarationMirror> get declarations { 496 Map<Symbol, DeclarationMirror> get declarations {
505 if (_declarations != null) return _declarations; 497 if (_declarations != null) return _declarations;
506 var decls = new Map<Symbol, DeclarationMirror>(); 498 var decls = new Map<Symbol, DeclarationMirror>();
507 decls.addAll(members); 499 decls.addAll(_members);
508 decls.addAll(constructors); 500 decls.addAll(_constructors);
509 typeVariables.forEach((tv) => decls[tv.simpleName] = tv); 501 typeVariables.forEach((tv) => decls[tv.simpleName] = tv);
510 return _declarations = 502 return _declarations =
511 new _UnmodifiableMapView<Symbol, DeclarationMirror>(decls); 503 new _UnmodifiableMapView<Symbol, DeclarationMirror>(decls);
512 } 504 }
513 505
514 Map<Symbol, Mirror> _members; 506 Map<Symbol, Mirror> _cachedMembers;
515 Map<Symbol, Mirror> get members { 507 Map<Symbol, Mirror> get _members {
516 if (_members == null) { 508 if (_cachedMembers == null) {
517 var whoseMembers = _isMixinAlias ? _trueSuperclass : this; 509 var whoseMembers = _isMixinAlias ? _trueSuperclass : this;
518 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee)); 510 _cachedMembers = _makeMemberMap(mixin._computeMembers(whoseMembers._reflec tee));
519 } 511 }
520 return _members; 512 return _cachedMembers;
521 } 513 }
522 514
523 Map<Symbol, MethodMirror> _methods; 515 Map<Symbol, MethodMirror> _cachedMethods;
524 Map<Symbol, MethodMirror> get methods { 516 Map<Symbol, MethodMirror> get _methods {
525 if (_methods == null) { 517 if (_cachedMethods == null) {
526 _methods = _filterMap( 518 _cachedMethods = _filterMap(
527 members, 519 _members,
528 (key, value) => (value is MethodMirror && value.isRegularMethod)); 520 (key, value) => (value is MethodMirror && value.isRegularMethod));
529 } 521 }
530 return _methods; 522 return _cachedMethods;
531 } 523 }
532 524
533 Map<Symbol, MethodMirror> _getters; 525 Map<Symbol, MethodMirror> _cachedConstructors;
534 Map<Symbol, MethodMirror> get getters { 526 Map<Symbol, MethodMirror> get _constructors {
535 if (_getters == null) { 527 if (_cachedConstructors == null) {
536 _getters = _filterMap(
537 members,
538 (key, value) => (value is MethodMirror && value.isGetter));
539 }
540 return _getters;
541 }
542
543 Map<Symbol, MethodMirror> _setters;
544 Map<Symbol, MethodMirror> get setters {
545 if (_setters == null) {
546 _setters = _filterMap(
547 members,
548 (key, value) => (value is MethodMirror && value.isSetter));
549 }
550 return _setters;
551 }
552
553 Map<Symbol, VariableMirror> _variables;
554 Map<Symbol, VariableMirror> get variables {
555 if (_variables == null) {
556 _variables = _filterMap(
557 members,
558 (key, value) => (value is VariableMirror));
559 }
560 return _variables;
561 }
562
563 Map<Symbol, MethodMirror> _constructors;
564 Map<Symbol, MethodMirror> get constructors {
565 if (_constructors == null) {
566 var constructorsList = _computeConstructors(_reflectee); 528 var constructorsList = _computeConstructors(_reflectee);
567 var stringName = _n(simpleName); 529 var stringName = _n(simpleName);
568 constructorsList.forEach((c) => c._patchConstructorName(stringName)); 530 constructorsList.forEach((c) => c._patchConstructorName(stringName));
569 _constructors = _makeMemberMap(constructorsList); 531 _cachedConstructors = _makeMemberMap(constructorsList);
570 } 532 }
571 return _constructors; 533 return _cachedConstructors;
572 } 534 }
573 535
574 bool get _isAnonymousMixinApplication { 536 bool get _isAnonymousMixinApplication {
575 if (_isMixinAlias) return false; // Named mixin application. 537 if (_isMixinAlias) return false; // Named mixin application.
576 if (mixin == this) return false; // Not a mixin application. 538 if (mixin == this) return false; // Not a mixin application.
577 return true; 539 return true;
578 } 540 }
579 541
580 List<TypeVariableMirror> _typeVariables = null; 542 List<TypeVariableMirror> _typeVariables = null;
581 List<TypeVariableMirror> get typeVariables { 543 List<TypeVariableMirror> get typeVariables {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 if (isOriginalDeclaration) { 577 if (isOriginalDeclaration) {
616 return this; 578 return this;
617 } else { 579 } else {
618 return reflectClass(_reflectedType); 580 return reflectClass(_reflectedType);
619 } 581 }
620 } 582 }
621 583
622 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'"; 584 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'";
623 585
624 Function operator [](Symbol selector) { 586 Function operator [](Symbol selector) {
625 var target = methods[selector]; 587 var target = _methods[selector];
626 if (target == null || !target.isStatic || !target.isRegularMethod) { 588 if (target == null || !target.isStatic || !target.isRegularMethod) {
627 throw new ArgumentError( 589 throw new ArgumentError(
628 "${MirrorSystem.getName(simpleName)} has no static method " 590 "${MirrorSystem.getName(simpleName)} has no static method "
629 "${MirrorSystem.getName(selector)}"); 591 "${MirrorSystem.getName(selector)}");
630 } 592 }
631 return new _InvocationTrampoline(this, selector); 593 return new _InvocationTrampoline(this, selector);
632 } 594 }
633 595
634 InstanceMirror newInstance(Symbol constructorName, 596 InstanceMirror newInstance(Symbol constructorName,
635 List positionalArguments, 597 List positionalArguments,
(...skipping 15 matching lines...) Expand all
651 }); 613 });
652 } 614 }
653 615
654 return reflect(_invokeConstructor(_reflectee, 616 return reflect(_invokeConstructor(_reflectee,
655 _reflectedType, 617 _reflectedType,
656 _n(constructorName), 618 _n(constructorName),
657 arguments, 619 arguments,
658 names)); 620 names));
659 } 621 }
660 622
661 Future<InstanceMirror> newInstanceAsync(Symbol constructorName,
662 List positionalArguments,
663 [Map<Symbol, dynamic> namedArguments]) {
664 return new Future(() {
665 return this.newInstance(constructorName,
666 _unwrapAsyncPositionals(positionalArguments),
667 _unwrapAsyncNamed(namedArguments));
668 });
669 }
670
671 List<InstanceMirror> get metadata { 623 List<InstanceMirror> get metadata {
672 // Get the metadata objects, convert them into InstanceMirrors using 624 // Get the metadata objects, convert them into InstanceMirrors using
673 // reflect() and then make them into a Dart list. 625 // reflect() and then make them into a Dart list.
674 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); 626 return new UnmodifiableListView(_metadata(_reflectee).map(reflect));
675 } 627 }
676 628
677 bool operator ==(other) { 629 bool operator ==(other) {
678 return this.runtimeType == other.runtimeType && 630 return this.runtimeType == other.runtimeType &&
679 this._reflectee == other._reflectee && 631 this._reflectee == other._reflectee &&
680 this._reflectedType == other._reflectedType && 632 this._reflectedType == other._reflectedType &&
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 Type get _instantiator => null; 941 Type get _instantiator => null;
990 942
991 SourceLocation get location { 943 SourceLocation get location {
992 throw new UnimplementedError('LibraryMirror.location is not implemented'); 944 throw new UnimplementedError('LibraryMirror.location is not implemented');
993 } 945 }
994 946
995 Map<Symbol, DeclarationMirror> _declarations; 947 Map<Symbol, DeclarationMirror> _declarations;
996 Map<Symbol, DeclarationMirror> get declarations { 948 Map<Symbol, DeclarationMirror> get declarations {
997 if (_declarations != null) return _declarations; 949 if (_declarations != null) return _declarations;
998 return _declarations = 950 return _declarations =
999 new _UnmodifiableMapView<Symbol, DeclarationMirror>(members); 951 new _UnmodifiableMapView<Symbol, DeclarationMirror>(_members);
1000 } 952 }
1001 953
1002 Map<Symbol, Mirror> _members; 954 Map<Symbol, Mirror> _cachedMembers;
1003 Map<Symbol, Mirror> get members { 955 Map<Symbol, Mirror> get _members {
1004 if (_members == null) { 956 if (_cachedMembers == null) {
1005 _members = _makeMemberMap(_computeMembers(_reflectee)); 957 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee));
1006 } 958 }
1007 return _members; 959 return _cachedMembers;
1008 } 960 }
1009 961
1010 Map<Symbol, ClassMirror> _types; 962 Map<Symbol, MethodMirror> _cachedFunctions;
1011 Map<Symbol, TypeMirror> get types { 963 Map<Symbol, MethodMirror> get _functions {
1012 if (_types == null) { 964 if (_cachedFunctions == null) {
1013 _types = _filterMap(members, (key, value) => (value is TypeMirror)); 965 _cachedFunctions = _filterMap(_members, (key, value) => (value is MethodMi rror));
1014 } 966 }
1015 return _types; 967 return _cachedFunctions;
1016 }
1017
1018 Map<Symbol, ClassMirror> _classes;
1019 Map<Symbol, ClassMirror> get classes {
1020 if (_classes == null) {
1021 _classes = _filterMap(members, (key, value) => (value is ClassMirror));
1022 }
1023 return _classes;
1024 }
1025
1026 Map<Symbol, MethodMirror> _functions;
1027 Map<Symbol, MethodMirror> get functions {
1028 if (_functions == null) {
1029 _functions = _filterMap(members, (key, value) => (value is MethodMirror));
1030 }
1031 return _functions;
1032 }
1033
1034 Map<Symbol, MethodMirror> _getters;
1035 Map<Symbol, MethodMirror> get getters {
1036 if (_getters == null) {
1037 _getters = _filterMap(functions, (key, value) => (value.isGetter));
1038 }
1039 return _getters;
1040 }
1041
1042 Map<Symbol, MethodMirror> _setters;
1043 Map<Symbol, MethodMirror> get setters {
1044 if (_setters == null) {
1045 _setters = _filterMap(functions, (key, value) => (value.isSetter));
1046 }
1047 return _setters;
1048 }
1049
1050 Map<Symbol, VariableMirror> _variables;
1051 Map<Symbol, VariableMirror> get variables {
1052 if (_variables == null) {
1053 _variables = _filterMap(members,
1054 (key, value) => (value is VariableMirror));
1055 }
1056 return _variables;
1057 } 968 }
1058 969
1059 List<InstanceMirror> get metadata { 970 List<InstanceMirror> get metadata {
1060 // Get the metadata objects, convert them into InstanceMirrors using 971 // Get the metadata objects, convert them into InstanceMirrors using
1061 // reflect() and then make them into a Dart list. 972 // reflect() and then make them into a Dart list.
1062 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); 973 return new UnmodifiableListView(_metadata(_reflectee).map(reflect));
1063 } 974 }
1064 975
1065 bool operator ==(other) { 976 bool operator ==(other) {
1066 return this.runtimeType == other.runtimeType && 977 return this.runtimeType == other.runtimeType &&
1067 this._reflectee == other._reflectee; 978 this._reflectee == other._reflectee;
1068 } 979 }
1069 980
1070 int get hashCode => simpleName.hashCode; 981 int get hashCode => simpleName.hashCode;
1071 982
1072 String toString() => "LibraryMirror on '${_n(simpleName)}'"; 983 String toString() => "LibraryMirror on '${_n(simpleName)}'";
1073 984
1074 Function operator [](Symbol selector) { 985 Function operator [](Symbol selector) {
1075 var target = functions[selector]; 986 var target = _functions[selector];
1076 if (target == null || !target.isRegularMethod) { 987 if (target == null || !target.isRegularMethod) {
1077 throw new ArgumentError( 988 throw new ArgumentError(
1078 "${MirrorSystem.getName(simpleName)} has no top-level method " 989 "${MirrorSystem.getName(simpleName)} has no top-level method "
1079 "${MirrorSystem.getName(selector)}"); 990 "${MirrorSystem.getName(selector)}");
1080 } 991 }
1081 return new _InvocationTrampoline(this, selector); 992 return new _InvocationTrampoline(this, selector);
1082 } 993 }
1083 994
1084 _invoke(reflectee, memberName, arguments, argumentNames) 995 _invoke(reflectee, memberName, arguments, argumentNames)
1085 native 'LibraryMirror_invoke'; 996 native 'LibraryMirror_invoke';
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 if (typeMirror == null) { 1336 if (typeMirror == null) {
1426 typeMirror = makeLocalTypeMirror(key); 1337 typeMirror = makeLocalTypeMirror(key);
1427 _instanitationCache[key] = typeMirror; 1338 _instanitationCache[key] = typeMirror;
1428 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1339 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1429 _declarationCache[key] = typeMirror; 1340 _declarationCache[key] = typeMirror;
1430 } 1341 }
1431 } 1342 }
1432 return typeMirror; 1343 return typeMirror;
1433 } 1344 }
1434 } 1345 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698