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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/elements.dart

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
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 library elements;
6
7
8 import '../constants/expressions.dart';
9 import '../tree/tree.dart';
10 import '../util/util.dart';
11 import '../resolution/resolution.dart';
12
13 import '../dart2jslib.dart' show InterfaceType,
14 DartType,
15 TypeVariableType,
16 TypedefType,
17 DualKind,
18 MessageKind,
19 DiagnosticListener,
20 Script,
21 FunctionType,
22 Selector,
23 Constant,
24 Compiler,
25 Backend,
26 isPrivateName;
27
28 import '../dart_types.dart';
29 import '../helpers/helpers.dart';
30
31 import '../scanner/scannerlib.dart' show Token,
32 isUserDefinableOperator,
33 isMinusOperator;
34
35 import '../ordered_typeset.dart' show OrderedTypeSet;
36
37 import 'visitor.dart' show ElementVisitor;
38
39 part 'names.dart';
40
41 const int STATE_NOT_STARTED = 0;
42 const int STATE_STARTED = 1;
43 const int STATE_DONE = 2;
44
45 class ElementCategory {
46 /**
47 * Represents things that we don't expect to find when looking in a
48 * scope.
49 */
50 static const int NONE = 0;
51
52 /** Field, parameter, or variable. */
53 static const int VARIABLE = 1;
54
55 /** Function, method, or foreign function. */
56 static const int FUNCTION = 2;
57
58 static const int CLASS = 4;
59
60 static const int PREFIX = 8;
61
62 /** Constructor or factory. */
63 static const int FACTORY = 16;
64
65 static const int ALIAS = 32;
66
67 static const int SUPER = 64;
68
69 /** Type variable */
70 static const int TYPE_VARIABLE = 128;
71
72 static const int IMPLIES_TYPE = CLASS | ALIAS | TYPE_VARIABLE;
73 }
74
75 class ElementKind {
76 final String id;
77 final int category;
78
79 const ElementKind(String this.id, this.category);
80
81 static const ElementKind VARIABLE =
82 const ElementKind('variable', ElementCategory.VARIABLE);
83 static const ElementKind PARAMETER =
84 const ElementKind('parameter', ElementCategory.VARIABLE);
85 // Parameters in constructors that directly initialize fields. For example:
86 // [:A(this.field):].
87 static const ElementKind INITIALIZING_FORMAL =
88 const ElementKind('initializing_formal', ElementCategory.VARIABLE);
89 static const ElementKind FUNCTION =
90 const ElementKind('function', ElementCategory.FUNCTION);
91 static const ElementKind CLASS =
92 const ElementKind('class', ElementCategory.CLASS);
93 static const ElementKind GENERATIVE_CONSTRUCTOR =
94 const ElementKind('generative_constructor', ElementCategory.FACTORY);
95 static const ElementKind FIELD =
96 const ElementKind('field', ElementCategory.VARIABLE);
97 static const ElementKind FIELD_LIST =
98 const ElementKind('field_list', ElementCategory.NONE);
99 static const ElementKind GENERATIVE_CONSTRUCTOR_BODY =
100 const ElementKind('generative_constructor_body', ElementCategory.NONE);
101 static const ElementKind COMPILATION_UNIT =
102 const ElementKind('compilation_unit', ElementCategory.NONE);
103 static const ElementKind GETTER =
104 const ElementKind('getter', ElementCategory.NONE);
105 static const ElementKind SETTER =
106 const ElementKind('setter', ElementCategory.NONE);
107 static const ElementKind TYPE_VARIABLE =
108 const ElementKind('type_variable', ElementCategory.TYPE_VARIABLE);
109 static const ElementKind ABSTRACT_FIELD =
110 const ElementKind('abstract_field', ElementCategory.VARIABLE);
111 static const ElementKind LIBRARY =
112 const ElementKind('library', ElementCategory.NONE);
113 static const ElementKind PREFIX =
114 const ElementKind('prefix', ElementCategory.PREFIX);
115 static const ElementKind TYPEDEF =
116 const ElementKind('typedef', ElementCategory.ALIAS);
117
118 static const ElementKind AMBIGUOUS =
119 const ElementKind('ambiguous', ElementCategory.NONE);
120 static const ElementKind WARN_ON_USE =
121 const ElementKind('warn_on_use', ElementCategory.NONE);
122 static const ElementKind ERROR =
123 const ElementKind('error', ElementCategory.NONE);
124
125 toString() => id;
126 }
127
128 /// Abstract interface for entities.
129 ///
130 /// Implement this directly if the entity is not a Dart language entity.
131 /// Entities defined within the Dart language should implement [Element].
132 ///
133 /// For instance, the JavaScript backend need to create synthetic variables for
134 /// calling intercepted classes and such variables do not correspond to an
135 /// entity in the Dart source code nor in the terminology of the Dart language
136 /// and should therefore implement [Entity] directly.
137 abstract class Entity implements Spannable {
138 String get name;
139 }
140
141 /**
142 * A declared element of a program.
143 *
144 * The declared elements of a program include classes, methods,
145 * fields, variables, parameters, etc.
146 *
147 * Sometimes it makes sense to construct "synthetic" elements that
148 * have not been declared anywhere in a program, for example, there
149 * are elements corresponding to "dynamic", "null", and unresolved
150 * references.
151 *
152 * Elements are distinct from types ([DartType]). For example, there
153 * is one declaration of the class List, but several related types,
154 * for example, List, List<int>, List<String>, etc.
155 *
156 * Elements are distinct from AST nodes ([Node]), and there normally is a
157 * one-to-one correspondence between an AST node and an element
158 * (except that not all kinds of AST nodes have an associated
159 * element).
160 *
161 * AST nodes represent precisely what is written in source code, for
162 * example, when a user writes "class MyClass {}", the corresponding
163 * AST node does not have a superclass. On the other hand, the
164 * corresponding element (once fully resolved) will record the
165 * information about the implicit superclass as defined by the
166 * language semantics.
167 *
168 * Generally, the contents of a method are represented as AST nodes
169 * without additional elements, but things like local functions, local
170 * variables, and labels have a corresponding element.
171 *
172 * We generally say that scanning, parsing, resolution, and type
173 * checking comprise the "front-end" of the compiler. The "back-end"
174 * includes things like SSA graph construction, optimizations, and
175 * code generation.
176 *
177 * The front-end data structures are designed to be reusable by
178 * several back-ends. For example, we may want to support emitting
179 * minified Dart and JavaScript code in one go. Also, we're planning
180 * on adding an incremental compilation server that should be able to
181 * reuse elements between compilations. So to keep things simple, it
182 * is best if the backends avoid setting state directly in elements.
183 * It is better to keep such state in a table on the side.
184 */
185 abstract class Element implements Entity {
186 String get name;
187 ElementKind get kind;
188 Element get enclosingElement;
189 Link<MetadataAnnotation> get metadata;
190
191 /// Do not use [computeType] outside of the resolver; instead retrieve the
192 /// type from the corresponding field:
193 /// - `type` for fields, variables, type variable, and function elements.
194 /// - `thisType` or `rawType` for [TypeDeclarationElement]s (classes and
195 /// typedefs), depending on the use case.
196 /// Trying to access a type that has not been computed in resolution is an
197 /// error and calling [computeType] covers that error.
198 /// This method will go away!
199 @deprecated DartType computeType(Compiler compiler);
200
201 /// `true` if this element is a library.
202 bool get isLibrary => kind == ElementKind.LIBRARY;
203
204 /// `true` if this element is a compilation unit.
205 bool get isCompilationUnit => kind == ElementKind.COMPILATION_UNIT;
206
207 /// `true` if this element is defines the scope of prefix used by one or
208 /// more import declarations.
209 bool get isPrefix => kind == ElementKind.PREFIX;
210
211 /// `true` if this element is a class declaration or a mixin application.
212 bool get isClass => kind == ElementKind.CLASS;
213
214 /// `true` if this element is a type variable declaration.
215 bool get isTypeVariable => kind == ElementKind.TYPE_VARIABLE;
216
217 /// `true` if this element is a typedef declaration.
218 bool get isTypedef => kind == ElementKind.TYPEDEF;
219
220 /// `true` if this element is a top level function, static or instance
221 /// method, local function or closure defined by a function expression.
222 ///
223 /// This property is `true` for operator methods and factory constructors but
224 /// `false` for getter and setter methods, and generative constructors.
225 ///
226 /// See also [isConstructor], [isGenerativeConstructor], and
227 /// [isFactoryConstructor] for constructor properties, and [isAccessor],
228 /// [isGetter] and [isSetter] for getter/setter properties.
229 bool get isFunction => kind == ElementKind.FUNCTION;
230
231 /// `true` if this element is an operator method.
232 bool get isOperator;
233
234 /// `true` if this element is an accessor, that is either an explicit
235 /// getter or an explicit setter.
236 bool get isAccessor => isGetter || isSetter;
237
238 /// `true` if this element is an explicit getter method.
239 bool get isGetter => kind == ElementKind.GETTER;
240
241 /// `true` if this element is an explicit setter method.
242 bool get isSetter => kind == ElementKind.SETTER;
243
244 /// `true` if this element is a generative or factory constructor.
245 bool get isConstructor => isGenerativeConstructor || isFactoryConstructor;
246
247 /// `true` if this element is a generative constructor, potentially
248 /// redirecting.
249 bool get isGenerativeConstructor =>
250 kind == ElementKind.GENERATIVE_CONSTRUCTOR;
251
252 /// `true` if this element is the body of a generative constructor.
253 ///
254 /// This is a synthetic element kind used only be the JavaScript backend.
255 bool get isGenerativeConstructorBody =>
256 kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY;
257
258 /// `true` if this element is a factory constructor,
259 /// potentially redirecting.
260 bool get isFactoryConstructor;
261
262 /// `true` if this element is a local variable.
263 bool get isVariable => kind == ElementKind.VARIABLE;
264
265 /// `true` if this element is a top level variable, static or instance field.
266 bool get isField => kind == ElementKind.FIELD;
267
268 /// `true` if this element is the abstract field implicitly defined by an
269 /// explicit getter and/or setter.
270 bool get isAbstractField => kind == ElementKind.ABSTRACT_FIELD;
271
272 /// `true` if this element is formal parameter either from a constructor,
273 /// method, or typedef declaration or from an inlined function typed
274 /// parameter.
275 ///
276 /// This property is `false` if this element is an initializing formal.
277 /// See [isInitializingFormal].
278 bool get isParameter => kind == ElementKind.PARAMETER;
279
280 /// `true` if this element is an initializing formal of constructor, that
281 /// is a formal of the form `this.foo`.
282 bool get isInitializingFormal => kind == ElementKind.INITIALIZING_FORMAL;
283
284 /// `true` if this element represents a resolution error.
285 bool get isErroneous => kind == ElementKind.ERROR;
286
287 /// `true` if this element represents an ambiguous name.
288 ///
289 /// Ambiguous names occur when two imports/exports contain different entities
290 /// by the same name. If an ambiguous name is resolved an warning or error
291 /// is produced.
292 bool get isAmbiguous => kind == ElementKind.AMBIGUOUS;
293
294 /// `true` if this element represents an entity whose access causes one or
295 /// more warnings.
296 bool get isWarnOnUse => kind == ElementKind.WARN_ON_USE;
297
298 bool get isClosure;
299
300 /// `true` if the element is a (static or instance) member of a class.
301 ///
302 /// Members are constructors, methods and fields.
303 bool get isClassMember;
304
305 /// `true` if the element is a nonstatic member of a class.
306 ///
307 /// Instance members are methods and fields but not constructors.
308 bool get isInstanceMember;
309
310 /// Returns true if this [Element] is a top level element.
311 /// That is, if it is not defined within the scope of a class.
312 ///
313 /// This means whether the enclosing element is a compilation unit.
314 /// With the exception of [ClosureClassElement] that is considered top level
315 /// as all other classes.
316 bool get isTopLevel;
317 bool get isAssignable;
318 bool get isNative;
319 bool get isDeferredLoaderGetter;
320
321 /// True if the element is declared in a patch library but has no
322 /// corresponding declaration in the origin library.
323 bool get isInjected;
324
325 /// `true` if this element is a constructor, top level or local variable,
326 /// or static field that is declared `const`.
327 bool get isConst;
328
329 /// `true` if this element is a top level or local variable, static or
330 /// instance field, or parameter that is declared `final`.
331 bool get isFinal;
332
333 /// `true` if this element is a method, getter, setter or field that
334 /// is declared `static`.
335 bool get isStatic;
336
337 /// `true` if this element is local element, that is, a local variable,
338 /// local function or parameter.
339 bool get isLocal;
340
341 bool get impliesType;
342
343 Token get position;
344
345 CompilationUnitElement get compilationUnit;
346 LibraryElement get library;
347 LibraryElement get implementationLibrary;
348 ClassElement get enclosingClass;
349 Element get enclosingClassOrCompilationUnit;
350 Element get outermostEnclosingMemberOrTopLevel;
351
352 /// The enclosing class that defines the type environment for this element.
353 ClassElement get contextClass;
354
355 FunctionElement asFunctionElement();
356
357 /// Is [:true:] if this element has a corresponding patch.
358 ///
359 /// If [:true:] this element has a non-null [patch] field.
360 ///
361 /// See [:patch_parser.dart:] for a description of the terminology.
362 bool get isPatched;
363
364 /// Is [:true:] if this element is a patch.
365 ///
366 /// If [:true:] this element has a non-null [origin] field.
367 ///
368 /// See [:patch_parser.dart:] for a description of the terminology.
369 bool get isPatch;
370
371 /// Is [:true:] if this element defines the implementation for the entity of
372 /// this element.
373 ///
374 /// See [:patch_parser.dart:] for a description of the terminology.
375 bool get isImplementation;
376
377 /// Is [:true:] if this element introduces the entity of this element.
378 ///
379 /// See [:patch_parser.dart:] for a description of the terminology.
380 bool get isDeclaration;
381
382 /// Returns the element which defines the implementation for the entity of
383 /// this element.
384 ///
385 /// See [:patch_parser.dart:] for a description of the terminology.
386 Element get implementation;
387
388 /// Returns the element which introduces the entity of this element.
389 ///
390 /// See [:patch_parser.dart:] for a description of the terminology.
391 Element get declaration;
392
393 /// Returns the patch for this element if this element is patched.
394 ///
395 /// See [:patch_parser.dart:] for a description of the terminology.
396 Element get patch;
397
398 /// Returns the origin for this element if this element is a patch.
399 ///
400 /// See [:patch_parser.dart:] for a description of the terminology.
401 Element get origin;
402
403 bool get isSynthesized;
404 bool get isForwardingConstructor;
405 bool get isMixinApplication;
406
407 bool get hasFixedBackendName;
408 String get fixedBackendName;
409
410 bool get isAbstract;
411 bool isForeign(Backend backend);
412
413 void addMetadata(MetadataAnnotation annotation);
414 void setNative(String name);
415 void setFixedBackendName(String name);
416
417 Scope buildScope();
418
419 void diagnose(Element context, DiagnosticListener listener);
420
421 // TODO(johnniwinther): Move this to [AstElement].
422 /// Returns the [Element] that holds the [TreeElements] for this element.
423 AnalyzableElement get analyzableElement;
424
425 accept(ElementVisitor visitor);
426 }
427
428 class Elements {
429 static bool isUnresolved(Element e) {
430 return e == null || e.isErroneous;
431 }
432 static bool isErroneousElement(Element e) => e != null && e.isErroneous;
433
434 /// Unwraps [element] reporting any warnings attached to it, if any.
435 static Element unwrap(Element element,
436 DiagnosticListener listener,
437 Spannable spannable) {
438 if (element != null && element.isWarnOnUse) {
439 WarnOnUseElement wrappedElement = element;
440 element = wrappedElement.unwrap(listener, spannable);
441 }
442 return element;
443 }
444
445 static bool isClass(Element e) => e != null && e.kind == ElementKind.CLASS;
446 static bool isTypedef(Element e) {
447 return e != null && e.kind == ElementKind.TYPEDEF;
448 }
449
450 static bool isLocal(Element element) {
451 return !Elements.isUnresolved(element) && element.isLocal;
452 }
453
454 static bool isInstanceField(Element element) {
455 return !Elements.isUnresolved(element)
456 && element.isInstanceMember
457 && (identical(element.kind, ElementKind.FIELD)
458 || identical(element.kind, ElementKind.GETTER)
459 || identical(element.kind, ElementKind.SETTER));
460 }
461
462 static bool isStaticOrTopLevel(Element element) {
463 // TODO(johnniwinther): Clean this up. This currently returns true for a
464 // PartialConstructorElement, SynthesizedConstructorElementX, and
465 // TypeVariableElementX though neither `element.isStatic` nor
466 // `element.isTopLevel` is true.
467 if (Elements.isUnresolved(element)) return false;
468 if (element.isStatic || element.isTopLevel) return true;
469 return !element.isAmbiguous
470 && !element.isInstanceMember
471 && !element.isPrefix
472 && element.enclosingElement != null
473 && (element.enclosingElement.kind == ElementKind.CLASS ||
474 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT ||
475 element.enclosingElement.kind == ElementKind.LIBRARY ||
476 element.enclosingElement.kind == ElementKind.PREFIX);
477 }
478
479 static bool isInStaticContext(Element element) {
480 if (isUnresolved(element)) return true;
481 if (element.enclosingElement.isClosure) {
482 var closureClass = element.enclosingElement;
483 element = closureClass.methodElement;
484 }
485 Element outer = element.outermostEnclosingMemberOrTopLevel;
486 if (isUnresolved(outer)) return true;
487 if (outer.isTopLevel) return true;
488 if (outer.isGenerativeConstructor) return false;
489 if (outer.isInstanceMember) return false;
490 return true;
491 }
492
493 static bool isStaticOrTopLevelField(Element element) {
494 return isStaticOrTopLevel(element)
495 && (identical(element.kind, ElementKind.FIELD)
496 || identical(element.kind, ElementKind.GETTER)
497 || identical(element.kind, ElementKind.SETTER));
498 }
499
500 static bool isStaticOrTopLevelFunction(Element element) {
501 return isStaticOrTopLevel(element)
502 && (identical(element.kind, ElementKind.FUNCTION));
503 }
504
505 static bool isInstanceMethod(Element element) {
506 return !Elements.isUnresolved(element)
507 && element.isInstanceMember
508 && (identical(element.kind, ElementKind.FUNCTION));
509 }
510
511 /// Also returns true for [ConstructorBodyElement]s and getters/setters.
512 static bool isNonAbstractInstanceMember(Element element) {
513 // The generative constructor body is not a function. We therefore treat
514 // it specially.
515 if (element.isGenerativeConstructorBody) return true;
516 return !Elements.isUnresolved(element) &&
517 !element.isAbstract &&
518 element.isInstanceMember &&
519 (element.isFunction || element.isAccessor);
520 }
521
522 static bool isNativeOrExtendsNative(ClassElement element) {
523 if (element == null) return false;
524 if (element.isNative) return true;
525 assert(element.resolutionState == STATE_DONE);
526 return isNativeOrExtendsNative(element.superclass);
527 }
528
529 static bool isInstanceSend(Send send, TreeElements elements) {
530 Element element = elements[send];
531 if (element == null) return !isClosureSend(send, element);
532 return isInstanceMethod(element) || isInstanceField(element);
533 }
534
535 static bool isClosureSend(Send send, Element element) {
536 if (send.isPropertyAccess) return false;
537 if (send.receiver != null) return false;
538 Node selector = send.selector;
539 // this().
540 if (selector.isThis()) return true;
541 // (o)() or foo()().
542 if (element == null && selector.asIdentifier() == null) return true;
543 if (element == null) return false;
544 // foo() with foo a local or a parameter.
545 return isLocal(element);
546 }
547
548 static String reconstructConstructorNameSourceString(Element element) {
549 if (element.name == '') {
550 return element.enclosingClass.name;
551 } else {
552 return reconstructConstructorName(element);
553 }
554 }
555
556 // TODO(johnniwinther): Remove this method.
557 static String reconstructConstructorName(Element element) {
558 String className = element.enclosingClass.name;
559 if (element.name == '') {
560 return className;
561 } else {
562 return '$className\$${element.name}';
563 }
564 }
565
566 static String constructorNameForDiagnostics(String className,
567 String constructorName) {
568 String classNameString = className;
569 String constructorNameString = constructorName;
570 return (constructorName == '')
571 ? classNameString
572 : "$classNameString.$constructorNameString";
573 }
574
575 /// Returns `true` if [name] is the name of an operator method.
576 static bool isOperatorName(String name) {
577 return name == 'unary-' || isUserDefinableOperator(name);
578 }
579
580 /**
581 * Map an operator-name to a valid JavaScript identifier.
582 *
583 * For non-operator names, this method just returns its input.
584 *
585 * The results returned from this method are guaranteed to be valid
586 * JavaScript identifers, except it may include reserved words for
587 * non-operator names.
588 */
589 static String operatorNameToIdentifier(String name) {
590 if (name == null) {
591 return name;
592 } else if (identical(name, '==')) {
593 return r'operator$eq';
594 } else if (identical(name, '~')) {
595 return r'operator$not';
596 } else if (identical(name, '[]')) {
597 return r'operator$index';
598 } else if (identical(name, '[]=')) {
599 return r'operator$indexSet';
600 } else if (identical(name, '*')) {
601 return r'operator$mul';
602 } else if (identical(name, '/')) {
603 return r'operator$div';
604 } else if (identical(name, '%')) {
605 return r'operator$mod';
606 } else if (identical(name, '~/')) {
607 return r'operator$tdiv';
608 } else if (identical(name, '+')) {
609 return r'operator$add';
610 } else if (identical(name, '<<')) {
611 return r'operator$shl';
612 } else if (identical(name, '>>')) {
613 return r'operator$shr';
614 } else if (identical(name, '>=')) {
615 return r'operator$ge';
616 } else if (identical(name, '>')) {
617 return r'operator$gt';
618 } else if (identical(name, '<=')) {
619 return r'operator$le';
620 } else if (identical(name, '<')) {
621 return r'operator$lt';
622 } else if (identical(name, '&')) {
623 return r'operator$and';
624 } else if (identical(name, '^')) {
625 return r'operator$xor';
626 } else if (identical(name, '|')) {
627 return r'operator$or';
628 } else if (identical(name, '-')) {
629 return r'operator$sub';
630 } else if (identical(name, 'unary-')) {
631 return r'operator$negate';
632 } else {
633 return name;
634 }
635 }
636
637 static String constructOperatorNameOrNull(String op, bool isUnary) {
638 if (isMinusOperator(op)) {
639 return isUnary ? 'unary-' : op;
640 } else if (isUserDefinableOperator(op)) {
641 return op;
642 } else {
643 return null;
644 }
645 }
646
647 static String constructOperatorName(String op, bool isUnary) {
648 String operatorName = constructOperatorNameOrNull(op, isUnary);
649 if (operatorName == null) throw 'Unhandled operator: $op';
650 else return operatorName;
651 }
652
653 static String mapToUserOperatorOrNull(String op) {
654 if (identical(op, '!=')) return '==';
655 if (identical(op, '*=')) return '*';
656 if (identical(op, '/=')) return '/';
657 if (identical(op, '%=')) return '%';
658 if (identical(op, '~/=')) return '~/';
659 if (identical(op, '+=')) return '+';
660 if (identical(op, '-=')) return '-';
661 if (identical(op, '<<=')) return '<<';
662 if (identical(op, '>>=')) return '>>';
663 if (identical(op, '&=')) return '&';
664 if (identical(op, '^=')) return '^';
665 if (identical(op, '|=')) return '|';
666
667 return null;
668 }
669
670 static String mapToUserOperator(String op) {
671 String userOperator = mapToUserOperatorOrNull(op);
672 if (userOperator == null) throw 'Unhandled operator: $op';
673 else return userOperator;
674 }
675
676 static bool isNumberOrStringSupertype(Element element, Compiler compiler) {
677 LibraryElement coreLibrary = compiler.coreLibrary;
678 return (element == coreLibrary.find('Comparable'));
679 }
680
681 static bool isStringOnlySupertype(Element element, Compiler compiler) {
682 LibraryElement coreLibrary = compiler.coreLibrary;
683 return element == coreLibrary.find('Pattern');
684 }
685
686 static bool isListSupertype(Element element, Compiler compiler) {
687 LibraryElement coreLibrary = compiler.coreLibrary;
688 return element == coreLibrary.find('Iterable');
689 }
690
691 /// A `compareTo` function that places [Element]s in a consistent order based
692 /// on the source code order.
693 static int compareByPosition(Element a, Element b) {
694 if (identical(a, b)) return 0;
695 int r = a.library.compareTo(b.library);
696 if (r != 0) return r;
697 r = a.compilationUnit.compareTo(b.compilationUnit);
698 if (r != 0) return r;
699 Token positionA = a.position;
700 Token positionB = b.position;
701 int offsetA = positionA == null ? -1 : positionA.charOffset;
702 int offsetB = positionB == null ? -1 : positionB.charOffset;
703 r = offsetA.compareTo(offsetB);
704 if (r != 0) return r;
705 r = a.name.compareTo(b.name);
706 if (r != 0) return r;
707 // Same file, position and name. If this happens, we should find out why
708 // and make the order total and independent of hashCode.
709 return a.hashCode.compareTo(b.hashCode);
710 }
711
712 static List<Element> sortedByPosition(Iterable<Element> elements) {
713 return elements.toList()..sort(compareByPosition);
714 }
715
716 static bool isFixedListConstructorCall(Element element,
717 Send node,
718 Compiler compiler) {
719 return element == compiler.unnamedListConstructor
720 && node.isCall
721 && !node.arguments.isEmpty
722 && node.arguments.tail.isEmpty;
723 }
724
725 static bool isGrowableListConstructorCall(Element element,
726 Send node,
727 Compiler compiler) {
728 return element == compiler.unnamedListConstructor
729 && node.isCall
730 && node.arguments.isEmpty;
731 }
732
733 static bool isFilledListConstructorCall(Element element,
734 Send node,
735 Compiler compiler) {
736 return element == compiler.filledListConstructor
737 && node.isCall
738 && !node.arguments.isEmpty
739 && !node.arguments.tail.isEmpty
740 && node.arguments.tail.tail.isEmpty;
741 }
742
743 static bool isConstructorOfTypedArraySubclass(Element element,
744 Compiler compiler) {
745 if (compiler.typedDataLibrary == null) return false;
746 if (!element.isConstructor) return false;
747 ConstructorElement constructor = element.implementation;
748 constructor = constructor.effectiveTarget;
749 ClassElement cls = constructor.enclosingClass;
750 return cls.library == compiler.typedDataLibrary
751 && cls.isNative
752 && compiler.world.isSubtypeOf(cls, compiler.typedDataClass)
753 && compiler.world.isSubtypeOf(cls, compiler.listClass)
754 && constructor.name == '';
755 }
756
757 static bool switchStatementHasContinue(SwitchStatement node,
758 TreeElements elements) {
759 for (SwitchCase switchCase in node.cases) {
760 for (Node labelOrCase in switchCase.labelsAndCases) {
761 Node label = labelOrCase.asLabel();
762 if (label != null) {
763 LabelDefinition labelElement = elements.getLabelDefinition(label);
764 if (labelElement != null && labelElement.isContinueTarget) {
765 return true;
766 }
767 }
768 }
769 }
770 return false;
771 }
772
773 static bool isUnusedLabel(LabeledStatement node, TreeElements elements) {
774 Node body = node.statement;
775 JumpTarget element = elements.getTargetDefinition(body);
776 // Labeled statements with no element on the body have no breaks.
777 // A different target statement only happens if the body is itself
778 // a break or continue for a different target. In that case, this
779 // label is also always unused.
780 return element == null || element.statement != body;
781 }
782 }
783
784 /// An element representing an erroneous resolution.
785 ///
786 /// An [ErroneousElement] is used instead of `null` to provide additional
787 /// information about the error that caused the element to be unresolvable
788 /// or otherwise invalid.
789 ///
790 /// Accessing any field or calling any method defined on [ErroneousElement]
791 /// except [isErroneous] will currently throw an exception. (This might
792 /// change when we actually want more information on the erroneous element,
793 /// e.g., the name of the element we were trying to resolve.)
794 ///
795 /// Code that cannot not handle an [ErroneousElement] should use
796 /// `Element.isUnresolved(element)` to check for unresolvable elements instead
797 /// of `element == null`.
798 abstract class ErroneousElement extends Element implements ConstructorElement {
799 MessageKind get messageKind;
800 Map get messageArguments;
801 String get message;
802 }
803
804 /// An [Element] whose usage should cause one or more warnings.
805 abstract class WarnOnUseElement extends Element {
806 /// The element whose usage cause a warning.
807 Element get wrappedElement;
808
809 /// Reports the attached warning and returns the wrapped element.
810 /// [usageSpannable] is used to report messages on the reference of
811 /// [wrappedElement].
812 Element unwrap(DiagnosticListener listener, Spannable usageSpannable);
813 }
814
815 /// An ambiguous element represents multiple elements accessible by the same
816 /// name.
817 ///
818 /// Ambiguous elements are created during handling of import/export scopes. If
819 /// an ambiguous element is encountered during resolution a warning/error is
820 /// reported.
821 abstract class AmbiguousElement extends Element {
822 MessageKind get messageKind;
823 Map get messageArguments;
824 Element get existingElement;
825 Element get newElement;
826 }
827
828 // TODO(kasperl): This probably shouldn't be called an element. It's
829 // just an interface shared by classes and libraries.
830 abstract class ScopeContainerElement implements Element {
831 Element localLookup(String elementName);
832
833 void forEachLocalMember(f(Element element));
834 }
835
836 abstract class CompilationUnitElement extends Element {
837 Script get script;
838 PartOf get partTag;
839
840 void forEachLocalMember(f(Element element));
841 void addMember(Element element, DiagnosticListener listener);
842 void setPartOf(PartOf tag, DiagnosticListener listener);
843 bool get hasMembers;
844
845 int compareTo(CompilationUnitElement other);
846 }
847
848 abstract class LibraryElement extends Element
849 implements ScopeContainerElement, AnalyzableElement {
850 /**
851 * The canonical uri for this library.
852 *
853 * For user libraries the canonical uri is the script uri. For platform
854 * libraries the canonical uri is of the form [:dart:x:].
855 */
856 Uri get canonicalUri;
857
858 /// Returns `true` if this library is 'dart:core'.
859 bool get isDartCore;
860
861 CompilationUnitElement get entryCompilationUnit;
862 Link<CompilationUnitElement> get compilationUnits;
863 Iterable<LibraryTag> get tags;
864 LibraryName get libraryTag;
865 Link<Element> get exports;
866
867 /**
868 * [:true:] if this library is part of the platform, that is, its canonical
869 * uri has the scheme 'dart'.
870 */
871 bool get isPlatformLibrary;
872
873 /**
874 * [:true:] if this library is from a package, that is, its canonical uri has
875 * the scheme 'package'.
876 */
877 bool get isPackageLibrary;
878
879 /**
880 * [:true:] if this library is a platform library whose path starts with
881 * an underscore.
882 */
883 bool get isInternalLibrary;
884 bool get canUseNative;
885 bool get exportsHandled;
886
887 // TODO(kasperl): We should try to get rid of these.
888 void set canUseNative(bool value);
889 void set libraryTag(LibraryName value);
890
891 LibraryElement get implementation;
892
893 void addCompilationUnit(CompilationUnitElement element);
894 void addTag(LibraryTag tag, DiagnosticListener listener);
895 void addImport(Element element, Import import, DiagnosticListener listener);
896
897 /// Record which element an import or export tag resolved to.
898 /// (Belongs on builder object).
899 void recordResolvedTag(LibraryDependency tag, LibraryElement library);
900
901 /// Return the library element corresponding to an import or export.
902 LibraryElement getLibraryFromTag(LibraryDependency tag);
903
904 void addMember(Element element, DiagnosticListener listener);
905 void addToScope(Element element, DiagnosticListener listener);
906
907 // TODO(kasperl): Get rid of this method.
908 Iterable<Element> getNonPrivateElementsInScope();
909
910 void setExports(Iterable<Element> exportedElements);
911
912 Element find(String elementName);
913 Element findLocal(String elementName);
914 Element findExported(String elementName);
915 void forEachExport(f(Element element));
916
917 /// Returns the imports that import element into this library.
918 Link<Import> getImportsFor(Element element);
919
920 bool hasLibraryName();
921 String getLibraryName();
922 String getLibraryOrScriptName();
923
924 int compareTo(LibraryElement other);
925 }
926
927 /// The implicit scope defined by a import declaration with a prefix clause.
928 abstract class PrefixElement extends Element {
929 void addImport(Element element, Import import, DiagnosticListener listener);
930 Element lookupLocalMember(String memberName);
931 /// Is true if this prefix belongs to a deferred import.
932 bool get isDeferred;
933 void markAsDeferred(Import import);
934 Import get deferredImport;
935 }
936
937 /// A type alias definition.
938 abstract class TypedefElement extends Element
939 implements AstElement, TypeDeclarationElement, FunctionTypedElement {
940
941 /// The type defined by this typedef with the type variables as its type
942 /// arguments.
943 ///
944 /// For instance `F<T>` for `typedef void F<T>(T t)`.
945 TypedefType get thisType;
946
947 /// The type defined by this typedef with `dynamic` as its type arguments.
948 ///
949 /// For instance `F<dynamic>` for `typedef void F<T>(T t)`.
950 TypedefType get rawType;
951
952 /// The type, function type if well-defined, for which this typedef is an
953 /// alias.
954 ///
955 /// For instance `(int)->void` for `typedef void F(int)`.
956 DartType get alias;
957
958 void checkCyclicReference(Compiler compiler);
959 }
960
961 /// An executable element is an element that can hold code.
962 ///
963 /// These elements variables (fields, parameters and locals), which can hold
964 /// code in their initializer, and functions (including methods and
965 /// constructors), which can hold code in their body.
966 abstract class ExecutableElement extends Element
967 implements TypedElement, AstElement {
968 /// The outermost member that contains this element.
969 ///
970 /// For top level, static or instance members, the member context is the
971 /// element itself. For parameters, local variables and nested closures, the
972 /// member context is the top level, static or instance member in which it is
973 /// defined.
974 MemberElement get memberContext;
975 }
976
977 /// A top-level, static or instance field or method, or a constructor.
978 ///
979 /// A [MemberElement] is the outermost executable element for any executable
980 /// context.
981 abstract class MemberElement extends Element implements ExecutableElement {
982 /// The local functions defined within this member.
983 List<FunctionElement> get nestedClosures;
984 }
985
986 /// A function, variable or parameter defined in an executable context.
987 abstract class LocalElement extends Element implements TypedElement, Local {
988 }
989
990 /// A top level, static or instance field, a formal parameter or local variable.
991 abstract class VariableElement extends ExecutableElement {
992 Expression get initializer;
993 }
994
995 /// An entity that defines a local entity (memory slot) in generated code.
996 ///
997 /// Parameters, local variables and local functions (can) define local entity
998 /// and thus implement [Local] through [LocalElement]. For non-element locals,
999 /// like `this` and boxes, specialized [Local] classes are created.
1000 ///
1001 /// Type variables can introduce locals in factories and constructors
1002 /// but since one type variable can introduce different locals in different
1003 /// factories and constructors it is not itself a [Local] but instead
1004 /// a non-element [Local] is created through a specialized class.
1005 // TODO(johnniwinther): Should [Local] have `isAssignable` or `type`?
1006 abstract class Local extends Entity {
1007 /// The context in which this local is defined.
1008 ExecutableElement get executableContext;
1009 }
1010
1011 /// A variable or parameter that is local to an executable context.
1012 ///
1013 /// The executable context is the [ExecutableElement] in which this variable
1014 /// is defined.
1015 abstract class LocalVariableElement extends VariableElement
1016 implements LocalElement {
1017 }
1018
1019 /// A top-level, static or instance field.
1020 abstract class FieldElement extends VariableElement implements MemberElement {
1021 }
1022
1023 /// A parameter-like element of a function signature.
1024 ///
1025 /// If the function signature comes from a typedef or an inline function-typed
1026 /// parameter (e.g. the parameter 'f' in `method(void f())`), then its
1027 /// parameters are not real parameters in that they can take no argument and
1028 /// hold no value. Such parameter-like elements are modeled by [FormalElement].
1029 ///
1030 /// If the function signature comes from a function or constructor, its
1031 /// parameters are real parameters and are modeled by [ParameterElement].
1032 abstract class FormalElement extends Element
1033 implements FunctionTypedElement, TypedElement, AstElement {
1034 /// Use [functionDeclaration] instead.
1035 @deprecated
1036 get enclosingElement;
1037
1038 /// The function, typedef or inline function-typed parameter on which
1039 /// this parameter is declared.
1040 FunctionTypedElement get functionDeclaration;
1041
1042 VariableDefinitions get node;
1043 }
1044
1045 /// A formal parameter of a function or constructor.
1046 ///
1047 /// Normal parameter that introduce a local variable are modeled by
1048 /// [LocalParameterElement] whereas initializing formals, that is parameter of
1049 /// the form `this.x`, are modeled by [InitializingFormalParameter].
1050 abstract class ParameterElement extends Element
1051 implements VariableElement, FormalElement, LocalElement {
1052 /// Use [functionDeclaration] instead.
1053 @deprecated
1054 get enclosingElement;
1055
1056 /// The function on which this parameter is declared.
1057 FunctionElement get functionDeclaration;
1058 }
1059
1060 /// A formal parameter on a function or constructor that introduces a local
1061 /// variable in the scope of the function or constructor.
1062 abstract class LocalParameterElement extends ParameterElement
1063 implements LocalVariableElement {
1064 }
1065
1066 /// A formal parameter in a constructor that directly initializes a field.
1067 ///
1068 /// For example: `A(this.field)`.
1069 abstract class InitializingFormalElement extends ParameterElement {
1070 /// The field initialized by this initializing formal.
1071 FieldElement get fieldElement;
1072
1073 /// The function on which this parameter is declared.
1074 ConstructorElement get functionDeclaration;
1075 }
1076
1077 /**
1078 * A synthetic element which holds a getter and/or a setter.
1079 *
1080 * This element unifies handling of fields and getters/setters. When
1081 * looking at code like "foo.x", we don't have to look for both a
1082 * field named "x", a getter named "x", and a setter named "x=".
1083 */
1084 abstract class AbstractFieldElement extends Element {
1085 FunctionElement get getter;
1086 FunctionElement get setter;
1087 }
1088
1089 abstract class FunctionSignature {
1090 FunctionType get type;
1091 Link<FormalElement> get requiredParameters;
1092 Link<FormalElement> get optionalParameters;
1093
1094 int get requiredParameterCount;
1095 int get optionalParameterCount;
1096 bool get optionalParametersAreNamed;
1097 FormalElement get firstOptionalParameter;
1098 bool get hasOptionalParameters;
1099
1100 int get parameterCount;
1101 List<FormalElement> get orderedOptionalParameters;
1102
1103 void forEachParameter(void function(FormalElement parameter));
1104 void forEachRequiredParameter(void function(FormalElement parameter));
1105 void forEachOptionalParameter(void function(FormalElement parameter));
1106
1107 void orderedForEachParameter(void function(FormalElement parameter));
1108
1109 bool isCompatibleWith(FunctionSignature constructorSignature);
1110 }
1111
1112 /// A top level, static or instance method, constructor, local function, or
1113 /// closure (anonymous local function).
1114 abstract class FunctionElement extends Element
1115 implements AstElement,
1116 TypedElement,
1117 FunctionTypedElement,
1118 ExecutableElement {
1119 FunctionExpression get node;
1120
1121 FunctionElement get patch;
1122 FunctionElement get origin;
1123
1124 /// Used to retrieve a link to the abstract field element representing this
1125 /// element.
1126 AbstractFieldElement get abstractField;
1127
1128 /// Do not use [computeSignature] outside of the resolver; instead retrieve
1129 /// the signature through the [functionSignature] field.
1130 /// Trying to access a function signature that has not been computed in
1131 /// resolution is an error and calling [computeSignature] covers that error.
1132 /// This method will go away!
1133 // TODO(johnniwinther): Rename to `ensureFunctionSignature`.
1134 @deprecated FunctionSignature computeSignature(Compiler compiler);
1135
1136 bool get hasFunctionSignature;
1137
1138 /// The type of this function.
1139 FunctionType get type;
1140
1141 /// The synchronous/asynchronous marker on this function.
1142 AsyncMarker get asyncMarker;
1143 }
1144
1145 /// Enum for the synchronous/asynchronous function body modifiers.
1146 class AsyncMarker {
1147 /// The default function body marker.
1148 static AsyncMarker SYNC = const AsyncMarker._();
1149
1150 /// The `sync*` function body marker.
1151 static AsyncMarker SYNC_STAR = const AsyncMarker._(isYielding: true);
1152
1153 /// The `async` function body marker.
1154 static AsyncMarker ASYNC = const AsyncMarker._(isAsync: true);
1155
1156 /// The `async*` function body marker.
1157 static AsyncMarker ASYNC_STAR =
1158 const AsyncMarker._(isAsync: true, isYielding: true);
1159
1160 /// Is `true` if this marker defines the function body to have an
1161 /// asynchronous result, that is, either a [Future] or a [Stream].
1162 final bool isAsync;
1163
1164 /// Is `true` if this marker defines the function body to have a plural
1165 /// result, that is, either an [Iterable] or a [Stream].
1166 final bool isYielding;
1167
1168 const AsyncMarker._({this.isAsync: false, this.isYielding: false});
1169
1170 String toString() {
1171 return '${isAsync ? 'async' : 'sync'}${isYielding ? '*' : ''}';
1172 }
1173 }
1174
1175 /// A top level, static or instance function.
1176 abstract class MethodElement extends FunctionElement
1177 implements MemberElement {
1178 }
1179
1180 /// A local function or closure (anonymous local function).
1181 abstract class LocalFunctionElement extends FunctionElement
1182 implements LocalElement {
1183 }
1184
1185 /// A constructor.
1186 abstract class ConstructorElement extends FunctionElement
1187 implements MemberElement {
1188 /// The effective target of this constructor, that is the non-redirecting
1189 /// constructor that is called on invocation of this constructor.
1190 ///
1191 /// Consider for instance this hierachy:
1192 ///
1193 /// class C { factory C.c() = D.d; }
1194 /// class D { factory D.d() = E.e2; }
1195 /// class E { E.e1();
1196 /// E.e2() : this.e1(); }
1197 ///
1198 /// The effective target of both `C.c`, `D.d`, and `E.e2` is `E.e2`, and the
1199 /// effective target of `E.e1` is `E.e1` itself.
1200 ConstructorElement get effectiveTarget;
1201
1202 /// The immediate redirection target of a redirecting factory constructor.
1203 ///
1204 /// Consider for instance this hierachy:
1205 ///
1206 /// class C { factory C() = D; }
1207 /// class D { factory D() = E; }
1208 /// class E { E(); }
1209 ///
1210 /// The immediate redirection target of `C` is `D` and the immediate
1211 /// redirection target of `D` is `E`. `E` is not a redirecting factory
1212 /// constructor so its immediate redirection target is `null`.
1213 ConstructorElement get immediateRedirectionTarget;
1214
1215 /// Is `true` if this constructor is a redirecting factory constructor.
1216 bool get isRedirectingFactory;
1217
1218 /// Compute the type of the effective target of this constructor for an
1219 /// instantiation site with type [:newType:].
1220 InterfaceType computeEffectiveTargetType(InterfaceType newType);
1221
1222 /// If this is a synthesized constructor [definingConstructor] points to
1223 /// the generative constructor from which this constructor was created.
1224 /// Otherwise [definingConstructor] is `null`.
1225 ///
1226 /// Consider for instance this hierarchy:
1227 ///
1228 /// class C { C.c(a, {b});
1229 /// class D {}
1230 /// class E = C with D;
1231 ///
1232 /// Class `E` has a synthesized constructor, `E.c`, whose defining constructor
1233 /// is `C.c`.
1234 ConstructorElement get definingConstructor;
1235
1236 /// Use [enclosingClass] instead.
1237 @deprecated
1238 get enclosingElement;
1239 }
1240
1241 /// JavaScript backend specific element for the body of constructor.
1242 // TODO(johnniwinther): Remove this class for the element model.
1243 abstract class ConstructorBodyElement extends FunctionElement {
1244 FunctionElement get constructor;
1245 }
1246
1247 /// [TypeDeclarationElement] defines the common interface for class/interface
1248 /// declarations and typedefs.
1249 abstract class TypeDeclarationElement extends Element implements AstElement {
1250 /**
1251 * The `this type` for this type declaration.
1252 *
1253 * The type of [:this:] is the generic type based on this element in which
1254 * the type arguments are the declared type variables. For instance,
1255 * [:List<E>:] for [:List:] and [:Map<K,V>:] for [:Map:].
1256 *
1257 * For a class declaration this is the type of [:this:].
1258 */
1259 GenericType get thisType;
1260
1261 /**
1262 * The raw type for this type declaration.
1263 *
1264 * The raw type is the generic type base on this element in which the type
1265 * arguments are all [dynamic]. For instance [:List<dynamic>:] for [:List:]
1266 * and [:Map<dynamic,dynamic>:] for [:Map:]. For non-generic classes [rawType]
1267 * is the same as [thisType].
1268 *
1269 * The [rawType] field is a canonicalization of the raw type and should be
1270 * used to distinguish explicit and implicit uses of the [dynamic]
1271 * type arguments. For instance should [:List:] be the [rawType] of the
1272 * [:List:] class element whereas [:List<dynamic>:] should be its own
1273 * instantiation of [InterfaceType] with [:dynamic:] as type argument. Using
1274 * this distinction, we can print the raw type with type arguments only when
1275 * the input source has used explicit type arguments.
1276 */
1277 GenericType get rawType;
1278
1279 /**
1280 * The type variables declared on this declaration. The type variables are not
1281 * available until the type of the element has been computed through
1282 * [computeType].
1283 */
1284 List<DartType> get typeVariables;
1285
1286 bool get isResolved;
1287
1288 int get resolutionState;
1289
1290 void ensureResolved(Compiler compiler);
1291 }
1292
1293 abstract class ClassElement extends TypeDeclarationElement
1294 implements ScopeContainerElement {
1295 int get id;
1296
1297 /// The length of the longest inheritance path from [:Object:].
1298 int get hierarchyDepth;
1299
1300 InterfaceType get rawType;
1301 InterfaceType get thisType;
1302 ClassElement get superclass;
1303
1304 /// The direct supertype of this class.
1305 DartType get supertype;
1306
1307 /// Ordered set of all supertypes of this class including the class itself.
1308 OrderedTypeSet get allSupertypesAndSelf;
1309
1310 /// A list of all supertypes of this class excluding the class itself.
1311 Link<DartType> get allSupertypes;
1312
1313 /// Returns the this type of this class as an instance of [cls].
1314 InterfaceType asInstanceOf(ClassElement cls);
1315
1316 /// A list of all direct superinterfaces of this class.
1317 Link<DartType> get interfaces;
1318
1319 bool get hasConstructor;
1320 Link<Element> get constructors;
1321
1322 ClassElement get patch;
1323 ClassElement get origin;
1324 ClassElement get declaration;
1325 ClassElement get implementation;
1326
1327 int get supertypeLoadState;
1328 String get nativeTagInfo;
1329
1330 bool get isMixinApplication;
1331 bool get isUnnamedMixinApplication;
1332 bool get hasBackendMembers;
1333 bool get hasLocalScopeMembers;
1334
1335 /// Returns `true` if this class is `Object` from dart:core.
1336 bool get isObject;
1337
1338 bool isSubclassOf(ClassElement cls);
1339 /// Returns true if `this` explicitly/nominally implements [intrface].
1340 ///
1341 /// Note that, if [intrface] is the `Function` class, this method returns
1342 /// falso for a class that has a `call` method but does not explicitly
1343 /// implement `Function`.
1344 bool implementsInterface(ClassElement intrface);
1345 bool hasFieldShadowedBy(Element fieldMember);
1346
1347 /// Returns `true` if this class has a @proxy annotation.
1348 bool get isProxy;
1349
1350 /// Returns `true` if the class hierarchy for this class contains errors.
1351 bool get hasIncompleteHierarchy;
1352
1353 void addMember(Element element, DiagnosticListener listener);
1354 void addToScope(Element element, DiagnosticListener listener);
1355
1356 void setDefaultConstructor(FunctionElement constructor, Compiler compiler);
1357
1358 void addBackendMember(Element element);
1359 void reverseBackendMembers();
1360
1361 Element lookupMember(String memberName);
1362 Element lookupSelector(Selector selector);
1363 Element lookupSuperSelector(Selector selector);
1364
1365 Element lookupLocalMember(String memberName);
1366 Element lookupBackendMember(String memberName);
1367 Element lookupSuperMember(String memberName);
1368
1369 Element lookupSuperMemberInLibrary(String memberName,
1370 LibraryElement library);
1371
1372 Element validateConstructorLookupResults(Selector selector,
1373 Element result,
1374 Element noMatch(Element));
1375
1376 Element lookupConstructor(Selector selector, [Element noMatch(Element)]);
1377
1378 void forEachMember(void f(ClassElement enclosingClass, Element member),
1379 {bool includeBackendMembers: false,
1380 bool includeSuperAndInjectedMembers: false});
1381
1382 void forEachInstanceField(void f(ClassElement enclosingClass,
1383 FieldElement field),
1384 {bool includeSuperAndInjectedMembers: false});
1385
1386 /// Similar to [forEachInstanceField] but visits static fields.
1387 void forEachStaticField(void f(ClassElement enclosingClass, Element field));
1388
1389 void forEachBackendMember(void f(Element member));
1390
1391 List<DartType> computeTypeParameters(Compiler compiler);
1392
1393 /// Looks up the member [name] in this class.
1394 Member lookupClassMember(Name name);
1395
1396 /// Calls [f] with each member of this class.
1397 void forEachClassMember(f(Member member));
1398
1399 /// Looks up the member [name] in the interface of this class.
1400 MemberSignature lookupInterfaceMember(Name name);
1401
1402 /// Calls [f] with each member of the interface of this class.
1403 void forEachInterfaceMember(f(MemberSignature member));
1404
1405 /// Returns the type of the 'call' method in the interface of this class, or
1406 /// `null` if the interface has no 'call' method.
1407 FunctionType get callType;
1408 }
1409
1410 abstract class MixinApplicationElement extends ClassElement {
1411 ClassElement get mixin;
1412 InterfaceType get mixinType;
1413 void set mixinType(InterfaceType value);
1414 void addConstructor(FunctionElement constructor);
1415 }
1416
1417 /// The label entity defined by a labeled statement.
1418 abstract class LabelDefinition extends Entity {
1419 Label get label;
1420 String get labelName;
1421 JumpTarget get target;
1422
1423 bool get isTarget;
1424 bool get isBreakTarget;
1425 bool get isContinueTarget;
1426
1427 void setBreakTarget();
1428 void setContinueTarget();
1429 }
1430
1431 /// A jump target is the reference point of a statement or switch-case,
1432 /// either by label or as the default target of a break or continue.
1433 abstract class JumpTarget extends Local {
1434 Node get statement;
1435 int get nestingLevel;
1436 Link<LabelDefinition> get labels;
1437
1438 bool get isTarget;
1439 bool get isBreakTarget;
1440 bool get isContinueTarget;
1441 bool get isSwitch;
1442
1443 // TODO(kasperl): Try to get rid of these.
1444 void set isBreakTarget(bool value);
1445 void set isContinueTarget(bool value);
1446
1447 LabelDefinition addLabel(Label label, String labelName);
1448 }
1449
1450 /// The [Element] for a type variable declaration on a generic class or typedef.
1451 abstract class TypeVariableElement extends Element
1452 implements AstElement, TypedElement {
1453
1454 /// Use [typeDeclaration] instead.
1455 @deprecated
1456 get enclosingElement;
1457
1458 /// The class or typedef on which this type variable is defined.
1459 TypeDeclarationElement get typeDeclaration;
1460
1461 /// The [type] defined by the type variable.
1462 TypeVariableType get type;
1463
1464 /// The upper bound on the type variable. If not explicitly declared, this is
1465 /// `Object`.
1466 DartType get bound;
1467 }
1468
1469 abstract class MetadataAnnotation implements Spannable {
1470 /// The front-end constant of this metadata annotation.
1471 ConstantExpression get constant;
1472 Element get annotatedElement;
1473 int get resolutionState;
1474 Token get beginToken;
1475 Token get endToken;
1476
1477 bool get hasNode;
1478 Node get node;
1479
1480 MetadataAnnotation ensureResolved(Compiler compiler);
1481 }
1482
1483 /// An [Element] that has a type.
1484 abstract class TypedElement extends Element {
1485 DartType get type;
1486 }
1487
1488 /// An [Element] that can define a function type.
1489 abstract class FunctionTypedElement extends Element {
1490 /// The function signature for the function type defined by this element,
1491 /// if any.
1492 FunctionSignature get functionSignature;
1493 }
1494
1495 /// An [Element] that holds a [TreeElements] mapping.
1496 abstract class AnalyzableElement extends Element {
1497 /// Return `true` if [treeElements] have been (partially) computed for this
1498 /// element.
1499 bool get hasTreeElements;
1500
1501 /// Returns the [TreeElements] that hold the resolution information for the
1502 /// AST nodes of this element.
1503 TreeElements get treeElements;
1504 }
1505
1506 /// An [Element] that (potentially) has a node.
1507 ///
1508 /// Synthesized elements may return `null` from [node].
1509 abstract class AstElement extends AnalyzableElement {
1510 /// `true` if [node] is available and non-null.
1511 bool get hasNode;
1512
1513 /// The AST node of this element.
1514 Node get node;
1515
1516 /// `true` if [resolvedAst] is available.
1517 bool get hasResolvedAst;
1518
1519 /// The defining AST node of this element with is corresponding
1520 /// [TreeElements]. This is not available if [hasResolvedAst] is `false`.
1521 ResolvedAst get resolvedAst;
1522 }
1523
1524 class ResolvedAst {
1525 final Element element;
1526 final Node node;
1527 final TreeElements elements;
1528
1529 ResolvedAst(this.element, this.node, this.elements);
1530 }
1531
1532 /// A [MemberSignature] is a member of an interface.
1533 ///
1534 /// A signature is either a method or a getter or setter, possibly implicitly
1535 /// defined by a field declarations. Fields themselves are not members of an
1536 /// interface.
1537 ///
1538 /// A [MemberSignature] may be defined by a member declaration or may be
1539 /// synthetized from a set of declarations.
1540 abstract class MemberSignature {
1541 /// The name of this member.
1542 Name get name;
1543
1544 /// The type of the member when accessed. For getters and setters this is the
1545 /// return type and argument type, respectively. For methods the type is the
1546 /// [functionType] defined by the return type and parameters.
1547 DartType get type;
1548
1549 /// The function type of the member. For a getter `Foo get foo` this is
1550 /// `() -> Foo`, for a setter `void set foo(Foo _)` this is `(Foo) -> void`.
1551 /// For methods the function type is defined by the return type and
1552 /// parameters.
1553 FunctionType get functionType;
1554
1555 /// Returns `true` if this member is a getter, possibly implictly defined by a
1556 /// field declaration.
1557 bool get isGetter;
1558
1559 /// Returns `true` if this member is a setter, possibly implictly defined by a
1560 /// field declaration.
1561 bool get isSetter;
1562
1563 /// Returns `true` if this member is a method, that is neither a getter nor
1564 /// setter.
1565 bool get isMethod;
1566
1567 /// Returns an iterable of the declarations that define this member.
1568 Iterable<Member> get declarations;
1569 }
1570
1571 /// A [Member] is a member of a class, that is either a method or a getter or
1572 /// setter, possibly implicitly defined by a field declarations. Fields
1573 /// themselves are not members of a class.
1574 ///
1575 /// A [Member] of a class also defines a signature which is a member of the
1576 /// corresponding interface type.
1577 ///
1578 /// A [Member] is implicitly concrete. An abstract declaration only declares
1579 /// a signature in the interface of its class.
1580 ///
1581 /// A [Member] is always declared by an [Element] which is accessibly through
1582 /// the [element] getter.
1583 abstract class Member extends MemberSignature {
1584 /// The [Element] that declared this member, possibly implicitly in case of
1585 /// a getter or setter defined by a field.
1586 Element get element;
1587
1588 /// The instance of the class that declared this member.
1589 ///
1590 /// For instance:
1591 /// class A<T> { T m() {} }
1592 /// class B<S> extends A<S> {}
1593 /// The declarer of `m` in `A` is `A<T>` whereas the declarer of `m` in `B` is
1594 /// `A<S>`.
1595 InterfaceType get declarer;
1596
1597 /// Returns `true` if this member is static.
1598 bool get isStatic;
1599
1600 /// Returns `true` if this member is a getter or setter implicitly declared
1601 /// by a field.
1602 bool get isDeclaredByField;
1603
1604 /// Returns `true` if this member is abstract.
1605 bool get isAbstract;
1606
1607 /// If abstract, [implementation] points to the overridden concrete member,
1608 /// if any. Otherwise [implementation] points to the member itself.
1609 Member get implementation;
1610 }
1611
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698