Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 elements; | 5 library elements; |
| 6 | 6 |
| 7 | 7 |
| 8 import '../tree/tree.dart'; | 8 import '../tree/tree.dart'; |
| 9 import '../util/util.dart'; | 9 import '../util/util.dart'; |
| 10 import '../resolution/resolution.dart'; | 10 import '../resolution/resolution.dart'; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 /// This property is `false` if this element is an initializing formal. | 278 /// This property is `false` if this element is an initializing formal. |
| 279 /// See [isInitializingFormal]. | 279 /// See [isInitializingFormal]. |
| 280 bool get isParameter => kind == ElementKind.PARAMETER; | 280 bool get isParameter => kind == ElementKind.PARAMETER; |
| 281 | 281 |
| 282 /// `true` if this element is an initializing formal of constructor, that | 282 /// `true` if this element is an initializing formal of constructor, that |
| 283 /// is a formal of the form `this.foo`. | 283 /// is a formal of the form `this.foo`. |
| 284 bool get isInitializingFormal => kind == ElementKind.INITIALIZING_FORMAL; | 284 bool get isInitializingFormal => kind == ElementKind.INITIALIZING_FORMAL; |
| 285 | 285 |
| 286 bool get isStatement; | 286 bool get isStatement; |
| 287 | 287 |
| 288 bool get isErroneous; | 288 /// `true` if this element represents a resolution error. |
| 289 bool get isAmbiguous; | 289 bool get isErroneous => kind == ElementKind.ERROR; |
| 290 bool get isWarnOnUse; | 290 |
| 291 /// `true` if this element represents an ambiguous name. | |
| 292 /// | |
| 293 /// Ambiguous names occur when two imports/exports contain different entities | |
| 294 /// by the same name. If an ambiguous name is resolved an warning or error | |
| 295 /// is produced. | |
| 296 bool get isAmbiguous => kind == ElementKind.AMBIGUOUS; | |
| 297 | |
| 298 /// `true` if this element represents an entity whose access should cause | |
|
floitsch
2014/07/21 08:55:34
If our compiler is correct it always reports the w
Johnni Winther
2014/07/23 12:49:40
Done.
| |
| 299 /// one or more warnings. | |
| 300 bool get isWarnOnUse => kind == ElementKind.WARN_ON_USE; | |
| 291 | 301 |
| 292 bool get isClosure; | 302 bool get isClosure; |
| 293 | 303 |
| 294 /// `true` if the element is a (static or instance) member of a class. | 304 /// `true` if the element is a (static or instance) member of a class. |
| 305 /// | |
| 295 /// Members are constructors, methods and fields. | 306 /// Members are constructors, methods and fields. |
| 296 bool get isClassMember; | 307 bool get isClassMember; |
| 297 | 308 |
| 298 /// `true` if the element is a nonstatic member of a class. | 309 /// `true` if the element is a nonstatic member of a class. |
| 310 /// | |
| 299 /// Instance members are methods and fields but not constructors. | 311 /// Instance members are methods and fields but not constructors. |
| 300 bool get isInstanceMember; | 312 bool get isInstanceMember; |
| 301 | 313 |
| 302 /// Returns true if this [Element] is a top level element. | 314 /// Returns true if this [Element] is a top level element. |
| 303 /// That is, if it is not defined within the scope of a class. | 315 /// That is, if it is not defined within the scope of a class. |
| 304 /// | 316 /// |
| 305 /// This means whether the enclosing element is a compilation unit. | 317 /// This means whether the enclosing element is a compilation unit. |
| 306 /// With the exception of [ClosureClassElement] that is considered top level | 318 /// With the exception of [ClosureClassElement] that is considered top level |
| 307 /// as all other classes. | 319 /// as all other classes. |
| 308 bool get isTopLevel; | 320 bool get isTopLevel; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 328 | 340 |
| 329 bool get impliesType; | 341 bool get impliesType; |
| 330 | 342 |
| 331 Token get position; | 343 Token get position; |
| 332 | 344 |
| 333 CompilationUnitElement get compilationUnit; | 345 CompilationUnitElement get compilationUnit; |
| 334 LibraryElement get library; | 346 LibraryElement get library; |
| 335 LibraryElement get implementationLibrary; | 347 LibraryElement get implementationLibrary; |
| 336 ClassElement get enclosingClass; | 348 ClassElement get enclosingClass; |
| 337 Element get enclosingClassOrCompilationUnit; | 349 Element get enclosingClassOrCompilationUnit; |
| 338 Element get enclosingMember; | |
| 339 Element get outermostEnclosingMemberOrTopLevel; | 350 Element get outermostEnclosingMemberOrTopLevel; |
| 340 | 351 |
| 341 /// The enclosing class that defines the type environment for this element. | 352 /// The enclosing class that defines the type environment for this element. |
| 342 ClassElement get contextClass; | 353 ClassElement get contextClass; |
| 343 | 354 |
| 344 FunctionElement asFunctionElement(); | 355 FunctionElement asFunctionElement(); |
| 345 | 356 |
| 346 /// Is [:true:] if this element has a corresponding patch. | 357 /// Is [:true:] if this element has a corresponding patch. |
| 347 /// | 358 /// |
| 348 /// If [:true:] this element has a non-null [patch] field. | 359 /// If [:true:] this element has a non-null [patch] field. |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 TargetElement element = elements[body]; | 771 TargetElement element = elements[body]; |
| 761 // Labeled statements with no element on the body have no breaks. | 772 // Labeled statements with no element on the body have no breaks. |
| 762 // A different target statement only happens if the body is itself | 773 // A different target statement only happens if the body is itself |
| 763 // a break or continue for a different target. In that case, this | 774 // a break or continue for a different target. In that case, this |
| 764 // label is also always unused. | 775 // label is also always unused. |
| 765 return element == null || element.statement != body; | 776 return element == null || element.statement != body; |
| 766 } | 777 } |
| 767 } | 778 } |
| 768 | 779 |
| 769 /// An element representing an erroneous resolution. | 780 /// An element representing an erroneous resolution. |
| 781 /// | |
| 782 /// An [ErroneousElement] is used instead of `null` to provide additional | |
| 783 /// information about the error that caused the element to be unresolvable | |
| 784 /// or otherwise invalid. | |
| 785 /// | |
| 786 /// Accessing any field or calling any method defined on [ErroneousElement] | |
| 787 /// except [isErroneous] will currently throw an exception. (This might | |
| 788 /// change when we actually want more information on the erroneous element, | |
| 789 /// e.g., the name of the element we were trying to resolve.) | |
| 790 /// | |
| 791 /// Code that cannot not handle an [ErroneousElement] should use | |
| 792 /// Element.isUnresolved(element) | |
|
floitsch
2014/07/21 08:55:34
I would use backticks. `Element.isUnresolved(eleme
Johnni Winther
2014/07/23 12:49:40
Done.
| |
| 793 /// to check for unresolvable elements instead of | |
| 794 /// element == null | |
| 770 abstract class ErroneousElement extends Element implements ConstructorElement { | 795 abstract class ErroneousElement extends Element implements ConstructorElement { |
| 771 MessageKind get messageKind; | 796 MessageKind get messageKind; |
| 772 Map get messageArguments; | 797 Map get messageArguments; |
| 773 String get message; | 798 String get message; |
| 774 } | 799 } |
| 775 | 800 |
| 776 /// An [Element] whose usage should cause a warning. | 801 /// An [Element] whose usage should cause one or more warnings. |
| 777 abstract class WarnOnUseElement extends Element { | 802 abstract class WarnOnUseElement extends Element { |
| 778 /// The element whose usage cause a warning. | 803 /// The element whose usage cause a warning. |
| 779 Element get wrappedElement; | 804 Element get wrappedElement; |
| 780 | 805 |
| 781 /// Reports the attached warning and returns the wrapped element. | 806 /// Reports the attached warning and returns the wrapped element. |
| 782 /// [usageSpannable] is used to report messages on the reference of | 807 /// [usageSpannable] is used to report messages on the reference of |
| 783 /// [wrappedElement]. | 808 /// [wrappedElement]. |
| 784 Element unwrap(DiagnosticListener listener, Spannable usageSpannable); | 809 Element unwrap(DiagnosticListener listener, Spannable usageSpannable); |
| 785 } | 810 } |
| 786 | 811 |
| 787 /// An element representing the ambiguous resolution of a name. | 812 /// An ambiguous element represents multiple elements accessible by the same |
| 813 /// name. | |
| 814 /// | |
| 815 /// Ambiguous elements are created during handling of import/export scopes. If | |
| 816 /// an ambiguous element is encountered during resolution a warning/error should | |
|
floitsch
2014/07/21 08:55:34
same remark (about "should") as above.
Johnni Winther
2014/07/23 12:49:40
Done.
| |
| 817 /// be reported. | |
| 788 abstract class AmbiguousElement extends Element { | 818 abstract class AmbiguousElement extends Element { |
| 789 MessageKind get messageKind; | 819 MessageKind get messageKind; |
| 790 Map get messageArguments; | 820 Map get messageArguments; |
| 791 Element get existingElement; | 821 Element get existingElement; |
| 792 Element get newElement; | 822 Element get newElement; |
| 793 } | 823 } |
| 794 | 824 |
| 795 // TODO(kasperl): This probably shouldn't be called an element. It's | 825 // TODO(kasperl): This probably shouldn't be called an element. It's |
| 796 // just an interface shared by classes and libraries. | 826 // just an interface shared by classes and libraries. |
| 797 abstract class ScopeContainerElement implements Element { | 827 abstract class ScopeContainerElement implements Element { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 } | 981 } |
| 952 | 982 |
| 953 /// A top level, static or instance field, a formal parameter or local variable. | 983 /// A top level, static or instance field, a formal parameter or local variable. |
| 954 abstract class VariableElement extends ExecutableElement { | 984 abstract class VariableElement extends ExecutableElement { |
| 955 Expression get initializer; | 985 Expression get initializer; |
| 956 } | 986 } |
| 957 | 987 |
| 958 /// An entity that defines a local entity (memory slot) in generated code. | 988 /// An entity that defines a local entity (memory slot) in generated code. |
| 959 /// | 989 /// |
| 960 /// Parameters, local variables and local functions (can) define local entity | 990 /// Parameters, local variables and local functions (can) define local entity |
| 961 /// and thus implement [Local] through [LocalElement]. For | 991 /// and thus implement [Local] through [LocalElement]. For non-element locals, |
| 962 /// non-element locals, like `this` and boxes, specialized [Local] class are | 992 /// like `this` and boxes, specialized [Local] classes are created. |
| 963 /// created. | |
| 964 /// | 993 /// |
| 965 /// Type variables can introduce locals in factories and constructors | 994 /// Type variables can introduce locals in factories and constructors |
| 966 /// but since one type variable can introduce different locals in different | 995 /// but since one type variable can introduce different locals in different |
| 967 /// factories and constructors it is not itself a [Local] but instead | 996 /// factories and constructors it is not itself a [Local] but instead |
| 968 /// a non-element [Local] is created through a specialized class. | 997 /// a non-element [Local] is created through a specialized class. |
| 969 // TODO(johnniwinther): Should [Local] have `isAssignable` or `type`? | 998 // TODO(johnniwinther): Should [Local] have `isAssignable` or `type`? |
| 970 abstract class Local extends Entity { | 999 abstract class Local extends Entity { |
| 971 /// The context in which this local is defined. | 1000 /// The context in which this local is defined. |
| 972 ExecutableElement get executableContext; | 1001 ExecutableElement get executableContext; |
| 973 } | 1002 } |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1516 bool get isDeclaredByField; | 1545 bool get isDeclaredByField; |
| 1517 | 1546 |
| 1518 /// Returns `true` if this member is abstract. | 1547 /// Returns `true` if this member is abstract. |
| 1519 bool get isAbstract; | 1548 bool get isAbstract; |
| 1520 | 1549 |
| 1521 /// If abstract, [implementation] points to the overridden concrete member, | 1550 /// If abstract, [implementation] points to the overridden concrete member, |
| 1522 /// if any. Otherwise [implementation] points to the member itself. | 1551 /// if any. Otherwise [implementation] points to the member itself. |
| 1523 Member get implementation; | 1552 Member get implementation; |
| 1524 } | 1553 } |
| 1525 | 1554 |
| OLD | NEW |