| 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 '../closure.dart'; | 7 import '../closure.dart'; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // of the type variables in an environment (like the [LocalsHandler]). | 109 // of the type variables in an environment (like the [LocalsHandler]). |
| 110 final List<ResolutionDartType> currentImplicitInstantiations = | 110 final List<ResolutionDartType> currentImplicitInstantiations = |
| 111 <ResolutionDartType>[]; | 111 <ResolutionDartType>[]; |
| 112 | 112 |
| 113 HInstruction rethrowableException; | 113 HInstruction rethrowableException; |
| 114 | 114 |
| 115 @override | 115 @override |
| 116 JavaScriptBackend get backend => compiler.backend; | 116 JavaScriptBackend get backend => compiler.backend; |
| 117 | 117 |
| 118 @override | 118 @override |
| 119 TreeElements get elements => resolvedAst.elements; | 119 TreeElements get elements => astAdapter.elements; |
| 120 | 120 |
| 121 SourceInformationBuilder sourceInformationBuilder; | 121 SourceInformationBuilder sourceInformationBuilder; |
| 122 KernelAstAdapter astAdapter; | 122 KernelAstAdapter astAdapter; |
| 123 LoopHandler<ir.Node> loopHandler; | 123 LoopHandler<ir.Node> loopHandler; |
| 124 TypeBuilder typeBuilder; | 124 TypeBuilder typeBuilder; |
| 125 | 125 |
| 126 final Map<ir.VariableDeclaration, HInstruction> letBindings = | 126 final Map<ir.VariableDeclaration, HInstruction> letBindings = |
| 127 <ir.VariableDeclaration, HInstruction>{}; | 127 <ir.VariableDeclaration, HInstruction>{}; |
| 128 | 128 |
| 129 /// True if we are visiting the expression of a throw statement; we assume | 129 /// True if we are visiting the expression of a throw statement; we assume |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 291 } |
| 292 | 292 |
| 293 /// Maps the fields of a class to their SSA values. | 293 /// Maps the fields of a class to their SSA values. |
| 294 Map<ir.Field, HInstruction> _collectFieldValues(ir.Class clazz) { | 294 Map<ir.Field, HInstruction> _collectFieldValues(ir.Class clazz) { |
| 295 final fieldValues = <ir.Field, HInstruction>{}; | 295 final fieldValues = <ir.Field, HInstruction>{}; |
| 296 | 296 |
| 297 for (var field in clazz.fields) { | 297 for (var field in clazz.fields) { |
| 298 if (field.initializer == null) { | 298 if (field.initializer == null) { |
| 299 fieldValues[field] = graph.addConstantNull(closedWorld); | 299 fieldValues[field] = graph.addConstantNull(closedWorld); |
| 300 } else { | 300 } else { |
| 301 // Gotta update the resolvedAst when we're looking at field values |
| 302 // outside the constructor. |
| 303 astAdapter.pushResolvedAst(field); |
| 301 field.initializer.accept(this); | 304 field.initializer.accept(this); |
| 302 fieldValues[field] = pop(); | 305 fieldValues[field] = pop(); |
| 306 astAdapter.popResolvedAstStack(); |
| 303 } | 307 } |
| 304 } | 308 } |
| 305 | 309 |
| 306 return fieldValues; | 310 return fieldValues; |
| 307 } | 311 } |
| 308 | 312 |
| 309 /// Collects field initializers all the way up the inheritance chain. | 313 /// Collects field initializers all the way up the inheritance chain. |
| 310 void _buildInitializers( | 314 void _buildInitializers( |
| 311 ir.Constructor constructor, Map<ir.Field, HInstruction> fieldValues) { | 315 ir.Constructor constructor, Map<ir.Field, HInstruction> fieldValues) { |
| 312 var foundSuperOrRedirectCall = false; | 316 var foundSuperOrRedirectCall = false; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 assert(invariant(element, constantValue != null, | 383 assert(invariant(element, constantValue != null, |
| 380 message: 'No constant computed for $element')); | 384 message: 'No constant computed for $element')); |
| 381 builtArguments.add(graph.addConstant(constantValue, closedWorld)); | 385 builtArguments.add(graph.addConstant(constantValue, closedWorld)); |
| 382 } | 386 } |
| 383 }); | 387 }); |
| 384 } | 388 } |
| 385 | 389 |
| 386 return builtArguments; | 390 return builtArguments; |
| 387 } | 391 } |
| 388 | 392 |
| 389 /// Inlines the given super [constructor]'s initializers by collecting it's | 393 /// Inlines the given super [constructor]'s initializers by collecting its |
| 390 /// field values and building its constructor initializers. We visit super | 394 /// field values and building its constructor initializers. We visit super |
| 391 /// constructors all the way up to the [Object] constructor. | 395 /// constructors all the way up to the [Object] constructor. |
| 392 void _buildInlinedInitializers(ir.Constructor constructor, | 396 void _buildInlinedInitializers(ir.Constructor constructor, |
| 393 List<HInstruction> arguments, Map<ir.Field, HInstruction> fieldValues) { | 397 List<HInstruction> arguments, Map<ir.Field, HInstruction> fieldValues) { |
| 394 // TODO(het): Handle RTI if class needs it | 398 // TODO(het): Handle RTI if class needs it |
| 395 fieldValues.addAll(_collectFieldValues(constructor.enclosingClass)); | 399 fieldValues.addAll(_collectFieldValues(constructor.enclosingClass)); |
| 396 | 400 |
| 397 var signature = astAdapter.getFunctionSignature(constructor.function); | 401 var signature = astAdapter.getFunctionSignature(constructor.function); |
| 398 var index = 0; | 402 var index = 0; |
| 399 signature.orderedForEachParameter((ParameterElement parameter) { | 403 signature.orderedForEachParameter((ParameterElement parameter) { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 @override | 790 @override |
| 787 visitDoStatement(ir.DoStatement doStatement) { | 791 visitDoStatement(ir.DoStatement doStatement) { |
| 788 // TODO(efortuna): I think this can be rewritten using | 792 // TODO(efortuna): I think this can be rewritten using |
| 789 // LoopHandler.handleLoop with some tricks about when the "update" happens. | 793 // LoopHandler.handleLoop with some tricks about when the "update" happens. |
| 790 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); | 794 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); |
| 791 localsHandler.startLoop(astAdapter.getNode(doStatement)); | 795 localsHandler.startLoop(astAdapter.getNode(doStatement)); |
| 792 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement); | 796 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement); |
| 793 HLoopInformation loopInfo = current.loopInformation; | 797 HLoopInformation loopInfo = current.loopInformation; |
| 794 HBasicBlock loopEntryBlock = current; | 798 HBasicBlock loopEntryBlock = current; |
| 795 HBasicBlock bodyEntryBlock = current; | 799 HBasicBlock bodyEntryBlock = current; |
| 796 JumpTarget target = | 800 JumpTarget target = astAdapter.elements |
| 797 elements.getTargetDefinition(astAdapter.getNode(doStatement)); | 801 .getTargetDefinition(astAdapter.getNode(doStatement)); |
| 798 bool hasContinues = target != null && target.isContinueTarget; | 802 bool hasContinues = target != null && target.isContinueTarget; |
| 799 if (hasContinues) { | 803 if (hasContinues) { |
| 800 // Add extra block to hang labels on. | 804 // Add extra block to hang labels on. |
| 801 // It doesn't currently work if they are on the same block as the | 805 // It doesn't currently work if they are on the same block as the |
| 802 // HLoopInfo. The handling of HLabeledBlockInformation will visit a | 806 // HLoopInfo. The handling of HLabeledBlockInformation will visit a |
| 803 // SubGraph that starts at the same block again, so the HLoopInfo is | 807 // SubGraph that starts at the same block again, so the HLoopInfo is |
| 804 // either handled twice, or it's handled after the labeled block info, | 808 // either handled twice, or it's handled after the labeled block info, |
| 805 // both of which generate the wrong code. | 809 // both of which generate the wrong code. |
| 806 // Using a separate block is just a simple workaround. | 810 // Using a separate block is just a simple workaround. |
| 807 bodyEntryBlock = openNewBlock(); | 811 bodyEntryBlock = openNewBlock(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 loopEntryBlock.loopInformation = null; | 903 loopEntryBlock.loopInformation = null; |
| 900 | 904 |
| 901 if (jumpHandler.hasAnyBreak()) { | 905 if (jumpHandler.hasAnyBreak()) { |
| 902 // Null branchBlock because the body of the do-while loop always aborts, | 906 // Null branchBlock because the body of the do-while loop always aborts, |
| 903 // so we never get to the condition. | 907 // so we never get to the condition. |
| 904 loopHandler.endLoop(loopEntryBlock, null, jumpHandler, localsHandler); | 908 loopHandler.endLoop(loopEntryBlock, null, jumpHandler, localsHandler); |
| 905 | 909 |
| 906 // Since the body of the loop has a break, we attach a synthesized label | 910 // Since the body of the loop has a break, we attach a synthesized label |
| 907 // to the body. | 911 // to the body. |
| 908 SubGraph bodyGraph = new SubGraph(bodyEntryBlock, bodyExitBlock); | 912 SubGraph bodyGraph = new SubGraph(bodyEntryBlock, bodyExitBlock); |
| 909 JumpTarget target = | 913 JumpTarget target = astAdapter.elements |
| 910 elements.getTargetDefinition(astAdapter.getNode(doStatement)); | 914 .getTargetDefinition(astAdapter.getNode(doStatement)); |
| 911 LabelDefinition label = target.addLabel(null, 'loop'); | 915 LabelDefinition label = target.addLabel(null, 'loop'); |
| 912 label.setBreakTarget(); | 916 label.setBreakTarget(); |
| 913 HLabeledBlockInformation info = new HLabeledBlockInformation( | 917 HLabeledBlockInformation info = new HLabeledBlockInformation( |
| 914 new HSubGraphBlockInformation(bodyGraph), <LabelDefinition>[label]); | 918 new HSubGraphBlockInformation(bodyGraph), <LabelDefinition>[label]); |
| 915 loopEntryBlock.setBlockFlow(info, current); | 919 loopEntryBlock.setBlockFlow(info, current); |
| 916 jumpHandler.forEachBreak((HBreak breakInstruction, _) { | 920 jumpHandler.forEachBreak((HBreak breakInstruction, _) { |
| 917 HBasicBlock block = breakInstruction.block; | 921 HBasicBlock block = breakInstruction.block; |
| 918 block.addAtExit(new HBreak.toLabel(label)); | 922 block.addAtExit(new HBreak.toLabel(label)); |
| 919 block.remove(breakInstruction); | 923 block.remove(breakInstruction); |
| 920 }); | 924 }); |
| (...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2480 kernelBuilder.open(exitBlock); | 2484 kernelBuilder.open(exitBlock); |
| 2481 enterBlock.setBlockFlow( | 2485 enterBlock.setBlockFlow( |
| 2482 new HTryBlockInformation( | 2486 new HTryBlockInformation( |
| 2483 kernelBuilder.wrapStatementGraph(bodyGraph), | 2487 kernelBuilder.wrapStatementGraph(bodyGraph), |
| 2484 exception, | 2488 exception, |
| 2485 kernelBuilder.wrapStatementGraph(catchGraph), | 2489 kernelBuilder.wrapStatementGraph(catchGraph), |
| 2486 kernelBuilder.wrapStatementGraph(finallyGraph)), | 2490 kernelBuilder.wrapStatementGraph(finallyGraph)), |
| 2487 exitBlock); | 2491 exitBlock); |
| 2488 } | 2492 } |
| 2489 } | 2493 } |
| OLD | NEW |