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

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

Issue 11595007: Revert "Mirrors implemented via patches." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | « sdk/lib/mirrors/mirrors.dart ('k') | sdk/lib/mirrors/mirrors_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * A [MirrorSystem] is the main interface used to reflect on a set of
7 * associated libraries.
8 *
9 * At runtime each running isolate has a distinct [MirrorSystem].
10 *
11 * It is also possible to have a [MirrorSystem] which represents a set
12 * of libraries which are not running -- perhaps at compile-time. In
13 * this case, all available reflective functionality would be
14 * supported, but runtime functionality (such as invoking a function
15 * or inspecting the contents of a variable) would fail dynamically.
16 */
17 abstract class MirrorSystem {
18 /**
19 * An immutable map from from library names to mirrors for all
20 * libraries known to this mirror system.
21 */
22 Map<String, LibraryMirror> get libraries;
23
24 /**
25 * A mirror on the isolate associated with this [MirrorSystem].
26 * This may be null if this mirror system is not running.
27 */
28 IsolateMirror get isolate;
29
30 /**
31 * A mirror on the [:dynamic:] type.
32 */
33 TypeMirror get dynamicType;
34
35 /**
36 * A mirror on the [:void:] type.
37 */
38 TypeMirror get voidType;
39 }
40
41 /**
42 * Returns a [MirrorSystem] for the current isolate.
43 */
44 external MirrorSystem currentMirrorSystem();
45
46 /**
47 * Creates a [MirrorSystem] for the isolate which is listening on
48 * the [SendPort].
49 */
50 external Future<MirrorSystem> mirrorSystemOf(SendPort port);
51
52 /**
53 * Returns an [InstanceMirror] for some Dart language object.
54 *
55 * This only works if this mirror system is associated with the
56 * current running isolate.
57 */
58 external InstanceMirror reflect(Object reflectee);
59
60 /**
61 * A [Mirror] reflects some Dart language entity.
62 *
63 * Every [Mirror] originates from some [MirrorSystem].
64 */
65 abstract class Mirror {
66 /**
67 * The [MirrorSystem] that contains this mirror.
68 */
69 MirrorSystem get mirrors;
70 }
71
72 /**
73 * An [IsolateMirror] reflects an isolate.
74 */
75 abstract class IsolateMirror implements Mirror {
76 /**
77 * A unique name used to refer to an isolate in debugging messages.
78 */
79 String get debugName;
80
81 /**
82 * Does this mirror reflect the currently running isolate?
83 */
84 bool get isCurrent;
85
86 /**
87 * A mirror on the root library for this isolate.
88 */
89 LibraryMirror get rootLibrary;
90 }
91
92 /**
93 * A [DeclarationMirror] reflects some entity declared in a Dart program.
94 */
95 abstract class DeclarationMirror implements Mirror {
96 /**
97 * The simple name for this Dart language entity.
98 *
99 * The simple name is in most cases the the identifier name of the
100 * entity, such as 'method' for a method [:void method() {...}:] or
101 * 'mylibrary' for a [:#library('mylibrary');:] declaration.
102 */
103 String get simpleName;
104
105 /**
106 * The fully-qualified name for this Dart language entity.
107 *
108 * This name is qualified by the name of the owner. For instance,
109 * the qualified name of a method 'method' in class 'Class' in
110 * library 'library' is 'library.Class.method'.
111 *
112 * TODO(turnidge): Specify whether this name is unique. Currently
113 * this is a gray area due to lack of clarity over whether library
114 * names are unique.
115 */
116 String get qualifiedName;
117
118 /**
119 * A mirror on the owner of this function. This is the declaration
120 * immediately surrounding the reflectee.
121 *
122 * Note that for libraries, the owner will be [:null:].
123 */
124 DeclarationMirror get owner;
125
126 /**
127 * Is this declaration private?
128 *
129 * Note that for libraries, this will be [:false:].
130 */
131 bool get isPrivate;
132
133 /**
134 * Is this declaration top-level?
135 *
136 * This is defined to be equivalent to:
137 * [:mirror.owner != null && mirror.owner is LibraryMirror:]
138 */
139 bool get isTopLevel;
140
141 /**
142 * The source location of this Dart language entity.
143 */
144 SourceLocation get location;
145 }
146
147 /**
148 * An [ObjectMirror] is a common superinterface of [InstanceMirror],
149 * [ClassMirror], and [LibraryMirror] that represents their shared
150 * functionality.
151 *
152 * For the purposes of the mirrors library, these types are all
153 * object-like, in that they support method invocation and field
154 * access. Real Dart objects are represented by the [InstanceMirror]
155 * type.
156 *
157 * See [InstanceMirror], [ClassMirror], and [LibraryMirror].
158 */
159 abstract class ObjectMirror implements Mirror {
160 /**
161 * Invokes the named function and returns a mirror on the result.
162 *
163 * TODO(turnidge): Properly document.
164 * TODO(turnidge): Handle ambiguous names.
165 * TODO(turnidge): Handle optional & named arguments.
166 */
167 Future<InstanceMirror> invoke(String memberName,
168 List<Object> positionalArguments,
169 [Map<String,Object> namedArguments]);
170
171 /**
172 * Invokes a getter and returns a mirror on the result. The getter
173 * can be the implicit getter for a field or a user-defined getter
174 * method.
175 *
176 * TODO(turnidge): Handle ambiguous names.
177 */
178 Future<InstanceMirror> getField(String fieldName);
179
180 /**
181 * Invokes a setter and returns a mirror on the result. The setter
182 * may be either the implicit setter for a non-final field or a
183 * user-defined setter method.
184 *
185 * TODO(turnidge): Handle ambiguous names.
186 */
187 Future<InstanceMirror> setField(String fieldName, Object value);
188 }
189
190 /**
191 * An [InstanceMirror] reflects an instance of a Dart language object.
192 */
193 abstract class InstanceMirror implements ObjectMirror {
194 /**
195 * A mirror on the type of the reflectee.
196 */
197 ClassMirror get type;
198
199 /**
200 * Does [reflectee] contain the instance reflected by this mirror?
201 * This will always be true in the local case (reflecting instances
202 * in the same isolate), but only true in the remote case if this
203 * mirror reflects a simple value.
204 *
205 * A value is simple if one of the following holds:
206 * - the value is null
207 * - the value is of type [num]
208 * - the value is of type [bool]
209 * - the value is of type [String]
210 */
211 bool get hasReflectee;
212
213 /**
214 * If the [InstanceMirror] reflects an instance it is meaningful to
215 * have a local reference to, we provide access to the actual
216 * instance here.
217 *
218 * If you access [reflectee] when [hasReflectee] is false, an
219 * exception is thrown.
220 */
221 get reflectee;
222 }
223
224 /**
225 * A [ClosureMirror] reflects a closure.
226 *
227 * A [ClosureMirror] provides access to its captured variables and
228 * provides the ability to execute its reflectee.
229 */
230 abstract class ClosureMirror implements InstanceMirror {
231 /**
232 * A mirror on the function associated with this closure.
233 */
234 MethodMirror get function;
235
236 /**
237 * The source code for this closure, if available. Otherwise null.
238 *
239 * TODO(turnidge): Would this just be available in function?
240 */
241 String get source;
242
243 /**
244 * Executes the closure. The arguments given in the descriptor need to
245 * be InstanceMirrors or simple values.
246 *
247 * A value is simple if one of the following holds:
248 * - the value is null
249 * - the value is of type [num]
250 * - the value is of type [bool]
251 * - the value is of type [String]
252 */
253 Future<InstanceMirror> apply(List<Object> positionalArguments,
254 [Map<String,Object> namedArguments]);
255
256 /**
257 * Looks up the value of a name in the scope of the closure. The
258 * result is a mirror on that value.
259 */
260 Future<InstanceMirror> findInContext(String name);
261 }
262
263 /**
264 * A [LibraryMirror] reflects a Dart language library, providing
265 * access to the variables, functions, and classes of the
266 * library.
267 */
268 abstract class LibraryMirror implements DeclarationMirror, ObjectMirror {
269 /**
270 * The url of the library.
271 *
272 * TODO(turnidge): Document where this url comes from. Will this
273 * value be sensible?
274 */
275 String get url;
276
277 /**
278 * An immutable map from from names to mirrors for all members in
279 * this library.
280 *
281 * The members of a library are its top-level classes,
282 * functions, variables, getters, and setters.
283 */
284 Map<String, Mirror> get members;
285
286 /**
287 * An immutable map from names to mirrors for all class
288 * declarations in this library.
289 */
290 Map<String, ClassMirror> get classes;
291
292 /**
293 * An immutable map from names to mirrors for all function, getter,
294 * and setter declarations in this library.
295 */
296 Map<String, MethodMirror> get functions;
297
298 /**
299 * An immutable map from names to mirrors for all getter
300 * declarations in this library.
301 */
302 Map<String, MethodMirror> get getters;
303
304 /**
305 * An immutable map from names to mirrors for all setter
306 * declarations in this library.
307 */
308 Map<String, MethodMirror> get setters;
309
310 /**
311 * An immutable map from names to mirrors for all variable
312 * declarations in this library.
313 */
314 Map<String, VariableMirror> get variables;
315 }
316
317 /**
318 * A [TypeMirror] reflects a Dart language class, typedef
319 * or type variable.
320 */
321 abstract class TypeMirror implements DeclarationMirror {
322 }
323
324 /**
325 * A [ClassMirror] reflects a Dart language class.
326 */
327 abstract class ClassMirror implements TypeMirror, ObjectMirror {
328 /**
329 * A mirror on the superclass on the reflectee.
330 *
331 * If this type is [:Object:] or a typedef, the superClass will be
332 * null.
333 */
334 ClassMirror get superclass;
335
336 /**
337 * A list of mirrors on the superinterfaces of the reflectee.
338 */
339 List<ClassMirror> get superinterfaces;
340
341 /**
342 * An immutable map from from names to mirrors for all members of
343 * this type.
344 *
345 * The members of a type are its methods, fields, getters, and
346 * setters. Note that constructors and type variables are not
347 * considered to be members of a type.
348 *
349 * This does not include inherited members.
350 */
351 Map<String, Mirror> get members;
352
353 /**
354 * An immutable map from names to mirrors for all method,
355 * declarations for this type. This does not include getters and
356 * setters.
357 */
358 Map<String, MethodMirror> get methods;
359
360 /**
361 * An immutable map from names to mirrors for all getter
362 * declarations for this type.
363 */
364 Map<String, MethodMirror> get getters;
365
366 /**
367 * An immutable map from names to mirrors for all setter
368 * declarations for this type.
369 */
370 Map<String, MethodMirror> get setters;
371
372 /**
373 * An immutable map from names to mirrors for all variable
374 * declarations for this type.
375 */
376 Map<String, VariableMirror> get variables;
377
378 /**
379 * An immutable map from names to mirrors for all constructor
380 * declarations for this type.
381 */
382 Map<String, MethodMirror> get constructors;
383
384 /**
385 * An immutable map from names to mirrors for all type variables for
386 * this type.
387 *
388 * This map preserves the order of declaration of the type variables.
389 */
390 Map<String, TypeVariableMirror> get typeVariables;
391
392 /**
393 * An immutable map from names to mirrors for all type arguments for
394 * this type.
395 *
396 * This map preserves the order of declaration of the type variables.
397 */
398 Map<String, TypeMirror> get typeArguments;
399
400 /**
401 * Is this the original declaration of this type?
402 *
403 * For most classes, they are their own original declaration. For
404 * generic classes, however, there is a distinction between the
405 * original class declaration, which has unbound type variables, and
406 * the instantiations of generic classes, which have bound type
407 * variables.
408 */
409 bool get isOriginalDeclaration;
410
411 /**
412 * A mirror on the original declaration of this type.
413 *
414 * For most classes, they are their own original declaration. For
415 * generic classes, however, there is a distinction between the
416 * original class declaration, which has unbound type variables, and
417 * the instantiations of generic classes, which have bound type
418 * variables.
419 */
420 ClassMirror get originalDeclaration;
421
422 /**
423 * Invokes the named constructor and returns a mirror on the result.
424 *
425 * TODO(turnidge): Properly document.
426 */
427 Future<InstanceMirror> newInstance(String constructorName,
428 List<Object> positionalArguments,
429 [Map<String,Object> namedArguments]);
430
431 /**
432 * Does this mirror represent a class?
433 *
434 * TODO(turnidge): This functions goes away after the
435 * class/interface changes.
436 */
437 bool get isClass;
438
439 /**
440 * A mirror on the default factory class or null if there is none.
441 *
442 * TODO(turnidge): This functions goes away after the
443 * class/interface changes.
444 */
445 ClassMirror get defaultFactory;
446 }
447
448 /**
449 * A [FunctionTypeMirror] represents the type of a function in the
450 * Dart language.
451 */
452 abstract class FunctionTypeMirror implements ClassMirror {
453 /**
454 * The return type of the reflectee.
455 */
456 TypeMirror get returnType;
457
458 /**
459 * A list of the parameter types of the reflectee.
460 */
461 List<ParameterMirror> get parameters;
462
463 /**
464 * A mirror on the [:call:] method for the reflectee.
465 *
466 * TODO(turnidge): What is this and what is it for?
467 */
468 MethodMirror get callMethod;
469 }
470
471 /**
472 * A [TypeVariableMirror] represents a type parameter of a generic
473 * type.
474 */
475 abstract class TypeVariableMirror extends TypeMirror {
476 /**
477 * A mirror on the type that is the upper bound of this type variable.
478 */
479 TypeMirror get upperBound;
480 }
481
482 /**
483 * A [TypedefMirror] represents a typedef in a Dart language program.
484 */
485 abstract class TypedefMirror implements ClassMirror {
486 /**
487 * The defining type for this typedef.
488 *
489 * For instance [:void f(int):] is the value for [:typedef void f(int):].
490 */
491 TypeMirror get value;
492 }
493
494 /**
495 * A [MethodMirror] reflects a Dart language function, method,
496 * constructor, getter, or setter.
497 */
498 abstract class MethodMirror implements DeclarationMirror {
499 /**
500 * A mirror on the return type for the reflectee.
501 */
502 TypeMirror get returnType;
503
504 /**
505 * A list of mirrors on the parameters for the reflectee.
506 */
507 List<ParameterMirror> get parameters;
508
509 /**
510 * Is the reflectee static?
511 *
512 * For the purposes of the mirrors library, a top-level function is
513 * considered static.
514 */
515 bool get isStatic;
516
517 /**
518 * Is the reflectee abstract?
519 */
520 bool get isAbstract;
521
522 /**
523 * Is the reflectee a regular function or method?
524 *
525 * A function or method is regular if it is not a getter, setter, or
526 * constructor. Note that operators, by this definition, are
527 * regular methods.
528 */
529 bool get isRegularMethod;
530
531 /**
532 * Is the reflectee an operator?
533 */
534 bool get isOperator;
535
536 /**
537 * Is the reflectee a getter?
538 */
539 bool get isGetter;
540
541 /**
542 * Is the reflectee a setter?
543 */
544 bool get isSetter;
545
546 /**
547 * Is the reflectee a constructor?
548 */
549 bool get isConstructor;
550
551 /**
552 * The constructor name for named constructors and factory methods.
553 *
554 * For unnamed constructors, this is the empty string. For
555 * non-constructors, this is the empty string.
556 *
557 * For example, [:'bar':] is the constructor name for constructor
558 * [:Foo.bar:] of type [:Foo:].
559 */
560 String get constructorName;
561
562 /**
563 * Is the reflectee a const constructor?
564 */
565 bool get isConstConstructor;
566
567 /**
568 * Is the reflectee a generative constructor?
569 */
570 bool get isGenerativeConstructor;
571
572 /**
573 * Is the reflectee a redirecting constructor?
574 */
575 bool get isRedirectingConstructor;
576
577 /**
578 * Is the reflectee a factory constructor?
579 */
580 bool get isFactoryConstructor;
581 }
582
583 /**
584 * A [VariableMirror] reflects a Dart language variable declaration.
585 */
586 abstract class VariableMirror implements DeclarationMirror {
587 /**
588 * A mirror on the type of the reflectee.
589 */
590 TypeMirror get type;
591
592 /**
593 * Is the reflectee a static variable?
594 *
595 * For the purposes of the mirror library, top-level variables are
596 * implicitly declared static.
597 */
598 bool get isStatic;
599
600 /**
601 * Is the reflectee a final variable?
602 */
603 bool get isFinal;
604 }
605
606 /**
607 * A [ParameterMirror] reflects a Dart formal parameter declaration.
608 */
609 abstract class ParameterMirror implements VariableMirror {
610 /**
611 * A mirror on the type of this parameter.
612 */
613 TypeMirror get type;
614
615 /**
616 * Is this parameter optional?
617 */
618 bool get isOptional;
619
620 /**
621 * Is this parameter named?
622 */
623 bool get isNamed;
624
625 /**
626 * Does this parameter have a default value?
627 */
628 bool get hasDefaultValue;
629
630 /**
631 * A mirror on the default value for this parameter, if it exists.
632 *
633 * TODO(turnidge): String may not be a good representation of this
634 * at runtime.
635 */
636 String get defaultValue;
637 }
638
639 /**
640 * A [SourceLocation] describes the span of an entity in Dart source code.
641 */
642 abstract class SourceLocation {
643 }
644
645 /**
646 * When an error occurs during the mirrored execution of code, a
647 * [MirroredError] is thrown.
648 *
649 * In general, there are three main classes of failure that can happen
650 * during mirrored execution of code in some isolate:
651 *
652 * - An exception is thrown but not caught. This is caught by the
653 * mirrors framework and a [MirroredUncaughtExceptionError] is
654 * created and thrown.
655 *
656 * - A compile-time error occurs, such as a syntax error. This is
657 * suppressed by the mirrors framework and a
658 * [MirroredCompilationError] is created and thrown.
659 *
660 * - A truly fatal error occurs, causing the isolate to be exited. If
661 * the reflector and reflectee share the same isolate, then they
662 * will both suffer. If the reflector and reflectee are in distinct
663 * isolates, then we hope to provide some information about the
664 * isolate death, but this has yet to be implemented.
665 *
666 * TODO(turnidge): Specify the behavior for remote fatal errors.
667 */
668 abstract class MirroredError implements Exception {
669 }
670
671 /**
672 * When an uncaught exception occurs during the mirrored execution
673 * of code, a [MirroredUncaughtExceptionError] is thrown.
674 *
675 * This exception contains a mirror on the original exception object.
676 * It also contains an object which can be used to recover the
677 * stacktrace.
678 */
679 class MirroredUncaughtExceptionError extends MirroredError {
680 MirroredUncaughtExceptionError(this.exception_mirror,
681 this.exception_string,
682 this.stacktrace) {}
683
684 /** A mirror on the exception object. */
685 final InstanceMirror exception_mirror;
686
687 /** The result of toString() for the exception object. */
688 final String exception_string;
689
690 /** A stacktrace object for the uncaught exception. */
691 final Object stacktrace;
692
693 String toString() {
694 return
695 "Uncaught exception during mirrored execution: <${exception_string}>";
696 }
697 }
698
699 /**
700 * When a compile-time error occurs during the mirrored execution
701 * of code, a [MirroredCompilationError] is thrown.
702 *
703 * This exception includes the compile-time error message that would
704 * have been displayed to the user, if the function had not been
705 * invoked via mirror.
706 */
707 class MirroredCompilationError extends MirroredError {
708 MirroredCompilationError(this.message) {}
709
710 final String message;
711
712 String toString() {
713 return "Compile-time error during mirrored execution: <$message>";
714 }
715 }
716
717 /**
718 * A [MirrorException] is used to indicate errors within the mirrors
719 * framework.
720 */
721 class MirrorException implements Exception {
722 const MirrorException(String this._message);
723 String toString() => "MirrorException: '$_message'";
724 final String _message;
725 }
OLDNEW
« no previous file with comments | « sdk/lib/mirrors/mirrors.dart ('k') | sdk/lib/mirrors/mirrors_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698