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

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

Issue 67203002: Implement topLevelMembers, staticMembers, instanceMembers in the VM. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: null source for synthetics, todo on isSynthetic 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
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 final Symbol _selector; 153 final Symbol _selector;
154 _InvocationTrampoline(this._receiver, this._selector); 154 _InvocationTrampoline(this._receiver, this._selector);
155 noSuchMethod(Invocation msg) { 155 noSuchMethod(Invocation msg) {
156 if (msg.memberName != #call) return super.noSuchMethod(msg); 156 if (msg.memberName != #call) return super.noSuchMethod(msg);
157 return _receiver.invoke(_selector, 157 return _receiver.invoke(_selector,
158 msg.positionalArguments, 158 msg.positionalArguments,
159 msg.namedArguments); 159 msg.namedArguments);
160 } 160 }
161 } 161 }
162 162
163 class _SyntheticAccessor implements MethodMirror {
164 final DeclarationMirror owner;
165 final Symbol simpleName;
166 final bool isGetter;
167 final bool isStatic;
168 final bool isTopLevel;
169 final _target;
170
171 _SyntheticAccessor(this.owner,
172 this.simpleName,
173 this.isGetter,
174 this.isStatic,
175 this.isTopLevel,
176 this._target);
177
178 bool get isSynthetic => true;
179 bool get isRegularMethod => false;
180 bool get isOperator => false;
181 bool get isConstructor => false;
182 bool get isConstConstructor => false;
183 bool get isGenerativeConstructor => false;
184 bool get isFactoryConstructor => false;
185 bool get isRedirectingConstructor => false;
186 bool get isAbstract => false;
187
188 bool get isSetter => !isGetter;
189 bool get isPrivate => _n(simpleName).startsWith('_');
190
191 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName);
192 Symbol get constructorName => const Symbol('');
193
194 TypeMirror get returnType => _target.type;
195 List<ParameterMirror> get parameters {
196 if (isGetter) return emptyList;
197 return new UnmodifiableListView(
198 [new _SyntheticSetterParameter(this, this._target)]);
199 }
200
201 List<InstanceMirror> get metadata => emptyList;
202
203 String get source => null;
204 }
205
206 class _SyntheticSetterParameter implements ParameterMirror {
207 final DeclarationMirror owner;
208 final VariableMirror _target;
209
210 _SyntheticSetterParameter(this.owner, this._target);
211
212 Symbol get simpleName => _target.simpleName;
213 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName);
214 TypeMirror get type => _target.type;
215
216 bool get isOptional => false;
217 bool get isNamed => false;
218 bool get isStatic => false;
219 bool get isTopLevel => false;
220 bool get isConst => false;
221 bool get isFinal => true;
222 bool get isPrivate => false;
223 bool get hasDefaultValue => false;
224 InstanceMirror get defaultValue => null;
225 }
226
163 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { 227 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror {
164 final _reflectee; // May be a MirrorReference or an ordinary object. 228 final _reflectee; // May be a MirrorReference or an ordinary object.
165 229
166 _LocalObjectMirror(this._reflectee); 230 _LocalObjectMirror(this._reflectee);
167 231
168 InstanceMirror invoke(Symbol memberName, 232 InstanceMirror invoke(Symbol memberName,
169 List positionalArguments, 233 List positionalArguments,
170 [Map<Symbol, dynamic> namedArguments]) { 234 [Map<Symbol, dynamic> namedArguments]) {
171 int numPositionalArguments = positionalArguments.length; 235 int numPositionalArguments = positionalArguments.length;
172 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 236 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // The reflectee is not a mixin application. 549 // The reflectee is not a mixin application.
486 _mixin = this; 550 _mixin = this;
487 } else { 551 } else {
488 _mixin = reflectType(mixinType); 552 _mixin = reflectType(mixinType);
489 } 553 }
490 } 554 }
491 } 555 }
492 return _mixin; 556 return _mixin;
493 } 557 }
494 558
559 var _cachedStaticMembers;
560 Map<Symbol, MethodMirror> get staticMembers {
561 if (_cachedStaticMembers != null) return _cachedStaticMembers;
562 var result = new Map<Symbol, MethodMirror>();
563 declarations.values.forEach((decl) {
564 if (decl is MethodMirror && decl.isStatic &&
565 !decl.isConstructor && !decl.isAbstract) {
566 result[decl.simpleName] = decl;
567 }
568 if (decl is VariableMirror && decl.isStatic) {
569 var getterName = decl.simpleName;
570 result[getterName] =
571 new _SyntheticAccessor(this, getterName, true, true, false, decl);
572 if (!decl.isFinal) {
573 var setterName = _asSetter(decl.simpleName, this.owner);
574 result[setterName] = new _SyntheticAccessor(
575 this, setterName, false, true, false, decl);
576 }
577 }
578 });
579 return _cachedStaticMembers = result;
siva 2013/12/11 00:54:43 Would it be more readable to write this as if (_ca
rmacnak 2013/12/11 01:17:10 It's about the same either way, but your suggestio
580 }
581
582 var _cachedInstanceMembers;
583 Map<Symbol, MethodMirror> get instanceMembers {
584 if (_cachedInstanceMembers != null) return _cachedInstanceMembers;
585 var result = new Map<Symbol, MethodMirror>();
586 if (superclass != null) {
587 result.addAll(superclass.instanceMembers);
588 }
589 declarations.values.forEach((decl) {
590 if (decl is MethodMirror && !decl.isStatic &&
591 !decl.isConstructor && !decl.isAbstract) {
592 result[decl.simpleName] = decl;
593 }
594 if (decl is VariableMirror && !decl.isStatic) {
595 var getterName = decl.simpleName;
596 result[getterName] =
597 new _SyntheticAccessor(this, getterName, true, false, false, decl);
598 if (!decl.isFinal) {
599 var setterName = _asSetter(decl.simpleName, this.owner);
600 result[setterName] = new _SyntheticAccessor(
601 this, setterName, false, false, false, decl);
602 }
603 }
604 });
605 return _cachedInstanceMembers = result;
siva 2013/12/11 00:54:43 Ditto.
606 }
607
495 Map<Symbol, DeclarationMirror> _declarations; 608 Map<Symbol, DeclarationMirror> _declarations;
496 Map<Symbol, DeclarationMirror> get declarations { 609 Map<Symbol, DeclarationMirror> get declarations {
497 if (_declarations != null) return _declarations; 610 if (_declarations != null) return _declarations;
498 var decls = new Map<Symbol, DeclarationMirror>(); 611 var decls = new Map<Symbol, DeclarationMirror>();
499 decls.addAll(_members); 612 decls.addAll(_members);
500 decls.addAll(_constructors); 613 decls.addAll(_constructors);
501 typeVariables.forEach((tv) => decls[tv.simpleName] = tv); 614 typeVariables.forEach((tv) => decls[tv.simpleName] = tv);
502 return _declarations = 615 return _declarations =
503 new _UnmodifiableMapView<Symbol, DeclarationMirror>(decls); 616 new _UnmodifiableMapView<Symbol, DeclarationMirror>(decls);
504 } 617 }
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 1024
912 String toString() => "TypedefMirror on '${_n(simpleName)}'"; 1025 String toString() => "TypedefMirror on '${_n(simpleName)}'";
913 1026
914 static _nativeReferent(reflectedType) 1027 static _nativeReferent(reflectedType)
915 native "TypedefMirror_referent"; 1028 native "TypedefMirror_referent";
916 1029
917 static _nativeDeclaration(reflectedType) 1030 static _nativeDeclaration(reflectedType)
918 native "TypedefMirror_declaration"; 1031 native "TypedefMirror_declaration";
919 } 1032 }
920 1033
921 class _LocalLibraryMirror extends _LocalObjectMirror 1034 Symbol _asSetter(Symbol getter, LibraryMirror library) {
922 implements LibraryMirror { 1035 var unwrapped = MirrorSystem.getName(getter);
1036 return MirrorSystem.getSymbol('${unwrapped}=', library);
1037 }
1038
1039 class _LocalLibraryMirror extends _LocalObjectMirror implements LibraryMirror {
923 final Symbol simpleName; 1040 final Symbol simpleName;
924 final Uri uri; 1041 final Uri uri;
925 1042
926 _LocalLibraryMirror(reflectee, 1043 _LocalLibraryMirror(reflectee,
927 String simpleName, 1044 String simpleName,
928 String url) 1045 String url)
929 : this.simpleName = _s(simpleName), 1046 : this.simpleName = _s(simpleName),
930 this.uri = Uri.parse(url), 1047 this.uri = Uri.parse(url),
931 super(reflectee); 1048 super(reflectee);
932 1049
(...skipping 11 matching lines...) Expand all
944 throw new UnimplementedError('LibraryMirror.location is not implemented'); 1061 throw new UnimplementedError('LibraryMirror.location is not implemented');
945 } 1062 }
946 1063
947 Map<Symbol, DeclarationMirror> _declarations; 1064 Map<Symbol, DeclarationMirror> _declarations;
948 Map<Symbol, DeclarationMirror> get declarations { 1065 Map<Symbol, DeclarationMirror> get declarations {
949 if (_declarations != null) return _declarations; 1066 if (_declarations != null) return _declarations;
950 return _declarations = 1067 return _declarations =
951 new _UnmodifiableMapView<Symbol, DeclarationMirror>(_members); 1068 new _UnmodifiableMapView<Symbol, DeclarationMirror>(_members);
952 } 1069 }
953 1070
1071 Map<Symbol, MethodMirror> get topLevelMembers {
1072 throw new UnimplementedError(
1073 'LibraryMirror.topLevelMembers is not implemented');
1074 }
1075
954 Map<Symbol, Mirror> _cachedMembers; 1076 Map<Symbol, Mirror> _cachedMembers;
955 Map<Symbol, Mirror> get _members { 1077 Map<Symbol, Mirror> get _members {
956 if (_cachedMembers == null) { 1078 if (_cachedMembers == null) {
957 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee)); 1079 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee));
958 } 1080 }
959 return _cachedMembers; 1081 return _cachedMembers;
960 } 1082 }
961 1083
962 Map<Symbol, MethodMirror> _cachedFunctions; 1084 Map<Symbol, MethodMirror> _cachedFunctions;
963 Map<Symbol, MethodMirror> get _functions { 1085 Map<Symbol, MethodMirror> get _functions {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 _invokeGetter(reflectee, getterName) 1120 _invokeGetter(reflectee, getterName)
999 native 'LibraryMirror_invokeGetter'; 1121 native 'LibraryMirror_invokeGetter';
1000 1122
1001 _invokeSetter(reflectee, setterName, value) 1123 _invokeSetter(reflectee, setterName, value)
1002 native 'LibraryMirror_invokeSetter'; 1124 native 'LibraryMirror_invokeSetter';
1003 1125
1004 _computeMembers(reflectee) 1126 _computeMembers(reflectee)
1005 native "LibraryMirror_members"; 1127 native "LibraryMirror_members";
1006 } 1128 }
1007 1129
1008 class _LocalMethodMirror extends _LocalDeclarationMirror 1130 class _LocalMethodMirror extends _LocalDeclarationMirror
1009 implements MethodMirror { 1131 implements MethodMirror {
1010 final bool isStatic; 1132 final bool isStatic;
1011 final bool isAbstract; 1133 final bool isAbstract;
1012 final bool isGetter; 1134 final bool isGetter;
1013 final bool isSetter; 1135 final bool isSetter;
1014 final bool isConstructor; 1136 final bool isConstructor;
1015 final bool isConstConstructor; 1137 final bool isConstConstructor;
1016 final bool isGenerativeConstructor; 1138 final bool isGenerativeConstructor;
1017 final bool isRedirectingConstructor; 1139 final bool isRedirectingConstructor;
1018 final bool isFactoryConstructor; 1140 final bool isFactoryConstructor;
(...skipping 24 matching lines...) Expand all
1043 if (_owner == null) { 1165 if (_owner == null) {
1044 _owner = _MethodMirror_owner(_reflectee); 1166 _owner = _MethodMirror_owner(_reflectee);
1045 } 1167 }
1046 return _owner; 1168 return _owner;
1047 } 1169 }
1048 1170
1049 bool get isPrivate => _n(simpleName).startsWith('_') || 1171 bool get isPrivate => _n(simpleName).startsWith('_') ||
1050 _n(constructorName).startsWith('_'); 1172 _n(constructorName).startsWith('_');
1051 1173
1052 bool get isTopLevel => owner is LibraryMirror; 1174 bool get isTopLevel => owner is LibraryMirror;
1175 bool get isSynthetic => false;
1053 1176
1054 SourceLocation get location { 1177 SourceLocation get location {
1055 throw new UnimplementedError('MethodMirror.location is not implemented'); 1178 throw new UnimplementedError('MethodMirror.location is not implemented');
1056 } 1179 }
1057 1180
1058 Type get _instantiator { 1181 Type get _instantiator {
1059 var o = owner; 1182 var o = owner;
1060 while (o is MethodMirror) o = o.owner; 1183 while (o is MethodMirror) o = o.owner;
1061 return o._instantiator; 1184 return o._instantiator;
1062 } 1185 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 if (typeMirror == null) { 1459 if (typeMirror == null) {
1337 typeMirror = makeLocalTypeMirror(key); 1460 typeMirror = makeLocalTypeMirror(key);
1338 _instanitationCache[key] = typeMirror; 1461 _instanitationCache[key] = typeMirror;
1339 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1462 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1340 _declarationCache[key] = typeMirror; 1463 _declarationCache[key] = typeMirror;
1341 } 1464 }
1342 } 1465 }
1343 return typeMirror; 1466 return typeMirror;
1344 } 1467 }
1345 } 1468 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/js_mirrors.dart » ('j') | sdk/lib/_internal/lib/js_mirrors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698