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 library fasta.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' | 7 import 'package:kernel/ast.dart' |
8 hide InvalidExpression, InvalidInitializer, InvalidStatement; | 8 hide InvalidExpression, InvalidInitializer, InvalidStatement; |
9 | 9 |
10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
(...skipping 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1723 // TODO(ahe): Unused code fasta.messageNonInstanceTypeVariableUse. | 1723 // TODO(ahe): Unused code fasta.messageNonInstanceTypeVariableUse. |
1724 } | 1724 } |
1725 | 1725 |
1726 @override | 1726 @override |
1727 void beginFunctionType(Token beginToken) { | 1727 void beginFunctionType(Token beginToken) { |
1728 debugEvent("beginFunctionType"); | 1728 debugEvent("beginFunctionType"); |
1729 enterFunctionTypeScope(); | 1729 enterFunctionTypeScope(); |
1730 } | 1730 } |
1731 | 1731 |
1732 void enterFunctionTypeScope() { | 1732 void enterFunctionTypeScope() { |
| 1733 debugEvent("enterFunctionTypeScope"); |
1733 List typeVariables = pop(); | 1734 List typeVariables = pop(); |
1734 enterLocalScope(scope.createNestedScope(isModifiable: false)); | 1735 enterLocalScope(null, |
| 1736 scope.createNestedScope("function-type scope", isModifiable: false)); |
1735 push(typeVariables ?? NullValue.TypeVariables); | 1737 push(typeVariables ?? NullValue.TypeVariables); |
1736 if (typeVariables != null) { | 1738 if (typeVariables != null) { |
1737 ScopeBuilder scopeBuilder = new ScopeBuilder(scope); | 1739 ScopeBuilder scopeBuilder = new ScopeBuilder(scope); |
1738 for (KernelTypeVariableBuilder builder in typeVariables) { | 1740 for (KernelTypeVariableBuilder builder in typeVariables) { |
1739 String name = builder.name; | 1741 String name = builder.name; |
1740 KernelTypeVariableBuilder existing = scopeBuilder[name]; | 1742 KernelTypeVariableBuilder existing = scopeBuilder[name]; |
1741 if (existing == null) { | 1743 if (existing == null) { |
1742 scopeBuilder.addMember(name, builder); | 1744 scopeBuilder.addMember(name, builder); |
1743 } else { | 1745 } else { |
1744 deprecated_addCompileTimeError( | 1746 deprecated_addCompileTimeError( |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 count--; | 1940 count--; |
1939 } | 1941 } |
1940 FormalParameters formals = new FormalParameters( | 1942 FormalParameters formals = new FormalParameters( |
1941 popList(count) ?? <VariableDeclaration>[], | 1943 popList(count) ?? <VariableDeclaration>[], |
1942 optional, | 1944 optional, |
1943 beginToken.charOffset); | 1945 beginToken.charOffset); |
1944 constantExpressionRequired = pop(); | 1946 constantExpressionRequired = pop(); |
1945 push(formals); | 1947 push(formals); |
1946 if ((inCatchClause || functionNestingLevel != 0) && | 1948 if ((inCatchClause || functionNestingLevel != 0) && |
1947 kind != MemberKind.GeneralizedFunctionType) { | 1949 kind != MemberKind.GeneralizedFunctionType) { |
1948 enterLocalScope(formals.computeFormalParameterScope( | 1950 enterLocalScope( |
1949 scope, member ?? classBuilder ?? library, this)); | 1951 null, |
| 1952 formals.computeFormalParameterScope( |
| 1953 scope, member ?? classBuilder ?? library, this)); |
1950 } | 1954 } |
1951 } | 1955 } |
1952 | 1956 |
1953 @override | 1957 @override |
1954 void beginCatchClause(Token token) { | 1958 void beginCatchClause(Token token) { |
1955 debugEvent("beginCatchClause"); | 1959 debugEvent("beginCatchClause"); |
1956 inCatchClause = true; | 1960 inCatchClause = true; |
1957 } | 1961 } |
1958 | 1962 |
1959 @override | 1963 @override |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2451 debugEvent("beginLocalFunctionDeclaration"); | 2455 debugEvent("beginLocalFunctionDeclaration"); |
2452 enterFunction(); | 2456 enterFunction(); |
2453 } | 2457 } |
2454 | 2458 |
2455 @override | 2459 @override |
2456 void beginNamedFunctionExpression(Token token) { | 2460 void beginNamedFunctionExpression(Token token) { |
2457 debugEvent("beginNamedFunctionExpression"); | 2461 debugEvent("beginNamedFunctionExpression"); |
2458 List typeVariables = pop(); | 2462 List typeVariables = pop(); |
2459 // Create an additional scope in which the named function expression is | 2463 // Create an additional scope in which the named function expression is |
2460 // declared. | 2464 // declared. |
2461 enterLocalScope(); | 2465 enterLocalScope("named function"); |
2462 push(typeVariables ?? NullValue.TypeVariables); | 2466 push(typeVariables ?? NullValue.TypeVariables); |
2463 enterFunction(); | 2467 enterFunction(); |
2464 } | 2468 } |
2465 | 2469 |
2466 @override | 2470 @override |
2467 void beginFunctionExpression(Token token) { | 2471 void beginFunctionExpression(Token token) { |
2468 debugEvent("beginFunctionExpression"); | 2472 debugEvent("beginFunctionExpression"); |
2469 enterFunction(); | 2473 enterFunction(); |
2470 } | 2474 } |
2471 | 2475 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2573 ..fileOffset = doKeyword.charOffset; | 2577 ..fileOffset = doKeyword.charOffset; |
2574 if (breakTarget.hasUsers) { | 2578 if (breakTarget.hasUsers) { |
2575 result = new KernelLabeledStatement(result); | 2579 result = new KernelLabeledStatement(result); |
2576 breakTarget.resolveBreaks(result); | 2580 breakTarget.resolveBreaks(result); |
2577 } | 2581 } |
2578 exitLoopOrSwitch(result); | 2582 exitLoopOrSwitch(result); |
2579 } | 2583 } |
2580 | 2584 |
2581 @override | 2585 @override |
2582 void beginForInExpression(Token token) { | 2586 void beginForInExpression(Token token) { |
2583 enterLocalScope(scope.parent); | 2587 enterLocalScope(null, scope.parent); |
2584 } | 2588 } |
2585 | 2589 |
2586 @override | 2590 @override |
2587 void endForInExpression(Token token) { | 2591 void endForInExpression(Token token) { |
2588 debugEvent("ForInExpression"); | 2592 debugEvent("ForInExpression"); |
2589 Expression expression = popForValue(); | 2593 Expression expression = popForValue(); |
2590 exitLocalScope(); | 2594 exitLocalScope(); |
2591 push(expression ?? NullValue.Expression); | 2595 push(expression ?? NullValue.Expression); |
2592 } | 2596 } |
2593 | 2597 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2651 void handleLabel(Token token) { | 2655 void handleLabel(Token token) { |
2652 debugEvent("Label"); | 2656 debugEvent("Label"); |
2653 Identifier identifier = pop(); | 2657 Identifier identifier = pop(); |
2654 push(new Label(identifier.name)); | 2658 push(new Label(identifier.name)); |
2655 } | 2659 } |
2656 | 2660 |
2657 @override | 2661 @override |
2658 void beginLabeledStatement(Token token, int labelCount) { | 2662 void beginLabeledStatement(Token token, int labelCount) { |
2659 debugEvent("beginLabeledStatement"); | 2663 debugEvent("beginLabeledStatement"); |
2660 List<Label> labels = popList(labelCount); | 2664 List<Label> labels = popList(labelCount); |
2661 enterLocalScope(scope.createNestedLabelScope()); | 2665 enterLocalScope(null, scope.createNestedLabelScope()); |
2662 LabelTarget target = | 2666 LabelTarget target = |
2663 new LabelTarget(member, functionNestingLevel, token.charOffset); | 2667 new LabelTarget(member, functionNestingLevel, token.charOffset); |
2664 for (Label label in labels) { | 2668 for (Label label in labels) { |
2665 scope.declareLabel(label.name, target); | 2669 scope.declareLabel(label.name, target); |
2666 } | 2670 } |
2667 push(target); | 2671 push(target); |
2668 } | 2672 } |
2669 | 2673 |
2670 @override | 2674 @override |
2671 void endLabeledStatement(int labelCount) { | 2675 void endLabeledStatement(int labelCount) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2793 @override | 2797 @override |
2794 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) { | 2798 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) { |
2795 debugEvent("YieldStatement"); | 2799 debugEvent("YieldStatement"); |
2796 push(new KernelYieldStatement(popForValue(), isYieldStar: starToken != null) | 2800 push(new KernelYieldStatement(popForValue(), isYieldStar: starToken != null) |
2797 ..fileOffset = yieldToken.charOffset); | 2801 ..fileOffset = yieldToken.charOffset); |
2798 } | 2802 } |
2799 | 2803 |
2800 @override | 2804 @override |
2801 void beginSwitchBlock(Token token) { | 2805 void beginSwitchBlock(Token token) { |
2802 debugEvent("beginSwitchBlock"); | 2806 debugEvent("beginSwitchBlock"); |
2803 enterLocalScope(); | 2807 enterLocalScope("switch block"); |
2804 enterSwitchScope(); | 2808 enterSwitchScope(); |
2805 enterBreakTarget(token.charOffset); | 2809 enterBreakTarget(token.charOffset); |
2806 } | 2810 } |
2807 | 2811 |
2808 @override | 2812 @override |
2809 void beginSwitchCase(int labelCount, int expressionCount, Token firstToken) { | 2813 void beginSwitchCase(int labelCount, int expressionCount, Token firstToken) { |
2810 debugEvent("beginSwitchCase"); | 2814 debugEvent("beginSwitchCase"); |
2811 List labelsAndExpressions = popList(labelCount + expressionCount); | 2815 List labelsAndExpressions = popList(labelCount + expressionCount); |
2812 List<Label> labels = <Label>[]; | 2816 List<Label> labels = <Label>[]; |
2813 List<Expression> expressions = <Expression>[]; | 2817 List<Expression> expressions = <Expression>[]; |
(...skipping 10 matching lines...) Expand all Loading... |
2824 for (Label label in labels) { | 2828 for (Label label in labels) { |
2825 if (scope.hasLocalLabel(label.name)) { | 2829 if (scope.hasLocalLabel(label.name)) { |
2826 // TODO(ahe): Should validate this is a goto target and not duplicated. | 2830 // TODO(ahe): Should validate this is a goto target and not duplicated. |
2827 scope.claimLabel(label.name); | 2831 scope.claimLabel(label.name); |
2828 } else { | 2832 } else { |
2829 scope.declareLabel(label.name, createGotoTarget(firstToken.charOffset)); | 2833 scope.declareLabel(label.name, createGotoTarget(firstToken.charOffset)); |
2830 } | 2834 } |
2831 } | 2835 } |
2832 push(expressions); | 2836 push(expressions); |
2833 push(labels); | 2837 push(labels); |
2834 enterLocalScope(); | 2838 enterLocalScope("switch case"); |
2835 } | 2839 } |
2836 | 2840 |
2837 @override | 2841 @override |
2838 void endSwitchCase(int labelCount, int expressionCount, Token defaultKeyword, | 2842 void endSwitchCase(int labelCount, int expressionCount, Token defaultKeyword, |
2839 int statementCount, Token firstToken, Token endToken) { | 2843 int statementCount, Token firstToken, Token endToken) { |
2840 debugEvent("SwitchCase"); | 2844 debugEvent("SwitchCase"); |
2841 // We always create a block here so that we later know that there's always | 2845 // We always create a block here so that we later know that there's always |
2842 // one synthetic block when we finish compiling the switch statement and | 2846 // one synthetic block when we finish compiling the switch statement and |
2843 // check this switch case to see if it falls through to the next case. | 2847 // check this switch case to see if it falls through to the next case. |
2844 Block block = popBlock(statementCount, firstToken); | 2848 Block block = popBlock(statementCount, firstToken); |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3757 if (optional != null) { | 3761 if (optional != null) { |
3758 for (VariableDeclaration parameter in optional.formals) { | 3762 for (VariableDeclaration parameter in optional.formals) { |
3759 if (local[parameter.name] != null) { | 3763 if (local[parameter.name] != null) { |
3760 helper.deprecated_addCompileTimeError( | 3764 helper.deprecated_addCompileTimeError( |
3761 parameter.fileOffset, "Duplicated name."); | 3765 parameter.fileOffset, "Duplicated name."); |
3762 } | 3766 } |
3763 local[parameter.name] = | 3767 local[parameter.name] = |
3764 new KernelVariableBuilder(parameter, builder, builder.fileUri); | 3768 new KernelVariableBuilder(parameter, builder, builder.fileUri); |
3765 } | 3769 } |
3766 } | 3770 } |
3767 return new Scope(local, null, parent, isModifiable: false); | 3771 return new Scope(local, null, parent, "formals", isModifiable: false); |
3768 } | 3772 } |
3769 } | 3773 } |
3770 | 3774 |
3771 /// Returns a block like this: | 3775 /// Returns a block like this: |
3772 /// | 3776 /// |
3773 /// { | 3777 /// { |
3774 /// statement; | 3778 /// statement; |
3775 /// body; | 3779 /// body; |
3776 /// } | 3780 /// } |
3777 /// | 3781 /// |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3818 return AsyncMarker.Async; | 3822 return AsyncMarker.Async; |
3819 } else { | 3823 } else { |
3820 assert(identical(starToken.stringValue, "*")); | 3824 assert(identical(starToken.stringValue, "*")); |
3821 return AsyncMarker.AsyncStar; | 3825 return AsyncMarker.AsyncStar; |
3822 } | 3826 } |
3823 } else { | 3827 } else { |
3824 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", | 3828 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", |
3825 asyncToken.charOffset, null); | 3829 asyncToken.charOffset, null); |
3826 } | 3830 } |
3827 } | 3831 } |
OLD | NEW |