Index: packages/analyzer/lib/src/generated/constant.dart |
diff --git a/analyzer/lib/src/generated/constant.dart b/packages/analyzer/lib/src/generated/constant.dart |
similarity index 96% |
rename from analyzer/lib/src/generated/constant.dart |
rename to packages/analyzer/lib/src/generated/constant.dart |
index 572caab8e0fff2200e8ff794b35ed9de9155d7d0..0f4c0f6ebb0de586599a9d557eb3e8bf46d75e68 100644 |
--- a/analyzer/lib/src/generated/constant.dart |
+++ b/packages/analyzer/lib/src/generated/constant.dart |
@@ -2,9 +2,6 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-// This code was auto-generated, is not intended to be edited, and is subject to |
-// significant change. Please see the README file for more information. |
- |
library engine.constant; |
import 'dart:collection'; |
@@ -217,6 +214,11 @@ class ConstantEvaluationEngine { |
"^(?:${ConstantValueComputer._OPERATOR_RE}\$|$_PUBLIC_IDENTIFIER_RE(?:=?\$|[.](?!\$)))+?\$"); |
/** |
+ * The type provider used to access the known types. |
+ */ |
+ final TypeProvider typeProvider; |
+ |
+ /** |
* The type system. This is used to gues the types of constants when their |
* exact value is unknown. |
*/ |
@@ -240,17 +242,12 @@ class ConstantEvaluationEngine { |
* given, is used to verify correct dependency analysis when running unit |
* tests. |
*/ |
- ConstantEvaluationEngine(TypeProvider typeProvider, this._declaredVariables, |
- {ConstantEvaluationValidator validator}) |
+ ConstantEvaluationEngine(this.typeProvider, this._declaredVariables, |
+ {ConstantEvaluationValidator validator, TypeSystem typeSystem}) |
: validator = validator != null |
- ? validator |
- : new ConstantEvaluationValidator_ForProduction(), |
- typeSystem = new TypeSystemImpl(typeProvider); |
- |
- /** |
- * The type provider used to access the known types. |
- */ |
- TypeProvider get typeProvider => typeSystem.typeProvider; |
+ ? validator |
+ : new ConstantEvaluationValidator_ForProduction(), |
+ typeSystem = typeSystem != null ? typeSystem : new TypeSystemImpl(); |
/** |
* Check that the arguments to a call to fromEnvironment() are correct. The |
@@ -261,7 +258,8 @@ class ConstantEvaluationEngine { |
* "defaultValue" is always allowed to be null. Return `true` if the arguments |
* are correct, `false` if there is an error. |
*/ |
- bool checkFromEnvironmentArguments(NodeList<Expression> arguments, |
+ bool checkFromEnvironmentArguments( |
+ NodeList<Expression> arguments, |
List<DartObjectImpl> argumentValues, |
HashMap<String, DartObjectImpl> namedArgumentValues, |
InterfaceType expectedDefaultValueType) { |
@@ -300,7 +298,8 @@ class ConstantEvaluationEngine { |
* named arguments. Return `true` if the arguments are correct, `false` if |
* there is an error. |
*/ |
- bool checkSymbolArguments(NodeList<Expression> arguments, |
+ bool checkSymbolArguments( |
+ NodeList<Expression> arguments, |
List<DartObjectImpl> argumentValues, |
HashMap<String, DartObjectImpl> namedArgumentValues) { |
if (arguments.length != 1) { |
@@ -352,7 +351,8 @@ class ConstantEvaluationEngine { |
if (!runtimeTypeMatch(dartObject, constant.type)) { |
errorReporter.reportErrorForElement( |
CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
- constant, [dartObject.type, constant.type]); |
+ constant, |
+ [dartObject.type, constant.type]); |
} |
} |
(constant as VariableElementImpl).evaluationResult = |
@@ -400,8 +400,11 @@ class ConstantEvaluationEngine { |
errorListener, sourceCompilationUnit.element.source); |
ConstantVisitor constantVisitor = |
new ConstantVisitor(this, errorReporter); |
- DartObjectImpl result = evaluateConstructorCall(constNode, |
- constNode.arguments.arguments, element, constantVisitor, |
+ DartObjectImpl result = evaluateConstructorCall( |
+ constNode, |
+ constNode.arguments.arguments, |
+ element, |
+ constantVisitor, |
errorReporter); |
elementAnnotation.evaluationResult = |
new EvaluationResultImpl(result, errorListener.errors); |
@@ -546,7 +549,8 @@ class ConstantEvaluationEngine { |
* fromEnvironment(). Return a [DartObjectImpl] object corresponding to the |
* evaluated result. |
*/ |
- DartObjectImpl computeValueFromEnvironment(DartObject environmentValue, |
+ DartObjectImpl computeValueFromEnvironment( |
+ DartObject environmentValue, |
DartObjectImpl builtInDefaultValue, |
HashMap<String, DartObjectImpl> namedArgumentValues) { |
DartObjectImpl value = environmentValue as DartObjectImpl; |
@@ -573,9 +577,12 @@ class ConstantEvaluationEngine { |
return value; |
} |
- DartObjectImpl evaluateConstructorCall(AstNode node, |
- NodeList<Expression> arguments, ConstructorElement constructor, |
- ConstantVisitor constantVisitor, ErrorReporter errorReporter) { |
+ DartObjectImpl evaluateConstructorCall( |
+ AstNode node, |
+ NodeList<Expression> arguments, |
+ ConstructorElement constructor, |
+ ConstantVisitor constantVisitor, |
+ ErrorReporter errorReporter) { |
if (!_getConstructorBase(constructor).isCycleFree) { |
// It's not safe to evaluate this constructor, so bail out. |
// TODO(paulberry): ensure that a reasonable error message is produced |
@@ -624,21 +631,24 @@ class ConstantEvaluationEngine { |
DartObject valueFromEnvironment; |
valueFromEnvironment = |
_declaredVariables.getBool(typeProvider, variableName); |
- return computeValueFromEnvironment(valueFromEnvironment, |
+ return computeValueFromEnvironment( |
+ valueFromEnvironment, |
new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE), |
namedArgumentValues); |
} else if (identical(definingClass, typeProvider.intType)) { |
DartObject valueFromEnvironment; |
valueFromEnvironment = |
_declaredVariables.getInt(typeProvider, variableName); |
- return computeValueFromEnvironment(valueFromEnvironment, |
+ return computeValueFromEnvironment( |
+ valueFromEnvironment, |
new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE), |
namedArgumentValues); |
} else if (identical(definingClass, typeProvider.stringType)) { |
DartObject valueFromEnvironment; |
valueFromEnvironment = |
_declaredVariables.getString(typeProvider, variableName); |
- return computeValueFromEnvironment(valueFromEnvironment, |
+ return computeValueFromEnvironment( |
+ valueFromEnvironment, |
new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE), |
namedArgumentValues); |
} |
@@ -690,7 +700,8 @@ class ConstantEvaluationEngine { |
if (fieldValue != null && !runtimeTypeMatch(fieldValue, fieldType)) { |
errorReporter.reportErrorForNode( |
CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
- node, [fieldValue.type, field.name, fieldType]); |
+ node, |
+ [fieldValue.type, field.name, fieldType]); |
} |
fieldMap[field.name] = evaluationResult.value; |
} |
@@ -737,7 +748,8 @@ class ConstantEvaluationEngine { |
if (!runtimeTypeMatch(argumentValue, parameter.type)) { |
errorReporter.reportErrorForNode( |
CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
- errorTarget, [argumentValue.type, parameter.type]); |
+ errorTarget, |
+ [argumentValue.type, parameter.type]); |
} |
if (baseParameter.isInitializingFormal) { |
FieldElement field = (parameter as FieldFormalParameterElement).field; |
@@ -750,7 +762,8 @@ class ConstantEvaluationEngine { |
if (!runtimeTypeMatch(argumentValue, fieldType)) { |
errorReporter.reportErrorForNode( |
CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
- errorTarget, [argumentValue.type, fieldType]); |
+ errorTarget, |
+ [argumentValue.type, fieldType]); |
} |
} |
String fieldName = field.name; |
@@ -767,7 +780,8 @@ class ConstantEvaluationEngine { |
} |
} |
ConstantVisitor initializerVisitor = new ConstantVisitor( |
- this, errorReporter, lexicalEnvironment: parameterMap); |
+ this, errorReporter, |
+ lexicalEnvironment: parameterMap); |
String superName = null; |
NodeList<Expression> superArguments = null; |
for (ConstructorInitializer initializer in initializers) { |
@@ -790,7 +804,8 @@ class ConstantEvaluationEngine { |
if (!runtimeTypeMatch(evaluationResult, field.type)) { |
errorReporter.reportErrorForNode( |
CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
- node, [evaluationResult.type, fieldName, field.type]); |
+ node, |
+ [evaluationResult.type, fieldName, field.type]); |
} |
} |
} |
@@ -806,9 +821,12 @@ class ConstantEvaluationEngine { |
// it redirects to. |
ConstructorElement constructor = initializer.staticElement; |
if (constructor != null && constructor.isConst) { |
- return evaluateConstructorCall(node, |
- initializer.argumentList.arguments, constructor, |
- initializerVisitor, errorReporter); |
+ return evaluateConstructorCall( |
+ node, |
+ initializer.argumentList.arguments, |
+ constructor, |
+ initializerVisitor, |
+ errorReporter); |
} |
} |
} |
@@ -828,10 +846,13 @@ class ConstantEvaluationEngine { |
return new DartObjectImpl(definingClass, new GenericState(fieldMap)); |
} |
- void evaluateSuperConstructorCall(AstNode node, |
+ void evaluateSuperConstructorCall( |
+ AstNode node, |
HashMap<String, DartObjectImpl> fieldMap, |
- ConstructorElement superConstructor, NodeList<Expression> superArguments, |
- ConstantVisitor initializerVisitor, ErrorReporter errorReporter) { |
+ ConstructorElement superConstructor, |
+ NodeList<Expression> superArguments, |
+ ConstantVisitor initializerVisitor, |
+ ErrorReporter errorReporter) { |
if (superConstructor != null && superConstructor.isConst) { |
DartObjectImpl evaluationResult = evaluateConstructorCall(node, |
superArguments, superConstructor, initializerVisitor, errorReporter); |
@@ -997,6 +1018,9 @@ class ConstantEvaluationTarget_Annotation implements ConstantEvaluationTarget { |
return false; |
} |
} |
+ |
+ @override |
+ String toString() => 'Constant: $annotation'; |
} |
/** |
@@ -1061,62 +1085,81 @@ class ConstantEvaluationValidator_ForProduction |
void beforeGetParameterDefault(ParameterElement parameter) {} |
} |
-/** |
- * Instances of the class `ConstantEvaluator` evaluate constant expressions to |
- * produce their compile-time value. According to the Dart Language |
- * Specification: |
- * <blockquote> |
- * A constant expression is one of the following: |
- * * A literal number. |
- * * A literal boolean. |
- * * A literal string where any interpolated expression is a compile-time |
- * constant that evaluates to a numeric, string or boolean value or to |
- * <b>null</b>. |
- * * A literal symbol. |
- * * <b>null</b>. |
- * * A qualified reference to a static constant variable. |
- * * An identifier expression that denotes a constant variable, class or type |
- * alias. |
- * * A constant constructor invocation. |
- * * A constant list literal. |
- * * A constant map literal. |
- * * A simple or qualified identifier denoting a top-level function or a static |
- * method. |
- * * A parenthesized expression <i>(e)</i> where <i>e</i> is a constant |
- * expression. |
- * * An expression of the form <i>identical(e<sub>1</sub>, e<sub>2</sub>)</i> |
- * where <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant |
- * expressions and <i>identical()</i> is statically bound to the predefined |
- * dart function <i>identical()</i> discussed above. |
- * * An expression of one of the forms <i>e<sub>1</sub> == e<sub>2</sub></i> or |
- * <i>e<sub>1</sub> != e<sub>2</sub></i> where <i>e<sub>1</sub></i> and |
- * <i>e<sub>2</sub></i> are constant expressions that evaluate to a numeric, |
- * string or boolean value. |
- * * An expression of one of the forms <i>!e</i>, <i>e<sub>1</sub> && |
- * e<sub>2</sub></i> or <i>e<sub>1</sub> || e<sub>2</sub></i>, where <i>e</i>, |
- * <i>e1</sub></i> and <i>e2</sub></i> are constant expressions that evaluate |
- * to a boolean value. |
- * * An expression of one of the forms <i>~e</i>, <i>e<sub>1</sub> ^ |
- * e<sub>2</sub></i>, <i>e<sub>1</sub> & e<sub>2</sub></i>, |
- * <i>e<sub>1</sub> | e<sub>2</sub></i>, <i>e<sub>1</sub> >> |
- * e<sub>2</sub></i> or <i>e<sub>1</sub> << e<sub>2</sub></i>, where |
- * <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant |
- * expressions that evaluate to an integer value or to <b>null</b>. |
- * * An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub> + |
- * e<sub>2</sub></i>, <i>e<sub>1</sub> -e<sub>2</sub></i>, <i>e<sub>1</sub> * |
- * e<sub>2</sub></i>, <i>e<sub>1</sub> / e<sub>2</sub></i>, <i>e<sub>1</sub> |
- * ~/ e<sub>2</sub></i>, <i>e<sub>1</sub> > e<sub>2</sub></i>, |
- * <i>e<sub>1</sub> < e<sub>2</sub></i>, <i>e<sub>1</sub> >= |
- * e<sub>2</sub></i>, <i>e<sub>1</sub> <= e<sub>2</sub></i> or |
- * <i>e<sub>1</sub> % e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> |
- * and <i>e<sub>2</sub></i> are constant expressions that evaluate to a |
- * numeric value or to <b>null</b>. |
- * * An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : |
- * e<sub>3</sub></i> where <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and |
- * <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i> |
- * evaluates to a boolean value. |
- * </blockquote> |
- */ |
+/// Instances of the class [ConstantEvaluator] evaluate constant expressions to |
+/// produce their compile-time value. |
+/// |
+/// According to the Dart Language Specification: |
+/// |
+/// > A constant expression is one of the following: |
+/// > |
+/// > * A literal number. |
+/// > * A literal boolean. |
+/// > * A literal string where any interpolated expression is a compile-time |
+/// > constant that evaluates to a numeric, string or boolean value or to |
+/// > **null**. |
+/// > * A literal symbol. |
+/// > * **null**. |
+/// > * A qualified reference to a static constant variable. |
+/// > * An identifier expression that denotes a constant variable, class or type |
+/// > alias. |
+/// > * A constant constructor invocation. |
+/// > * A constant list literal. |
+/// > * A constant map literal. |
+/// > * A simple or qualified identifier denoting a top-level function or a |
+/// > static method. |
+/// > * A parenthesized expression _(e)_ where _e_ is a constant expression. |
+/// > * <span> |
+/// > An expression of the form <i>identical(e<sub>1</sub>, e<sub>2</sub>)</i> |
+/// > where <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant |
+/// > expressions and <i>identical()</i> is statically bound to the predefined |
+/// > dart function <i>identical()</i> discussed above. |
+/// > </span> |
+/// > * <span> |
+/// > An expression of one of the forms <i>e<sub>1</sub> == e<sub>2</sub></i> |
+/// > or <i>e<sub>1</sub> != e<sub>2</sub></i> where <i>e<sub>1</sub></i> and |
+/// > <i>e<sub>2</sub></i> are constant expressions that evaluate to a |
+/// > numeric, string or boolean value. |
+/// > </span> |
+/// > * <span> |
+/// > An expression of one of the forms <i>!e</i>, <i>e<sub>1</sub> && |
+/// > e<sub>2</sub></i> or <i>e<sub>1</sub> || e<sub>2</sub></i>, where |
+/// > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant |
+/// > expressions that evaluate to a boolean value. |
+/// > </span> |
+/// > * <span> |
+/// > An expression of one of the forms <i>~e</i>, <i>e<sub>1</sub> ^ |
+/// > e<sub>2</sub></i>, <i>e<sub>1</sub> & e<sub>2</sub></i>, |
+/// > <i>e<sub>1</sub> | e<sub>2</sub></i>, <i>e<sub>1</sub> >> |
+/// > e<sub>2</sub></i> or <i>e<sub>1</sub> << e<sub>2</sub></i>, where |
+/// > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant |
+/// > expressions that evaluate to an integer value or to <b>null</b>. |
+/// > </span> |
+/// > * <span> |
+/// > An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub> + |
+/// > e<sub>2</sub></i>, <i>e<sub>1</sub> -e<sub>2</sub></i>, |
+/// > <i>e<sub>1</sub> * e<sub>2</sub></i>, <i>e<sub>1</sub> / |
+/// > e<sub>2</sub></i>, <i>e<sub>1</sub> ~/ e<sub>2</sub></i>, |
+/// > <i>e<sub>1</sub> > e<sub>2</sub></i>, <i>e<sub>1</sub> < |
+/// > e<sub>2</sub></i>, <i>e<sub>1</sub> >= e<sub>2</sub></i>, |
+/// > <i>e<sub>1</sub> <= e<sub>2</sub></i> or <i>e<sub>1</sub> % |
+/// > e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> and |
+/// > <i>e<sub>2</sub></i> are constant expressions that evaluate to a numeric |
+/// > value or to <b>null</b>. |
+/// > </span> |
+/// > * <span> |
+/// > An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : |
+/// > e<sub>3</sub></i> where <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and |
+/// > <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i> |
+/// > evaluates to a boolean value. |
+/// > </span> |
+/// |
+/// The values returned by instances of this class are therefore `null` and |
+/// instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and |
+/// `DartObject`. |
+/// |
+/// In addition, this class defines several values that can be returned to |
+/// indicate various conditions encountered during evaluation. These are |
+/// documented with the static fields that define those values. |
class ConstantEvaluator { |
/** |
* The source containing the expression(s) that will be evaluated. |
@@ -1129,17 +1172,24 @@ class ConstantEvaluator { |
final TypeProvider _typeProvider; |
/** |
+ * The type system primitives. |
+ */ |
+ final TypeSystem _typeSystem; |
+ |
+ /** |
* Initialize a newly created evaluator to evaluate expressions in the given |
* [source]. The [typeProvider] is the type provider used to access known |
* types. |
*/ |
- ConstantEvaluator(this._source, this._typeProvider); |
+ ConstantEvaluator(this._source, this._typeProvider, {TypeSystem typeSystem}) |
+ : _typeSystem = typeSystem != null ? typeSystem : new TypeSystemImpl(); |
EvaluationResult evaluate(Expression expression) { |
RecordingErrorListener errorListener = new RecordingErrorListener(); |
ErrorReporter errorReporter = new ErrorReporter(errorListener, _source); |
DartObjectImpl result = expression.accept(new ConstantVisitor( |
- new ConstantEvaluationEngine(_typeProvider, new DeclaredVariables()), |
+ new ConstantEvaluationEngine(_typeProvider, new DeclaredVariables(), |
+ typeSystem: _typeSystem), |
errorReporter)); |
if (result != null) { |
return EvaluationResult.forValue(result); |
@@ -1283,9 +1333,10 @@ class ConstantValueComputer { |
*/ |
ConstantValueComputer(this._context, TypeProvider typeProvider, |
DeclaredVariables declaredVariables, |
- [ConstantEvaluationValidator validator]) |
+ [ConstantEvaluationValidator validator, TypeSystem typeSystem]) |
: evaluationEngine = new ConstantEvaluationEngine( |
- typeProvider, declaredVariables, validator: validator); |
+ typeProvider, declaredVariables, |
+ validator: validator, typeSystem: typeSystem); |
/** |
* Add the constants in the given compilation [unit] to the list of constants |
@@ -1555,7 +1606,8 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> { |
ParameterizedType thenType = thenResult.type; |
ParameterizedType elseType = elseResult.type; |
return new DartObjectImpl.validWithUnknownValue( |
- _typeSystem.getLeastUpperBound(thenType, elseType) as InterfaceType); |
+ _typeSystem.getLeastUpperBound(_typeProvider, thenType, elseType) |
+ as InterfaceType); |
} |
@override |
@@ -2593,9 +2645,10 @@ class DartObjectImpl implements DartObject { |
* Throws an [EvaluationException] if the operator is not appropriate for an |
* object of this kind. |
*/ |
- DartObjectImpl greaterThanOrEqual(TypeProvider typeProvider, |
- DartObjectImpl rightOperand) => new DartObjectImpl( |
- typeProvider.boolType, _state.greaterThanOrEqual(rightOperand._state)); |
+ DartObjectImpl greaterThanOrEqual( |
+ TypeProvider typeProvider, DartObjectImpl rightOperand) => |
+ new DartObjectImpl(typeProvider.boolType, |
+ _state.greaterThanOrEqual(rightOperand._state)); |
/** |
* Return the result of invoking the '~/' operator on this object with the |
@@ -3526,9 +3579,7 @@ class EvaluationResultImpl { |
} |
@deprecated // Use new EvaluationResultImpl(value, errors) |
- EvaluationResultImpl.con2(this.value, List<AnalysisError> errors) { |
- this._errors = errors; |
- } |
+ EvaluationResultImpl.con2(this.value, List<AnalysisError> this._errors); |
List<AnalysisError> get errors => _errors; |