| 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.analyzer.ast_builder; | 5 library fasta.analyzer.ast_builder; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; | 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; |
| 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; | 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; |
| 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; | 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 rightParenthesis, | 826 rightParenthesis, |
| 827 body)); | 827 body)); |
| 828 } | 828 } |
| 829 } | 829 } |
| 830 | 830 |
| 831 void endFormalParameter(Token thisKeyword, Token nameToken, | 831 void endFormalParameter(Token thisKeyword, Token nameToken, |
| 832 FormalParameterType kind, MemberKind memberKind) { | 832 FormalParameterType kind, MemberKind memberKind) { |
| 833 debugEvent("FormalParameter"); | 833 debugEvent("FormalParameter"); |
| 834 _ParameterDefaultValue defaultValue = pop(); | 834 _ParameterDefaultValue defaultValue = pop(); |
| 835 | 835 |
| 836 AstNode nameOrFunctionTypedParameter = pop(); | 836 SimpleIdentifier name = pop(); |
| 837 |
| 838 AstNode typeOrFunctionTypedParameter = pop(); |
| 839 |
| 840 _Modifiers modifiers = pop(); |
| 841 Token keyword = modifiers?.finalConstOrVarKeyword; |
| 842 Token covariantKeyword = modifiers?.covariantKeyword; |
| 843 pop(); // TODO(paulberry): Metadata. |
| 844 Comment comment = pop(); |
| 837 | 845 |
| 838 FormalParameter node; | 846 FormalParameter node; |
| 839 SimpleIdentifier name; | 847 if (typeOrFunctionTypedParameter is FunctionTypedFormalParameter) { |
| 840 if (nameOrFunctionTypedParameter is FormalParameter) { | 848 // This is a temporary AST node that was constructed in |
| 841 node = nameOrFunctionTypedParameter; | 849 // [endFunctionTypedFormalParameter]. We now deconstruct it and create |
| 842 name = nameOrFunctionTypedParameter.identifier; | 850 // the final AST node. |
| 851 if (thisKeyword == null) { |
| 852 node = ast.functionTypedFormalParameter2( |
| 853 identifier: name, |
| 854 comment: comment, |
| 855 covariantKeyword: covariantKeyword, |
| 856 returnType: typeOrFunctionTypedParameter.returnType, |
| 857 typeParameters: typeOrFunctionTypedParameter.typeParameters, |
| 858 parameters: typeOrFunctionTypedParameter.parameters); |
| 859 } else { |
| 860 node = ast.fieldFormalParameter2( |
| 861 identifier: name, |
| 862 comment: comment, |
| 863 covariantKeyword: covariantKeyword, |
| 864 type: typeOrFunctionTypedParameter.returnType, |
| 865 thisKeyword: thisKeyword, |
| 866 period: thisKeyword.next, |
| 867 typeParameters: typeOrFunctionTypedParameter.typeParameters, |
| 868 parameters: typeOrFunctionTypedParameter.parameters); |
| 869 } |
| 843 } else { | 870 } else { |
| 844 name = nameOrFunctionTypedParameter; | 871 TypeAnnotation type = typeOrFunctionTypedParameter; |
| 845 TypeAnnotation type = pop(); | |
| 846 _Modifiers modifiers = pop(); | |
| 847 Token keyword = modifiers?.finalConstOrVarKeyword; | |
| 848 Token covariantKeyword = modifiers?.covariantKeyword; | |
| 849 pop(); // TODO(paulberry): Metadata. | |
| 850 Comment comment = pop(); | |
| 851 if (thisKeyword == null) { | 872 if (thisKeyword == null) { |
| 852 node = ast.simpleFormalParameter2( | 873 node = ast.simpleFormalParameter2( |
| 853 comment: comment, | 874 comment: comment, |
| 854 covariantKeyword: covariantKeyword, | 875 covariantKeyword: covariantKeyword, |
| 855 keyword: keyword, | 876 keyword: keyword, |
| 856 type: type, | 877 type: type, |
| 857 identifier: name); | 878 identifier: name); |
| 858 } else { | 879 } else { |
| 859 // TODO(scheglov): Ideally the period token should be passed in. | |
| 860 Token period = identical('.', thisKeyword.next?.stringValue) | |
| 861 ? thisKeyword.next | |
| 862 : null; | |
| 863 node = ast.fieldFormalParameter2( | 880 node = ast.fieldFormalParameter2( |
| 864 comment: comment, | 881 comment: comment, |
| 865 covariantKeyword: covariantKeyword, | 882 covariantKeyword: covariantKeyword, |
| 866 keyword: keyword, | 883 keyword: keyword, |
| 867 type: type, | 884 type: type, |
| 868 thisKeyword: thisKeyword, | 885 thisKeyword: thisKeyword, |
| 869 period: period, | 886 period: thisKeyword.next, |
| 870 identifier: name); | 887 identifier: name); |
| 871 } | 888 } |
| 872 } | 889 } |
| 873 | 890 |
| 874 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); | 891 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); |
| 875 if (analyzerKind != ParameterKind.REQUIRED) { | 892 if (analyzerKind != ParameterKind.REQUIRED) { |
| 876 node = ast.defaultFormalParameter( | 893 node = ast.defaultFormalParameter( |
| 877 node, analyzerKind, defaultValue?.separator, defaultValue?.value); | 894 node, analyzerKind, defaultValue?.separator, defaultValue?.value); |
| 878 } | 895 } |
| 879 | 896 |
| 880 if (name != null) { | 897 if (name != null) { |
| 881 scope.declare( | 898 scope.declare( |
| 882 name.name, | 899 name.name, |
| 883 name.staticElement = new AnalyzerParameterElement(node), | 900 name.staticElement = new AnalyzerParameterElement(node), |
| 884 name.offset, | 901 name.offset, |
| 885 uri); | 902 uri); |
| 886 } | 903 } |
| 887 push(node); | 904 push(node); |
| 888 } | 905 } |
| 889 | 906 |
| 890 @override | 907 @override |
| 891 void endFunctionTypedFormalParameter( | 908 void endFunctionTypedFormalParameter() { |
| 892 Token thisKeyword, FormalParameterType kind) { | |
| 893 debugEvent("FunctionTypedFormalParameter"); | 909 debugEvent("FunctionTypedFormalParameter"); |
| 894 | 910 |
| 895 FormalParameterList formalParameters = pop(); | 911 FormalParameterList formalParameters = pop(); |
| 912 TypeAnnotation returnType = pop(); |
| 896 TypeParameterList typeParameters = pop(); | 913 TypeParameterList typeParameters = pop(); |
| 897 SimpleIdentifier name = pop(); | |
| 898 TypeAnnotation returnType = pop(); | |
| 899 | 914 |
| 900 _Modifiers modifiers = pop(); | 915 // Create a temporary formal parameter that will be dissected later in |
| 901 Token covariantKeyword = modifiers?.covariantKeyword; | 916 // [endFormalParameter]. |
| 902 | 917 push(ast.functionTypedFormalParameter2( |
| 903 pop(); // TODO(paulberry): Metadata. | 918 identifier: null, |
| 904 Comment comment = pop(); | 919 returnType: returnType, |
| 905 | 920 typeParameters: typeParameters, |
| 906 FormalParameter node; | 921 parameters: formalParameters)); |
| 907 if (thisKeyword == null) { | |
| 908 node = ast.functionTypedFormalParameter2( | |
| 909 comment: comment, | |
| 910 covariantKeyword: covariantKeyword, | |
| 911 returnType: returnType, | |
| 912 identifier: name, | |
| 913 typeParameters: typeParameters, | |
| 914 parameters: formalParameters); | |
| 915 } else { | |
| 916 // TODO(scheglov): Ideally the period token should be passed in. | |
| 917 Token period = identical('.', thisKeyword?.next?.stringValue) | |
| 918 ? thisKeyword.next | |
| 919 : null; | |
| 920 node = ast.fieldFormalParameter2( | |
| 921 comment: comment, | |
| 922 covariantKeyword: covariantKeyword, | |
| 923 type: returnType, | |
| 924 thisKeyword: thisKeyword, | |
| 925 period: period, | |
| 926 identifier: name, | |
| 927 typeParameters: typeParameters, | |
| 928 parameters: formalParameters); | |
| 929 } | |
| 930 | |
| 931 scope.declare( | |
| 932 name.name, | |
| 933 name.staticElement = new AnalyzerParameterElement(node), | |
| 934 name.offset, | |
| 935 uri); | |
| 936 push(node); | |
| 937 } | 922 } |
| 938 | 923 |
| 939 void endFormalParameters( | 924 void endFormalParameters( |
| 940 int count, Token beginToken, Token endToken, MemberKind kind) { | 925 int count, Token beginToken, Token endToken, MemberKind kind) { |
| 941 debugEvent("FormalParameters"); | 926 debugEvent("FormalParameters"); |
| 942 List rawParameters = popList(count) ?? const <Object>[]; | 927 List rawParameters = popList(count) ?? const <Object>[]; |
| 943 List<FormalParameter> parameters = <FormalParameter>[]; | 928 List<FormalParameter> parameters = <FormalParameter>[]; |
| 944 Token leftDelimiter; | 929 Token leftDelimiter; |
| 945 Token rightDelimiter; | 930 Token rightDelimiter; |
| 946 for (Object raw in rawParameters) { | 931 for (Object raw in rawParameters) { |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 } else if (identical('var', s)) { | 2024 } else if (identical('var', s)) { |
| 2040 finalConstOrVarKeyword = token; | 2025 finalConstOrVarKeyword = token; |
| 2041 } else if (identical('covariant', s)) { | 2026 } else if (identical('covariant', s)) { |
| 2042 covariantKeyword = token; | 2027 covariantKeyword = token; |
| 2043 } else { | 2028 } else { |
| 2044 internalError('Unhandled modifier: $s'); | 2029 internalError('Unhandled modifier: $s'); |
| 2045 } | 2030 } |
| 2046 } | 2031 } |
| 2047 } | 2032 } |
| 2048 } | 2033 } |
| OLD | NEW |