| OLD | NEW |
| 1 library tree_ir.optimization; | 1 library tree_ir.optimization; |
| 2 | 2 |
| 3 import '../tree_ir_nodes.dart'; | 3 import '../tree_ir_nodes.dart'; |
| 4 import '../../elements/elements.dart'; | |
| 5 import '../../constants/values.dart' as values; | 4 import '../../constants/values.dart' as values; |
| 6 import 'variable_merger.dart'; | 5 import 'variable_merger.dart'; |
| 7 | 6 |
| 8 export 'variable_merger.dart' show VariableMerger; | 7 export 'variable_merger.dart' show VariableMerger; |
| 9 | 8 |
| 10 part 'logical_rewriter.dart'; | 9 part 'logical_rewriter.dart'; |
| 11 part 'loop_rewriter.dart'; | 10 part 'loop_rewriter.dart'; |
| 12 part 'statement_rewriter.dart'; | 11 part 'statement_rewriter.dart'; |
| 13 | 12 |
| 14 /// An optimization pass over the Tree IR. | 13 /// An optimization pass over the Tree IR. |
| 15 abstract class Pass { | 14 abstract class Pass { |
| 16 /// Applies optimizations to root, rewriting it in the process. | 15 /// Applies optimizations to root, rewriting it in the process. |
| 17 void rewrite(ExecutableDefinition root) => root.applyPass(this); | 16 void rewrite(RootNode root); |
| 18 void rewriteFieldDefinition(FieldDefinition root); | |
| 19 void rewriteFunctionDefinition(FunctionDefinition root); | |
| 20 void rewriteConstructorDefinition(ConstructorDefinition root); | |
| 21 | 17 |
| 22 String get passName; | 18 String get passName; |
| 23 } | 19 } |
| 24 | |
| 25 | |
| 26 abstract class PassMixin implements Pass { | |
| 27 void rewrite(ExecutableDefinition root) => root.applyPass(this); | |
| 28 void rewriteExecutableDefinition(ExecutableDefinition root); | |
| 29 void rewriteFieldDefinition(FieldDefinition root) { | |
| 30 if (!root.hasInitializer) return; | |
| 31 rewriteExecutableDefinition(root); | |
| 32 } | |
| 33 void rewriteFunctionDefinition(FunctionDefinition root) { | |
| 34 if (root.isAbstract) return; | |
| 35 rewriteExecutableDefinition(root); | |
| 36 } | |
| 37 void rewriteConstructorDefinition(ConstructorDefinition root) { | |
| 38 if (root.isAbstract) return; | |
| 39 rewriteExecutableDefinition(root); | |
| 40 } | |
| 41 } | |
| 42 | |
| OLD | NEW |