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

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

Issue 1345983007: dart2js CPS: Clean up the S-Expression builder. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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 unified diff | Download patch
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 import '../universe/call_structure.dart' show 10 import '../universe/call_structure.dart' show
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 String name = newValueName(node.primitive); 69 String name = newValueName(node.primitive);
70 String value = visit(node.primitive); 70 String value = visit(node.primitive);
71 String body = indentBlock(() => visit(node.body)); 71 String body = indentBlock(() => visit(node.body));
72 return '$indentation(LetPrim ($name $value)\n$body)'; 72 return '$indentation(LetPrim ($name $value)\n$body)';
73 } 73 }
74 74
75 String visitLetCont(LetCont node) { 75 String visitLetCont(LetCont node) {
76 String conts; 76 String conts;
77 bool first = true; 77 bool first = true;
78 for (Continuation continuation in node.continuations) { 78 for (Continuation continuation in node.continuations) {
79 String name = newContinuationName(continuation);
80 if (continuation.isRecursive) name = 'rec $name';
81 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and
82 // should recurse to [visit]. Currently we can't do that, because the
83 // unstringifier_test produces [LetConts] with dummy arguments on them.
84 String parameters = continuation.parameters
85 .map((p) => '${decorator(p, newValueName(p))}')
86 .join(' ');
87 String body =
88 indentBlock(() => indentBlock(() => visit(continuation.body)));
89 if (first) { 79 if (first) {
90 first = false; 80 first = false;
91 conts = '($name ($parameters)\n$body)'; 81 conts = visit(continuation);
92 } else { 82 } else {
93 // Each subsequent line is indented additional spaces to align it 83 // Each subsequent line is indented additional spaces to align it
94 // with the previous continuation. 84 // with the previous continuation.
95 String indent = '$indentation${' ' * '(LetCont ('.length}'; 85 String indent = '$indentation${' ' * '(LetCont ('.length}';
96 conts = '$conts\n$indent($name ($parameters)\n$body)'; 86 conts = '$conts\n$indent${visit(continuation)}';
97 } 87 }
98 } 88 }
99 String body = indentBlock(() => visit(node.body)); 89 String body = indentBlock(() => visit(node.body));
100 return '$indentation(LetCont ($conts)\n$body)'; 90 return '$indentation(LetCont ($conts)\n$body)';
101 } 91 }
102 92
103 String visitLetHandler(LetHandler node) { 93 String visitLetHandler(LetHandler node) {
104 // There are no explicit references to the handler, so we leave it 94 // There are no explicit references to the handler, so we leave it
105 // anonymous in the printed representation. 95 // anonymous in the printed representation.
106 String parameters = node.handler.parameters 96 String parameters = node.handler.parameters
107 .map((p) => '${decorator(p, newValueName(p))}') 97 .map((p) => '${decorator(p, newValueName(p))}')
108 .join(' '); 98 .join(' ');
109 String handlerBody = 99 String handlerBody =
110 indentBlock(() => indentBlock(() => visit(node.handler.body))); 100 indentBlock(() => indentBlock(() => visit(node.handler.body)));
111 String body = indentBlock(() => visit(node.body)); 101 String body = indentBlock(() => visit(node.body));
112 return '$indentation(LetHandler (($parameters)\n$handlerBody)\n$body)'; 102 return '$indentation(LetHandler (($parameters)\n$handlerBody)\n$body)';
113 } 103 }
114 104
115 String visitLetMutable(LetMutable node) { 105 String visitLetMutable(LetMutable node) {
116 String name = visit(node.variable); 106 String name = visit(node.variable);
117 String value = access(node.value); 107 String value = access(node.value);
118 String body = indentBlock(() => visit(node.body)); 108 String body = indentBlock(() => visit(node.body));
119 return '$indentation(LetMutable ($name $value)\n$body)'; 109 return '$indentation(LetMutable ($name $value)\n$body)';
120 } 110 }
121 111
122 String formatArguments(CallStructure call, 112 String formatArguments(CallStructure call,
123 List<Reference<Primitive>> arguments) { 113 List<Reference<Primitive>> arguments,
114 {bool isIntercepted: false}) {
124 int positionalArgumentCount = call.positionalArgumentCount; 115 int positionalArgumentCount = call.positionalArgumentCount;
125 List<String> args = new List<String>(); 116 if (positionalArgumentCount > arguments.length) {
126 args.addAll(arguments.getRange(0, positionalArgumentCount).map(access)); 117 print('bae');
118 }
119 List<String> args =
120 arguments.getRange(0, positionalArgumentCount).map(access).toList();
127 List<String> argumentNames = call.getOrderedNamedArguments(); 121 List<String> argumentNames = call.getOrderedNamedArguments();
128 for (int i = 0; i < argumentNames.length; ++i) { 122 for (int i = 0; i < argumentNames.length; ++i) {
129 String name = argumentNames[i]; 123 String name = argumentNames[i];
130 String arg = access(arguments[positionalArgumentCount + i]); 124 String arg = access(arguments[positionalArgumentCount + i]);
131 args.add("($name: $arg)"); 125 args.add("($name: $arg)");
132 } 126 }
133 return '(${args.join(' ')})'; 127 return '(${args.join(' ')})';
134 } 128 }
135 129
136 String visitInvokeStatic(InvokeStatic node) { 130 String visitInvokeStatic(InvokeStatic node) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return '(Constant $value)'; 205 return '(Constant $value)';
212 } 206 }
213 207
214 String visitCreateFunction(CreateFunction node) { 208 String visitCreateFunction(CreateFunction node) {
215 String function = 209 String function =
216 indentBlock(() => indentBlock(() => visit(node.definition))); 210 indentBlock(() => indentBlock(() => visit(node.definition)));
217 return '(CreateFunction\n$function)'; 211 return '(CreateFunction\n$function)';
218 } 212 }
219 213
220 String visitContinuation(Continuation node) { 214 String visitContinuation(Continuation node) {
221 // Continuations are visited directly in visitLetCont. 215 String name = newContinuationName(node);
222 return '(Unexpected Continuation)'; 216 if (node.isRecursive) name = 'rec $name';
217 // TODO(karlklose): this should be changed to `.map(visit).join(' ')` and
218 // should recurse to [visit]. Currently we can't do that, because the
219 // unstringifier_test produces [LetConts] with dummy arguments on them.
220 String parameters = node.parameters
221 .map((p) => '${decorator(p, newValueName(p))}')
222 .join(' ');
223 String body = indentBlock(() => indentBlock(() => visit(node.body)));
224 return '($name ($parameters)\n$body)';
223 } 225 }
224 226
225 String visitGetMutable(GetMutable node) { 227 String visitGetMutable(GetMutable node) {
226 return '(GetMutable ${access(node.variable)})'; 228 return '(GetMutable ${access(node.variable)})';
227 } 229 }
228 230
229 String visitSetMutable(SetMutable node) { 231 String visitSetMutable(SetMutable node) {
230 String value = access(node.value); 232 String value = access(node.value);
231 return '(SetMutable ${access(node.variable)} $value)'; 233 return '(SetMutable ${access(node.variable)} $value)';
232 } 234 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 289 }
288 290
289 String visitCreateBox(CreateBox node) { 291 String visitCreateBox(CreateBox node) {
290 return '(CreateBox)'; 292 return '(CreateBox)';
291 } 293 }
292 294
293 String visitCreateInstance(CreateInstance node) { 295 String visitCreateInstance(CreateInstance node) {
294 String className = node.classElement.name; 296 String className = node.classElement.name;
295 String arguments = node.arguments.map(access).join(' '); 297 String arguments = node.arguments.map(access).join(' ');
296 String typeInformation = node.typeInformation.map(access).join(' '); 298 String typeInformation = node.typeInformation.map(access).join(' ');
297 return '(CreateInstance $className ($arguments)$typeInformation)'; 299 return '(CreateInstance $className ($arguments) ($typeInformation))';
298 } 300 }
299 301
300 String visitInterceptor(Interceptor node) { 302 String visitInterceptor(Interceptor node) {
301 return '(Interceptor ${access(node.input)})'; 303 return '(Interceptor ${access(node.input)})';
302 } 304 }
303 305
304 String visitReifyRuntimeType(ReifyRuntimeType node) { 306 String visitReifyRuntimeType(ReifyRuntimeType node) {
305 return '(ReifyRuntimeType ${access(node.value)})'; 307 return '(ReifyRuntimeType ${access(node.value)})';
306 } 308 }
307 309
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 void setReturnContinuation(Continuation node) { 480 void setReturnContinuation(Continuation node) {
479 assert(!_names.containsKey(node) || _names[node] == 'return'); 481 assert(!_names.containsKey(node) || _names[node] == 'return');
480 _names[node] = 'return'; 482 _names[node] = 'return';
481 } 483 }
482 484
483 String getName(Node node) { 485 String getName(Node node) {
484 if (!_names.containsKey(node)) return 'MISSING_NAME'; 486 if (!_names.containsKey(node)) return 'MISSING_NAME';
485 return _names[node]; 487 return _names[node];
486 } 488 }
487 } 489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698