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

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 'LocalMirrorImpl_metadata';
ahe 2013/06/11 08:48:10 I don't think you can wrap the native declaration
hausner 2013/06/11 16:17:13 This isn't legal dart code.
ahe 2013/06/11 16:21:22 Neither is this: List<InstanceMirror> _metadata(m
gbracha 2013/06/12 21:21:18 Done.
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
171 int get hashCode => _reference.hashCode;
ahe 2013/06/11 08:48:10 This is a bad hashCode. It should be the hashCode
gbracha 2013/06/12 21:21:18 This really should be part of a different CL deali
172
173 bool operator == (m) {
174 return (runtimeType == m.runtimeType) && (_reference == m._reference);
ahe 2013/06/11 08:48:10 I don't understand the need to check for runtimeTy
gbracha 2013/06/12 21:21:18 Indeed, it probably is in the equality CL. This wa
175 }
176
166 } 177 }
167 178
168 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl 179 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl
169 implements ObjectMirror { 180 implements ObjectMirror {
170 _LocalObjectMirrorImpl(ref) : super(ref) {} 181 _LocalObjectMirrorImpl(ref) : super(ref) {}
171 182
172 InstanceMirror invoke(Symbol memberName, 183 InstanceMirror invoke(Symbol memberName,
173 List positionalArguments, 184 List positionalArguments,
174 [Map<Symbol, dynamic> namedArguments]) { 185 [Map<Symbol, dynamic> namedArguments]) {
175 if (namedArguments != null) { 186 if (namedArguments != null) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 return new Future<InstanceMirror>.value( 606 return new Future<InstanceMirror>.value(
596 _invokeConstructor(this, 607 _invokeConstructor(this,
597 _n(constructorName), 608 _n(constructorName),
598 positionalArguments, 609 positionalArguments,
599 true)); 610 true));
600 } catch (exception) { 611 } catch (exception) {
601 return new Future<InstanceMirror>.error(exception); 612 return new Future<InstanceMirror>.error(exception);
602 } 613 }
603 } 614 }
604 615
616 List<InstanceMirror> get metadata {
617 return _metadata(this).map((o) => reflect(o));
ahe 2013/06/11 08:48:10 This should be: List<InstanceMirror> get metadata
gbracha 2013/06/12 21:21:18 Done. In all 5 places.
618 }
619
605 static _invokeConstructor(ref, constructorName, positionalArguments, async) 620 static _invokeConstructor(ref, constructorName, positionalArguments, async)
606 native 'LocalClassMirrorImpl_invokeConstructor'; 621 native 'LocalClassMirrorImpl_invokeConstructor';
607 } 622 }
608 623
609 class _LazyFunctionTypeMirror { 624 class _LazyFunctionTypeMirror {
610 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} 625 _LazyFunctionTypeMirror(this.returnType, this.parameters) {}
611 626
612 ClassMirror resolve(MirrorSystem mirrors) { 627 ClassMirror resolve(MirrorSystem mirrors) {
613 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), 628 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors),
614 parameters); 629 parameters);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 712 }
698 713
699 var _upperBound; 714 var _upperBound;
700 TypeMirror get upperBound { 715 TypeMirror get upperBound {
701 if (_upperBound is! Mirror) { 716 if (_upperBound is! Mirror) {
702 _upperBound = _upperBound.resolve(mirrors); 717 _upperBound = _upperBound.resolve(mirrors);
703 } 718 }
704 return _upperBound; 719 return _upperBound;
705 } 720 }
706 721
722 List<InstanceMirror> get metadata {
723 return _metadata(this).map((o) => reflect(o));
724 }
725
707 String toString() => "TypeVariableMirror on '$simpleName'"; 726 String toString() => "TypeVariableMirror on '$simpleName'";
708 } 727 }
709 728
710 729
711 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl 730 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl
712 implements TypedefMirror { 731 implements TypedefMirror {
713 _LocalTypedefMirrorImpl(String simpleName, 732 _LocalTypedefMirrorImpl(String simpleName,
714 this._owner, 733 this._owner,
715 this._referent) 734 this._referent)
716 : this.simpleName = _s(simpleName); 735 : this.simpleName = _s(simpleName);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 855 }
837 856
838 Map<Symbol, VariableMirror> get variables { 857 Map<Symbol, VariableMirror> get variables {
839 if (_variables == null) { 858 if (_variables == null) {
840 _variables = _filterMap(members, 859 _variables = _filterMap(members,
841 (key, value) => (value is VariableMirror)); 860 (key, value) => (value is VariableMirror));
842 } 861 }
843 return _variables; 862 return _variables;
844 } 863 }
845 864
865 List<InstanceMirror> get metadata {
866 return _metadata(this).map((o) => reflect(o));
867 }
868
846 String toString() => "LibraryMirror on '$simpleName'"; 869 String toString() => "LibraryMirror on '$simpleName'";
847 } 870 }
848 871
849 class _LocalMethodMirrorImpl extends _LocalMirrorImpl 872 class _LocalMethodMirrorImpl extends _LocalMirrorImpl
850 implements MethodMirror { 873 implements MethodMirror {
851 _LocalMethodMirrorImpl(String simpleName, 874 _LocalMethodMirrorImpl(String simpleName,
852 this._owner, 875 this._owner,
853 this.parameters, 876 this.parameters,
854 this._returnType, 877 this._returnType,
855 this.isStatic, 878 this.isStatic,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 } 959 }
937 } 960 }
938 return _constructorName; 961 return _constructorName;
939 } 962 }
940 963
941 final bool isConstConstructor; 964 final bool isConstConstructor;
942 final bool isGenerativeConstructor; 965 final bool isGenerativeConstructor;
943 final bool isRedirectingConstructor; 966 final bool isRedirectingConstructor;
944 final bool isFactoryConstructor; 967 final bool isFactoryConstructor;
945 968
969 List<InstanceMirror> get metadata {
970 return _metadata(this).map((o) => reflect(o));
971 }
972
946 String toString() => "MethodMirror on '$simpleName'"; 973 String toString() => "MethodMirror on '$simpleName'";
947 } 974 }
948 975
949 class _LocalVariableMirrorImpl extends _LocalMirrorImpl 976 class _LocalVariableMirrorImpl extends _LocalMirrorImpl
950 implements VariableMirror { 977 implements VariableMirror {
951 _LocalVariableMirrorImpl(String simpleName, 978 _LocalVariableMirrorImpl(String simpleName,
952 this._owner, 979 this._owner,
953 this._type, 980 this._type,
954 this.isStatic, 981 this.isStatic,
955 this.isFinal) 982 this.isFinal)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 TypeMirror get type { 1017 TypeMirror get type {
991 if (_type is! Mirror) { 1018 if (_type is! Mirror) {
992 _type = _type.resolve(mirrors); 1019 _type = _type.resolve(mirrors);
993 } 1020 }
994 return _type; 1021 return _type;
995 } 1022 }
996 1023
997 final bool isStatic; 1024 final bool isStatic;
998 final bool isFinal; 1025 final bool isFinal;
999 1026
1027 List<InstanceMirror> get metadata {
1028 return _metadata(this).map((o) => reflect(o));
1029 }
1030
1000 String toString() => "VariableMirror on '$simpleName'"; 1031 String toString() => "VariableMirror on '$simpleName'";
1001 } 1032 }
1002 1033
1003 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl 1034 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
1004 implements ParameterMirror { 1035 implements ParameterMirror {
1005 _LocalParameterMirrorImpl(type, this.isOptional) 1036 _LocalParameterMirrorImpl(type, this.isOptional)
1006 : super('<TODO:unnamed>', null, type, false, false) {} 1037 : super('<TODO:unnamed>', null, type, false, false) {}
1007 1038
1008 final bool isOptional; 1039 final bool isOptional;
1009 1040
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1092 }
1062 1093
1063 // Creates a new local ClassMirror. 1094 // Creates a new local ClassMirror.
1064 static ClassMirror makeLocalClassMirror(Type key) 1095 static ClassMirror makeLocalClassMirror(Type key)
1065 native "Mirrors_makeLocalClassMirror"; 1096 native "Mirrors_makeLocalClassMirror";
1066 1097
1067 static ClassMirror reflectClass(Type key) { 1098 static ClassMirror reflectClass(Type key) {
1068 return makeLocalClassMirror(key); 1099 return makeLocalClassMirror(key);
1069 } 1100 }
1070 } 1101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698