| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library cps_ir.cps_fragment; | 5 library cps_ir.cps_fragment; |
| 6 | 6 |
| 7 import 'cps_ir_nodes.dart'; | 7 import 'cps_ir_nodes.dart'; |
| 8 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
| 9 import '../universe/universe.dart' show Selector; | 9 import '../universe/universe.dart' show Selector; |
| 10 import '../types/types.dart' show TypeMask; | 10 import '../types/types.dart' show TypeMask; |
| 11 import '../io/source_information.dart'; | 11 import '../io/source_information.dart'; |
| 12 import '../elements/elements.dart'; | 12 import '../elements/elements.dart'; |
| 13 import 'shrinking_reductions.dart' show ParentVisitor; |
| 13 | 14 |
| 14 /// Builds a CPS fragment that can be plugged into another CPS term. | 15 /// Builds a CPS fragment that can be plugged into another CPS term. |
| 15 /// | 16 /// |
| 16 /// A CPS fragment contains a CPS term, possibly with a "hole" in it denoting | 17 /// A CPS fragment contains a CPS term, possibly with a "hole" in it denoting |
| 17 /// where to insert new IR nodes. We say a fragment is "open" if it has such | 18 /// where to insert new IR nodes. We say a fragment is "open" if it has such |
| 18 /// a hole. Otherwise, the fragment is "closed" and cannot be extended further. | 19 /// a hole. Otherwise, the fragment is "closed" and cannot be extended further. |
| 19 /// | 20 /// |
| 20 /// This class is designed for building non-trivial CPS terms in a readable and | 21 /// This class is designed for building non-trivial CPS terms in a readable and |
| 21 /// non-error prone manner. It is not designed to manipulate existing IR nodes, | 22 /// non-error prone manner. It is not designed to manipulate existing IR nodes, |
| 22 /// nor is it intended to shield the user from every complexity in the IR. | 23 /// nor is it intended to shield the user from every complexity in the IR. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 letPrim(new SetMutable(variable, value)); | 292 letPrim(new SetMutable(variable, value)); |
| 292 } | 293 } |
| 293 | 294 |
| 294 /// Declare a new mutable variable. | 295 /// Declare a new mutable variable. |
| 295 void letMutable(MutableVariable variable, Primitive initialValue) { | 296 void letMutable(MutableVariable variable, Primitive initialValue) { |
| 296 LetMutable let = new LetMutable(variable, initialValue); | 297 LetMutable let = new LetMutable(variable, initialValue); |
| 297 put(let); | 298 put(let); |
| 298 context = let; | 299 context = let; |
| 299 } | 300 } |
| 300 } | 301 } |
| 302 |
| 303 /// Removes [node], unlinking all its references and replaces it with [newNode], |
| 304 /// setting all parent pointers in [newNode]. |
| 305 /// |
| 306 /// Be careful not to pass in a [newNode] containing a existing IR subtree as |
| 307 /// this will generally cause expensive redundant reprocessing. |
| 308 void replaceExpression(Expression node, Expression newNode) { |
| 309 InteriorNode parent = node.parent; |
| 310 RemovalVisitor.remove(node); |
| 311 parent.body = newNode; |
| 312 newNode.parent = parent; |
| 313 ParentVisitor.setParentPointers(newNode); |
| 314 } |
| 315 |
| OLD | NEW |