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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 String formatThisParameter(Parameter thisParameter) { | 49 String formatThisParameter(Parameter thisParameter) { |
50 return thisParameter == null ? '()' : '(${visit(thisParameter)})'; | 50 return thisParameter == null ? '()' : '(${visit(thisParameter)})'; |
51 } | 51 } |
52 | 52 |
53 String visitFunctionDefinition(FunctionDefinition node) { | 53 String visitFunctionDefinition(FunctionDefinition node) { |
54 String name = node.element.name; | 54 String name = node.element.name; |
55 String thisParameter = formatThisParameter(node.thisParameter); | 55 String thisParameter = formatThisParameter(node.thisParameter); |
56 String parameters = node.parameters.map(visit).join(' '); | 56 String parameters = node.parameters.map(visit).join(' '); |
57 String body = visit(node.body); | 57 namer.setReturnContinuation(node.returnContinuation); |
| 58 String body = indentBlock(() => visit(node.body)); |
58 return '$indentation' | 59 return '$indentation' |
59 '(FunctionDefinition $name $thisParameter ($parameters) return\n' | 60 '(FunctionDefinition $name $thisParameter ($parameters) return\n' |
60 '$body)'; | 61 '$body)'; |
61 } | 62 } |
62 | 63 |
63 String visitFieldDefinition(FieldDefinition node) { | |
64 String name = node.element.name; | |
65 if (node.body != null) { | |
66 String body = visit(node.body); | |
67 return '$indentation(FieldDefinition $name () return\n' | |
68 '$body)'; | |
69 } else { | |
70 return '$indentation(FieldDefinition $name)'; | |
71 } | |
72 } | |
73 | |
74 String visitConstructorDefinition(ConstructorDefinition node) { | |
75 String name = node.element.name; | |
76 if (name != '') name = '$name '; | |
77 String thisParameter = formatThisParameter(node.thisParameter); | |
78 String parameters = node.parameters.map(visit).join(' '); | |
79 if (node.body != null) { | |
80 String initializers = indentBlock(() { | |
81 return indentBlock(() { | |
82 if (node.initializers.isEmpty) { | |
83 return '$indentation'; | |
84 } else { | |
85 return node.initializers.map(visit).join('\n'); | |
86 } | |
87 }); | |
88 }); | |
89 String body = visit(node.body); | |
90 return '$indentation' | |
91 '(ConstructorDefinition $name$thisParameter ($parameters) return' | |
92 ' (\n$initializers)\n$body)'; | |
93 } else { | |
94 return '$indentation' | |
95 '(ConstructorDefinition $name$thisParameter ($parameters) return)'; | |
96 } | |
97 } | |
98 | |
99 String visitFieldInitializer(FieldInitializer node) { | |
100 String name = node.element.name; | |
101 String body = visit(node.body); | |
102 return '$indentation(FieldInitializer $name\n$body)'; | |
103 } | |
104 | |
105 String visitSuperInitializer(SuperInitializer node) { | |
106 String target = node.target.name; | |
107 String selector = node.selector.name; | |
108 String arguments = | |
109 indentBlock(() => | |
110 indentBlock(() => node.arguments.map(visit).join('\n'))); | |
111 return '$indentation(SuperInitializer $target $selector (\n$arguments)'; | |
112 } | |
113 | |
114 String visitBody(Body node) { | |
115 namer.setReturnContinuation(node.returnContinuation); | |
116 return indentBlock(() => visit(node.body)); | |
117 } | |
118 | |
119 String visitLetPrim(LetPrim node) { | 64 String visitLetPrim(LetPrim node) { |
120 String name = newValueName(node.primitive); | 65 String name = newValueName(node.primitive); |
121 String value = visit(node.primitive); | 66 String value = visit(node.primitive); |
122 String body = indentBlock(() => visit(node.body)); | 67 String body = indentBlock(() => visit(node.body)); |
123 return '$indentation(LetPrim ($name $value)\n$body)'; | 68 return '$indentation(LetPrim ($name $value)\n$body)'; |
124 } | 69 } |
125 | 70 |
126 String visitLetCont(LetCont node) { | 71 String visitLetCont(LetCont node) { |
127 String conts; | 72 String conts; |
128 bool first = true; | 73 bool first = true; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 String falseCont = access(node.falseContinuation); | 201 String falseCont = access(node.falseContinuation); |
257 return '$indentation(Branch $condition $trueCont $falseCont)'; | 202 return '$indentation(Branch $condition $trueCont $falseCont)'; |
258 } | 203 } |
259 | 204 |
260 String visitConstant(Constant node) { | 205 String visitConstant(Constant node) { |
261 String value = | 206 String value = |
262 node.expression.value.accept(new ConstantStringifier(), null); | 207 node.expression.value.accept(new ConstantStringifier(), null); |
263 return '(Constant $value)'; | 208 return '(Constant $value)'; |
264 } | 209 } |
265 | 210 |
266 String visitReifyTypeVar(ReifyTypeVar node) { | |
267 return '$indentation(ReifyTypeVar ${node.typeVariable.name})'; | |
268 } | |
269 | |
270 String visitCreateFunction(CreateFunction node) { | 211 String visitCreateFunction(CreateFunction node) { |
271 String function = | 212 String function = |
272 indentBlock(() => indentBlock(() => visit(node.definition))); | 213 indentBlock(() => indentBlock(() => visit(node.definition))); |
273 return '(CreateFunction\n$function)'; | 214 return '(CreateFunction\n$function)'; |
274 } | 215 } |
275 | 216 |
276 String visitContinuation(Continuation node) { | 217 String visitContinuation(Continuation node) { |
277 // Continuations are visited directly in visitLetCont. | 218 // Continuations are visited directly in visitLetCont. |
278 return '(Unexpected Continuation)'; | 219 return '(Unexpected Continuation)'; |
279 } | 220 } |
(...skipping 22 matching lines...) Expand all Loading... |
302 String values = node.values.map(access).join(' '); | 243 String values = node.values.map(access).join(' '); |
303 return '(LiteralList ($values))'; | 244 return '(LiteralList ($values))'; |
304 } | 245 } |
305 | 246 |
306 String visitLiteralMap(LiteralMap node) { | 247 String visitLiteralMap(LiteralMap node) { |
307 String keys = node.entries.map((e) => access(e.key)).join(' '); | 248 String keys = node.entries.map((e) => access(e.key)).join(' '); |
308 String values = node.entries.map((e) => access(e.value)).join(' '); | 249 String values = node.entries.map((e) => access(e.value)).join(' '); |
309 return '(LiteralMap ($keys) ($values))'; | 250 return '(LiteralMap ($keys) ($values))'; |
310 } | 251 } |
311 | 252 |
312 String visitDeclareFunction(DeclareFunction node) { | |
313 String name = visit(node.variable); | |
314 String function = indentBlock(() => visit(node.definition)); | |
315 String body = indentBlock(() => visit(node.body)); | |
316 return '$indentation(DeclareFunction $name =\n' | |
317 '$function in\n' | |
318 '$body)'; | |
319 } | |
320 | |
321 String visitIsTrue(IsTrue node) { | 253 String visitIsTrue(IsTrue node) { |
322 String value = access(node.value); | 254 String value = access(node.value); |
323 return '(IsTrue $value)'; | 255 return '(IsTrue $value)'; |
324 } | 256 } |
325 | 257 |
326 String visitSetField(SetField node) { | 258 String visitSetField(SetField node) { |
327 String object = access(node.object); | 259 String object = access(node.object); |
328 String field = node.field.name; | 260 String field = node.field.name; |
329 String value = access(node.value); | 261 String value = access(node.value); |
330 String body = indentBlock(() => visit(node.body)); | 262 String body = indentBlock(() => visit(node.body)); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 void setReturnContinuation(Continuation node) { | 438 void setReturnContinuation(Continuation node) { |
507 assert(!_names.containsKey(node) || _names[node] == 'return'); | 439 assert(!_names.containsKey(node) || _names[node] == 'return'); |
508 _names[node] = 'return'; | 440 _names[node] = 'return'; |
509 } | 441 } |
510 | 442 |
511 String getName(Node node) { | 443 String getName(Node node) { |
512 if (!_names.containsKey(node)) return 'MISSING_NAME'; | 444 if (!_names.containsKey(node)) return 'MISSING_NAME'; |
513 return _names[node]; | 445 return _names[node]; |
514 } | 446 } |
515 } | 447 } |
OLD | NEW |