OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fletchc.fletch_system_builder; | 5 library fletchc.fletch_system_builder; |
6 | 6 |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import 'package:compiler/src/constants/values.dart' show | 9 import 'package:compiler/src/constants/values.dart' show |
10 ConstantValue, | 10 ConstantValue, |
11 ConstructedConstantValue, | 11 ConstructedConstantValue, |
12 DeferredConstantValue, | 12 DeferredConstantValue, |
13 FunctionConstantValue, | 13 FunctionConstantValue, |
14 IntConstantValue, | 14 IntConstantValue, |
15 ListConstantValue, | 15 ListConstantValue, |
16 MapConstantValue, | 16 MapConstantValue, |
17 StringConstantValue; | 17 StringConstantValue; |
18 | 18 |
19 import 'package:compiler/src/elements/elements.dart' show | 19 import 'package:compiler/src/elements/elements.dart' show |
20 ClassElement, | 20 ClassElement, |
21 ConstructorElement, | 21 ConstructorElement, |
22 Element, | 22 Element, |
23 FieldElement, | |
23 FunctionElement, | 24 FunctionElement, |
24 FunctionSignature; | 25 FunctionSignature, |
26 MemberElement; | |
25 | 27 |
26 import 'package:compiler/src/universe/universe.dart' show | 28 import 'package:compiler/src/universe/call_structure.dart' show |
27 CallStructure; | 29 CallStructure; |
28 | 30 |
29 import 'package:persistent/persistent.dart' show | 31 import 'package:persistent/persistent.dart' show |
30 PersistentMap; | 32 PersistentMap; |
31 | 33 |
32 import 'fletch_constants.dart' show | 34 import 'fletch_constants.dart' show |
33 FletchClassConstant, | 35 FletchClassConstant, |
34 FletchFunctionConstant, | 36 FletchFunctionConstant, |
35 FletchClassInstanceConstant; | 37 FletchClassInstanceConstant; |
36 | 38 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 int changes = 0; | 356 int changes = 0; |
355 | 357 |
356 // Remove all removed FletchFunctions. | 358 // Remove all removed FletchFunctions. |
357 for (FletchFunction function in _removedFunctions) { | 359 for (FletchFunction function in _removedFunctions) { |
358 commands.add(new RemoveFromMap(MapId.methods, function.functionId)); | 360 commands.add(new RemoveFromMap(MapId.methods, function.functionId)); |
359 } | 361 } |
360 | 362 |
361 // Create all new FletchFunctions. | 363 // Create all new FletchFunctions. |
362 List<FletchFunction> functions = <FletchFunction>[]; | 364 List<FletchFunction> functions = <FletchFunction>[]; |
363 for (FletchFunctionBuilder builder in _newFunctions) { | 365 for (FletchFunctionBuilder builder in _newFunctions) { |
364 context.compiler.withCurrentElement(builder.element, () { | 366 context.compiler.reporter.withCurrentElement(builder.element, () { |
365 functions.add(builder.finalizeFunction(context, commands)); | 367 functions.add(builder.finalizeFunction(context, commands)); |
366 }); | 368 }); |
367 } | 369 } |
368 | 370 |
369 // Create all new FletchClasses. | 371 // Create all new FletchClasses. |
370 List<FletchClass> classes = <FletchClass>[]; | 372 List<FletchClass> classes = <FletchClass>[]; |
371 for (FletchClassBuilder builder in _newClasses.values) { | 373 for (FletchClassBuilder builder in _newClasses.values) { |
372 classes.add(builder.finalizeClass(context, commands)); | 374 classes.add(builder.finalizeClass(context, commands)); |
373 changes++; | 375 changes++; |
374 } | 376 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 int tearoffId = lookupTearOffById(function.functionId); | 480 int tearoffId = lookupTearOffById(function.functionId); |
479 FletchFunctionBase tearoff = lookupFunction(tearoffId); | 481 FletchFunctionBase tearoff = lookupFunction(tearoffId); |
480 commands | 482 commands |
481 ..add(new PushFromMap(MapId.classes, tearoff.memberOf)) | 483 ..add(new PushFromMap(MapId.classes, tearoff.memberOf)) |
482 ..add(const PushNewInstance()); | 484 ..add(const PushNewInstance()); |
483 } else if (constant.isConstructedObject) { | 485 } else if (constant.isConstructedObject) { |
484 ConstructedConstantValue value = constant; | 486 ConstructedConstantValue value = constant; |
485 ClassElement classElement = value.type.element; | 487 ClassElement classElement = value.type.element; |
486 // TODO(ajohnsen): Avoid usage of builders (should be FletchClass). | 488 // TODO(ajohnsen): Avoid usage of builders (should be FletchClass). |
487 FletchClassBuilder classBuilder = _classBuildersByElement[classElement]; | 489 FletchClassBuilder classBuilder = _classBuildersByElement[classElement]; |
488 for (ConstantValue field in value.fields.values) { | 490 |
489 int fieldId = context.compiledConstants[field]; | 491 void addIfField(MemberElement member) { |
492 if (!member.isField || member.isStatic || member.isPatch) return; | |
493 FieldElement fieldElement = member; | |
494 ConstantValue fieldValue = value.fields[fieldElement]; | |
495 int fieldId = context.compiledConstants[fieldValue]; | |
490 commands.add(new PushFromMap(MapId.constants, fieldId)); | 496 commands.add(new PushFromMap(MapId.constants, fieldId)); |
491 } | 497 } |
498 | |
499 // Adds all the fields of [currentClass] in order starting from the top | |
500 // of the inheritance chain, and for each class adds non-patch fields | |
501 // before patch fields. | |
502 void addFields(ClassElement currentClass) { | |
503 if (currentClass.superclass != null) { | |
504 addFields(currentClass.superclass); | |
505 } | |
506 currentClass.forEachLocalMember(addIfField); | |
ahe
2015/11/17 16:44:09
Why not forEachInstanceField?
sigurdm
2015/11/19 14:33:47
forEachInstanceField has in the end calls forEachL
| |
507 if (currentClass.isPatched) { | |
508 currentClass.patch.forEachLocalMember(addIfField); | |
509 } | |
510 } | |
511 | |
512 addFields(classElement); | |
513 | |
492 commands | 514 commands |
493 ..add(new PushFromMap(MapId.classes, classBuilder.classId)) | 515 ..add(new PushFromMap(MapId.classes, classBuilder.classId)) |
494 ..add(const PushNewInstance()); | 516 ..add(const PushNewInstance()); |
495 } else if (constant is FletchClassInstanceConstant) { | 517 } else if (constant is FletchClassInstanceConstant) { |
496 commands | 518 commands |
497 ..add(new PushFromMap(MapId.classes, constant.classId)) | 519 ..add(new PushFromMap(MapId.classes, constant.classId)) |
498 ..add(const PushNewInstance()); | 520 ..add(const PushNewInstance()); |
499 } else if (constant.isType) { | 521 } else if (constant.isType) { |
500 // TODO(kasperl): Implement proper support for class literals. At this | 522 // TODO(kasperl): Implement proper support for class literals. At this |
501 // point, we've already issues unimplemented errors for the individual | 523 // point, we've already issues unimplemented errors for the individual |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 constructorInitializersByElement, | 690 constructorInitializersByElement, |
669 tearoffsById, | 691 tearoffsById, |
670 classesById, | 692 classesById, |
671 classesByElement, | 693 classesByElement, |
672 constants, | 694 constants, |
673 symbolByFletchSelectorId, | 695 symbolByFletchSelectorId, |
674 gettersByFieldIndex, | 696 gettersByFieldIndex, |
675 settersByFieldIndex); | 697 settersByFieldIndex); |
676 } | 698 } |
677 } | 699 } |
OLD | NEW |