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

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

Issue 165773002: Remove ObjectMirror.[]. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync Created 6 years, 9 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 | « no previous file | sdk/lib/_internal/lib/js_mirrors.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 final emptyList = new UnmodifiableListView([]); 9 final emptyList = new UnmodifiableListView([]);
10 final emptyMap = new _UnmodifiableMapView({}); 10 final emptyMap = new _UnmodifiableMapView({});
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 final String debugName; 148 final String debugName;
149 final LibraryMirror rootLibrary; 149 final LibraryMirror rootLibrary;
150 150
151 _LocalIsolateMirror(this.debugName, this.rootLibrary); 151 _LocalIsolateMirror(this.debugName, this.rootLibrary);
152 152
153 bool get isCurrent => true; 153 bool get isCurrent => true;
154 154
155 String toString() => "IsolateMirror on '$debugName'"; 155 String toString() => "IsolateMirror on '$debugName'";
156 } 156 }
157 157
158 class _InvocationTrampoline implements Function {
159 final ObjectMirror _receiver;
160 final Symbol _selector;
161 _InvocationTrampoline(this._receiver, this._selector);
162 noSuchMethod(Invocation msg) {
163 if (msg.memberName != #call) return super.noSuchMethod(msg);
164 return _receiver.invoke(_selector,
165 msg.positionalArguments,
166 msg.namedArguments);
167 }
168 }
169
170 class _SyntheticAccessor implements MethodMirror { 158 class _SyntheticAccessor implements MethodMirror {
171 final DeclarationMirror owner; 159 final DeclarationMirror owner;
172 final Symbol simpleName; 160 final Symbol simpleName;
173 final bool isGetter; 161 final bool isGetter;
174 final bool isStatic; 162 final bool isStatic;
175 final bool isTopLevel; 163 final bool isTopLevel;
176 final _target; 164 final _target;
177 165
178 _SyntheticAccessor(this.owner, 166 _SyntheticAccessor(this.owner,
179 this.simpleName, 167 this.simpleName,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 return other is _LocalInstanceMirror && 302 return other is _LocalInstanceMirror &&
315 identical(_reflectee, other._reflectee); 303 identical(_reflectee, other._reflectee);
316 } 304 }
317 305
318 int get hashCode { 306 int get hashCode {
319 // Avoid hash collisions with the reflectee. This constant is in Smi range 307 // Avoid hash collisions with the reflectee. This constant is in Smi range
320 // and happens to be the inner padding from RFC 2104. 308 // and happens to be the inner padding from RFC 2104.
321 return identityHashCode(_reflectee) ^ 0x36363636; 309 return identityHashCode(_reflectee) ^ 0x36363636;
322 } 310 }
323 311
324 Function operator [](Symbol selector) {
325 bool found = false;
326 for (ClassMirror c = type; c != null; c = c.superclass) {
327 var target = c._methods[selector];
328 if (target != null && !target.isStatic && target.isRegularMethod) {
329 found = true;
330 break;
331 }
332 }
333 if (!found) {
334 throw new ArgumentError(
335 "${MirrorSystem.getName(type.simpleName)} has no instance method "
336 "${MirrorSystem.getName(selector)}");
337 }
338 return new _InvocationTrampoline(this, selector);
339 }
340
341 // TODO(16539): Make these weak or soft. 312 // TODO(16539): Make these weak or soft.
342 static var _getFieldClosures = new HashMap(); 313 static var _getFieldClosures = new HashMap();
343 static var _setFieldClosures = new HashMap(); 314 static var _setFieldClosures = new HashMap();
344 static var _getFieldCallCounts = new HashMap(); 315 static var _getFieldCallCounts = new HashMap();
345 static var _setFieldCallCounts = new HashMap(); 316 static var _setFieldCallCounts = new HashMap();
346 static const _closureThreshold = 20; 317 static const _closureThreshold = 20;
347 318
348 _getFieldSlow(unwrapped) { 319 _getFieldSlow(unwrapped) {
349 // Slow path factored out to give the fast path a better chance at being 320 // Slow path factored out to give the fast path a better chance at being
350 // inlined. 321 // inlined.
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 ClassMirror get originalDeclaration { 778 ClassMirror get originalDeclaration {
808 if (isOriginalDeclaration) { 779 if (isOriginalDeclaration) {
809 return this; 780 return this;
810 } else { 781 } else {
811 return reflectClass(_reflectedType); 782 return reflectClass(_reflectedType);
812 } 783 }
813 } 784 }
814 785
815 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'"; 786 String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'";
816 787
817 Function operator [](Symbol selector) {
818 var target = _methods[selector];
819 if (target == null || !target.isStatic || !target.isRegularMethod) {
820 throw new ArgumentError(
821 "${MirrorSystem.getName(simpleName)} has no static method "
822 "${MirrorSystem.getName(selector)}");
823 }
824 return new _InvocationTrampoline(this, selector);
825 }
826
827 InstanceMirror newInstance(Symbol constructorName, 788 InstanceMirror newInstance(Symbol constructorName,
828 List positionalArguments, 789 List positionalArguments,
829 [Map<Symbol, dynamic> namedArguments]) { 790 [Map<Symbol, dynamic> namedArguments]) {
830 // Native code will add the 1 or 2 implicit arguments depending on whether 791 // Native code will add the 1 or 2 implicit arguments depending on whether
831 // we end up invoking a factory or constructor respectively. 792 // we end up invoking a factory or constructor respectively.
832 int numPositionalArguments = positionalArguments.length; 793 int numPositionalArguments = positionalArguments.length;
833 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 794 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
834 int numArguments = numPositionalArguments + numNamedArguments; 795 int numArguments = numPositionalArguments + numNamedArguments;
835 List arguments = new List(numArguments); 796 List arguments = new List(numArguments);
836 arguments.setRange(0, numPositionalArguments, positionalArguments); 797 arguments.setRange(0, numPositionalArguments, positionalArguments);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 } 1211 }
1251 1212
1252 Map<Symbol, Mirror> _cachedMembers; 1213 Map<Symbol, Mirror> _cachedMembers;
1253 Map<Symbol, Mirror> get _members { 1214 Map<Symbol, Mirror> get _members {
1254 if (_cachedMembers == null) { 1215 if (_cachedMembers == null) {
1255 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee)); 1216 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee));
1256 } 1217 }
1257 return _cachedMembers; 1218 return _cachedMembers;
1258 } 1219 }
1259 1220
1260 Map<Symbol, MethodMirror> _cachedFunctions;
1261 Map<Symbol, MethodMirror> get _functions {
1262 if (_cachedFunctions == null) {
1263 _cachedFunctions = _filterMap(_members, (key, value) => (value is MethodMi rror));
1264 }
1265 return _cachedFunctions;
1266 }
1267
1268 List<InstanceMirror> get metadata { 1221 List<InstanceMirror> get metadata {
1269 // Get the metadata objects, convert them into InstanceMirrors using 1222 // Get the metadata objects, convert them into InstanceMirrors using
1270 // reflect() and then make them into a Dart list. 1223 // reflect() and then make them into a Dart list.
1271 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); 1224 return new UnmodifiableListView(_metadata(_reflectee).map(reflect));
1272 } 1225 }
1273 1226
1274 bool operator ==(other) { 1227 bool operator ==(other) {
1275 return this.runtimeType == other.runtimeType && 1228 return this.runtimeType == other.runtimeType &&
1276 this._reflectee == other._reflectee; 1229 this._reflectee == other._reflectee;
1277 } 1230 }
1278 1231
1279 int get hashCode => simpleName.hashCode; 1232 int get hashCode => simpleName.hashCode;
1280 1233
1281 String toString() => "LibraryMirror on '${_n(simpleName)}'"; 1234 String toString() => "LibraryMirror on '${_n(simpleName)}'";
1282 1235
1283 Function operator [](Symbol selector) {
1284 var target = _functions[selector];
1285 if (target == null || !target.isRegularMethod) {
1286 throw new ArgumentError(
1287 "${MirrorSystem.getName(simpleName)} has no top-level method "
1288 "${MirrorSystem.getName(selector)}");
1289 }
1290 return new _InvocationTrampoline(this, selector);
1291 }
1292
1293 var _cachedLibraryDependencies; 1236 var _cachedLibraryDependencies;
1294 get libraryDependencies { 1237 get libraryDependencies {
1295 if (_cachedLibraryDependencies == null) { 1238 if (_cachedLibraryDependencies == null) {
1296 _cachedLibraryDependencies = _libraryDependencies(_reflectee); 1239 _cachedLibraryDependencies = _libraryDependencies(_reflectee);
1297 } 1240 }
1298 return _cachedLibraryDependencies; 1241 return _cachedLibraryDependencies;
1299 } 1242 }
1300 1243
1301 _libraryDependencies(reflectee) 1244 _libraryDependencies(reflectee)
1302 native 'LibraryMirror_libraryDependencies'; 1245 native 'LibraryMirror_libraryDependencies';
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 if (typeMirror == null) { 1630 if (typeMirror == null) {
1688 typeMirror = makeLocalTypeMirror(key); 1631 typeMirror = makeLocalTypeMirror(key);
1689 _instanitationCache[key] = typeMirror; 1632 _instanitationCache[key] = typeMirror;
1690 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1633 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1691 _declarationCache[key] = typeMirror; 1634 _declarationCache[key] = typeMirror;
1692 } 1635 }
1693 } 1636 }
1694 return typeMirror; 1637 return typeMirror;
1695 } 1638 }
1696 } 1639 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698