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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_fragment.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: 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 unified diff | Download patch
OLDNEW
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/selector.dart' show Selector; 9 import '../universe/selector.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 'parent_visitor.dart';
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 /// 77 ///
77 /// Afterwards the fragment is closed and cannot be extended until a new 78 /// Afterwards the fragment is closed and cannot be extended until a new
78 /// [context] is set. 79 /// [context] is set.
79 void put(Expression node) { 80 void put(Expression node) {
80 assert(root == null || context != null); // We must put the node somewhere. 81 assert(root == null || context != null); // We must put the node somewhere.
81 if (root == null) { 82 if (root == null) {
82 root = node; 83 root = node;
83 } 84 }
84 if (context != null) { 85 if (context != null) {
85 context.body = node; 86 context.body = node;
87 node.parent = context;
86 } 88 }
87 context = null; 89 context = null;
88 } 90 }
89 91
90 /// Bind a primitive. Returns the same primitive for convenience. 92 /// Bind a primitive. Returns the same primitive for convenience.
91 Primitive letPrim(Primitive prim) { 93 Primitive letPrim(Primitive prim) {
92 assert(prim != null); 94 assert(prim != null);
93 LetPrim let = new LetPrim(prim); 95 LetPrim let = new LetPrim(prim);
94 put(let); 96 put(let);
95 context = let; 97 context = let;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 void setMutable(MutableVariable variable, Primitive value) { 292 void setMutable(MutableVariable variable, Primitive value) {
291 letPrim(new SetMutable(variable, value)); 293 letPrim(new SetMutable(variable, value));
292 } 294 }
293 295
294 /// Declare a new mutable variable. 296 /// Declare a new mutable variable.
295 void letMutable(MutableVariable variable, Primitive initialValue) { 297 void letMutable(MutableVariable variable, Primitive initialValue) {
296 LetMutable let = new LetMutable(variable, initialValue); 298 LetMutable let = new LetMutable(variable, initialValue);
297 put(let); 299 put(let);
298 context = let; 300 context = let;
299 } 301 }
302
303 void insertBelow(InteriorNode node) {
304 assert(isOpen);
305 if (isEmpty) return;
306 Expression child = node.body;
307 node.body = root;
308 root.parent = node;
309 context.body = child;
310 child.parent = context;
311 root = context = null;
312 }
313
314 void insertAbove(InteriorExpression node) {
315 insertBelow(node.parent);
316 }
300 } 317 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698