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

Unified Diff: frog/value.dart

Issue 9666031: Frog: preserve initialization order. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: status Created 8 years, 9 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 | « frog/minfrog ('k') | tests/language/language.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/value.dart
diff --git a/frog/value.dart b/frog/value.dart
index 7268e160ce4a37ce4a530a2bdc285b042b64ae20..c3758ec3877028738da8e310ab4e2e932a9033bd 100644
--- a/frog/value.dart
+++ b/frog/value.dart
@@ -1344,12 +1344,13 @@ class MapValue extends EvaluatedValue {
class ObjectValue extends EvaluatedValue {
final Map<FieldMember, Value> fields;
+ final List<FieldMember> fieldsInInitOrder;
bool seenNativeInitializer = false;
String _code;
ObjectValue(bool isConst, Type type, SourceSpan span):
- fields = {}, super(isConst, type, span);
+ fields = {}, fieldsInInitOrder = [], super(isConst, type, span);
String get code() {
if (_code === null) validateInitialized(null);
@@ -1360,7 +1361,7 @@ class ObjectValue extends EvaluatedValue {
var allMembers = world.gen._orderValues(type.genericType.getAllMembers());
for (var f in allMembers) {
if (f.isField && !f.isStatic && f.declaringType.isClass) {
- fields[f] = f.computeValue();
+ _replaceField(f, f.computeValue(), true);
}
}
}
@@ -1376,7 +1377,7 @@ class ObjectValue extends EvaluatedValue {
}
if (currentValue === null) {
- fields[field] = value;
+ _replaceField(field, value, duringInit);
if (field.isFinal && !duringInit) {
world.error('cannot initialize final fields outside of initializer',
value.span);
@@ -1387,11 +1388,25 @@ class ObjectValue extends EvaluatedValue {
world.error('reassignment of field not allowed', value.span,
field.span);
} else {
- fields[field] = value; //currentValue.union(value);
+ _replaceField(field, value, duringInit);
}
}
}
+ _replaceField(Member field, Value value, bool duringInit) {
+ if (duringInit) {
+ for (int i = 0; i < fieldsInInitOrder.length; i++) {
+ if (fieldsInInitOrder[i] == field) {
+ fieldsInInitOrder[i] = null;
+ break;
+ }
+ }
+ // TODO(sra): What if the overridden value contains an effect?
+ fieldsInInitOrder.add(field);
+ }
+ fields[field] = value; //currentValue.union(value);
+ }
+
validateInitialized(SourceSpan span) {
var buf = new StringBuffer();
buf.add('Object.create(');
« no previous file with comments | « frog/minfrog ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698