| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 String visitInvokeMethodDirectly(InvokeMethodDirectly node) { | 201 String visitInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 202 String receiver = access(node.receiver); | 202 String receiver = access(node.receiver); |
| 203 String name = node.selector.name; | 203 String name = node.selector.name; |
| 204 String cont = access(node.continuation); | 204 String cont = access(node.continuation); |
| 205 String args = formatArguments(node); | 205 String args = formatArguments(node); |
| 206 return '$indentation(InvokeMethodDirectly $receiver $name $args $cont)'; | 206 return '$indentation(InvokeMethodDirectly $receiver $name $args $cont)'; |
| 207 } | 207 } |
| 208 | 208 |
| 209 String visitInvokeConstructor(InvokeConstructor node) { | 209 String visitInvokeConstructor(InvokeConstructor node) { |
| 210 String className; |
| 211 // TODO(karlklose): for illegal nodes constructed for tests or unresolved |
| 212 // constructor calls in the DartBackend, we get an element with no enclosing |
| 213 // class. Clean this up by introducing a name field to the node and |
| 214 // removing [ErroneousElement]s from the IR. |
| 215 if (node.type != null) { |
| 216 className = node.type.toString(); |
| 217 } else { |
| 218 className = node.target.enclosingClass.name; |
| 219 } |
| 210 String callName; | 220 String callName; |
| 211 if (node.target.name.isEmpty) { | 221 if (node.target.name.isEmpty) { |
| 212 callName = '${node.type}'; | 222 callName = '${className}'; |
| 213 } else { | 223 } else { |
| 214 callName = '${node.type}.${node.target.name}'; | 224 callName = '${className}.${node.target.name}'; |
| 215 } | 225 } |
| 216 String cont = access(node.continuation); | 226 String cont = access(node.continuation); |
| 217 String args = formatArguments(node); | 227 String args = formatArguments(node); |
| 218 return '$indentation(InvokeConstructor $callName $args $cont)'; | 228 return '$indentation(InvokeConstructor $callName $args $cont)'; |
| 219 } | 229 } |
| 220 | 230 |
| 221 String visitConcatenateStrings(ConcatenateStrings node) { | 231 String visitConcatenateStrings(ConcatenateStrings node) { |
| 222 String cont = access(node.continuation); | 232 String cont = access(node.continuation); |
| 223 String args = node.arguments.map(access).join(' '); | 233 String args = node.arguments.map(access).join(' '); |
| 224 return '$indentation(ConcatenateStrings ($args) $cont)'; | 234 return '$indentation(ConcatenateStrings ($args) $cont)'; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 return '(GetField $object $field)'; | 326 return '(GetField $object $field)'; |
| 317 } | 327 } |
| 318 | 328 |
| 319 String visitCreateBox(CreateBox node) { | 329 String visitCreateBox(CreateBox node) { |
| 320 return '(CreateBox)'; | 330 return '(CreateBox)'; |
| 321 } | 331 } |
| 322 | 332 |
| 323 String visitCreateInstance(CreateInstance node) { | 333 String visitCreateInstance(CreateInstance node) { |
| 324 String className = node.classElement.name; | 334 String className = node.classElement.name; |
| 325 String arguments = node.arguments.map(access).join(' '); | 335 String arguments = node.arguments.map(access).join(' '); |
| 326 return '(CreateInstance $className ($arguments))'; | 336 String typeInformation = node.hasTypeInformation |
| 337 ? ' ${node.typeInformation.map(access).join(' ')}' : ''; |
| 338 return '(CreateInstance $className ($arguments)$typeInformation)'; |
| 327 } | 339 } |
| 328 | 340 |
| 329 String visitIdentical(Identical node) { | 341 String visitIdentical(Identical node) { |
| 330 String left = access(node.left); | 342 String left = access(node.left); |
| 331 String right = access(node.right); | 343 String right = access(node.right); |
| 332 return '(Identical $left $right)'; | 344 return '(Identical $left $right)'; |
| 333 } | 345 } |
| 334 | 346 |
| 335 String visitInterceptor(Interceptor node) { | 347 String visitInterceptor(Interceptor node) { |
| 336 return '(Interceptor ${access(node.input)})'; | 348 return '(Interceptor ${access(node.input)})'; |
| 337 } | 349 } |
| 338 | 350 |
| 339 String visitReifyRuntimeType(ReifyRuntimeType node) { | 351 String visitReifyRuntimeType(ReifyRuntimeType node) { |
| 340 return '(ReifyRuntimeType ${access(node.value)})'; | 352 return '(ReifyRuntimeType ${access(node.value)})'; |
| 341 } | 353 } |
| 342 | 354 |
| 343 String visitReadTypeVariable(ReadTypeVariable node) { | 355 String visitReadTypeVariable(ReadTypeVariable node) { |
| 344 return '(ReadTypeVariable ${access(node.target)}.${node.variable})'; | 356 return '(ReadTypeVariable ${access(node.target)}.${node.variable})'; |
| 345 } | 357 } |
| 358 |
| 359 @override |
| 360 String visitTypeExpression(TypeExpression node) { |
| 361 String args = node.arguments.map(access).join(', '); |
| 362 return '(TypeExpression ${node.dartType.toString()} $args)'; |
| 363 } |
| 346 } | 364 } |
| 347 | 365 |
| 348 class ConstantStringifier extends ConstantValueVisitor<String, Null> { | 366 class ConstantStringifier extends ConstantValueVisitor<String, Null> { |
| 349 // Some of these methods are unimplemented because we haven't had a need | 367 // Some of these methods are unimplemented because we haven't had a need |
| 350 // to print such constants. When printing is implemented, the corresponding | 368 // to print such constants. When printing is implemented, the corresponding |
| 351 // parsing support should be added to SExpressionUnstringifier.parseConstant | 369 // parsing support should be added to SExpressionUnstringifier.parseConstant |
| 352 // in the dart2js tests (currently in the file | 370 // in the dart2js tests (currently in the file |
| 353 // tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart). | 371 // tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart). |
| 354 | 372 |
| 355 String _failWith(ConstantValue constant) { | 373 String _failWith(ConstantValue constant) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 class _Namer { | 438 class _Namer { |
| 421 final Map<Node, String> _names = <Node, String>{}; | 439 final Map<Node, String> _names = <Node, String>{}; |
| 422 int _valueCounter = 0; | 440 int _valueCounter = 0; |
| 423 int _continuationCounter = 0; | 441 int _continuationCounter = 0; |
| 424 | 442 |
| 425 // TODO(sra): Make the methods not assert and print something indicating an | 443 // TODO(sra): Make the methods not assert and print something indicating an |
| 426 // error, so printer can be used to inspect broken terms. | 444 // error, so printer can be used to inspect broken terms. |
| 427 | 445 |
| 428 String nameParameter(Parameter parameter) { | 446 String nameParameter(Parameter parameter) { |
| 429 assert(!_names.containsKey(parameter)); | 447 assert(!_names.containsKey(parameter)); |
| 430 return _names[parameter] = parameter.hint.name; | 448 String name = |
| 449 parameter.hint != null ? parameter.hint.name : nameValue(parameter); |
| 450 return _names[parameter] = name; |
| 431 } | 451 } |
| 432 | 452 |
| 433 String nameMutableVariable(MutableVariable variable) { | 453 String nameMutableVariable(MutableVariable variable) { |
| 434 assert(!_names.containsKey(variable)); | 454 assert(!_names.containsKey(variable)); |
| 435 return _names[variable] = variable.hint.name; | 455 return _names[variable] = variable.hint.name; |
| 436 } | 456 } |
| 437 | 457 |
| 438 String nameContinuation(Continuation node) { | 458 String nameContinuation(Continuation node) { |
| 439 assert(!_names.containsKey(node)); | 459 assert(!_names.containsKey(node)); |
| 440 return _names[node] = 'k${_continuationCounter++}'; | 460 return _names[node] = 'k${_continuationCounter++}'; |
| 441 } | 461 } |
| 442 | 462 |
| 443 String nameValue(Primitive node) { | 463 String nameValue(Primitive node) { |
| 444 assert(!_names.containsKey(node)); | 464 assert(!_names.containsKey(node)); |
| 445 return _names[node] = 'v${_valueCounter++}'; | 465 return _names[node] = 'v${_valueCounter++}'; |
| 446 } | 466 } |
| 447 | 467 |
| 448 void setReturnContinuation(Continuation node) { | 468 void setReturnContinuation(Continuation node) { |
| 449 assert(!_names.containsKey(node) || _names[node] == 'return'); | 469 assert(!_names.containsKey(node) || _names[node] == 'return'); |
| 450 _names[node] = 'return'; | 470 _names[node] = 'return'; |
| 451 } | 471 } |
| 452 | 472 |
| 453 String getName(Node node) { | 473 String getName(Node node) { |
| 454 assert(_names.containsKey(node)); | 474 assert(_names.containsKey(node)); |
| 455 return _names[node]; | 475 return _names[node]; |
| 456 } | 476 } |
| 457 } | 477 } |
| OLD | NEW |