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

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

Issue 1021813002: Redo "Use an explicit 'this' parameter instead of 'This' nodes." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 28 matching lines...) Expand all
39 return namer.nameMutableVariable(node); 39 return namer.nameMutableVariable(node);
40 } 40 }
41 41
42 /// Main entry point for creating a [String] from a [Node]. All recursive 42 /// Main entry point for creating a [String] from a [Node]. All recursive
43 /// calls must go through this method. 43 /// calls must go through this method.
44 String visit(Node node) { 44 String visit(Node node) {
45 String s = node.accept(this); 45 String s = node.accept(this);
46 return decorator(node, s); 46 return decorator(node, s);
47 } 47 }
48 48
49 String formatThisParameter(Parameter thisParameter) {
50 return thisParameter == null ? '()' : '(${visit(thisParameter)})';
51 }
52
49 String visitFunctionDefinition(FunctionDefinition node) { 53 String visitFunctionDefinition(FunctionDefinition node) {
50 String name = node.element.name; 54 String name = node.element.name;
55 String thisParameter = formatThisParameter(node.thisParameter);
51 String parameters = node.parameters.map(visit).join(' '); 56 String parameters = node.parameters.map(visit).join(' ');
52 String body = visit(node.body); 57 String body = visit(node.body);
53 return '$indentation(FunctionDefinition $name ($parameters) return\n' 58 return '$indentation'
59 '(FunctionDefinition $name $thisParameter ($parameters) return\n'
54 '$body)'; 60 '$body)';
55 } 61 }
56 62
57 String visitFieldDefinition(FieldDefinition node) { 63 String visitFieldDefinition(FieldDefinition node) {
58 String name = node.element.name; 64 String name = node.element.name;
59 if (node.hasInitializer) { 65 if (node.hasInitializer) {
60 String body = visit(node.body); 66 String body = visit(node.body);
61 return '$indentation(FieldDefinition $name () return\n' 67 return '$indentation(FieldDefinition $name () return\n'
62 '$body)'; 68 '$body)';
63 } else { 69 } else {
64 return '$indentation(FieldDefinition $name)'; 70 return '$indentation(FieldDefinition $name)';
65 } 71 }
66 } 72 }
67 73
68 String visitConstructorDefinition(ConstructorDefinition node) { 74 String visitConstructorDefinition(ConstructorDefinition node) {
69 String name = node.element.name; 75 String name = node.element.name;
70 if (name != '') name = '$name '; 76 if (name != '') name = '$name ';
77 String thisParameter = formatThisParameter(node.thisParameter);
71 String parameters = node.parameters.map(visit).join(' '); 78 String parameters = node.parameters.map(visit).join(' ');
72 if (node.body != null) { 79 if (node.body != null) {
73 String initializers = indentBlock(() { 80 String initializers = indentBlock(() {
74 return indentBlock(() { 81 return indentBlock(() {
75 if (node.initializers.isEmpty) { 82 if (node.initializers.isEmpty) {
76 return '$indentation'; 83 return '$indentation';
77 } else { 84 } else {
78 return node.initializers.map(visit).join('\n'); 85 return node.initializers.map(visit).join('\n');
79 } 86 }
80 }); 87 });
81 }); 88 });
82 String body = visit(node.body); 89 String body = visit(node.body);
83 return '$indentation(ConstructorDefinition $name($parameters) return' 90 return '$indentation'
91 '(ConstructorDefinition $name$thisParameter ($parameters) return'
84 ' (\n$initializers)\n$body)'; 92 ' (\n$initializers)\n$body)';
85 } else { 93 } else {
86 return '$indentation(ConstructorDefinition $name($parameters) return)'; 94 return '$indentation'
95 '(ConstructorDefinition $name$thisParameter ($parameters) return)';
87 } 96 }
88 } 97 }
89 98
90 String visitFieldInitializer(FieldInitializer node) { 99 String visitFieldInitializer(FieldInitializer node) {
91 String name = node.element.name; 100 String name = node.element.name;
92 String body = visit(node.body); 101 String body = visit(node.body);
93 return '$indentation(FieldInitializer $name\$body)'; 102 return '$indentation(FieldInitializer $name\n$body)';
94 } 103 }
95 104
96 String visitSuperInitializer(SuperInitializer node) { 105 String visitSuperInitializer(SuperInitializer node) {
97 String target = node.target.name; 106 String target = node.target.name;
98 String selector = node.selector.name; 107 String selector = node.selector.name;
99 String arguments = 108 String arguments =
100 indentBlock(() => 109 indentBlock(() =>
101 indentBlock(() => node.arguments.map(visit).join('\n'))); 110 indentBlock(() => node.arguments.map(visit).join('\n')));
102 return '$indentation(SuperInitializer $target $selector (\n$arguments)'; 111 return '$indentation(SuperInitializer $target $selector (\n$arguments)';
103 } 112 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 String falseCont = access(node.falseContinuation); 237 String falseCont = access(node.falseContinuation);
229 return '$indentation(Branch $condition $trueCont $falseCont)'; 238 return '$indentation(Branch $condition $trueCont $falseCont)';
230 } 239 }
231 240
232 String visitConstant(Constant node) { 241 String visitConstant(Constant node) {
233 String value = 242 String value =
234 node.expression.value.accept(new ConstantStringifier(), null); 243 node.expression.value.accept(new ConstantStringifier(), null);
235 return '(Constant $value)'; 244 return '(Constant $value)';
236 } 245 }
237 246
238 String visitThis(This node) {
239 return '(This)';
240 }
241
242 String visitReifyTypeVar(ReifyTypeVar node) { 247 String visitReifyTypeVar(ReifyTypeVar node) {
243 return '$indentation(ReifyTypeVar ${node.typeVariable.name})'; 248 return '$indentation(ReifyTypeVar ${node.typeVariable.name})';
244 } 249 }
245 250
246 String visitCreateFunction(CreateFunction node) { 251 String visitCreateFunction(CreateFunction node) {
247 String function = 252 String function =
248 indentBlock(() => indentBlock(() => visit(node.definition))); 253 indentBlock(() => indentBlock(() => visit(node.definition)));
249 return '(CreateFunction\n$function)'; 254 return '(CreateFunction\n$function)';
250 } 255 }
251 256
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 String visitDeferred(DeferredConstantValue constant, _) { 415 String visitDeferred(DeferredConstantValue constant, _) {
411 return _failWith(constant); 416 return _failWith(constant);
412 } 417 }
413 } 418 }
414 419
415 class _Namer { 420 class _Namer {
416 final Map<Node, String> _names = <Node, String>{}; 421 final Map<Node, String> _names = <Node, String>{};
417 int _valueCounter = 0; 422 int _valueCounter = 0;
418 int _continuationCounter = 0; 423 int _continuationCounter = 0;
419 424
425 // TODO(sra): Make the methods not assert and print something indicating an
426 // error, so printer can be used to inspect broken terms.
427
420 String nameParameter(Parameter parameter) { 428 String nameParameter(Parameter parameter) {
421 assert(!_names.containsKey(parameter)); 429 assert(!_names.containsKey(parameter));
422 return _names[parameter] = parameter.hint.name; 430 return _names[parameter] = parameter.hint.name;
423 } 431 }
424 432
425 String nameMutableVariable(MutableVariable variable) { 433 String nameMutableVariable(MutableVariable variable) {
426 assert(!_names.containsKey(variable)); 434 assert(!_names.containsKey(variable));
427 return _names[variable] = variable.hint.name; 435 return _names[variable] = variable.hint.name;
428 } 436 }
429 437
(...skipping 10 matching lines...) Expand all
440 void setReturnContinuation(Continuation node) { 448 void setReturnContinuation(Continuation node) {
441 assert(!_names.containsKey(node) || _names[node] == 'return'); 449 assert(!_names.containsKey(node) || _names[node] == 'return');
442 _names[node] = 'return'; 450 _names[node] = 'return';
443 } 451 }
444 452
445 String getName(Node node) { 453 String getName(Node node) {
446 assert(_names.containsKey(node)); 454 assert(_names.containsKey(node));
447 return _names[node]; 455 return _names[node];
448 } 456 }
449 } 457 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698