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

Unified Diff: pkg/kernel/lib/interpreter/interpreter.dart

Issue 2877733002: Add suport for initializer list execution in constructor invocation (Closed)
Patch Set: Created 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/interpreter/interpreter.dart
diff --git a/pkg/kernel/lib/interpreter/interpreter.dart b/pkg/kernel/lib/interpreter/interpreter.dart
index c512a8869125b346f7624a586d32ebf6d121a97a..4ff4ec1e738ae82132348520081ee57f8106ae83 100644
--- a/pkg/kernel/lib/interpreter/interpreter.dart
+++ b/pkg/kernel/lib/interpreter/interpreter.dart
@@ -543,7 +543,7 @@ class ConstructorInvocationApplication extends ApplicationContinuation {
}
var cont = new InstanceFieldsApplication(
- newObject, constructor, expressionContinuation);
+ newObject, constructor, ctrEnv, expressionContinuation);
var fieldExpressions = _createInstanceInitializers(constructor);
return new ExpressionListConfiguration(fieldExpressions, ctrEnv, cont);
@@ -611,12 +611,13 @@ class RedirectingConstructorInvocationApplication
class InstanceFieldsApplication extends ApplicationContinuation {
final ObjectValue newObject;
final Constructor constructor;
+ final Environment environment;
final ExpressionContinuation expressionContinuation;
final Class _currentClass;
- InstanceFieldsApplication(
- this.newObject, this.constructor, this.expressionContinuation)
+ InstanceFieldsApplication(this.newObject, this.constructor, this.environment,
+ this.expressionContinuation)
: _currentClass = new Class(constructor.enclosingClass.reference);
Configuration call(List<InterpreterValue> fieldValues) {
@@ -624,6 +625,50 @@ class InstanceFieldsApplication extends ApplicationContinuation {
_currentClass.setProperty(newObject, current.field, current.value);
}
+ var es = _createInitializerListExpressions(constructor.initializers);
+ List<Initializer> initializers = constructor.initializers.skip(es.length);
+
+ ApplicationContinuation cont = new InitializerListApplication(newObject,
+ constructor, environment, initializers, expressionContinuation);
+
+ return new ExpressionListConfiguration(es, environment, cont);
+ }
+}
+
+/// Represents the application continuation applied on the list of evaluated
+/// initializer expressions preceding a super call in the list.
+class InitializerListApplication extends ApplicationContinuation {
+ final ObjectValue newObject;
+ final Constructor constructor;
+ final Environment environment;
+ final List<Initializer> remainingInitializers;
+ final ExpressionContinuation expressionContinuation;
+
+ final Class _currentClass;
+
+ InitializerListApplication(this.newObject, this.constructor, this.environment,
+ this.remainingInitializers, this.expressionContinuation)
+ : _currentClass = new Class(constructor.enclosingClass.reference);
+
+ Configuration call(List<InterpreterValue> values) {
+ var initEnv = new Environment(environment);
+
+ // Apply values from evaluation to object or/and initializer environment.
+ for (InterpreterValue current in values.reversed) {
+ if (current is LocalInitializerValue) {
+ initEnv.expand(current.variable, current.value);
+ } else if (current is FieldInitializerValue) {
+ _currentClass.setProperty(newObject, current.field, current.value);
+ } else {
+ throw '${current.runtimeType} in InitializerListApplication';
+ }
+ }
+
+ if (remainingInitializers.isNotEmpty) {
+ assert(remainingInitializers.first is SuperInitializer);
+ // todo: Evaluate arguments for super invocation.
+ }
+
return new ContinuationConfiguration(expressionContinuation, newObject);
}
}
@@ -1329,3 +1374,21 @@ List<InterpreterExpression> _createArgumentExpressionList(
return args;
}
+
+List<InterpreterExpression> _createInitializerListExpressions(
+ List<Initializer> initializers) {
+ List<InterpreterExpression> es = <InterpreterExpression>[];
+
+ for (Initializer current in initializers) {
+ if (current is FieldInitializer) {
+ es.add(new FieldInitializerExpression(current.field, current.value));
+ } else if (current is LocalInitializer) {
+ es.add(new LocalInitializerExpression(current.variable));
+ } else {
+ assert(current is SuperInitializer);
+ return es;
+ }
+ }
+
+ return es;
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698