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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart

Issue 833353002: Make scoping more prominent in the CPS IR's printed representation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart2js.ir_nodes_sexpr; 5 library dart2js.ir_nodes_sexpr;
6 6
7 import '../constants/values.dart'; 7 import '../constants/values.dart';
8 import '../util/util.dart'; 8 import '../util/util.dart';
9 import 'cps_ir_nodes.dart'; 9 import 'cps_ir_nodes.dart';
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 String body = indentBlock(() => visit(node.body.body)); 54 String body = indentBlock(() => visit(node.body.body));
55 return '$indentation(FunctionDefinition $name ($parameters) return' 55 return '$indentation(FunctionDefinition $name ($parameters) return'
56 ' ($closureVariables)\n$body)'; 56 ' ($closureVariables)\n$body)';
57 } 57 }
58 58
59 String visitFieldDefinition(FieldDefinition node) { 59 String visitFieldDefinition(FieldDefinition node) {
60 String name = node.element.name; 60 String name = node.element.name;
61 if (node.hasInitializer) { 61 if (node.hasInitializer) {
62 namer.setReturnContinuation(node.body.returnContinuation); 62 namer.setReturnContinuation(node.body.returnContinuation);
63 String body = indentBlock(() => visit(node.body.body)); 63 String body = indentBlock(() => visit(node.body.body));
64 return '$indentation(FieldDefinition $name (return)\n' 64 return '$indentation(FieldDefinition $name () return\n'
65 '$body)'; 65 '$body)';
66 } else { 66 } else {
67 return '$indentation(FieldDefinition $name)'; 67 return '$indentation(FieldDefinition $name)';
68 } 68 }
69 } 69 }
70 70
71 String visitLetPrim(LetPrim node) { 71 String visitLetPrim(LetPrim node) {
72 String name = newValueName(node.primitive); 72 String name = newValueName(node.primitive);
73 String value = visit(node.primitive); 73 String value = visit(node.primitive);
74 String body = visit(node.body); 74 String body = indentBlock(() => visit(node.body));
75 return '$indentation(LetPrim $name $value)\n$body'; 75 return '$indentation(LetPrim ($name $value)\n$body)';
76 } 76 }
77 77
78 String visitLetCont(LetCont node) { 78 String visitLetCont(LetCont node) {
79 String cont = newContinuationName(node.continuation); 79 String cont = newContinuationName(node.continuation);
80 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and 80 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and
81 // should recurse to [visit]. Currently we can't do that, because the 81 // should recurse to [visit]. Currently we can't do that, because the
82 // unstringifier_test produces [LetConts] with dummy arguments on them. 82 // unstringifier_test produces [LetConts] with dummy arguments on them.
83 String parameters = node.continuation.parameters 83 String parameters = node.continuation.parameters
84 .map((p) => ' ${decorator(p, newValueName(p))}') 84 .map((p) => '${decorator(p, newValueName(p))}')
85 .join(''); 85 .join(' ');
86 String contBody = indentBlock(() => visit(node.continuation.body)); 86 String contBody =
87 String body = visit(node.body); 87 indentBlock(() => indentBlock(() => visit(node.continuation.body)));
Kevin Millikin (Google) 2015/01/06 08:01:52 I'd actually like to align these bodies, but that'
88 String body = indentBlock(() => visit(node.body));
88 String op = node.continuation.isRecursive ? 'LetCont*' : 'LetCont'; 89 String op = node.continuation.isRecursive ? 'LetCont*' : 'LetCont';
89 return '$indentation($op ($cont$parameters)\n' 90 return '$indentation($op ($cont ($parameters)\n'
90 '$contBody)\n' 91 '$contBody)\n'
91 '$body'; 92 '$body)';
92 } 93 }
93 94
94 String formatArguments(Invoke node) { 95 String formatArguments(Invoke node) {
95 int positionalArgumentCount = node.selector.positionalArgumentCount; 96 int positionalArgumentCount = node.selector.positionalArgumentCount;
96 List<String> args = new List<String>(); 97 List<String> args = new List<String>();
97 args.addAll( 98 args.addAll(
98 node.arguments.getRange(0, positionalArgumentCount).map(access)); 99 node.arguments.getRange(0, positionalArgumentCount).map(access));
99 for (int i = 0; i < node.selector.namedArgumentCount; ++i) { 100 for (int i = 0; i < node.selector.namedArgumentCount; ++i) {
100 String name = node.selector.namedArguments[i]; 101 String name = node.selector.namedArguments[i];
101 Definition arg = node.arguments[positionalArgumentCount + i].definition; 102 Definition arg = node.arguments[positionalArgumentCount + i].definition;
102 args.add("($name: $arg)"); 103 args.add("($name: $arg)");
103 } 104 }
104 return args.join(' '); 105 return '(${args.join(' ')})';
105 } 106 }
106 107
107 String visitInvokeStatic(InvokeStatic node) { 108 String visitInvokeStatic(InvokeStatic node) {
108 String name = node.target.name; 109 String name = node.target.name;
109 String cont = access(node.continuation); 110 String cont = access(node.continuation);
110 String args = formatArguments(node); 111 String args = formatArguments(node);
111 return '$indentation(InvokeStatic $name $args $cont)'; 112 return '$indentation(InvokeStatic $name $args $cont)';
112 } 113 }
113 114
114 String visitInvokeMethod(InvokeMethod node) { 115 String visitInvokeMethod(InvokeMethod node) {
(...skipping 19 matching lines...) Expand all
134 callName = '${node.type}.${node.target.name}'; 135 callName = '${node.type}.${node.target.name}';
135 } 136 }
136 String cont = access(node.continuation); 137 String cont = access(node.continuation);
137 String args = formatArguments(node); 138 String args = formatArguments(node);
138 return '$indentation(InvokeConstructor $callName $args $cont)'; 139 return '$indentation(InvokeConstructor $callName $args $cont)';
139 } 140 }
140 141
141 String visitConcatenateStrings(ConcatenateStrings node) { 142 String visitConcatenateStrings(ConcatenateStrings node) {
142 String cont = access(node.continuation); 143 String cont = access(node.continuation);
143 String args = node.arguments.map(access).join(' '); 144 String args = node.arguments.map(access).join(' ');
144 return '$indentation(ConcatenateStrings $args $cont)'; 145 return '$indentation(ConcatenateStrings ($args) $cont)';
145 } 146 }
146 147
147 String visitInvokeContinuation(InvokeContinuation node) { 148 String visitInvokeContinuation(InvokeContinuation node) {
148 String cont = access(node.continuation); 149 String cont = access(node.continuation);
149 String args = node.arguments.map(access).join(' '); 150 String args = node.arguments.map(access).join(' ');
150 String op = 151 String op =
151 node.isRecursive ? 'InvokeContinuation*' : 'InvokeContinuation'; 152 node.isRecursive ? 'InvokeContinuation*' : 'InvokeContinuation';
152 return '$indentation($op $cont $args)'; 153 return '$indentation($op $cont ($args))';
153 } 154 }
154 155
155 String visitBranch(Branch node) { 156 String visitBranch(Branch node) {
156 String condition = visit(node.condition); 157 String condition = visit(node.condition);
157 String trueCont = access(node.trueContinuation); 158 String trueCont = access(node.trueContinuation);
158 String falseCont = access(node.falseContinuation); 159 String falseCont = access(node.falseContinuation);
159 return '$indentation(Branch $condition $trueCont $falseCont)'; 160 return '$indentation(Branch $condition $trueCont $falseCont)';
160 } 161 }
161 162
162 String visitConstant(Constant node) { 163 String visitConstant(Constant node) {
163 String value = 164 String value =
164 node.expression.value.accept(new ConstantStringifier(), null); 165 node.expression.value.accept(new ConstantStringifier(), null);
165 return '(Constant $value)'; 166 return '(Constant $value)';
166 } 167 }
167 168
168 String visitThis(This node) { 169 String visitThis(This node) {
169 return '(This)'; 170 return '(This)';
170 } 171 }
171 172
172 String visitReifyTypeVar(ReifyTypeVar node) { 173 String visitReifyTypeVar(ReifyTypeVar node) {
173 return '$indentation(ReifyTypeVar ${node.typeVariable.name})'; 174 return '$indentation(ReifyTypeVar ${node.typeVariable.name})';
174 } 175 }
175 176
176 String visitCreateFunction(CreateFunction node) { 177 String visitCreateFunction(CreateFunction node) {
177 String function = indentBlock(() => visit(node.definition)); 178 String function =
179 indentBlock(() => indentBlock(() => visit(node.definition)));
178 return '(CreateFunction\n$function)'; 180 return '(CreateFunction\n$function)';
179 } 181 }
180 182
181 String visitContinuation(Continuation node) { 183 String visitContinuation(Continuation node) {
182 // Continuations are visited directly in visitLetCont. 184 // Continuations are visited directly in visitLetCont.
183 return '(Unexpected Continuation)'; 185 return '(Unexpected Continuation)';
184 } 186 }
185 187
186 String visitGetClosureVariable(GetClosureVariable node) { 188 String visitGetClosureVariable(GetClosureVariable node) {
187 return '(GetClosureVariable ${visit(node.variable.definition)})'; 189 return '(GetClosureVariable ${visit(node.variable.definition)})';
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 void setReturnContinuation(Continuation node) { 331 void setReturnContinuation(Continuation node) {
330 assert(!_names.containsKey(node) || _names[node] == 'return'); 332 assert(!_names.containsKey(node) || _names[node] == 'return');
331 _names[node] = 'return'; 333 _names[node] = 'return';
332 } 334 }
333 335
334 String getName(Node node) { 336 String getName(Node node) {
335 assert(_names.containsKey(node)); 337 assert(_names.containsKey(node));
336 return _names[node]; 338 return _names[node];
337 } 339 }
338 } 340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698