| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 // TODO(karlklose): consider removing this and keeping the (substituted) types | 661 // TODO(karlklose): consider removing this and keeping the (substituted) types |
| 662 // of the type variables in an environment (like the [LocalsHandler]). | 662 // of the type variables in an environment (like the [LocalsHandler]). |
| 663 final List<ResolutionDartType> currentInlinedInstantiations = | 663 final List<ResolutionDartType> currentInlinedInstantiations = |
| 664 <ResolutionDartType>[]; | 664 <ResolutionDartType>[]; |
| 665 | 665 |
| 666 final List<AstInliningState> inliningStack = <AstInliningState>[]; | 666 final List<AstInliningState> inliningStack = <AstInliningState>[]; |
| 667 | 667 |
| 668 Local returnLocal; | 668 Local returnLocal; |
| 669 ResolutionDartType returnType; | 669 ResolutionDartType returnType; |
| 670 | 670 |
| 671 bool inTryStatement = false; | |
| 672 | |
| 673 ConstantValue getConstantForNode(ast.Node node) { | 671 ConstantValue getConstantForNode(ast.Node node) { |
| 674 ConstantValue constantValue = | 672 ConstantValue constantValue = |
| 675 backend.constants.getConstantValueForNode(node, elements); | 673 backend.constants.getConstantValueForNode(node, elements); |
| 676 assert(invariant(node, constantValue != null, | 674 assert(invariant(node, constantValue != null, |
| 677 message: 'No constant computed for $node')); | 675 message: 'No constant computed for $node')); |
| 678 return constantValue; | 676 return constantValue; |
| 679 } | 677 } |
| 680 | 678 |
| 681 HInstruction addConstant(ast.Node node) { | 679 HInstruction addConstant(ast.Node node) { |
| 682 return graph.addConstant(getConstantForNode(node), closedWorld); | 680 return graph.addConstant(getConstantForNode(node), closedWorld); |
| (...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1904 | 1902 |
| 1905 visitIdentifier(ast.Identifier node) { | 1903 visitIdentifier(ast.Identifier node) { |
| 1906 if (node.isThis()) { | 1904 if (node.isThis()) { |
| 1907 visitThisGet(node); | 1905 visitThisGet(node); |
| 1908 } else { | 1906 } else { |
| 1909 reporter.internalError( | 1907 reporter.internalError( |
| 1910 node, "SsaFromAstMixin.visitIdentifier on non-this."); | 1908 node, "SsaFromAstMixin.visitIdentifier on non-this."); |
| 1911 } | 1909 } |
| 1912 } | 1910 } |
| 1913 | 1911 |
| 1912 void handleIf( |
| 1913 {ast.Node node, |
| 1914 void visitCondition(), |
| 1915 void visitThen(), |
| 1916 void visitElse(), |
| 1917 SourceInformation sourceInformation}) { |
| 1918 SsaBranchBuilder branchBuilder = new SsaBranchBuilder(this, compiler, node); |
| 1919 branchBuilder.handleIf(visitCondition, visitThen, visitElse, |
| 1920 sourceInformation: sourceInformation); |
| 1921 } |
| 1922 |
| 1914 visitIf(ast.If node) { | 1923 visitIf(ast.If node) { |
| 1915 assert(isReachable); | 1924 assert(isReachable); |
| 1916 handleIf( | 1925 handleIf( |
| 1917 node: node, | 1926 node: node, |
| 1918 visitCondition: () => visit(node.condition), | 1927 visitCondition: () => visit(node.condition), |
| 1919 visitThen: () => visit(node.thenPart), | 1928 visitThen: () => visit(node.thenPart), |
| 1920 visitElse: node.elsePart != null ? () => visit(node.elsePart) : null, | 1929 visitElse: node.elsePart != null ? () => visit(node.elsePart) : null, |
| 1921 sourceInformation: sourceInformationBuilder.buildIf(node)); | 1930 sourceInformation: sourceInformationBuilder.buildIf(node)); |
| 1922 } | 1931 } |
| 1923 | 1932 |
| (...skipping 3123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5047 visit(node.expression); | 5056 visit(node.expression); |
| 5048 // Remove the result and reveal the duplicated receiver on the stack. | 5057 // Remove the result and reveal the duplicated receiver on the stack. |
| 5049 pop(); | 5058 pop(); |
| 5050 } | 5059 } |
| 5051 | 5060 |
| 5052 visitCascadeReceiver(ast.CascadeReceiver node) { | 5061 visitCascadeReceiver(ast.CascadeReceiver node) { |
| 5053 visit(node.expression); | 5062 visit(node.expression); |
| 5054 dup(); | 5063 dup(); |
| 5055 } | 5064 } |
| 5056 | 5065 |
| 5057 void handleInTryStatement() { | |
| 5058 if (!inTryStatement) return; | |
| 5059 HBasicBlock block = close(new HExitTry()); | |
| 5060 HBasicBlock newBlock = graph.addNewBlock(); | |
| 5061 block.addSuccessor(newBlock); | |
| 5062 open(newBlock); | |
| 5063 } | |
| 5064 | |
| 5065 visitRethrow(ast.Rethrow node) { | 5066 visitRethrow(ast.Rethrow node) { |
| 5066 HInstruction exception = rethrowableException; | 5067 HInstruction exception = rethrowableException; |
| 5067 if (exception == null) { | 5068 if (exception == null) { |
| 5068 exception = graph.addConstantNull(closedWorld); | 5069 exception = graph.addConstantNull(closedWorld); |
| 5069 reporter.internalError(node, 'rethrowableException should not be null.'); | 5070 reporter.internalError(node, 'rethrowableException should not be null.'); |
| 5070 } | 5071 } |
| 5071 handleInTryStatement(); | 5072 handleInTryStatement(); |
| 5072 closeAndGotoExit(new HThrow( | 5073 closeAndGotoExit(new HThrow( |
| 5073 exception, sourceInformationBuilder.buildThrow(node), | 5074 exception, sourceInformationBuilder.buildThrow(node), |
| 5074 isRethrow: true)); | 5075 isRethrow: true)); |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5979 } | 5980 } |
| 5980 | 5981 |
| 5981 /** | 5982 /** |
| 5982 * Creates a switch statement. | 5983 * Creates a switch statement. |
| 5983 * | 5984 * |
| 5984 * [jumpHandler] is the [JumpHandler] for the created switch statement. | 5985 * [jumpHandler] is the [JumpHandler] for the created switch statement. |
| 5985 * [buildExpression] creates the switch expression. | 5986 * [buildExpression] creates the switch expression. |
| 5986 * [switchCases] must be either an [Iterable] of [ast.SwitchCase] nodes or | 5987 * [switchCases] must be either an [Iterable] of [ast.SwitchCase] nodes or |
| 5987 * a [Link] or a [ast.NodeList] of [ast.SwitchCase] nodes. | 5988 * a [Link] or a [ast.NodeList] of [ast.SwitchCase] nodes. |
| 5988 * [getConstants] returns the set of constants for a switch case. | 5989 * [getConstants] returns the set of constants for a switch case. |
| 5989 * [isDefaultCase] returns [:true:] if the provided switch case should be | 5990 * [isDefaultCase] returns true if the provided switch case should be |
| 5990 * considered default for the created switch statement. | 5991 * considered default for the created switch statement. |
| 5991 * [buildSwitchCase] creates the statements for the switch case. | 5992 * [buildSwitchCase] creates the statements for the switch case. |
| 5992 */ | 5993 */ |
| 5993 void handleSwitch( | 5994 void handleSwitch( |
| 5994 ast.Node errorNode, | 5995 ast.Node errorNode, |
| 5995 JumpHandler jumpHandler, | 5996 JumpHandler jumpHandler, |
| 5996 HInstruction buildExpression(), | 5997 HInstruction buildExpression(), |
| 5997 var switchCases, | 5998 var switchCases, |
| 5998 Iterable<ConstantValue> getConstants(ast.SwitchCase switchCase), | 5999 Iterable<ConstantValue> getConstants(ast.SwitchCase switchCase), |
| 5999 bool isDefaultCase(ast.SwitchCase switchCase), | 6000 bool isDefaultCase(ast.SwitchCase switchCase), |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6771 this.oldReturnLocal, | 6772 this.oldReturnLocal, |
| 6772 this.oldReturnType, | 6773 this.oldReturnType, |
| 6773 this.oldResolvedAst, | 6774 this.oldResolvedAst, |
| 6774 this.oldStack, | 6775 this.oldStack, |
| 6775 this.oldLocalsHandler, | 6776 this.oldLocalsHandler, |
| 6776 this.inTryStatement, | 6777 this.inTryStatement, |
| 6777 this.allFunctionsCalledOnce, | 6778 this.allFunctionsCalledOnce, |
| 6778 this.oldElementInferenceResults) | 6779 this.oldElementInferenceResults) |
| 6779 : super(function); | 6780 : super(function); |
| 6780 } | 6781 } |
| OLD | NEW |