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

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

Issue 898463002: Rename ClosureVariable, use separate IR forms for declaration and assignment. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 16 matching lines...) Expand all
27 } 27 }
28 28
29 String access(Reference<Definition> r) { 29 String access(Reference<Definition> r) {
30 return decorator(r.definition, namer.getName(r.definition)); 30 return decorator(r.definition, namer.getName(r.definition));
31 } 31 }
32 32
33 String visitParameter(Parameter node) { 33 String visitParameter(Parameter node) {
34 return namer.nameParameter(node); 34 return namer.nameParameter(node);
35 } 35 }
36 36
37 String visitClosureVariable(ClosureVariable node) { 37 String visitMutableVariable(MutableVariable node) {
38 return namer.nameClosureVariable(node); 38 return namer.nameMutableVariable(node);
39 } 39 }
40 40
41 /// Main entry point for creating a [String] from a [Node]. All recursive 41 /// Main entry point for creating a [String] from a [Node]. All recursive
42 /// calls must go through this method. 42 /// calls must go through this method.
43 String visit(Node node) { 43 String visit(Node node) {
44 String s = super.visit(node); 44 String s = super.visit(node);
45 return decorator(node, s); 45 return decorator(node, s);
46 } 46 }
47 47
48 String visitFunctionDefinition(FunctionDefinition node) { 48 String visitFunctionDefinition(FunctionDefinition node) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Each subsequent line is indented additional spaces to align it 94 // Each subsequent line is indented additional spaces to align it
95 // with the previous continuation. 95 // with the previous continuation.
96 String indent = '$indentation${' ' * '(LetCont ('.length}'; 96 String indent = '$indentation${' ' * '(LetCont ('.length}';
97 conts = '$conts\n$indent($name ($parameters)\n$body)'; 97 conts = '$conts\n$indent($name ($parameters)\n$body)';
98 } 98 }
99 } 99 }
100 String body = indentBlock(() => visit(node.body)); 100 String body = indentBlock(() => visit(node.body));
101 return '$indentation($LetCont ($conts)\n$body)'; 101 return '$indentation($LetCont ($conts)\n$body)';
102 } 102 }
103 103
104 String visitLetMutable(LetMutable node) {
105 String name = visit(node.variable);
106 String value = access(node.value);
107 String body = indentBlock(() => visit(node.body));
108 return '$indentation(LetMutable ($name $value)\n$body)';
109 }
110
104 String formatArguments(Invoke node) { 111 String formatArguments(Invoke node) {
105 int positionalArgumentCount = node.selector.positionalArgumentCount; 112 int positionalArgumentCount = node.selector.positionalArgumentCount;
106 List<String> args = new List<String>(); 113 List<String> args = new List<String>();
107 args.addAll( 114 args.addAll(
108 node.arguments.getRange(0, positionalArgumentCount).map(access)); 115 node.arguments.getRange(0, positionalArgumentCount).map(access));
109 for (int i = 0; i < node.selector.namedArgumentCount; ++i) { 116 for (int i = 0; i < node.selector.namedArgumentCount; ++i) {
110 String name = node.selector.namedArguments[i]; 117 String name = node.selector.namedArguments[i];
111 String arg = access(node.arguments[positionalArgumentCount + i]); 118 String arg = access(node.arguments[positionalArgumentCount + i]);
112 args.add("($name: $arg)"); 119 args.add("($name: $arg)");
113 } 120 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 String function = 194 String function =
188 indentBlock(() => indentBlock(() => visit(node.definition))); 195 indentBlock(() => indentBlock(() => visit(node.definition)));
189 return '(CreateFunction\n$function)'; 196 return '(CreateFunction\n$function)';
190 } 197 }
191 198
192 String visitContinuation(Continuation node) { 199 String visitContinuation(Continuation node) {
193 // Continuations are visited directly in visitLetCont. 200 // Continuations are visited directly in visitLetCont.
194 return '(Unexpected Continuation)'; 201 return '(Unexpected Continuation)';
195 } 202 }
196 203
197 String visitGetClosureVariable(GetClosureVariable node) { 204 String visitGetMutableVariable(GetMutableVariable node) {
198 namer.nameClosureVariableIfAbsent(node.variable.definition); 205 return '(${node.runtimeType} ${access(node.variable)})';
asgerf 2015/02/03 10:27:31 What karl said about runtimeType, unless we're cer
Kevin Millikin (Google) 2015/02/03 14:11:49 I had thought that the entire file was unused, but
199 return '(GetClosureVariable ${access(node.variable)})';
200 } 206 }
201 207
202 String visitSetClosureVariable(SetClosureVariable node) { 208 String visitSetMutableVariable(SetMutableVariable node) {
203 namer.nameClosureVariableIfAbsent(node.variable.definition);
204 String value = access(node.value); 209 String value = access(node.value);
205 String body = indentBlock(() => visit(node.body)); 210 String body = indentBlock(() => visit(node.body));
206 return '$indentation(SetClosureVariable ${access(node.variable)} ' 211 return '$indentation(${node.runtimeType} ${access(node.variable)} '
207 '$value\n$body)'; 212 '$value\n$body)';
208 } 213 }
209 214
210 String visitTypeOperator(TypeOperator node) { 215 String visitTypeOperator(TypeOperator node) {
211 String receiver = access(node.receiver); 216 String receiver = access(node.receiver);
212 String cont = access(node.continuation); 217 String cont = access(node.continuation);
213 String operator = node.isTypeTest ? 'is' : 'as'; 218 String operator = node.isTypeTest ? 'is' : 'as';
214 return '$indentation(TypeOperator $operator $receiver ${node.type} $cont)'; 219 return '$indentation(TypeOperator $operator $receiver ${node.type} $cont)';
215 } 220 }
216 221
217 String visitLiteralList(LiteralList node) { 222 String visitLiteralList(LiteralList node) {
218 String values = node.values.map(access).join(' '); 223 String values = node.values.map(access).join(' ');
219 return '(LiteralList ($values))'; 224 return '(LiteralList ($values))';
220 } 225 }
221 226
222 String visitLiteralMap(LiteralMap node) { 227 String visitLiteralMap(LiteralMap node) {
223 String keys = node.entries.map((e) => access(e.key)).join(' '); 228 String keys = node.entries.map((e) => access(e.key)).join(' ');
224 String values = node.entries.map((e) => access(e.value)).join(' '); 229 String values = node.entries.map((e) => access(e.value)).join(' ');
225 return '(LiteralMap ($keys) ($values))'; 230 return '(LiteralMap ($keys) ($values))';
226 } 231 }
227 232
228 String visitDeclareFunction(DeclareFunction node) { 233 String visitDeclareFunction(DeclareFunction node) {
234 String name = visit(node.variable);
229 String function = indentBlock(() => visit(node.definition)); 235 String function = indentBlock(() => visit(node.definition));
230 String body = indentBlock(() => visit(node.body)); 236 String body = indentBlock(() => visit(node.body));
231 String name = namer.getName(node.variable.definition);
232 return '$indentation(DeclareFunction $name =\n' 237 return '$indentation(DeclareFunction $name =\n'
233 '$function in\n' 238 '$function in\n'
234 '$body)'; 239 '$body)';
235 } 240 }
236 241
237 String visitIsTrue(IsTrue node) { 242 String visitIsTrue(IsTrue node) {
238 String value = access(node.value); 243 String value = access(node.value);
239 return '(IsTrue $value)'; 244 return '(IsTrue $value)';
240 } 245 }
241 246
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 class _Namer { 346 class _Namer {
342 final Map<Node, String> _names = <Node, String>{}; 347 final Map<Node, String> _names = <Node, String>{};
343 int _valueCounter = 0; 348 int _valueCounter = 0;
344 int _continuationCounter = 0; 349 int _continuationCounter = 0;
345 350
346 String nameParameter(Parameter parameter) { 351 String nameParameter(Parameter parameter) {
347 assert(!_names.containsKey(parameter)); 352 assert(!_names.containsKey(parameter));
348 return _names[parameter] = parameter.hint.name; 353 return _names[parameter] = parameter.hint.name;
349 } 354 }
350 355
351 String nameClosureVariable(ClosureVariable variable) { 356 String nameMutableVariable(MutableVariable variable) {
352 assert(!_names.containsKey(variable)); 357 assert(!_names.containsKey(variable));
353 return _names[variable] = variable.hint.name; 358 return _names[variable] = variable.hint.name;
354 } 359 }
355 360
356 String nameClosureVariableIfAbsent(ClosureVariable variable) {
karlklose 2015/02/03 09:56:16 is this dead code now?
Kevin Millikin (Google) 2015/02/03 14:11:49 Yes.
357 if (!_names.containsKey(variable)) {
358 _names[variable] = variable.hint.name;
359 }
360 }
361
362 String nameContinuation(Continuation node) { 361 String nameContinuation(Continuation node) {
363 assert(!_names.containsKey(node)); 362 assert(!_names.containsKey(node));
364 return _names[node] = 'k${_continuationCounter++}'; 363 return _names[node] = 'k${_continuationCounter++}';
365 } 364 }
366 365
367 String nameValue(Primitive node) { 366 String nameValue(Primitive node) {
368 assert(!_names.containsKey(node)); 367 assert(!_names.containsKey(node));
369 return _names[node] = 'v${_valueCounter++}'; 368 return _names[node] = 'v${_valueCounter++}';
370 } 369 }
371 370
372 void setReturnContinuation(Continuation node) { 371 void setReturnContinuation(Continuation node) {
373 assert(!_names.containsKey(node) || _names[node] == 'return'); 372 assert(!_names.containsKey(node) || _names[node] == 'return');
374 _names[node] = 'return'; 373 _names[node] = 'return';
375 } 374 }
376 375
377 String getName(Node node) { 376 String getName(Node node) {
378 assert(_names.containsKey(node)); 377 assert(_names.containsKey(node));
379 return _names[node]; 378 return _names[node];
380 } 379 }
381 } 380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698