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

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

Issue 19496003: Make ClassMirror.members internal-native and lazy. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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/vm/bootstrap_natives.h » ('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 // These values are allowed to be passed directly over the wire. 7 // These values are allowed to be passed directly over the wire.
8 bool _isSimpleValue(var value) { 8 bool _isSimpleValue(var value) {
9 return (value == null || value is num || value is String || value is bool); 9 return (value == null || value is num || value is String || value is bool);
10 } 10 }
11 11
12 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { 12 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) {
13 Map new_map = new Map<Symbol, dynamic>(); 13 Map new_map = new Map<Symbol, dynamic>();
14 old_map.forEach((key, value) { 14 old_map.forEach((key, value) {
15 if (filter(key, value)) { 15 if (filter(key, value)) {
16 new_map[key] = value; 16 new_map[key] = value;
17 } 17 }
18 }); 18 });
19 return new_map; 19 return new_map;
20 } 20 }
21 21
22 Map _makeMemberMap(List mirrors) {
23 Map<Symbol, dynamic> result = new Map();
ahe 2013/07/24 10:11:54 I think it is more important to have the type on t
24 mirrors.forEach((mirror) => result[mirror.simpleName] = mirror);
25 return result;
26 }
27
22 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); 28 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
23 29
24 Symbol _s(String name) { 30 Symbol _s(String name) {
25 if (name == null) return null; 31 if (name == null) return null;
26 return new _symbol_dev.Symbol.unvalidated(name); 32 return new _symbol_dev.Symbol.unvalidated(name);
27 } 33 }
28 34
29 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { 35 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) {
30 if (owner == null) return simpleName; 36 if (owner == null) return simpleName;
31 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}'); 37 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}');
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 393
388 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 394 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
389 implements ClassMirror { 395 implements ClassMirror {
390 _LocalClassMirrorImpl(reflectee, 396 _LocalClassMirrorImpl(reflectee,
391 String simpleName, 397 String simpleName,
392 this.isClass, 398 this.isClass,
393 this._owner, 399 this._owner,
394 this._superclass, 400 this._superclass,
395 this._superinterfaces, 401 this._superinterfaces,
396 this._defaultFactory, 402 this._defaultFactory,
397 Map<String, Mirror> members,
398 Map<String, Mirror> constructors, 403 Map<String, Mirror> constructors,
399 Map<String, Mirror> typeVariables) 404 Map<String, Mirror> typeVariables)
400 : this._simpleName = _s(simpleName), 405 : this._simpleName = _s(simpleName),
401 this.members = _convertStringToSymbolMap(members),
402 this.constructors = _convertStringToSymbolMap(constructors), 406 this.constructors = _convertStringToSymbolMap(constructors),
403 this.typeVariables = _convertStringToSymbolMap(typeVariables), 407 this.typeVariables = _convertStringToSymbolMap(typeVariables),
404 super(reflectee); 408 super(reflectee);
405 409
406 Symbol _simpleName; 410 Symbol _simpleName;
407 Symbol get simpleName { 411 Symbol get simpleName {
408 // dynamic, void and the function types have their names set eagerly in the 412 // dynamic, void and the function types have their names set eagerly in the
409 // constructor. 413 // constructor.
410 if(_simpleName == null) { 414 if(_simpleName == null) {
411 _simpleName = _s(_name(_reflectee)); 415 _simpleName = _s(_name(_reflectee));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 469 }
466 470
467 var _defaultFactory; 471 var _defaultFactory;
468 ClassMirror get defaultFactory { 472 ClassMirror get defaultFactory {
469 if (_defaultFactory != null && _defaultFactory is! Mirror) { 473 if (_defaultFactory != null && _defaultFactory is! Mirror) {
470 _defaultFactory = _defaultFactory.resolve(mirrors); 474 _defaultFactory = _defaultFactory.resolve(mirrors);
471 } 475 }
472 return _defaultFactory; 476 return _defaultFactory;
473 } 477 }
474 478
475 final Map<Symbol, Mirror> members; 479 Map<Symbol, Mirror> _members;
480
481 Map<Symbol, Mirror> get members {
482 if (_members == null) {
483 _members = _makeMemberMap(_computeMembers(_reflectee));
484 }
485 return _members;
486 }
476 487
477 Map<Symbol, MethodMirror> _methods = null; 488 Map<Symbol, MethodMirror> _methods = null;
478 Map<Symbol, MethodMirror> _getters = null; 489 Map<Symbol, MethodMirror> _getters = null;
479 Map<Symbol, MethodMirror> _setters = null; 490 Map<Symbol, MethodMirror> _setters = null;
480 Map<Symbol, VariableMirror> _variables = null; 491 Map<Symbol, VariableMirror> _variables = null;
481 492
482 Map<Symbol, MethodMirror> get methods { 493 Map<Symbol, MethodMirror> get methods {
483 if (_methods == null) { 494 if (_methods == null) {
484 _methods = _filterMap( 495 _methods = _filterMap(
485 members, 496 members,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 // reflect() and then make them into a Dart list. 584 // reflect() and then make them into a Dart list.
574 return _metadata(_reflectee).map(reflect).toList(growable:false); 585 return _metadata(_reflectee).map(reflect).toList(growable:false);
575 } 586 }
576 587
577 static _name(reflectee) 588 static _name(reflectee)
578 native "ClassMirror_name"; 589 native "ClassMirror_name";
579 590
580 static _library(reflectee) 591 static _library(reflectee)
581 native "ClassMirror_library"; 592 native "ClassMirror_library";
582 593
594 _computeMembers(reflectee)
595 native "ClassMirror_members";
596
583 _invoke(reflectee, memberName, positionalArguments) 597 _invoke(reflectee, memberName, positionalArguments)
584 native 'ClassMirror_invoke'; 598 native 'ClassMirror_invoke';
585 599
586 _invokeGetter(reflectee, getterName) 600 _invokeGetter(reflectee, getterName)
587 native 'ClassMirror_invokeGetter'; 601 native 'ClassMirror_invokeGetter';
588 602
589 _invokeSetter(reflectee, setterName, value) 603 _invokeSetter(reflectee, setterName, value)
590 native 'ClassMirror_invokeSetter'; 604 native 'ClassMirror_invokeSetter';
591 605
592 static _invokeConstructor(reflectee, constructorName, positionalArguments) 606 static _invokeConstructor(reflectee, constructorName, positionalArguments)
(...skipping 19 matching lines...) Expand all
612 this._returnType, 626 this._returnType,
613 this.parameters) 627 this.parameters)
614 : super(reflectee, 628 : super(reflectee,
615 simpleName, 629 simpleName,
616 true, 630 true,
617 null, 631 null,
618 new _LazyTypeMirror('dart:core', 'Object'), 632 new _LazyTypeMirror('dart:core', 'Object'),
619 [ new _LazyTypeMirror('dart:core', 'Function') ], 633 [ new _LazyTypeMirror('dart:core', 'Function') ],
620 null, 634 null,
621 const {}, 635 const {},
622 const {},
623 const {}); 636 const {});
624 637
638 Map<Symbol, Mirror> get members => const {};
ahe 2013/07/24 10:11:54 Add type arguments.
639
625 var _returnType; 640 var _returnType;
626 TypeMirror get returnType { 641 TypeMirror get returnType {
627 if (_returnType is! Mirror) { 642 if (_returnType is! Mirror) {
628 _returnType = _returnType.resolve(mirrors); 643 _returnType = _returnType.resolve(mirrors);
629 } 644 }
630 return _returnType; 645 return _returnType;
631 } 646 }
632 647
633 final List<ParameterMirror> parameters; 648 final List<ParameterMirror> parameters;
634 649
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1193 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1179 static ClassMirror reflectClass(Type key) { 1194 static ClassMirror reflectClass(Type key) {
1180 var classMirror = _classMirrorCache[key]; 1195 var classMirror = _classMirrorCache[key];
1181 if (classMirror == null) { 1196 if (classMirror == null) {
1182 classMirror = makeLocalClassMirror(key); 1197 classMirror = makeLocalClassMirror(key);
1183 _classMirrorCache[key] = classMirror; 1198 _classMirrorCache[key] = classMirror;
1184 } 1199 }
1185 return classMirror; 1200 return classMirror;
1186 } 1201 }
1187 } 1202 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698