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

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

Issue 16757007: Changes to mirrors in support of metadata access at runtime. Assumes VM changes in flight.… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
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 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 Map<Uri, LibraryMirror> _createLibrariesMap(Map<String, LibraryMirror> map) { 65 Map<Uri, LibraryMirror> _createLibrariesMap(Map<String, LibraryMirror> map) {
66 var result = new Map<Uri, LibraryMirror>(); 66 var result = new Map<Uri, LibraryMirror>();
67 map.forEach((String url, LibraryMirror mirror) { 67 map.forEach((String url, LibraryMirror mirror) {
68 result[Uri.parse(url)] = mirror; 68 result[Uri.parse(url)] = mirror;
69 }); 69 });
70 return result; 70 return result;
71 } 71 }
72 72
73 List<InstanceMirror> _metadata(mirror)
74 native 'Mirrors_metadata';
75
76
73 class _LocalMirrorSystemImpl extends MirrorSystem { 77 class _LocalMirrorSystemImpl extends MirrorSystem {
74 // Change parameter back to "this.libraries" when native code is changed. 78 // Change parameter back to "this.libraries" when native code is changed.
75 _LocalMirrorSystemImpl(Map<String, LibraryMirror> libraries, this.isolate) 79 _LocalMirrorSystemImpl(Map<String, LibraryMirror> libraries, this.isolate)
76 : this.libraries = _createLibrariesMap(libraries), 80 : this.libraries = _createLibrariesMap(libraries),
77 _functionTypes = new Map<String, FunctionTypeMirror>(); 81 _functionTypes = new Map<String, FunctionTypeMirror>();
78 82
79 final Map<Uri, LibraryMirror> libraries; 83 final Map<Uri, LibraryMirror> libraries;
80 final IsolateMirror isolate; 84 final IsolateMirror isolate;
81 85
82 TypeMirror _dynamicType = null; 86 TypeMirror _dynamicType = null;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 160 }
157 161
158 abstract class _LocalVMObjectMirrorImpl extends _LocalMirrorImpl { 162 abstract class _LocalVMObjectMirrorImpl extends _LocalMirrorImpl {
159 _LocalVMObjectMirrorImpl(this._reference) {} 163 _LocalVMObjectMirrorImpl(this._reference) {}
160 164
161 // For now, all VMObjects hold a VMReference. We could consider 165 // For now, all VMObjects hold a VMReference. We could consider
162 // storing the Object reference itself here if the object is a Dart 166 // storing the Object reference itself here if the object is a Dart
163 // language objects (except for objects of type VMReference, of 167 // language objects (except for objects of type VMReference, of
164 // course). 168 // course).
165 VMReference _reference; 169 VMReference _reference;
170
Ivan Posva 2013/06/14 15:16:48 Extra line?
gbracha 2013/06/14 20:42:46 Done.
166 } 171 }
167 172
168 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl 173 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl
169 implements ObjectMirror { 174 implements ObjectMirror {
170 _LocalObjectMirrorImpl(ref) : super(ref) {} 175 _LocalObjectMirrorImpl(ref) : super(ref) {}
171 176
172 InstanceMirror invoke(Symbol memberName, 177 InstanceMirror invoke(Symbol memberName,
173 List positionalArguments, 178 List positionalArguments,
174 [Map<Symbol, dynamic> namedArguments]) { 179 [Map<Symbol, dynamic> namedArguments]) {
175 if (namedArguments != null) { 180 if (namedArguments != null) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 return new Future<InstanceMirror>.value( 600 return new Future<InstanceMirror>.value(
596 _invokeConstructor(this, 601 _invokeConstructor(this,
597 _n(constructorName), 602 _n(constructorName),
598 positionalArguments, 603 positionalArguments,
599 true)); 604 true));
600 } catch (exception) { 605 } catch (exception) {
601 return new Future<InstanceMirror>.error(exception); 606 return new Future<InstanceMirror>.error(exception);
602 } 607 }
603 } 608 }
604 609
610 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList();
Ivan Posva 2013/06/14 15:16:48 You might want to explain what you are using refle
gbracha 2013/06/14 20:42:46 Done.
611
605 static _invokeConstructor(ref, constructorName, positionalArguments, async) 612 static _invokeConstructor(ref, constructorName, positionalArguments, async)
606 native 'LocalClassMirrorImpl_invokeConstructor'; 613 native 'LocalClassMirrorImpl_invokeConstructor';
607 } 614 }
608 615
609 class _LazyFunctionTypeMirror { 616 class _LazyFunctionTypeMirror {
610 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} 617 _LazyFunctionTypeMirror(this.returnType, this.parameters) {}
611 618
612 ClassMirror resolve(MirrorSystem mirrors) { 619 ClassMirror resolve(MirrorSystem mirrors) {
613 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), 620 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors),
614 parameters); 621 parameters);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 704 }
698 705
699 var _upperBound; 706 var _upperBound;
700 TypeMirror get upperBound { 707 TypeMirror get upperBound {
701 if (_upperBound is! Mirror) { 708 if (_upperBound is! Mirror) {
702 _upperBound = _upperBound.resolve(mirrors); 709 _upperBound = _upperBound.resolve(mirrors);
703 } 710 }
704 return _upperBound; 711 return _upperBound;
705 } 712 }
706 713
714 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList();
715
707 String toString() => "TypeVariableMirror on '$simpleName'"; 716 String toString() => "TypeVariableMirror on '$simpleName'";
708 } 717 }
709 718
710 719
711 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl 720 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl
712 implements TypedefMirror { 721 implements TypedefMirror {
713 _LocalTypedefMirrorImpl(String simpleName, 722 _LocalTypedefMirrorImpl(String simpleName,
714 this._owner, 723 this._owner,
715 this._referent) 724 this._referent)
716 : this.simpleName = _s(simpleName); 725 : this.simpleName = _s(simpleName);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 845 }
837 846
838 Map<Symbol, VariableMirror> get variables { 847 Map<Symbol, VariableMirror> get variables {
839 if (_variables == null) { 848 if (_variables == null) {
840 _variables = _filterMap(members, 849 _variables = _filterMap(members,
841 (key, value) => (value is VariableMirror)); 850 (key, value) => (value is VariableMirror));
842 } 851 }
843 return _variables; 852 return _variables;
844 } 853 }
845 854
855
856 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList();
857
846 String toString() => "LibraryMirror on '$simpleName'"; 858 String toString() => "LibraryMirror on '$simpleName'";
847 } 859 }
848 860
849 class _LocalMethodMirrorImpl extends _LocalMirrorImpl 861 class _LocalMethodMirrorImpl extends _LocalMirrorImpl
850 implements MethodMirror { 862 implements MethodMirror {
851 _LocalMethodMirrorImpl(String simpleName, 863 _LocalMethodMirrorImpl(String simpleName,
852 this._owner, 864 this._owner,
853 this.parameters, 865 this.parameters,
854 this._returnType, 866 this._returnType,
855 this.isStatic, 867 this.isStatic,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 } 948 }
937 } 949 }
938 return _constructorName; 950 return _constructorName;
939 } 951 }
940 952
941 final bool isConstConstructor; 953 final bool isConstConstructor;
942 final bool isGenerativeConstructor; 954 final bool isGenerativeConstructor;
943 final bool isRedirectingConstructor; 955 final bool isRedirectingConstructor;
944 final bool isFactoryConstructor; 956 final bool isFactoryConstructor;
945 957
958 List<InstanceMirror> get metadata {
959 owner; // ensure owner is computed
960 return _metadata(this).map(reflect).toList();
961 }
962
946 String toString() => "MethodMirror on '$simpleName'"; 963 String toString() => "MethodMirror on '$simpleName'";
947 } 964 }
948 965
949 class _LocalVariableMirrorImpl extends _LocalMirrorImpl 966 class _LocalVariableMirrorImpl extends _LocalMirrorImpl
950 implements VariableMirror { 967 implements VariableMirror {
951 _LocalVariableMirrorImpl(String simpleName, 968 _LocalVariableMirrorImpl(String simpleName,
952 this._owner, 969 this._owner,
953 this._type, 970 this._type,
954 this.isStatic, 971 this.isStatic,
955 this.isFinal) 972 this.isFinal)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 TypeMirror get type { 1007 TypeMirror get type {
991 if (_type is! Mirror) { 1008 if (_type is! Mirror) {
992 _type = _type.resolve(mirrors); 1009 _type = _type.resolve(mirrors);
993 } 1010 }
994 return _type; 1011 return _type;
995 } 1012 }
996 1013
997 final bool isStatic; 1014 final bool isStatic;
998 final bool isFinal; 1015 final bool isFinal;
999 1016
1017 List<InstanceMirror> get metadata {
1018 owner; // ensure owner is computed
1019 return _metadata(this).map(reflect).toList();
1020 }
1021
1000 String toString() => "VariableMirror on '$simpleName'"; 1022 String toString() => "VariableMirror on '$simpleName'";
1001 } 1023 }
1002 1024
1003 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl 1025 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
1004 implements ParameterMirror { 1026 implements ParameterMirror {
1005 _LocalParameterMirrorImpl(type, this.isOptional) 1027 _LocalParameterMirrorImpl(type, this.isOptional)
1006 : super('<TODO:unnamed>', null, type, false, false) {} 1028 : super('<TODO:unnamed>', null, type, false, false) {}
1007 1029
1008 final bool isOptional; 1030 final bool isOptional;
1009 1031
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1083 }
1062 1084
1063 // Creates a new local ClassMirror. 1085 // Creates a new local ClassMirror.
1064 static ClassMirror makeLocalClassMirror(Type key) 1086 static ClassMirror makeLocalClassMirror(Type key)
1065 native "Mirrors_makeLocalClassMirror"; 1087 native "Mirrors_makeLocalClassMirror";
1066 1088
1067 static ClassMirror reflectClass(Type key) { 1089 static ClassMirror reflectClass(Type key) {
1068 return makeLocalClassMirror(key); 1090 return makeLocalClassMirror(key);
1069 } 1091 }
1070 } 1092 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698