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

Unified Diff: pkg/compiler/lib/src/compile_time_constants.dart

Issue 1994613004: Handle use of constant constructors with default values. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment Created 4 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | pkg/compiler/lib/src/elements/elements.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/compile_time_constants.dart
diff --git a/pkg/compiler/lib/src/compile_time_constants.dart b/pkg/compiler/lib/src/compile_time_constants.dart
index 82cc6de475a33f0a2bab749c9271307236783804..3aa8779a43713833f6006254639b3be91a78b316 100644
--- a/pkg/compiler/lib/src/compile_time_constants.dart
+++ b/pkg/compiler/lib/src/compile_time_constants.dart
@@ -16,7 +16,7 @@ import 'constants/values.dart';
import 'core_types.dart' show CoreTypes;
import 'dart_types.dart';
import 'elements/elements.dart';
-import 'elements/modelx.dart' show FieldElementX, FunctionElementX;
+import 'elements/modelx.dart' show FieldElementX, FunctionElementX, ConstantVariableMixin;
import 'resolution/tree_elements.dart' show TreeElements;
import 'resolution/operators.dart';
import 'tree/tree.dart';
@@ -187,8 +187,15 @@ abstract class ConstantCompilerBase implements ConstantCompiler {
ConstantExpression result = initialVariableValues[element.declaration];
return result;
}
+ if (element.hasConstant) {
+ if (element.constant != null &&
+ compiler.serialization.supportsDeserialization) {
+ evaluate(element.constant);
+ }
+ return element.constant;
+ }
AstElement currentElement = element.analyzableElement;
- return reporter.withCurrentElement(currentElement, () {
+ return reporter.withCurrentElement(element, () {
// TODO(johnniwinther): Avoid this eager analysis.
compiler.resolution.ensureResolved(currentElement.declaration);
@@ -206,7 +213,7 @@ abstract class ConstantCompilerBase implements ConstantCompiler {
* error.
*/
ConstantExpression compileVariableWithDefinitions(
- VariableElement element, TreeElements definitions,
+ ConstantVariableMixin element, TreeElements definitions,
{bool isConst: false, bool checkType: true}) {
Node node = element.node;
if (pendingVariables.contains(element)) {
@@ -262,6 +269,7 @@ abstract class ConstantCompilerBase implements ConstantCompiler {
}
}
if (expression != null) {
+ element.constant = expression;
initialVariableValues[element.declaration] = expression;
} else {
assert(invariant(element, !isConst,
@@ -1280,13 +1288,12 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
Map<FieldElement, AstConstant> fieldConstants =
<FieldElement, AstConstant>{};
classElement.implementation.forEachInstanceField(
- (ClassElement enclosing, FieldElementX field) {
+ (ClassElement enclosing, FieldElement field) {
AstConstant fieldValue = fieldValues[field];
if (fieldValue == null) {
// Use the default value.
ConstantExpression fieldExpression =
handler.internalCompileVariable(field, true, false);
- field.constant = fieldExpression;
fieldValue = new AstConstant.fromDefaultValue(
field, fieldExpression, handler.getConstantValue(fieldExpression));
// TODO(het): If the field value doesn't typecheck due to the type
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | pkg/compiler/lib/src/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698