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

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

Issue 20851002: Create the local MirrorSystem with internal code. (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/symbols.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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 buf.write(', '); 61 buf.write(', ');
62 } 62 }
63 } 63 }
64 if (found_optional_param) { 64 if (found_optional_param) {
65 buf.write(']'); 65 buf.write(']');
66 } 66 }
67 buf.write(')'); 67 buf.write(')');
68 return buf.toString(); 68 return buf.toString();
69 } 69 }
70 70
71 Map<Uri, LibraryMirror> _createLibrariesMap(Map<String, LibraryMirror> map) { 71 Map<Uri, LibraryMirror> _createLibrariesMap(List<LibraryMirror> list) {
72 var result = new Map<Uri, LibraryMirror>(); 72 var map = new Map<Uri, LibraryMirror>();
73 map.forEach((String url, LibraryMirror mirror) { 73 list.forEach((LibraryMirror mirror) => map[mirror.uri] = mirror);
74 result[Uri.parse(url)] = mirror; 74 return map;
75 });
76 return result;
77 } 75 }
78 76
79 List _metadata(reflectee) 77 List _metadata(reflectee)
80 native 'DeclarationMirror_metadata'; 78 native 'DeclarationMirror_metadata';
81 79
82 // This will verify the argument types, unwrap them, and ensure we have a fixed 80 // This will verify the argument types, unwrap them, and ensure we have a fixed
83 // array. 81 // array.
84 List _unwarpAsyncPositionals(wrappedArgs){ 82 List _unwarpAsyncPositionals(wrappedArgs){
85 List unwrappedArgs = new List(wrappedArgs.length); 83 List unwrappedArgs = new List(wrappedArgs.length);
86 for(int i = 0; i < wrappedArgs.length; i++){ 84 for(int i = 0; i < wrappedArgs.length; i++){
87 var wrappedArg = wrappedArgs[i]; 85 var wrappedArg = wrappedArgs[i];
88 if(_isSimpleValue(wrappedArg)) { 86 if(_isSimpleValue(wrappedArg)) {
89 unwrappedArgs[i] = wrappedArg; 87 unwrappedArgs[i] = wrappedArg;
90 } else if(wrappedArg is InstanceMirror) { 88 } else if(wrappedArg is InstanceMirror) {
91 unwrappedArgs[i] = wrappedArg._reflectee; 89 unwrappedArgs[i] = wrappedArg._reflectee;
92 } else { 90 } else {
93 throw "positional argument $i ($arg) was not a simple value or InstanceMir ror"; 91 throw "positional argument $i ($arg) was not a simple value or InstanceMir ror";
94 } 92 }
95 } 93 }
96 return unwrappedArgs; 94 return unwrappedArgs;
97 } 95 }
98 96
99 class _LocalMirrorSystemImpl extends MirrorSystem { 97 class _LocalMirrorSystemImpl extends MirrorSystem {
100 // Change parameter back to "this.libraries" when native code is changed. 98 // Change parameter back to "this.libraries" when native code is changed.
101 _LocalMirrorSystemImpl(Map<String, LibraryMirror> libraries, this.isolate) 99 _LocalMirrorSystemImpl(List<LibraryMirror> libraries, this.isolate)
102 : this.libraries = _createLibrariesMap(libraries), 100 : this.libraries = _createLibrariesMap(libraries),
103 _functionTypes = new Map<String, FunctionTypeMirror>(); 101 _functionTypes = new Map<String, FunctionTypeMirror>();
104 102
105 final Map<Uri, LibraryMirror> libraries; 103 final Map<Uri, LibraryMirror> libraries;
106 final IsolateMirror isolate; 104 final IsolateMirror isolate;
107 105
108 TypeMirror _dynamicType = null; 106 TypeMirror _dynamicType = null;
109 107
110 TypeMirror get dynamicType { 108 TypeMirror get dynamicType {
111 if (_dynamicType == null) { 109 if (_dynamicType == null) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 throw new UnimplementedError('Mirror.hashCode is not implemented'); 145 throw new UnimplementedError('Mirror.hashCode is not implemented');
148 } 146 }
149 147
150 // Local mirrors always return the same MirrorSystem. This field 148 // Local mirrors always return the same MirrorSystem. This field
151 // is more interesting once we implement remote mirrors. 149 // is more interesting once we implement remote mirrors.
152 MirrorSystem get mirrors => _Mirrors.currentMirrorSystem(); 150 MirrorSystem get mirrors => _Mirrors.currentMirrorSystem();
153 } 151 }
154 152
155 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl 153 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl
156 implements IsolateMirror { 154 implements IsolateMirror {
157 _LocalIsolateMirrorImpl(this.debugName, this._rootLibrary) {} 155 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary) {}
158 156
159 final String debugName; 157 final String debugName;
160 final bool isCurrent = true; 158 final bool isCurrent = true;
161 159 final LibraryMirror rootLibrary;
162 var _rootLibrary;
163 LibraryMirror get rootLibrary {
164 if (_rootLibrary is _LazyLibraryMirror) {
165 _rootLibrary = _rootLibrary.resolve(mirrors);
166 }
167 return _rootLibrary;
168 }
169 160
170 String toString() => "IsolateMirror on '$debugName'"; 161 String toString() => "IsolateMirror on '$debugName'";
171 } 162 }
172 163
173 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl 164 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl
174 implements ObjectMirror { 165 implements ObjectMirror {
175 _LocalObjectMirrorImpl(this._reflectee); 166 _LocalObjectMirrorImpl(this._reflectee);
176 167
177 final _reflectee; // May be a MirrorReference or an ordinary object. 168 final _reflectee; // May be a MirrorReference or an ordinary object.
178 169
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1224 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1234 static ClassMirror reflectClass(Type key) { 1225 static ClassMirror reflectClass(Type key) {
1235 var classMirror = _classMirrorCache[key]; 1226 var classMirror = _classMirrorCache[key];
1236 if (classMirror == null) { 1227 if (classMirror == null) {
1237 classMirror = makeLocalClassMirror(key); 1228 classMirror = makeLocalClassMirror(key);
1238 _classMirrorCache[key] = classMirror; 1229 _classMirrorCache[key] = classMirror;
1239 } 1230 }
1240 return classMirror; 1231 return classMirror;
1241 } 1232 }
1242 } 1233 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698