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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « frog/minfrog ('k') | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 5
6 interface CallingContext { 6 interface CallingContext {
7 MemberSet findMembers(String name); 7 MemberSet findMembers(String name);
8 CounterLog get counters(); 8 CounterLog get counters();
9 Library get library(); 9 Library get library();
10 bool get isStatic(); 10 bool get isStatic();
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 isConst && other.isConst, node.span); 1337 isConst && other.isConst, node.span);
1338 } 1338 }
1339 1339
1340 return super.binop(kind, other, context, node); 1340 return super.binop(kind, other, context, node);
1341 } 1341 }
1342 } 1342 }
1343 1343
1344 1344
1345 class ObjectValue extends EvaluatedValue { 1345 class ObjectValue extends EvaluatedValue {
1346 final Map<FieldMember, Value> fields; 1346 final Map<FieldMember, Value> fields;
1347 final List<FieldMember> fieldsInInitOrder;
1347 bool seenNativeInitializer = false; 1348 bool seenNativeInitializer = false;
1348 1349
1349 String _code; 1350 String _code;
1350 1351
1351 ObjectValue(bool isConst, Type type, SourceSpan span): 1352 ObjectValue(bool isConst, Type type, SourceSpan span):
1352 fields = {}, super(isConst, type, span); 1353 fields = {}, fieldsInInitOrder = [], super(isConst, type, span);
1353 1354
1354 String get code() { 1355 String get code() {
1355 if (_code === null) validateInitialized(null); 1356 if (_code === null) validateInitialized(null);
1356 return _code; 1357 return _code;
1357 } 1358 }
1358 1359
1359 initFields() { 1360 initFields() {
1360 var allMembers = world.gen._orderValues(type.genericType.getAllMembers()); 1361 var allMembers = world.gen._orderValues(type.genericType.getAllMembers());
1361 for (var f in allMembers) { 1362 for (var f in allMembers) {
1362 if (f.isField && !f.isStatic && f.declaringType.isClass) { 1363 if (f.isField && !f.isStatic && f.declaringType.isClass) {
1363 fields[f] = f.computeValue(); 1364 _replaceField(f, f.computeValue(), true);
1364 } 1365 }
1365 } 1366 }
1366 } 1367 }
1367 1368
1368 setField(Member field, Value value, [bool duringInit = false]) { 1369 setField(Member field, Value value, [bool duringInit = false]) {
1369 // Unpack constant values 1370 // Unpack constant values
1370 if (value.isConst && value is VariableValue) { 1371 if (value.isConst && value is VariableValue) {
1371 value = value.dynamic.value; 1372 value = value.dynamic.value;
1372 } 1373 }
1373 var currentValue = fields[field]; 1374 var currentValue = fields[field];
1374 if (isConst && !value.isConst) { 1375 if (isConst && !value.isConst) {
1375 world.error('used of non-const value in const intializer', value.span); 1376 world.error('used of non-const value in const intializer', value.span);
1376 } 1377 }
1377 1378
1378 if (currentValue === null) { 1379 if (currentValue === null) {
1379 fields[field] = value; 1380 _replaceField(field, value, duringInit);
1380 if (field.isFinal && !duringInit) { 1381 if (field.isFinal && !duringInit) {
1381 world.error('cannot initialize final fields outside of initializer', 1382 world.error('cannot initialize final fields outside of initializer',
1382 value.span); 1383 value.span);
1383 } 1384 }
1384 } else { 1385 } else {
1385 // TODO(jimhug): Clarify spec on reinitializing fields with defaults. 1386 // TODO(jimhug): Clarify spec on reinitializing fields with defaults.
1386 if (field.isFinal && field.computeValue() === null) { 1387 if (field.isFinal && field.computeValue() === null) {
1387 world.error('reassignment of field not allowed', value.span, 1388 world.error('reassignment of field not allowed', value.span,
1388 field.span); 1389 field.span);
1389 } else { 1390 } else {
1390 fields[field] = value; //currentValue.union(value); 1391 _replaceField(field, value, duringInit);
1391 } 1392 }
1392 } 1393 }
1393 } 1394 }
1394 1395
1396 _replaceField(Member field, Value value, bool duringInit) {
1397 if (duringInit) {
1398 for (int i = 0; i < fieldsInInitOrder.length; i++) {
1399 if (fieldsInInitOrder[i] == field) {
1400 fieldsInInitOrder[i] = null;
1401 break;
1402 }
1403 }
1404 // TODO(sra): What if the overridden value contains an effect?
1405 fieldsInInitOrder.add(field);
1406 }
1407 fields[field] = value; //currentValue.union(value);
1408 }
1409
1395 validateInitialized(SourceSpan span) { 1410 validateInitialized(SourceSpan span) {
1396 var buf = new StringBuffer(); 1411 var buf = new StringBuffer();
1397 buf.add('Object.create('); 1412 buf.add('Object.create(');
1398 buf.add('${type.jsname}.prototype, '); 1413 buf.add('${type.jsname}.prototype, ');
1399 1414
1400 buf.add('{'); 1415 buf.add('{');
1401 bool addComma = false; 1416 bool addComma = false;
1402 for (var field in fields.getKeys()) { 1417 for (var field in fields.getKeys()) {
1403 if (addComma) buf.add(', '); 1418 if (addComma) buf.add(', ');
1404 buf.add(field.name); 1419 buf.add(field.name);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 } 1652 }
1638 return super.unop(kind, context, node); 1653 return super.unop(kind, context, node);
1639 } 1654 }
1640 Value binop(int kind, var other, CallingContext context, var node) { 1655 Value binop(int kind, var other, CallingContext context, var node) {
1641 if (value != null) { 1656 if (value != null) {
1642 return replaceValue(value.binop(kind, _unwrap(other), context, node)); 1657 return replaceValue(value.binop(kind, _unwrap(other), context, node));
1643 } 1658 }
1644 return super.binop(kind, other, context, node); 1659 return super.binop(kind, other, context, node);
1645 } 1660 }
1646 } 1661 }
OLDNEW
« 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