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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart

Issue 1375513002: dart2js cps: Add helpers for common IR manipulation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix type annotation Created 5 years, 3 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 | « no previous file | pkg/compiler/lib/src/cps_ir/insert_refinements.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
index 44152148716a7d7f89dcd38c424dd8cabb29c78e..19b0543c179877ab2a4d7ba2c7061d8822b6f116 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
@@ -76,6 +76,42 @@ abstract class InteriorNode extends Node {
/// [LetMutable].
abstract class InteriorExpression extends Expression implements InteriorNode {
Expression get next => body;
+
+ /// Removes this expression from its current position in the IR.
+ ///
+ /// The node can be re-inserted elsewhere or remain orphaned.
+ ///
+ /// If orphaned, the caller is responsible for unlinking all references in
+ /// the orphaned node. Use [Reference.unlink] or [Primitive.destroy] for this.
+ void remove() {
+ assert(parent != null);
+ assert(parent.body == this);
+ assert(body.parent == this);
+ parent.body = body;
+ body.parent = parent;
+ parent = null;
+ body = null;
+ }
+
+ /// Inserts this above [node].
+ ///
+ /// This node must be orphaned first.
+ void insertAbove(Expression node) {
+ insertBelow(node.parent);
+ }
+
+ /// Inserts this below [node].
+ ///
+ /// This node must be orphaned first.
+ void insertBelow(InteriorNode newParent) {
+ assert(parent == null);
+ assert(body == null);
+ Expression child = newParent.body;
+ newParent.body = this;
+ this.body = child;
+ child.parent = this;
+ this.parent = newParent;
+ }
}
/// An expression that passes a continuation to a call.
@@ -217,6 +253,12 @@ abstract class Primitive extends Variable<Primitive> {
bool get hasNoEffectiveUses {
return effectiveUses.isEmpty;
}
+
+ /// Unlinks all references contained in this node.
+ void destroy() {
+ assert(hasNoUses);
+ RemovalVisitor.remove(this);
+ }
}
/// Operands to invocations and primitives are always variables. They point to
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/insert_refinements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698