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

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

Issue 1018403002: Revert "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
53 String visitFunctionDefinition(FunctionDefinition node) { 49 String visitFunctionDefinition(FunctionDefinition node) {
54 String name = node.element.name; 50 String name = node.element.name;
55 String thisParameter = formatThisParameter(node.thisParameter);
56 String parameters = node.parameters.map(visit).join(' '); 51 String parameters = node.parameters.map(visit).join(' ');
57 String body = visit(node.body); 52 String body = visit(node.body);
58 return '$indentation' 53 return '$indentation(FunctionDefinition $name ($parameters) return\n'
59 '(FunctionDefinition $name $thisParameter ($parameters) return\n'
60 '$body)'; 54 '$body)';
61 } 55 }
62 56
63 String visitFieldDefinition(FieldDefinition node) { 57 String visitFieldDefinition(FieldDefinition node) {
64 String name = node.element.name; 58 String name = node.element.name;
65 if (node.hasInitializer) { 59 if (node.hasInitializer) {
66 String body = visit(node.body); 60 String body = visit(node.body);
67 return '$indentation(FieldDefinition $name () return\n' 61 return '$indentation(FieldDefinition $name () return\n'
68 '$body)'; 62 '$body)';
69 } else { 63 } else {
70 return '$indentation(FieldDefinition $name)'; 64 return '$indentation(FieldDefinition $name)';
71 } 65 }
72 } 66 }
73 67
74 String visitConstructorDefinition(ConstructorDefinition node) { 68 String visitConstructorDefinition(ConstructorDefinition node) {
75 String name = node.element.name; 69 String name = node.element.name;
76 if (name != '') name = '$name '; 70 if (name != '') name = '$name ';
77 String thisParameter = formatThisParameter(node.thisParameter);
78 String parameters = node.parameters.map(visit).join(' '); 71 String parameters = node.parameters.map(visit).join(' ');
79 if (node.body != null) { 72 if (node.body != null) {
80 String initializers = indentBlock(() { 73 String initializers = indentBlock(() {
81 return indentBlock(() { 74 return indentBlock(() {
82 if (node.initializers.isEmpty) { 75 if (node.initializers.isEmpty) {
83 return '$indentation'; 76 return '$indentation';
84 } else { 77 } else {
85 return node.initializers.map(visit).join('\n'); 78 return node.initializers.map(visit).join('\n');
86 } 79 }
87 }); 80 });
88 }); 81 });
89 String body = visit(node.body); 82 String body = visit(node.body);
90 return '$indentation' 83 return '$indentation(ConstructorDefinition $name($parameters) return'
91 '(ConstructorDefinition $name$thisParameter ($parameters) return'
92 ' (\n$initializers)\n$body)'; 84 ' (\n$initializers)\n$body)';
93 } else { 85 } else {
94 return '$indentation' 86 return '$indentation(ConstructorDefinition $name($parameters) return)';
95 '(ConstructorDefinition $name$thisParameter ($parameters) return)';
96 } 87 }
97 } 88 }
98 89
99 String visitFieldInitializer(FieldInitializer node) { 90 String visitFieldInitializer(FieldInitializer node) {
100 String name = node.element.name; 91 String name = node.element.name;
101 String body = visit(node.body); 92 String body = visit(node.body);
102 return '$indentation(FieldInitializer $name\n$body)'; 93 return '$indentation(FieldInitializer $name\$body)';
103 } 94 }
104 95
105 String visitSuperInitializer(SuperInitializer node) { 96 String visitSuperInitializer(SuperInitializer node) {
106 String target = node.target.name; 97 String target = node.target.name;
107 String selector = node.selector.name; 98 String selector = node.selector.name;
108 String arguments = 99 String arguments =
109 indentBlock(() => 100 indentBlock(() =>
110 indentBlock(() => node.arguments.map(visit).join('\n'))); 101 indentBlock(() => node.arguments.map(visit).join('\n')));
111 return '$indentation(SuperInitializer $target $selector (\n$arguments)'; 102 return '$indentation(SuperInitializer $target $selector (\n$arguments)';
112 } 103 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 String falseCont = access(node.falseContinuation); 228 String falseCont = access(node.falseContinuation);
238 return '$indentation(Branch $condition $trueCont $falseCont)'; 229 return '$indentation(Branch $condition $trueCont $falseCont)';
239 } 230 }
240 231
241 String visitConstant(Constant node) { 232 String visitConstant(Constant node) {
242 String value = 233 String value =
243 node.expression.value.accept(new ConstantStringifier(), null); 234 node.expression.value.accept(new ConstantStringifier(), null);
244 return '(Constant $value)'; 235 return '(Constant $value)';
245 } 236 }
246 237
238 String visitThis(This node) {
239 return '(This)';
240 }
241
247 String visitReifyTypeVar(ReifyTypeVar node) { 242 String visitReifyTypeVar(ReifyTypeVar node) {
248 return '$indentation(ReifyTypeVar ${node.typeVariable.name})'; 243 return '$indentation(ReifyTypeVar ${node.typeVariable.name})';
249 } 244 }
250 245
251 String visitCreateFunction(CreateFunction node) { 246 String visitCreateFunction(CreateFunction node) {
252 String function = 247 String function =
253 indentBlock(() => indentBlock(() => visit(node.definition))); 248 indentBlock(() => indentBlock(() => visit(node.definition)));
254 return '(CreateFunction\n$function)'; 249 return '(CreateFunction\n$function)';
255 } 250 }
256 251
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 String visitDeferred(DeferredConstantValue constant, _) { 410 String visitDeferred(DeferredConstantValue constant, _) {
416 return _failWith(constant); 411 return _failWith(constant);
417 } 412 }
418 } 413 }
419 414
420 class _Namer { 415 class _Namer {
421 final Map<Node, String> _names = <Node, String>{}; 416 final Map<Node, String> _names = <Node, String>{};
422 int _valueCounter = 0; 417 int _valueCounter = 0;
423 int _continuationCounter = 0; 418 int _continuationCounter = 0;
424 419
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
428 String nameParameter(Parameter parameter) { 420 String nameParameter(Parameter parameter) {
429 assert(!_names.containsKey(parameter)); 421 assert(!_names.containsKey(parameter));
430 return _names[parameter] = parameter.hint.name; 422 return _names[parameter] = parameter.hint.name;
431 } 423 }
432 424
433 String nameMutableVariable(MutableVariable variable) { 425 String nameMutableVariable(MutableVariable variable) {
434 assert(!_names.containsKey(variable)); 426 assert(!_names.containsKey(variable));
435 return _names[variable] = variable.hint.name; 427 return _names[variable] = variable.hint.name;
436 } 428 }
437 429
(...skipping 10 matching lines...) Expand all
448 void setReturnContinuation(Continuation node) { 440 void setReturnContinuation(Continuation node) {
449 assert(!_names.containsKey(node) || _names[node] == 'return'); 441 assert(!_names.containsKey(node) || _names[node] == 'return');
450 _names[node] = 'return'; 442 _names[node] = 'return';
451 } 443 }
452 444
453 String getName(Node node) { 445 String getName(Node node) {
454 assert(_names.containsKey(node)); 446 assert(_names.containsKey(node));
455 return _names[node]; 447 return _names[node];
456 } 448 }
457 } 449 }
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