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

Side by Side Diff: lib/mirrors/mirrors.dart

Issue 10538043: Second local mirrors CL. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « no previous file | runtime/include/dart_api.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 // #library("mirrors"); 5 // #library("mirrors");
6 6
7 // The dart:mirrors library provides reflective access for Dart program. 7 // The dart:mirrors library provides reflective access for Dart program.
8 // 8 //
9 // For the purposes of the mirrors library, we adopt a naming
10 // convention with respect to getters and setters. Specifically, for
11 // some variable or field...
12 //
13 // var myField;
14 //
15 // ...the getter is named 'myField' and the setter is named
16 // 'myField='. This allows us to assign unique names to getters and
17 // setters for the purposes of member lookup.
18 // TODO(turnidge): Implement getter/setter lookup.
19 //
9 // TODO(turnidge): Finish implementing this api. 20 // TODO(turnidge): Finish implementing this api.
10 21
11 /** 22 /**
23 * Returns an [IsolateMirror] for the current isolate.
24 */
25 IsolateMirror currentIsolateMirror() {
ahe 2012/06/15 13:45:46 Long term, I think it would be great if we can sep
26 return _Mirrors.currentIsolateMirror();
27 }
28
29 /**
30 * Returns an [InstanceMirror] for some Dart language object.
31 */
32 InstanceMirror mirrorOf(Object reflectee) {
33 return _Mirrors.mirrorOf(reflectee);
34 }
35
36 /**
12 * Creates an [IsolateMirror] on the isolate which is listening on 37 * Creates an [IsolateMirror] on the isolate which is listening on
13 * the [SendPort]. 38 * the [SendPort].
14 */ 39 */
15 Future<IsolateMirror> isolateMirrorOf(SendPort port) { 40 Future<IsolateMirror> isolateMirrorOf(SendPort port) {
16 return _Mirrors.isolateMirrorOf(port); 41 return _Mirrors.isolateMirrorOf(port);
17 } 42 }
18 43
19 /** 44 /**
20 * A [Mirror] reflects some Dart language entity. 45 * A [Mirror] reflects some Dart language entity.
21 * 46 *
(...skipping 17 matching lines...) Expand all
39 64
40 /** 65 /**
41 * A mirror on the root library of the reflectee. 66 * A mirror on the root library of the reflectee.
42 */ 67 */
43 final LibraryMirror rootLibrary; 68 final LibraryMirror rootLibrary;
44 69
45 /** 70 /**
46 * An immutable map from from library names to mirrors for all 71 * An immutable map from from library names to mirrors for all
47 * libraries loaded in the reflectee. 72 * libraries loaded in the reflectee.
48 */ 73 */
49 final Map<String, LibraryMirror> libraries; 74 Map<String, LibraryMirror> libraries();
50 } 75 }
51 76
52 77
53 /** 78 /**
54 * An [ObjectMirror] is a common superinterface of [InstanceMirror], 79 * An [ObjectMirror] is a common superinterface of [InstanceMirror],
55 * [InterfaceMirror], and [LibraryMirror] that represents their shared 80 * [InterfaceMirror], and [LibraryMirror] that represents their shared
56 * functionality. 81 * functionality.
57 * 82 *
58 * For the purposes of the mirrors api, these types are all 83 * For the purposes of the mirrors library, these types are all
59 * object-like, in that they support method invocation and field 84 * object-like, in that they support method invocation and field
60 * access. Real Dart objects are represented by the [InstanceMirror] 85 * access. Real Dart objects are represented by the [InstanceMirror]
61 * type. 86 * type.
62 * 87 *
63 * See [InstanceMirror], [InterfaceMirror], and [LibraryMirror]. 88 * See [InstanceMirror], [InterfaceMirror], and [LibraryMirror].
64 */ 89 */
65 interface ObjectMirror extends Mirror { 90 interface ObjectMirror extends Mirror {
66 /** 91 /**
67 * Invokes the named function and returns a mirror on the result. 92 * Invokes the named function and returns a mirror on the result.
68 * 93 *
69 * TODO(turnidge): Properly document. 94 * TODO(turnidge): Properly document.
70 * 95 *
71 * TODO(turnidge): what to do if invoke causes the death of the reflectee? 96 * TODO(turnidge): what to do if invoke causes the death of the reflectee?
72 */ 97 */
73 Future<InstanceMirror> invoke(String memberName, 98 Future<InstanceMirror> invoke(String memberName,
74 List<Object> positionalArguments, 99 List<Object> positionalArguments,
75 [Map<String,Object> namedArguments]); 100 [Map<String,Object> namedArguments]);
76 } 101 }
77 102
78 /** 103 /**
79 * An [InstanceMirror] reflects an instance of a Dart language object. 104 * An [InstanceMirror] reflects an instance of a Dart language object.
80 */ 105 */
81 interface InstanceMirror extends ObjectMirror { 106 interface InstanceMirror extends ObjectMirror {
82 /** 107 /**
83 * If the [InstanceMirror] refers to a simple type, we provide 108 * Returns a mirror on the class of the reflectee.
84 * access to the actual value here. Simple types are... 109 */
110 InterfaceMirror getClass();
111
112 /**
113 * Does [simpleValue] contain the value of the reflectee?
114 */
115 bool hasSimpleValue;
116
117 /**
118 * If the [InstanceMirror] refers to a simple value, we provide
119 * access to the actual value here.
85 * 120 *
86 * TODO(turnidge): Properly document. 121 * A value is simple if:
122 * - it is null
123 * - it is of type [num]
124 * - it is of type [bool]
125 * - it is of type [String]
87 * 126 *
88 * TODO(turnidge): How best to represent a null simple value versus 127 * If you access [simpleValue] when [hasSimpleValue] is false an
89 * the absence of a simple value? 128 * exception is thrown.
90 */ 129 */
91 final simpleValue; 130 final simpleValue;
131
92 } 132 }
93 133
94 /** 134 /**
95 * An [InterfaceMirror] reflects a Dart language class or interface. 135 * An [InterfaceMirror] reflects a Dart language class or interface.
96 */ 136 */
97 interface InterfaceMirror extends ObjectMirror { 137 interface InterfaceMirror extends ObjectMirror {
138 /**
139 * The name of this interface.
140 */
141 final String simpleName;
ahe 2012/06/15 13:45:46 Shouldn't this just be "name"?
142
143 /**
144 * The library in which this interface is declared.
145 */
146 final LibraryMirror library;
147
148 /**
149 * Does this mirror represent a class?
150 */
151 final bool isClass;
152
153 /**
154 * Returns a mirror on the superclass on the reflectee.
155 *
156 * For interfaces, the superclass is Object.
157 */
158 InterfaceMirror superclass();
159
160 /**
161 * Returns a list of mirrors on the superinterfaces for the reflectee.
162 */
163 List<InterfaceMirror> superinterfaces();
164
165 /**
166 * Returns a mirror on the default factory class or null if there is
167 * none.
168 */
169 InterfaceMirror defaultFactory();
ahe 2012/06/15 13:45:46 Rename to "factoryClass"?
170
171 /**
172 * An immutable map from from names to mirrors for all members of
ahe 2012/06/15 13:45:46 Why immutable? Do you mean read-only?
173 * this type, including inherited members.
174 *
175 * The members of an interface are its constructors, methods,
176 * fields, getters, and setters.
177 *
178 * TODO(turnidge): Currently empty.
ahe 2012/06/15 13:45:46 General comment. I think it would be best to move
179 */
180 Map<String, Mirror> members();
ahe 2012/06/15 13:45:46 For example, add the TODO here using //.
98 } 181 }
99 182
100 /** 183 /**
101 * A [LibraryMirror] reflects a Dart language library, providing 184 * A [LibraryMirror] reflects a Dart language library, providing
102 * access to the variables, functions, classes, and interfaces of the 185 * access to the variables, functions, classes, and interfaces of the
103 * library. 186 * library.
104 */ 187 */
105 interface LibraryMirror extends ObjectMirror { 188 interface LibraryMirror extends ObjectMirror {
106 /** 189 /**
107 * The name of the library, as provided in the [#library] declaration. 190 * The name of this library, as provided in the [#library] declaration.
108 */ 191 */
109 final String simpleName; 192 final String simpleName;
110 193
111 /** 194 /**
112 * The url of the library. 195 * The url of the library.
113 * 196 *
114 * TODO(turnidge): Document where this url comes from. Will this 197 * TODO(turnidge): Document where this url comes from. Will this
115 * value be sensible? 198 * value be sensible?
116 */ 199 */
117 final String url; 200 final String url;
201
202 /**
203 * An immutable map from from top-level names to mirrors for all
ahe 2012/06/15 13:45:46 Why immutable?
204 * members in this library.
205 *
206 * The members of a library are its top-level classes, interfaces,
207 * functions, variables, getters, and setters.
208 *
209 * TODO(turnidge): Currently only contains classes and interfaces.
210 */
211 Map<String, Mirror> members();
212 }
213
214 /**
215 * When an error occurs during the mirrored execution of code, a
216 * [MirroredError] is thrown.
217 *
218 * In general, there are three main classes of failure that can happen
219 * during mirrored execution of code in some isolate:
220 *
221 * - An exception is thrown but not caught. This is caught by the
222 * mirrors framework and a [MirroredUncaughtExceptionError] is
223 * created and thrown.
224 *
225 * - A compile-time error occurs, such as a syntax error. This is
226 * suppressed by the mirrors framework and a
227 * [MirroredCompilationError] is created and thrown.
228 *
229 * - A truly fatal error occurs, causing the isolate to be exited. If
230 * the reflector and reflectee share the same isolate, then they
231 * will both suffer. If the reflector and reflectee are in distinct
232 * isolates, then we hope to provide some information about the
233 * isolate death, but this is yet to be implemented.
234 *
235 * TODO(turnidge): Specify the behavior for remote fatal errors.
236 */
237 abstract class MirroredError implements Exception {
238 }
239
240 /**
241 * When an uncaught exception occurs during the mirrored execution
242 * of code, a [MirroredUncaughtExceptionError] is thrown.
243 *
244 * This exception contains a mirror on the original exception object.
245 * It also contains an object which can be used to recover the
246 * stacktrace.
247 */
248 class MirroredUncaughtExceptionError extends MirroredError {
249 MirroredUncaughtExceptionError(this.exception_mirror,
250 this.exception_string,
251 this.stacktrace) {}
252
253 /** A mirror on the exception object. */
254 final InstanceMirror exception_mirror;
255
256 /** The result of toString() for the exception object. */
257 final String exception_string;
258
259 /** A stacktrace object for the uncaught exception. */
260 final Object stacktrace;
261
262 String toString() {
263 return
264 "Uncaught exception during mirrored execution: <${exception_string}>";
ahe 2012/06/15 13:45:46 I think you can remove the <...> around the origin
265 }
266 }
267
268 /**
269 * When a compile-time error occurs during the mirrored execution
270 * of code, a [MirroredCompilationError] is thrown.
271 *
272 * This exception includes the compile-time error message that would
273 * have been displayed to the user, if the function had not been
274 * invoked via mirror.
275 */
276 class MirroredCompilationError extends MirroredError {
277 MirroredCompilationError(this.message) {}
278
279 final String message;
280
281 String toString() {
282 return "Compile-time error during mirrored execution: <$message>";
ahe 2012/06/15 13:45:46 Ditto for <...>
283 }
118 } 284 }
119 285
120 /** 286 /**
121 * A [MirrorException] is used to indicate errors within the mirrors 287 * A [MirrorException] is used to indicate errors within the mirrors
122 * framework. 288 * framework.
123 */ 289 */
124 class MirrorException implements Exception { 290 class MirrorException implements Exception {
125 const MirrorException(String this._message); 291 const MirrorException(String this._message);
126 String toString() => "MirrorException: '$_message'"; 292 String toString() => "MirrorException: '$_message'";
127 final String _message; 293 final String _message;
128 } 294 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698