Chromium Code Reviews| Index: pkg/analyzer/lib/src/generated/element.dart |
| diff --git a/pkg/analyzer/lib/src/generated/element.dart b/pkg/analyzer/lib/src/generated/element.dart |
| index 082415cd58cedbf4d92a52ce267d67378d23f01b..24f5c13e72725730d8f558b5ba3fcb474fc69cf6 100644 |
| --- a/pkg/analyzer/lib/src/generated/element.dart |
| +++ b/pkg/analyzer/lib/src/generated/element.dart |
| @@ -1493,13 +1493,19 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl |
| /** |
| * A [FieldElement] for a 'const' field that has an initializer. |
| */ |
| -class ConstFieldElementImpl extends FieldElementImpl { |
| +class ConstFieldElementImpl extends FieldElementImpl |
| + implements ConstVariableElementImpl { |
| /** |
| * The result of evaluating this variable's initializer. |
| */ |
| EvaluationResultImpl _result; |
| /** |
| + * A copy of the AST for the variable's initializer. |
| + */ |
| + Expression _constantInitializer; |
| + |
| + /** |
| * Initialize a newly created field element to have the given [name]. |
| */ |
| ConstFieldElementImpl.con1(Identifier name) : super.forNode(name); |
| @@ -1511,6 +1517,14 @@ class ConstFieldElementImpl extends FieldElementImpl { |
| ConstFieldElementImpl.con2(String name, int offset) : super(name, offset); |
| @override |
| + Expression get constantInitializer => _constantInitializer; |
|
scheglov
2015/04/01 23:34:16
It looks that we don't process this field.
So, why
Paul Berry
2015/04/02 15:18:49
Done.
|
| + |
| + @override |
| + void set constantInitializer(Expression value) { |
| + _constantInitializer = value; |
| + } |
| + |
| + @override |
| EvaluationResultImpl get evaluationResult => _result; |
| @override |
| @@ -1523,16 +1537,36 @@ class ConstFieldElementImpl extends FieldElementImpl { |
| * A [LocalVariableElement] for a local 'const' variable that has an |
| * initializer. |
| */ |
| -class ConstLocalVariableElementImpl extends LocalVariableElementImpl { |
| +class ConstLocalVariableElementImpl extends LocalVariableElementImpl |
| + implements ConstVariableElementImpl { |
| /** |
| * The result of evaluating this variable's initializer. |
| */ |
| EvaluationResultImpl _result; |
| /** |
| + * A copy of the AST for the variable's initializer. |
| + */ |
| + Expression _constantInitializer; |
| + |
| + /** |
| + * Initialize a newly created local variable element to have the given [name] |
| + * and [offset]. |
| + */ |
| + ConstLocalVariableElementImpl(String name, int offset) : super(name, offset); |
| + |
| + /** |
| * Initialize a newly created local variable element to have the given [name]. |
| */ |
| - ConstLocalVariableElementImpl(Identifier name) : super.forNode(name); |
| + ConstLocalVariableElementImpl.forNode(Identifier name) : super.forNode(name); |
| + |
| + @override |
| + Expression get constantInitializer => _constantInitializer; |
| + |
| + @override |
| + void set constantInitializer(Expression value) { |
| + _constantInitializer = value; |
| + } |
| @override |
| EvaluationResultImpl get evaluationResult => _result; |
| @@ -1629,6 +1663,12 @@ class ConstructorElementImpl extends ExecutableElementImpl |
| int nameEnd; |
| /** |
| + * True if this constructor has been found by constant evaluation to be free |
| + * of redirect cycles, and is thus safe to evaluate. |
| + */ |
| + bool isCycleFree = false; |
| + |
| + /** |
| * Initialize a newly created constructor element to have the given [name] and |
| * [offset]. |
| */ |
| @@ -1826,19 +1866,33 @@ class ConstructorMember extends ExecutableMember implements ConstructorElement { |
| * A [TopLevelVariableElement] for a top-level 'const' variable that has an |
| * initializer. |
| */ |
| -class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl { |
| +class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl |
| + implements ConstVariableElementImpl { |
| /** |
| * The result of evaluating this variable's initializer. |
| */ |
| EvaluationResultImpl _result; |
| /** |
| + * A copy of the AST for the variable's initializer. |
| + */ |
| + Expression _constantInitializer; |
| + |
| + /** |
| * Initialize a newly created top-level variable element to have the given |
| * [name]. |
| */ |
| ConstTopLevelVariableElementImpl(Identifier name) : super.forNode(name); |
| @override |
| + Expression get constantInitializer => _constantInitializer; |
| + |
| + @override |
| + void set constantInitializer(Expression value) { |
| + _constantInitializer = value; |
| + } |
| + |
| + @override |
| EvaluationResultImpl get evaluationResult => _result; |
| @override |
| @@ -1848,6 +1902,27 @@ class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl { |
| } |
| /** |
| + * Common interface shared by elements that represent constant variables and |
| + * have initializers. |
| + * |
| + * Note that in correct Dart code, all constant variables must have |
| + * initializers. However, analyzer also needs to handle incorrect Dart code, |
| + * in which case there might be some constant variables that lack initializers. |
| + * This interface is only used for constant variables that have initializers. |
| + * |
| + * This class has "Impl" in the name to emphasize the fact that it is not |
| + * intended to be part of the public API for analyzer. |
|
Brian Wilkerson
2015/04/01 20:31:54
That's a little odd. When I first saw it I assumed
Paul Berry
2015/04/02 15:18:49
Fair enough. I've removed "Impl" from the name of
|
| + */ |
| +abstract class ConstVariableElementImpl |
| + extends PotentiallyConstVariableElementImpl { |
| + /** |
| + * Store a copy of the initializer for this variable (which will later be |
| + * usd for evaluating constants). |
|
Brian Wilkerson
2015/04/01 20:31:54
"usd" --> "used"
Paul Berry
2015/04/02 15:18:49
Done.
|
| + */ |
| + void set constantInitializer(Expression value); |
| +} |
| + |
| +/** |
| * The type associated with elements in the element model. |
| */ |
| abstract class DartType { |
| @@ -3732,7 +3807,7 @@ abstract class FieldElement |
| * A concrete implementation of a [FieldElement]. |
| */ |
| class FieldElementImpl extends PropertyInducingElementImpl |
| - implements FieldElement { |
| + implements FieldElement, PotentiallyConstVariableElementImpl { |
| /** |
| * An empty list of field elements. |
| */ |
| @@ -3750,6 +3825,9 @@ class FieldElementImpl extends PropertyInducingElementImpl |
| FieldElementImpl.forNode(Identifier name) : super.forNode(name); |
| @override |
| + Expression get constantInitializer => null; |
| + |
| + @override |
| ClassElement get enclosingElement => super.enclosingElement as ClassElement; |
| @override |
| @@ -7335,7 +7413,7 @@ abstract class LocalVariableElement implements LocalElement, VariableElement {} |
| * A concrete implementation of a [LocalVariableElement]. |
| */ |
| class LocalVariableElementImpl extends VariableElementImpl |
| - implements LocalVariableElement { |
| + implements LocalVariableElement, PotentiallyConstVariableElementImpl { |
| /** |
| * An empty list of field elements. |
| */ |
| @@ -7365,6 +7443,9 @@ class LocalVariableElementImpl extends VariableElementImpl |
| LocalVariableElementImpl.forNode(Identifier name) : super.forNode(name); |
| @override |
| + Expression get constantInitializer => null; |
| + |
| + @override |
| String get identifier { |
| int enclosingOffset = |
| enclosingElement != null ? enclosingElement.nameOffset : 0; |
| @@ -8527,6 +8608,25 @@ class ParameterMember extends VariableMember implements ParameterElement { |
| } |
| /** |
| + * Common interface shared by elements that might represent constant variables. |
| + * |
| + * This class has "Impl" in the name to emphasize the fact that it is not |
| + * intended to be part of the public API for analyzer. |
| + */ |
| +abstract class PotentiallyConstVariableElementImpl extends VariableElement { |
| + /** |
| + * If this element represents a constant variable, and it has an initializer, |
| + * a copy of the initializer for the constant. Otherwise `null`. |
| + * |
| + * Note that in correct Dart code, all constant variables must have |
| + * initializers. However, analyzer also needs to handle incorrect Dart code, |
| + * in which case there might be some constant variables that lack |
| + * initializers. |
| + */ |
| + Expression get constantInitializer; |
| +} |
| + |
| +/** |
| * A prefix used to import one or more libraries into another library. |
| */ |
| abstract class PrefixElement implements Element { |
| @@ -9307,7 +9407,7 @@ abstract class TopLevelVariableElement implements PropertyInducingElement {} |
| * A concrete implementation of a [TopLevelVariableElement]. |
| */ |
| class TopLevelVariableElementImpl extends PropertyInducingElementImpl |
| - implements TopLevelVariableElement { |
| + implements TopLevelVariableElement, PotentiallyConstVariableElementImpl { |
| /** |
| * An empty list of top-level variable elements. |
| */ |
| @@ -9327,6 +9427,9 @@ class TopLevelVariableElementImpl extends PropertyInducingElementImpl |
| TopLevelVariableElementImpl.forNode(Identifier name) : super.forNode(name); |
| @override |
| + Expression get constantInitializer => null; |
| + |
| + @override |
| bool get isStatic => true; |
| @override |