Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 visitThisParameter(Parameter thisParameter) { | |
| 50 return thisParameter == null ? '' : visit(thisParameter) + ' '; | |
| 51 } | |
|
asgerf
2015/03/18 13:28:25
I think we try to avoid `visitXXX` names for metho
sra1
2015/03/19 10:42:51
Done.
| |
| 49 String visitFunctionDefinition(FunctionDefinition node) { | 52 String visitFunctionDefinition(FunctionDefinition node) { |
| 50 String name = node.element.name; | 53 String name = node.element.name; |
| 54 String thisName = visitThisParameter(node.thisParameter); | |
| 51 String parameters = node.parameters.map(visit).join(' '); | 55 String parameters = node.parameters.map(visit).join(' '); |
| 52 String body = visit(node.body); | 56 String body = visit(node.body); |
| 53 return '$indentation(FunctionDefinition $name ($parameters) return\n' | 57 return '$indentation(FunctionDefinition $name $thisName($parameters) return\ n' |
|
asgerf
2015/03/18 13:28:25
Long line
sra1
2015/03/19 10:42:51
Done.
| |
| 54 '$body)'; | 58 '$body)'; |
| 55 } | 59 } |
| 56 | 60 |
| 57 String visitFieldDefinition(FieldDefinition node) { | 61 String visitFieldDefinition(FieldDefinition node) { |
| 58 String name = node.element.name; | 62 String name = node.element.name; |
| 59 if (node.hasInitializer) { | 63 if (node.hasInitializer) { |
| 60 String body = visit(node.body); | 64 String body = visit(node.body); |
| 61 return '$indentation(FieldDefinition $name () return\n' | 65 return '$indentation(FieldDefinition $name () return\n' |
| 62 '$body)'; | 66 '$body)'; |
| 63 } else { | 67 } else { |
| 64 return '$indentation(FieldDefinition $name)'; | 68 return '$indentation(FieldDefinition $name)'; |
| 65 } | 69 } |
| 66 } | 70 } |
| 67 | 71 |
| 68 String visitConstructorDefinition(ConstructorDefinition node) { | 72 String visitConstructorDefinition(ConstructorDefinition node) { |
| 69 String name = node.element.name; | 73 String name = node.element.name; |
| 70 if (name != '') name = '$name '; | 74 if (name != '') name = '$name '; |
| 75 String thisName = visitThisParameter(node.thisParameter); | |
| 71 String parameters = node.parameters.map(visit).join(' '); | 76 String parameters = node.parameters.map(visit).join(' '); |
| 72 if (node.body != null) { | 77 if (node.body != null) { |
| 73 String initializers = indentBlock(() { | 78 String initializers = indentBlock(() { |
| 74 return indentBlock(() { | 79 return indentBlock(() { |
| 75 if (node.initializers.isEmpty) { | 80 if (node.initializers.isEmpty) { |
| 76 return '$indentation'; | 81 return '$indentation'; |
| 77 } else { | 82 } else { |
| 78 return node.initializers.map(visit).join('\n'); | 83 return node.initializers.map(visit).join('\n'); |
| 79 } | 84 } |
| 80 }); | 85 }); |
| 81 }); | 86 }); |
| 82 String body = visit(node.body); | 87 String body = visit(node.body); |
| 83 return '$indentation(ConstructorDefinition $name($parameters) return' | 88 return '$indentation(ConstructorDefinition $name$thisName($parameters) ret urn' |
|
asgerf
2015/03/18 13:28:25
Long line
sra1
2015/03/19 10:42:51
Done.
| |
| 84 ' (\n$initializers)\n$body)'; | 89 ' (\n$initializers)\n$body)'; |
| 85 } else { | 90 } else { |
| 86 return '$indentation(ConstructorDefinition $name($parameters) return)'; | 91 return '$indentation(ConstructorDefinition $name$thisName($parameters) ret urn)'; |
| 87 } | 92 } |
| 88 } | 93 } |
| 89 | 94 |
| 90 String visitFieldInitializer(FieldInitializer node) { | 95 String visitFieldInitializer(FieldInitializer node) { |
| 91 String name = node.element.name; | 96 String name = node.element.name; |
| 92 String body = visit(node.body); | 97 String body = visit(node.body); |
| 93 return '$indentation(FieldInitializer $name\$body)'; | 98 return '$indentation(FieldInitializer $name\$body)'; |
| 94 } | 99 } |
| 95 | 100 |
| 96 String visitSuperInitializer(SuperInitializer node) { | 101 String visitSuperInitializer(SuperInitializer node) { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 assert(!_names.containsKey(node)); | 441 assert(!_names.containsKey(node)); |
| 437 return _names[node] = 'v${_valueCounter++}'; | 442 return _names[node] = 'v${_valueCounter++}'; |
| 438 } | 443 } |
| 439 | 444 |
| 440 void setReturnContinuation(Continuation node) { | 445 void setReturnContinuation(Continuation node) { |
| 441 assert(!_names.containsKey(node) || _names[node] == 'return'); | 446 assert(!_names.containsKey(node) || _names[node] == 'return'); |
| 442 _names[node] = 'return'; | 447 _names[node] = 'return'; |
| 443 } | 448 } |
| 444 | 449 |
| 445 String getName(Node node) { | 450 String getName(Node node) { |
| 446 assert(_names.containsKey(node)); | 451 //assert(_names.containsKey(node)); |
| 447 return _names[node]; | 452 //return _names[node]; |
| 453 if (_names.containsKey(node)) return _names[node]; | |
| 454 return '<<${node}>>'; | |
|
asgerf
2015/03/18 13:28:25
It's not clear if this is leftover debugging code
sra1
2015/03/19 10:42:51
I have reverted this change, and added a TODO to m
| |
| 448 } | 455 } |
| 449 } | 456 } |
| OLD | NEW |