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

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

Issue 99473008: Revert "Remove implementation of deprecated 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
340 InstanceMirror findInContext(Symbol name, {ifAbsent: null}) { 348 InstanceMirror findInContext(Symbol name, {ifAbsent: null}) {
341 List<String> parts = _n(name).split(".").toList(growable: false); 349 List<String> parts = _n(name).split(".").toList(growable: false);
342 if (parts.length > 3) { 350 if (parts.length > 3) {
343 throw new ArgumentError("Invalid symbol: ${name}"); 351 throw new ArgumentError("Invalid symbol: ${name}");
344 } 352 }
345 List tuple = _computeFindInContext(_reflectee, parts); 353 List tuple = _computeFindInContext(_reflectee, parts);
346 if (tuple.length == 0) { 354 if (tuple.length == 0) {
347 throw new UnsupportedError( 355 throw new UnsupportedError(
348 "ClosureMirror.findInContext not yet supported"); 356 "ClosureMirror.findInContext not yet supported");
349 } 357 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 } 497 }
490 } 498 }
491 } 499 }
492 return _mixin; 500 return _mixin;
493 } 501 }
494 502
495 Map<Symbol, DeclarationMirror> _declarations; 503 Map<Symbol, DeclarationMirror> _declarations;
496 Map<Symbol, DeclarationMirror> get declarations { 504 Map<Symbol, DeclarationMirror> get declarations {
497 if (_declarations != null) return _declarations; 505 if (_declarations != null) return _declarations;
498 var decls = new Map<Symbol, DeclarationMirror>(); 506 var decls = new Map<Symbol, DeclarationMirror>();
499 decls.addAll(_members); 507 decls.addAll(members);
500 decls.addAll(_constructors); 508 decls.addAll(constructors);
501 typeVariables.forEach((tv) => decls[tv.simpleName] = tv); 509 typeVariables.forEach((tv) => decls[tv.simpleName] = tv);
502 return _declarations = 510 return _declarations =
503 new _UnmodifiableMapView<Symbol, DeclarationMirror>(decls); 511 new _UnmodifiableMapView<Symbol, DeclarationMirror>(decls);
504 } 512 }
505 513
506 Map<Symbol, Mirror> _cachedMembers; 514 Map<Symbol, Mirror> _members;
507 Map<Symbol, Mirror> get _members { 515 Map<Symbol, Mirror> get members {
508 if (_cachedMembers == null) { 516 if (_members == null) {
509 var whoseMembers = _isMixinAlias ? _trueSuperclass : this; 517 var whoseMembers = _isMixinAlias ? _trueSuperclass : this;
510 _cachedMembers = _makeMemberMap(mixin._computeMembers(whoseMembers._reflec tee)); 518 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee));
511 } 519 }
512 return _cachedMembers; 520 return _members;
513 } 521 }
514 522
515 Map<Symbol, MethodMirror> _cachedMethods; 523 Map<Symbol, MethodMirror> _methods;
516 Map<Symbol, MethodMirror> get _methods { 524 Map<Symbol, MethodMirror> get methods {
517 if (_cachedMethods == null) { 525 if (_methods == null) {
518 _cachedMethods = _filterMap( 526 _methods = _filterMap(
519 _members, 527 members,
520 (key, value) => (value is MethodMirror && value.isRegularMethod)); 528 (key, value) => (value is MethodMirror && value.isRegularMethod));
521 } 529 }
522 return _cachedMethods; 530 return _methods;
523 } 531 }
524 532
525 Map<Symbol, MethodMirror> _cachedConstructors; 533 Map<Symbol, MethodMirror> _getters;
526 Map<Symbol, MethodMirror> get _constructors { 534 Map<Symbol, MethodMirror> get getters {
527 if (_cachedConstructors == null) { 535 if (_getters == 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) {
528 var constructorsList = _computeConstructors(_reflectee); 566 var constructorsList = _computeConstructors(_reflectee);
529 var stringName = _n(simpleName); 567 var stringName = _n(simpleName);
530 constructorsList.forEach((c) => c._patchConstructorName(stringName)); 568 constructorsList.forEach((c) => c._patchConstructorName(stringName));
531 _cachedConstructors = _makeMemberMap(constructorsList); 569 _constructors = _makeMemberMap(constructorsList);
532 } 570 }
533 return _cachedConstructors; 571 return _constructors;
534 } 572 }
535 573
536 bool get _isAnonymousMixinApplication { 574 bool get _isAnonymousMixinApplication {
537 if (_isMixinAlias) return false; // Named mixin application. 575 if (_isMixinAlias) return false; // Named mixin application.
538 if (mixin == this) return false; // Not a mixin application. 576 if (mixin == this) return false; // Not a mixin application.
539 return true; 577 return true;
540 } 578 }
541 579
542 List<TypeVariableMirror> _typeVariables = null; 580 List<TypeVariableMirror> _typeVariables = null;
543 List<TypeVariableMirror> get typeVariables { 581 List<TypeVariableMirror> get typeVariables {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 if (isOriginalDeclaration) { 615 if (isOriginalDeclaration) {
578 return this; 616 return this;
579 } else { 617 } else {
580 return reflectClass(_reflectedType); 618 return reflectClass(_reflectedType);
581 } 619 }
582 } 620 }
583 621
584 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'"; 622 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'";
585 623
586 Function operator [](Symbol selector) { 624 Function operator [](Symbol selector) {
587 var target = _methods[selector]; 625 var target = methods[selector];
588 if (target == null || !target.isStatic || !target.isRegularMethod) { 626 if (target == null || !target.isStatic || !target.isRegularMethod) {
589 throw new ArgumentError( 627 throw new ArgumentError(
590 "${MirrorSystem.getName(simpleName)} has no static method " 628 "${MirrorSystem.getName(simpleName)} has no static method "
591 "${MirrorSystem.getName(selector)}"); 629 "${MirrorSystem.getName(selector)}");
592 } 630 }
593 return new _InvocationTrampoline(this, selector); 631 return new _InvocationTrampoline(this, selector);
594 } 632 }
595 633
596 InstanceMirror newInstance(Symbol constructorName, 634 InstanceMirror newInstance(Symbol constructorName,
597 List positionalArguments, 635 List positionalArguments,
(...skipping 15 matching lines...) Expand all
613 }); 651 });
614 } 652 }
615 653
616 return reflect(_invokeConstructor(_reflectee, 654 return reflect(_invokeConstructor(_reflectee,
617 _reflectedType, 655 _reflectedType,
618 _n(constructorName), 656 _n(constructorName),
619 arguments, 657 arguments,
620 names)); 658 names));
621 } 659 }
622 660
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
623 List<InstanceMirror> get metadata { 671 List<InstanceMirror> get metadata {
624 // Get the metadata objects, convert them into InstanceMirrors using 672 // Get the metadata objects, convert them into InstanceMirrors using
625 // reflect() and then make them into a Dart list. 673 // reflect() and then make them into a Dart list.
626 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); 674 return new UnmodifiableListView(_metadata(_reflectee).map(reflect));
627 } 675 }
628 676
629 bool operator ==(other) { 677 bool operator ==(other) {
630 return this.runtimeType == other.runtimeType && 678 return this.runtimeType == other.runtimeType &&
631 this._reflectee == other._reflectee && 679 this._reflectee == other._reflectee &&
632 this._reflectedType == other._reflectedType && 680 this._reflectedType == other._reflectedType &&
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 Type get _instantiator => null; 989 Type get _instantiator => null;
942 990
943 SourceLocation get location { 991 SourceLocation get location {
944 throw new UnimplementedError('LibraryMirror.location is not implemented'); 992 throw new UnimplementedError('LibraryMirror.location is not implemented');
945 } 993 }
946 994
947 Map<Symbol, DeclarationMirror> _declarations; 995 Map<Symbol, DeclarationMirror> _declarations;
948 Map<Symbol, DeclarationMirror> get declarations { 996 Map<Symbol, DeclarationMirror> get declarations {
949 if (_declarations != null) return _declarations; 997 if (_declarations != null) return _declarations;
950 return _declarations = 998 return _declarations =
951 new _UnmodifiableMapView<Symbol, DeclarationMirror>(_members); 999 new _UnmodifiableMapView<Symbol, DeclarationMirror>(members);
952 } 1000 }
953 1001
954 Map<Symbol, Mirror> _cachedMembers; 1002 Map<Symbol, Mirror> _members;
955 Map<Symbol, Mirror> get _members { 1003 Map<Symbol, Mirror> get members {
956 if (_cachedMembers == null) { 1004 if (_members == null) {
957 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee)); 1005 _members = _makeMemberMap(_computeMembers(_reflectee));
958 } 1006 }
959 return _cachedMembers; 1007 return _members;
960 } 1008 }
961 1009
962 Map<Symbol, MethodMirror> _cachedFunctions; 1010 Map<Symbol, ClassMirror> _types;
963 Map<Symbol, MethodMirror> get _functions { 1011 Map<Symbol, TypeMirror> get types {
964 if (_cachedFunctions == null) { 1012 if (_types == null) {
965 _cachedFunctions = _filterMap(_members, (key, value) => (value is MethodMi rror)); 1013 _types = _filterMap(members, (key, value) => (value is TypeMirror));
966 } 1014 }
967 return _cachedFunctions; 1015 return _types;
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;
968 } 1057 }
969 1058
970 List<InstanceMirror> get metadata { 1059 List<InstanceMirror> get metadata {
971 // Get the metadata objects, convert them into InstanceMirrors using 1060 // Get the metadata objects, convert them into InstanceMirrors using
972 // reflect() and then make them into a Dart list. 1061 // reflect() and then make them into a Dart list.
973 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); 1062 return new UnmodifiableListView(_metadata(_reflectee).map(reflect));
974 } 1063 }
975 1064
976 bool operator ==(other) { 1065 bool operator ==(other) {
977 return this.runtimeType == other.runtimeType && 1066 return this.runtimeType == other.runtimeType &&
978 this._reflectee == other._reflectee; 1067 this._reflectee == other._reflectee;
979 } 1068 }
980 1069
981 int get hashCode => simpleName.hashCode; 1070 int get hashCode => simpleName.hashCode;
982 1071
983 String toString() => "LibraryMirror on '${_n(simpleName)}'"; 1072 String toString() => "LibraryMirror on '${_n(simpleName)}'";
984 1073
985 Function operator [](Symbol selector) { 1074 Function operator [](Symbol selector) {
986 var target = _functions[selector]; 1075 var target = functions[selector];
987 if (target == null || !target.isRegularMethod) { 1076 if (target == null || !target.isRegularMethod) {
988 throw new ArgumentError( 1077 throw new ArgumentError(
989 "${MirrorSystem.getName(simpleName)} has no top-level method " 1078 "${MirrorSystem.getName(simpleName)} has no top-level method "
990 "${MirrorSystem.getName(selector)}"); 1079 "${MirrorSystem.getName(selector)}");
991 } 1080 }
992 return new _InvocationTrampoline(this, selector); 1081 return new _InvocationTrampoline(this, selector);
993 } 1082 }
994 1083
995 _invoke(reflectee, memberName, arguments, argumentNames) 1084 _invoke(reflectee, memberName, arguments, argumentNames)
996 native 'LibraryMirror_invoke'; 1085 native 'LibraryMirror_invoke';
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 if (typeMirror == null) { 1425 if (typeMirror == null) {
1337 typeMirror = makeLocalTypeMirror(key); 1426 typeMirror = makeLocalTypeMirror(key);
1338 _instanitationCache[key] = typeMirror; 1427 _instanitationCache[key] = typeMirror;
1339 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1428 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1340 _declarationCache[key] = typeMirror; 1429 _declarationCache[key] = typeMirror;
1341 } 1430 }
1342 } 1431 }
1343 return typeMirror; 1432 return typeMirror;
1344 } 1433 }
1345 } 1434 }
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