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

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') | runtime/include/dart_api.h » ('J')
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() {
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;
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 * TODO(turnidge): Gilad had this as a Map. Consider changing this.
Ivan Posva 2012/06/11 16:45:02 What would you map here?
turnidge 2012/06/12 20:51:46 I have no idea. Removing the TODO.
164 */
165 List<InterfaceMirror> superinterfaces();
166
167 /**
168 * Returns a mirror on the default factory class or null if there is
169 * none.
170 */
171 InterfaceMirror defaultFactory();
172
173 /**
174 * An immutable map from from names to mirrors for all members of
175 * this type, including inherited members.
176 *
177 * The members of an interface are its constructors, methods,
178 * fields, getters, and setters.
179 *
180 * TODO(turnidge): Currently empty.
181 */
182 Map<String, Mirror> members();
98 } 183 }
99 184
100 /** 185 /**
101 * A [LibraryMirror] reflects a Dart language library, providing 186 * A [LibraryMirror] reflects a Dart language library, providing
102 * access to the variables, functions, classes, and interfaces of the 187 * access to the variables, functions, classes, and interfaces of the
103 * library. 188 * library.
104 */ 189 */
105 interface LibraryMirror extends ObjectMirror { 190 interface LibraryMirror extends ObjectMirror {
106 /** 191 /**
107 * The name of the library, as provided in the [#library] declaration. 192 * The name of this library, as provided in the [#library] declaration.
108 */ 193 */
109 final String simpleName; 194 final String simpleName;
110 195
111 /** 196 /**
112 * The url of the library. 197 * The url of the library.
113 * 198 *
114 * TODO(turnidge): Document where this url comes from. Will this 199 * TODO(turnidge): Document where this url comes from. Will this
115 * value be sensible? 200 * value be sensible?
116 */ 201 */
117 final String url; 202 final String url;
203
204 /**
205 * An immutable map from from top-level names to mirrors for all
206 * members in this library.
207 *
208 * The members of a library are its top-level classes, interfaces,
209 * functions, variables, getters, and setters.
210 *
211 * TODO(turnidge): Currently only contains classes and interfaces.
212 */
213 Map<String, Mirror> members();
214 }
215
216 /**
217 * When an error occurs during the mirrored execution of code, a
218 * [MirroredError] is thrown.
219 *
220 * In general, there are three main classes of failure that can happen
221 * during mirrored execution of code in some isolate:
222 *
223 * - An exception is thrown but not caught. This is caught by the
224 * mirrors framework and a [MirroredUncaughtExceptionError] is
225 * created and thrown.
226 *
227 * - A compile-time error occurs, such as a syntax error. This is
228 * suppressed by the mirrors framework and a
229 * [MirroredCompilationError] is created and thrown.
230 *
231 * - A truly fatal error occurs, causing the isolate to be exited. If
232 * the reflector and reflectee share the same isolate, then they
233 * will both suffer. If the reflector and reflectee are in distinct
234 * isolates, then we hope to provide some information about the
235 * isolate death, but this is yet to be implemented.
236 *
237 * TODO(turnidge): Specify the behavior for remote fatal errors.
238 */
239 abstract class MirroredError implements Exception {
Ivan Posva 2012/06/11 16:45:02 I am not sure how the empty Exception interface he
turnidge 2012/06/12 20:51:46 I thought that it would be useful for people who w
240 }
241
242 /**
243 * When an uncaught exception occurs during the mirrored execution
244 * of code, a [MirroredUncaughtExceptionError] is thrown.
245 *
246 * This exception contains a mirror on the original exception object.
247 * It also contains an object which can be used to recover the
248 * stacktrace.
249 */
250 class MirroredUncaughtExceptionError extends MirroredError {
251 MirroredUncaughtExceptionError(this.exception_mirror,
252 this.exception_string,
253 this.stacktrace) {}
254
255 /** A mirror on the exception object. */
256 final InstanceMirror exception_mirror;
257
258 /** The result of toString() for the exception object. */
259 final String exception_string;
260
261 /** A stacktrace object for the uncaught exception. */
262 final Object stacktrace;
263
264 String toString() {
265 return
266 "Uncaught exception during mirrored execution: <${exception_string}>";
267 }
268 }
269
270 /**
271 * When a compile-time error occurs during the mirrored execution
272 * of code, a [MirroredCompilationError] is thrown.
273 *
274 * This exception includes the compile-time error message that would
275 * have been displayed to the user, if the function had not been
276 * invoked via mirror.
277 */
278 class MirroredCompilationError extends MirroredError {
279 MirroredCompilationError(this.message) {}
280
281 final String message;
282
283 String toString() {
284 return "Compile-time error during mirrored execution: <$message>";
285 }
118 } 286 }
119 287
120 /** 288 /**
121 * A [MirrorException] is used to indicate errors within the mirrors 289 * A [MirrorException] is used to indicate errors within the mirrors
122 * framework. 290 * framework.
123 */ 291 */
124 class MirrorException implements Exception { 292 class MirrorException implements Exception {
125 const MirrorException(String this._message); 293 const MirrorException(String this._message);
126 String toString() => "MirrorException: '$_message'"; 294 String toString() => "MirrorException: '$_message'";
127 final String _message; 295 final String _message;
128 } 296 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/include/dart_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698