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

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

Issue 1375213003: dart2js cps: Maintain parent pointers instead of recomputing them. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rebase Created 5 years, 2 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 | « pkg/compiler/lib/src/cps_ir/optimizers.dart ('k') | pkg/compiler/lib/src/cps_ir/redundant_join.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/parent_visitor.dart
diff --git a/pkg/compiler/lib/src/cps_ir/parent_visitor.dart b/pkg/compiler/lib/src/cps_ir/parent_visitor.dart
new file mode 100644
index 0000000000000000000000000000000000000000..33896e0e834e96e7fd73b805f98d44c10d28590f
--- /dev/null
+++ b/pkg/compiler/lib/src/cps_ir/parent_visitor.dart
@@ -0,0 +1,43 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library cps_ir.parent_visitor;
+
+import 'cps_ir_nodes.dart';
+
+/// Traverses the CPS term and sets node.parent for each visited node.
+class ParentVisitor extends DeepRecursiveVisitor {
+ static void setParents(Node node) {
+ ParentVisitor visitor = new ParentVisitor._make();
+ visitor._worklist.add(node);
+ visitor.trampoline();
+ }
+
+ /// Private to avoid accidental `new ParentVisitor().visit(node)` calls.
+ ParentVisitor._make();
+
+ Node _parent;
+ final List<Node> _worklist = <Node>[];
+
+ void trampoline() {
+ while (_worklist.isNotEmpty) {
+ _parent = _worklist.removeLast();
+ _parent.accept(this);
+ }
+ }
+
+ @override
+ visit(Node node) {
+ _worklist.add(node);
+ assert(_parent != node);
+ assert(_parent != null);
+ node.parent = _parent;
+ }
+
+ @override
+ processReference(Reference node) {
+ node.parent = _parent;
+ }
+}
+
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/optimizers.dart ('k') | pkg/compiler/lib/src/cps_ir/redundant_join.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698