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

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
« 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 }
(...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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 return new Future<InstanceMirror>.value( 599 return new Future<InstanceMirror>.value(
596 _invokeConstructor(this, 600 _invokeConstructor(this,
597 _n(constructorName), 601 _n(constructorName),
598 positionalArguments, 602 positionalArguments,
599 true)); 603 true));
600 } catch (exception) { 604 } catch (exception) {
601 return new Future<InstanceMirror>.error(exception); 605 return new Future<InstanceMirror>.error(exception);
602 } 606 }
603 } 607 }
604 608
609 // get the metadata objects, convert them into InstanceMirrors using
610 // reflect() and then make them into a Dart list
611 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList();
612
605 static _invokeConstructor(ref, constructorName, positionalArguments, async) 613 static _invokeConstructor(ref, constructorName, positionalArguments, async)
606 native 'LocalClassMirrorImpl_invokeConstructor'; 614 native 'LocalClassMirrorImpl_invokeConstructor';
607 } 615 }
608 616
609 class _LazyFunctionTypeMirror { 617 class _LazyFunctionTypeMirror {
610 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} 618 _LazyFunctionTypeMirror(this.returnType, this.parameters) {}
611 619
612 ClassMirror resolve(MirrorSystem mirrors) { 620 ClassMirror resolve(MirrorSystem mirrors) {
613 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), 621 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors),
614 parameters); 622 parameters);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 705 }
698 706
699 var _upperBound; 707 var _upperBound;
700 TypeMirror get upperBound { 708 TypeMirror get upperBound {
701 if (_upperBound is! Mirror) { 709 if (_upperBound is! Mirror) {
702 _upperBound = _upperBound.resolve(mirrors); 710 _upperBound = _upperBound.resolve(mirrors);
703 } 711 }
704 return _upperBound; 712 return _upperBound;
705 } 713 }
706 714
715 // get the metadata objects, convert them into InstanceMirrors using
716 // reflect() and then make them into a Dart list
717 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList();
718
707 String toString() => "TypeVariableMirror on '$simpleName'"; 719 String toString() => "TypeVariableMirror on '$simpleName'";
708 } 720 }
709 721
710 722
711 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl 723 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl
712 implements TypedefMirror { 724 implements TypedefMirror {
713 _LocalTypedefMirrorImpl(String simpleName, 725 _LocalTypedefMirrorImpl(String simpleName,
714 this._owner, 726 this._owner,
715 this._referent) 727 this._referent)
716 : this.simpleName = _s(simpleName); 728 : this.simpleName = _s(simpleName);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 848 }
837 849
838 Map<Symbol, VariableMirror> get variables { 850 Map<Symbol, VariableMirror> get variables {
839 if (_variables == null) { 851 if (_variables == null) {
840 _variables = _filterMap(members, 852 _variables = _filterMap(members,
841 (key, value) => (value is VariableMirror)); 853 (key, value) => (value is VariableMirror));
842 } 854 }
843 return _variables; 855 return _variables;
844 } 856 }
845 857
858 // get the metadata objects, convert them into InstanceMirrors using
859 // reflect() and then make them into a Dart list
860 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList();
861
846 String toString() => "LibraryMirror on '$simpleName'"; 862 String toString() => "LibraryMirror on '$simpleName'";
847 } 863 }
848 864
849 class _LocalMethodMirrorImpl extends _LocalMirrorImpl 865 class _LocalMethodMirrorImpl extends _LocalMirrorImpl
850 implements MethodMirror { 866 implements MethodMirror {
851 _LocalMethodMirrorImpl(String simpleName, 867 _LocalMethodMirrorImpl(String simpleName,
852 this._owner, 868 this._owner,
853 this.parameters, 869 this.parameters,
854 this._returnType, 870 this._returnType,
855 this.isStatic, 871 this.isStatic,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 } 952 }
937 } 953 }
938 return _constructorName; 954 return _constructorName;
939 } 955 }
940 956
941 final bool isConstConstructor; 957 final bool isConstConstructor;
942 final bool isGenerativeConstructor; 958 final bool isGenerativeConstructor;
943 final bool isRedirectingConstructor; 959 final bool isRedirectingConstructor;
944 final bool isFactoryConstructor; 960 final bool isFactoryConstructor;
945 961
962 List<InstanceMirror> get metadata {
963 owner; // ensure owner is computed
964 // get the metadata objects, convert them into InstanceMirrors using
965 // reflect() and then make them into a Dart list
966 return _metadata(this).map(reflect).toList();
967 }
968
946 String toString() => "MethodMirror on '$simpleName'"; 969 String toString() => "MethodMirror on '$simpleName'";
947 } 970 }
948 971
949 class _LocalVariableMirrorImpl extends _LocalMirrorImpl 972 class _LocalVariableMirrorImpl extends _LocalMirrorImpl
950 implements VariableMirror { 973 implements VariableMirror {
951 _LocalVariableMirrorImpl(String simpleName, 974 _LocalVariableMirrorImpl(String simpleName,
952 this._owner, 975 this._owner,
953 this._type, 976 this._type,
954 this.isStatic, 977 this.isStatic,
955 this.isFinal) 978 this.isFinal)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 TypeMirror get type { 1013 TypeMirror get type {
991 if (_type is! Mirror) { 1014 if (_type is! Mirror) {
992 _type = _type.resolve(mirrors); 1015 _type = _type.resolve(mirrors);
993 } 1016 }
994 return _type; 1017 return _type;
995 } 1018 }
996 1019
997 final bool isStatic; 1020 final bool isStatic;
998 final bool isFinal; 1021 final bool isFinal;
999 1022
1023 List<InstanceMirror> get metadata {
1024 owner; // ensure owner is computed
1025 // get the metadata objects, convert them into InstanceMirrors using
1026 // reflect() and then make them into a Dart list
1027 return _metadata(this).map(reflect).toList();
1028 }
1029
1000 String toString() => "VariableMirror on '$simpleName'"; 1030 String toString() => "VariableMirror on '$simpleName'";
1001 } 1031 }
1002 1032
1003 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl 1033 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
1004 implements ParameterMirror { 1034 implements ParameterMirror {
1005 _LocalParameterMirrorImpl(type, this.isOptional) 1035 _LocalParameterMirrorImpl(type, this.isOptional)
1006 : super('<TODO:unnamed>', null, type, false, false) {} 1036 : super('<TODO:unnamed>', null, type, false, false) {}
1007 1037
1008 final bool isOptional; 1038 final bool isOptional;
1009 1039
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1091 }
1062 1092
1063 // Creates a new local ClassMirror. 1093 // Creates a new local ClassMirror.
1064 static ClassMirror makeLocalClassMirror(Type key) 1094 static ClassMirror makeLocalClassMirror(Type key)
1065 native "Mirrors_makeLocalClassMirror"; 1095 native "Mirrors_makeLocalClassMirror";
1066 1096
1067 static ClassMirror reflectClass(Type key) { 1097 static ClassMirror reflectClass(Type key) {
1068 return makeLocalClassMirror(key); 1098 return makeLocalClassMirror(key);
1069 } 1099 }
1070 } 1100 }
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