| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
| 10 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 buildField(target); | 101 buildField(target); |
| 102 } else if (target is ir.Constructor) { | 102 } else if (target is ir.Constructor) { |
| 103 buildConstructor(target); | 103 buildConstructor(target); |
| 104 } | 104 } |
| 105 assert(graph.isValid()); | 105 assert(graph.isValid()); |
| 106 return graph; | 106 return graph; |
| 107 } | 107 } |
| 108 | 108 |
| 109 void buildField(ir.Field field) { | 109 void buildField(ir.Field field) { |
| 110 openFunction(); | 110 openFunction(); |
| 111 field.initializer.accept(this); | 111 if (field.initializer != null) { |
| 112 field.initializer.accept(this); |
| 113 } else { |
| 114 stack.add(graph.addConstantNull(compiler)); |
| 115 } |
| 112 HInstruction value = pop(); | 116 HInstruction value = pop(); |
| 113 closeAndGotoExit(new HReturn(value, null)); | 117 closeAndGotoExit(new HReturn(value, null)); |
| 114 closeFunction(); | 118 closeFunction(); |
| 115 } | 119 } |
| 116 | 120 |
| 117 @override | 121 @override |
| 118 HInstruction popBoolified() { | 122 HInstruction popBoolified() { |
| 119 HInstruction value = pop(); | 123 HInstruction value = pop(); |
| 120 // TODO(het): add boolean conversion type check | 124 // TODO(het): add boolean conversion type check |
| 121 HInstruction result = new HBoolify(value, backend.boolType); | 125 HInstruction result = new HBoolify(value, backend.boolType); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 return popBoolified(); | 409 return popBoolified(); |
| 406 } | 410 } |
| 407 | 411 |
| 408 loopHandler.handleLoop(whileStatement, () {}, buildCondition, () {}, () { | 412 loopHandler.handleLoop(whileStatement, () {}, buildCondition, () {}, () { |
| 409 whileStatement.body.accept(this); | 413 whileStatement.body.accept(this); |
| 410 }); | 414 }); |
| 411 } | 415 } |
| 412 | 416 |
| 413 @override | 417 @override |
| 414 void visitIfStatement(ir.IfStatement ifStatement) { | 418 void visitIfStatement(ir.IfStatement ifStatement) { |
| 415 SsaBranchBuilder brancher = new SsaBranchBuilder(this, compiler); | 419 handleIf( |
| 416 brancher.handleIf( | 420 visitCondition: () => ifStatement.condition.accept(this), |
| 417 () => ifStatement.condition.accept(this), | 421 visitThen: () => ifStatement.then.accept(this), |
| 418 () => ifStatement.then.accept(this), | 422 visitElse: () => ifStatement.otherwise?.accept(this)); |
| 419 () => ifStatement.otherwise?.accept(this)); | |
| 420 } | 423 } |
| 421 | 424 |
| 422 @override | 425 @override |
| 426 void visitAssertStatement(ir.AssertStatement assertStatement) { |
| 427 if (!compiler.options.enableUserAssertions) return; |
| 428 if (assertStatement.message == null) { |
| 429 assertStatement.condition.accept(this); |
| 430 _pushStaticInvocation(astAdapter.assertHelper, <HInstruction>[pop()], |
| 431 astAdapter.assertHelperReturnType); |
| 432 pop(); |
| 433 return; |
| 434 } |
| 435 |
| 436 // if (assertTest(condition)) assertThrow(message); |
| 437 void buildCondition() { |
| 438 assertStatement.condition.accept(this); |
| 439 _pushStaticInvocation(astAdapter.assertTest, <HInstruction>[pop()], |
| 440 astAdapter.assertTestReturnType); |
| 441 } |
| 442 |
| 443 void fail() { |
| 444 assertStatement.message.accept(this); |
| 445 _pushStaticInvocation(astAdapter.assertThrow, <HInstruction>[pop()], |
| 446 astAdapter.assertThrowReturnType); |
| 447 pop(); |
| 448 } |
| 449 |
| 450 handleIf(visitCondition: buildCondition, visitThen: fail); |
| 451 } |
| 452 |
| 453 @override |
| 423 void visitConditionalExpression(ir.ConditionalExpression conditional) { | 454 void visitConditionalExpression(ir.ConditionalExpression conditional) { |
| 424 SsaBranchBuilder brancher = new SsaBranchBuilder(this, compiler); | 455 SsaBranchBuilder brancher = new SsaBranchBuilder(this, compiler); |
| 425 brancher.handleConditional( | 456 brancher.handleConditional( |
| 426 () => conditional.condition.accept(this), | 457 () => conditional.condition.accept(this), |
| 427 () => conditional.then.accept(this), | 458 () => conditional.then.accept(this), |
| 428 () => conditional.otherwise.accept(this)); | 459 () => conditional.otherwise.accept(this)); |
| 429 } | 460 } |
| 430 | 461 |
| 431 @override | 462 @override |
| 432 void visitLogicalExpression(ir.LogicalExpression logicalExpression) { | 463 void visitLogicalExpression(ir.LogicalExpression logicalExpression) { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 push(new HNot(popBoolified(), backend.boolType)); | 817 push(new HNot(popBoolified(), backend.boolType)); |
| 787 } | 818 } |
| 788 | 819 |
| 789 @override | 820 @override |
| 790 void visitStringConcatenation(ir.StringConcatenation stringConcat) { | 821 void visitStringConcatenation(ir.StringConcatenation stringConcat) { |
| 791 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); | 822 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); |
| 792 stringConcat.accept(stringBuilder); | 823 stringConcat.accept(stringBuilder); |
| 793 stack.add(stringBuilder.result); | 824 stack.add(stringBuilder.result); |
| 794 } | 825 } |
| 795 } | 826 } |
| OLD | NEW |