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

Unified Diff: pkg/compiler/lib/src/resolution/constructors.dart

Issue 1559233002: WIP: Compute constant expressions in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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/js_backend/namer.dart ('k') | pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/resolution/constructors.dart
diff --git a/pkg/compiler/lib/src/resolution/constructors.dart b/pkg/compiler/lib/src/resolution/constructors.dart
index 7b6808fcf4e62ec0c2cbc8d9857b1a76be2ba3a8..de5be38d6e3e7af0bb519d0a7aa95f1084d0af58 100644
--- a/pkg/compiler/lib/src/resolution/constructors.dart
+++ b/pkg/compiler/lib/src/resolution/constructors.dart
@@ -8,6 +8,7 @@ import '../common.dart';
import '../compiler.dart' show
Compiler;
import '../constants/constructors.dart' show
+ ErroneousConstantConstructor,
GenerativeConstantConstructor,
RedirectingGenerativeConstantConstructor;
import '../constants/expressions.dart';
@@ -131,12 +132,20 @@ class InitializerResolver {
init.arguments.head,
inConstantInitializer: isConst);
if (isConst) {
- if (result.isConstant && field != null) {
- // TODO(johnniwinther): Report error if `result.constant` is `null`.
- fieldInitializers[field] = result.constant;
+ ConstantExpression constant;
+ if (result.isConstant) {
+ constant = result.constant;
} else {
+ if (field != null) {
+ reporter.reportErrorMessage(
+ init, MessageKind.NOT_A_COMPILE_TIME_CONSTANT);
+ }
+ constant = new ErroneousConstantExpression();
isValidAsConstant = false;
}
+ if (field != null) {
+ fieldInitializers[field] = constant;
+ }
}
}
@@ -393,11 +402,16 @@ class InitializerResolver {
} else {
isValidAsConstant = false;
}
- if (isConst && isValidAsConstant) {
- constructor.constantConstructor =
- new RedirectingGenerativeConstantConstructor(
- defaultValues,
- constructorInvocation);
+ if (isConst) {
+ if (isValidAsConstant) {
+ constructor.constantConstructor =
+ new RedirectingGenerativeConstantConstructor(
+ defaultValues,
+ constructorInvocation);
+ } else {
+ constructor.constantConstructor =
+ const ErroneousConstantConstructor();
+ }
}
}
return result.element;
@@ -409,17 +423,43 @@ class InitializerResolver {
} else {
reporter.reportErrorMessage(
link.head, MessageKind.INVALID_INITIALIZER);
+ isValidAsConstant = false;
}
}
if (!resolvedSuper) {
constructorInvocation = resolveImplicitSuperConstructorSend();
}
- if (isConst && isValidAsConstant) {
- constructor.constantConstructor = new GenerativeConstantConstructor(
- constructor.enclosingClass.thisType,
- defaultValues,
- fieldInitializers,
- constructorInvocation);
+ if (isConst) {
+ ClassElement enclosingClass = constructor.enclosingClass;
+ enclosingClass.implementation.forEachInstanceField(
+ (ClassElement enclosingClass, FieldElementX field) {
+ if (field.isFinal) {
+ if (!fieldInitializers.containsKey(field)) {
+ visitor.compiler.resolver.resolveField(field);
+ Expression initializer = field.initializer;
+ if (initializer != null) {
+ fieldInitializers[field] = field.constant;
+ } else {
+ /*warning(functionNode, MessageKind.UNINITIALIZED_FINAL_FIELD, {
+ 'fieldName': field.name,
+ });*/
+ fieldInitializers[field] = new NullConstantExpression();
+ }
+ }
+ } else {
+ isValidAsConstant = false;
+ }
+ });
+ if (isValidAsConstant) {
+ constructor.constantConstructor = new GenerativeConstantConstructor(
+ enclosingClass.thisType,
+ defaultValues,
+ fieldInitializers,
+ constructorInvocation);
+ } else {
+ constructor.constantConstructor =
+ const ErroneousConstantConstructor();
+ }
}
return null; // If there was no redirection always return null.
}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698