| 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 tree_ir_builder; | 5 library tree_ir_builder; |
| 6 | 6 |
| 7 import '../dart2jslib.dart' as dart2js; | 7 import '../dart2jslib.dart' as dart2js; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; | 9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; |
| 10 import '../util/util.dart' show CURRENT_ELEMENT_SPANNABLE; | 10 import '../util/util.dart' show CURRENT_ELEMENT_SPANNABLE; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 267 } |
| 268 | 268 |
| 269 Expression visitInterceptor(cps_ir.Interceptor node) { | 269 Expression visitInterceptor(cps_ir.Interceptor node) { |
| 270 return new Interceptor(getVariableUse(node.input), node.interceptedClasses); | 270 return new Interceptor(getVariableUse(node.input), node.interceptedClasses); |
| 271 } | 271 } |
| 272 | 272 |
| 273 Expression visitCreateInstance(cps_ir.CreateInstance node) { | 273 Expression visitCreateInstance(cps_ir.CreateInstance node) { |
| 274 return new CreateInstance( | 274 return new CreateInstance( |
| 275 node.classElement, | 275 node.classElement, |
| 276 translateArguments(node.arguments), | 276 translateArguments(node.arguments), |
| 277 translateArguments(node.typeInformation)); | 277 translateArguments(node.typeInformation), |
| 278 node.sourceInformation); |
| 278 } | 279 } |
| 279 | 280 |
| 280 Expression visitGetField(cps_ir.GetField node) { | 281 Expression visitGetField(cps_ir.GetField node) { |
| 281 return new GetField(getVariableUse(node.object), node.field); | 282 return new GetField(getVariableUse(node.object), node.field); |
| 282 } | 283 } |
| 283 | 284 |
| 284 Expression visitCreateBox(cps_ir.CreateBox node) { | 285 Expression visitCreateBox(cps_ir.CreateBox node) { |
| 285 return new CreateBox(); | 286 return new CreateBox(); |
| 286 } | 287 } |
| 287 | 288 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 349 |
| 349 Statement visitInvokeStatic(cps_ir.InvokeStatic node) { | 350 Statement visitInvokeStatic(cps_ir.InvokeStatic node) { |
| 350 // Calls are translated to direct style. | 351 // Calls are translated to direct style. |
| 351 List<Expression> arguments = translateArguments(node.arguments); | 352 List<Expression> arguments = translateArguments(node.arguments); |
| 352 Expression invoke = new InvokeStatic(node.target, node.selector, arguments, | 353 Expression invoke = new InvokeStatic(node.target, node.selector, arguments, |
| 353 node.sourceInformation); | 354 node.sourceInformation); |
| 354 return continueWithExpression(node.continuation, invoke); | 355 return continueWithExpression(node.continuation, invoke); |
| 355 } | 356 } |
| 356 | 357 |
| 357 Statement visitInvokeMethod(cps_ir.InvokeMethod node) { | 358 Statement visitInvokeMethod(cps_ir.InvokeMethod node) { |
| 358 InvokeMethod invoke = new InvokeMethod(getVariableUse(node.receiver), | 359 InvokeMethod invoke = new InvokeMethod( |
| 359 node.selector, | 360 getVariableUse(node.receiver), |
| 360 node.mask, | 361 node.selector, |
| 361 translateArguments(node.arguments)); | 362 node.mask, |
| 363 translateArguments(node.arguments), |
| 364 node.sourceInformation); |
| 362 invoke.receiverIsNotNull = node.receiverIsNotNull; | 365 invoke.receiverIsNotNull = node.receiverIsNotNull; |
| 363 return continueWithExpression(node.continuation, invoke); | 366 return continueWithExpression(node.continuation, invoke); |
| 364 } | 367 } |
| 365 | 368 |
| 366 Statement visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly node) { | 369 Statement visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly node) { |
| 367 Expression receiver = getVariableUse(node.receiver); | 370 Expression receiver = getVariableUse(node.receiver); |
| 368 List<Expression> arguments = translateArguments(node.arguments); | 371 List<Expression> arguments = translateArguments(node.arguments); |
| 369 Expression invoke = new InvokeMethodDirectly(receiver, node.target, | 372 Expression invoke = new InvokeMethodDirectly(receiver, node.target, |
| 370 node.selector, arguments); | 373 node.selector, arguments, node.sourceInformation); |
| 371 return continueWithExpression(node.continuation, invoke); | 374 return continueWithExpression(node.continuation, invoke); |
| 372 } | 375 } |
| 373 | 376 |
| 374 Statement visitThrow(cps_ir.Throw node) { | 377 Statement visitThrow(cps_ir.Throw node) { |
| 375 Expression value = getVariableUse(node.value); | 378 Expression value = getVariableUse(node.value); |
| 376 return new Throw(value); | 379 return new Throw(value); |
| 377 } | 380 } |
| 378 | 381 |
| 379 Statement visitRethrow(cps_ir.Rethrow node) { | 382 Statement visitRethrow(cps_ir.Rethrow node) { |
| 380 return new Rethrow(); | 383 return new Rethrow(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 List<Expression> typeArgs = translateArguments(node.typeArguments); | 435 List<Expression> typeArgs = translateArguments(node.typeArguments); |
| 433 return new TypeOperator(value, node.type, typeArgs, isTypeTest: true); | 436 return new TypeOperator(value, node.type, typeArgs, isTypeTest: true); |
| 434 } | 437 } |
| 435 | 438 |
| 436 Statement visitInvokeConstructor(cps_ir.InvokeConstructor node) { | 439 Statement visitInvokeConstructor(cps_ir.InvokeConstructor node) { |
| 437 List<Expression> arguments = translateArguments(node.arguments); | 440 List<Expression> arguments = translateArguments(node.arguments); |
| 438 Expression invoke = new InvokeConstructor( | 441 Expression invoke = new InvokeConstructor( |
| 439 node.type, | 442 node.type, |
| 440 node.target, | 443 node.target, |
| 441 node.selector, | 444 node.selector, |
| 442 arguments); | 445 arguments, |
| 446 node.sourceInformation); |
| 443 return continueWithExpression(node.continuation, invoke); | 447 return continueWithExpression(node.continuation, invoke); |
| 444 } | 448 } |
| 445 | 449 |
| 446 Statement visitInvokeContinuation(cps_ir.InvokeContinuation node) { | 450 Statement visitInvokeContinuation(cps_ir.InvokeContinuation node) { |
| 447 // Invocations of the return continuation are translated to returns. | 451 // Invocations of the return continuation are translated to returns. |
| 448 // Other continuation invocations are replaced with assignments of the | 452 // Other continuation invocations are replaced with assignments of the |
| 449 // arguments to formal parameter variables, followed by the body if | 453 // arguments to formal parameter variables, followed by the body if |
| 450 // the continuation is singly reference or a break if it is multiply | 454 // the continuation is singly reference or a break if it is multiply |
| 451 // referenced. | 455 // referenced. |
| 452 cps_ir.Continuation cont = node.continuation.definition; | 456 cps_ir.Continuation cont = node.continuation.definition; |
| 453 if (cont == returnContinuation) { | 457 if (cont == returnContinuation) { |
| 454 assert(node.arguments.length == 1); | 458 assert(node.arguments.length == 1); |
| 455 return new Return(getVariableUse(node.arguments.single)); | 459 return new Return(getVariableUse(node.arguments.single), |
| 460 sourceInformation: node.sourceInformation); |
| 456 } else { | 461 } else { |
| 457 List<Expression> arguments = translateArguments(node.arguments); | 462 List<Expression> arguments = translateArguments(node.arguments); |
| 458 return buildPhiAssignments(cont.parameters, arguments, | 463 return buildPhiAssignments(cont.parameters, arguments, |
| 459 () { | 464 () { |
| 460 // Translate invocations of recursive and non-recursive | 465 // Translate invocations of recursive and non-recursive |
| 461 // continuations differently. | 466 // continuations differently. |
| 462 // * Non-recursive continuations | 467 // * Non-recursive continuations |
| 463 // - If there is one use, translate the continuation body | 468 // - If there is one use, translate the continuation body |
| 464 // inline at the invocation site. | 469 // inline at the invocation site. |
| 465 // - If there are multiple uses, translate to Break. | 470 // - If there are multiple uses, translate to Break. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 493 thenStatement = | 498 thenStatement = |
| 494 cont.hasExactlyOneUse ? visit(cont.body) : new Break(labels[cont]); | 499 cont.hasExactlyOneUse ? visit(cont.body) : new Break(labels[cont]); |
| 495 cont = node.falseContinuation.definition; | 500 cont = node.falseContinuation.definition; |
| 496 assert(cont.parameters.isEmpty); | 501 assert(cont.parameters.isEmpty); |
| 497 elseStatement = | 502 elseStatement = |
| 498 cont.hasExactlyOneUse ? visit(cont.body) : new Break(labels[cont]); | 503 cont.hasExactlyOneUse ? visit(cont.body) : new Break(labels[cont]); |
| 499 return new If(condition, thenStatement, elseStatement); | 504 return new If(condition, thenStatement, elseStatement); |
| 500 } | 505 } |
| 501 | 506 |
| 502 Expression visitConstant(cps_ir.Constant node) { | 507 Expression visitConstant(cps_ir.Constant node) { |
| 503 return new Constant(node.value); | 508 return new Constant(node.value, sourceInformation: node.sourceInformation); |
| 504 } | 509 } |
| 505 | 510 |
| 506 Expression visitLiteralList(cps_ir.LiteralList node) { | 511 Expression visitLiteralList(cps_ir.LiteralList node) { |
| 507 return new LiteralList( | 512 return new LiteralList( |
| 508 node.type, | 513 node.type, |
| 509 translateArguments(node.values)); | 514 translateArguments(node.values)); |
| 510 } | 515 } |
| 511 | 516 |
| 512 Expression visitLiteralMap(cps_ir.LiteralMap node) { | 517 Expression visitLiteralMap(cps_ir.LiteralMap node) { |
| 513 return new LiteralMap( | 518 return new LiteralMap( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 // These occur as parameters or bound by LetMutable. They are not visited | 550 // These occur as parameters or bound by LetMutable. They are not visited |
| 546 // directly. | 551 // directly. |
| 547 unexpectedNode(node); | 552 unexpectedNode(node); |
| 548 } | 553 } |
| 549 | 554 |
| 550 Expression visitIsTrue(cps_ir.IsTrue node) { | 555 Expression visitIsTrue(cps_ir.IsTrue node) { |
| 551 return getVariableUse(node.value); | 556 return getVariableUse(node.value); |
| 552 } | 557 } |
| 553 | 558 |
| 554 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { | 559 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { |
| 555 return new ReifyRuntimeType(getVariableUse(node.value)); | 560 return new ReifyRuntimeType( |
| 561 getVariableUse(node.value), node.sourceInformation); |
| 556 } | 562 } |
| 557 | 563 |
| 558 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { | 564 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { |
| 559 return new ReadTypeVariable(node.variable, getVariableUse(node.target)); | 565 return new ReadTypeVariable( |
| 566 node.variable, |
| 567 getVariableUse(node.target), |
| 568 node.sourceInformation); |
| 560 } | 569 } |
| 561 | 570 |
| 562 @override | 571 @override |
| 563 Node visitTypeExpression(cps_ir.TypeExpression node) { | 572 Node visitTypeExpression(cps_ir.TypeExpression node) { |
| 564 return new TypeExpression( | 573 return new TypeExpression( |
| 565 node.dartType, | 574 node.dartType, |
| 566 node.arguments.map(getVariableUse).toList()); | 575 node.arguments.map(getVariableUse).toList()); |
| 567 } | 576 } |
| 568 | 577 |
| 569 Expression visitGetStatic(cps_ir.GetStatic node) { | 578 Expression visitGetStatic(cps_ir.GetStatic node) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 getVariableUse(node.index)); | 631 getVariableUse(node.index)); |
| 623 } | 632 } |
| 624 | 633 |
| 625 Expression visitSetIndex(cps_ir.SetIndex node) { | 634 Expression visitSetIndex(cps_ir.SetIndex node) { |
| 626 return new SetIndex(getVariableUse(node.object), | 635 return new SetIndex(getVariableUse(node.object), |
| 627 getVariableUse(node.index), | 636 getVariableUse(node.index), |
| 628 getVariableUse(node.value)); | 637 getVariableUse(node.value)); |
| 629 } | 638 } |
| 630 } | 639 } |
| 631 | 640 |
| OLD | NEW |