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) { |
Johnni Winther
2017/07/05 10:46:00
Add comment that this is created as an temp object
ahe
2017/07/05 11:52:12
Done.
| |
840 if (nameOrFunctionTypedParameter is FormalParameter) { | 848 if (thisKeyword == null) { |
841 node = nameOrFunctionTypedParameter; | 849 node = ast.functionTypedFormalParameter2( |
842 name = nameOrFunctionTypedParameter.identifier; | 850 identifier: name, |
851 comment: comment, | |
852 covariantKeyword: covariantKeyword, | |
853 returnType: typeOrFunctionTypedParameter.returnType, | |
854 typeParameters: typeOrFunctionTypedParameter.typeParameters, | |
855 parameters: typeOrFunctionTypedParameter.parameters); | |
856 } else { | |
857 node = ast.fieldFormalParameter2( | |
858 identifier: name, | |
859 comment: comment, | |
860 covariantKeyword: covariantKeyword, | |
861 type: typeOrFunctionTypedParameter.returnType, | |
862 thisKeyword: thisKeyword, | |
863 period: thisKeyword.next, | |
864 typeParameters: typeOrFunctionTypedParameter.typeParameters, | |
865 parameters: typeOrFunctionTypedParameter.parameters); | |
866 } | |
843 } else { | 867 } else { |
844 name = nameOrFunctionTypedParameter; | 868 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) { | 869 if (thisKeyword == null) { |
852 node = ast.simpleFormalParameter2( | 870 node = ast.simpleFormalParameter2( |
853 comment: comment, | 871 comment: comment, |
854 covariantKeyword: covariantKeyword, | 872 covariantKeyword: covariantKeyword, |
855 keyword: keyword, | 873 keyword: keyword, |
856 type: type, | 874 type: type, |
857 identifier: name); | 875 identifier: name); |
858 } else { | 876 } 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( | 877 node = ast.fieldFormalParameter2( |
864 comment: comment, | 878 comment: comment, |
865 covariantKeyword: covariantKeyword, | 879 covariantKeyword: covariantKeyword, |
866 keyword: keyword, | 880 keyword: keyword, |
867 type: type, | 881 type: type, |
868 thisKeyword: thisKeyword, | 882 thisKeyword: thisKeyword, |
869 period: period, | 883 period: thisKeyword.next, |
870 identifier: name); | 884 identifier: name); |
871 } | 885 } |
872 } | 886 } |
873 | 887 |
874 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); | 888 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); |
875 if (analyzerKind != ParameterKind.REQUIRED) { | 889 if (analyzerKind != ParameterKind.REQUIRED) { |
876 node = ast.defaultFormalParameter( | 890 node = ast.defaultFormalParameter( |
877 node, analyzerKind, defaultValue?.separator, defaultValue?.value); | 891 node, analyzerKind, defaultValue?.separator, defaultValue?.value); |
878 } | 892 } |
879 | 893 |
880 if (name != null) { | 894 if (name != null) { |
881 scope.declare( | 895 scope.declare( |
882 name.name, | 896 name.name, |
883 name.staticElement = new AnalyzerParameterElement(node), | 897 name.staticElement = new AnalyzerParameterElement(node), |
884 name.offset, | 898 name.offset, |
885 uri); | 899 uri); |
886 } | 900 } |
887 push(node); | 901 push(node); |
888 } | 902 } |
889 | 903 |
890 @override | 904 @override |
891 void endFunctionTypedFormalParameter( | 905 void endFunctionTypedFormalParameter() { |
892 Token thisKeyword, FormalParameterType kind) { | |
893 debugEvent("FunctionTypedFormalParameter"); | 906 debugEvent("FunctionTypedFormalParameter"); |
894 | 907 |
895 FormalParameterList formalParameters = pop(); | 908 FormalParameterList formalParameters = pop(); |
909 TypeAnnotation returnType = pop(); | |
896 TypeParameterList typeParameters = pop(); | 910 TypeParameterList typeParameters = pop(); |
897 SimpleIdentifier name = pop(); | |
898 TypeAnnotation returnType = pop(); | |
899 | 911 |
900 _Modifiers modifiers = pop(); | 912 // Create a temporary formal parameter that will be dissected later in |
901 Token covariantKeyword = modifiers?.covariantKeyword; | 913 // [endFormalParameter]. |
902 | 914 push(ast.functionTypedFormalParameter2( |
903 pop(); // TODO(paulberry): Metadata. | 915 identifier: null, |
904 Comment comment = pop(); | 916 returnType: returnType, |
905 | 917 typeParameters: typeParameters, |
906 FormalParameter node; | 918 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 } | 919 } |
938 | 920 |
939 void endFormalParameters( | 921 void endFormalParameters( |
940 int count, Token beginToken, Token endToken, MemberKind kind) { | 922 int count, Token beginToken, Token endToken, MemberKind kind) { |
941 debugEvent("FormalParameters"); | 923 debugEvent("FormalParameters"); |
942 List rawParameters = popList(count) ?? const <Object>[]; | 924 List rawParameters = popList(count) ?? const <Object>[]; |
943 List<FormalParameter> parameters = <FormalParameter>[]; | 925 List<FormalParameter> parameters = <FormalParameter>[]; |
944 Token leftDelimiter; | 926 Token leftDelimiter; |
945 Token rightDelimiter; | 927 Token rightDelimiter; |
946 for (Object raw in rawParameters) { | 928 for (Object raw in rawParameters) { |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2039 } else if (identical('var', s)) { | 2021 } else if (identical('var', s)) { |
2040 finalConstOrVarKeyword = token; | 2022 finalConstOrVarKeyword = token; |
2041 } else if (identical('covariant', s)) { | 2023 } else if (identical('covariant', s)) { |
2042 covariantKeyword = token; | 2024 covariantKeyword = token; |
2043 } else { | 2025 } else { |
2044 internalError('Unhandled modifier: $s'); | 2026 internalError('Unhandled modifier: $s'); |
2045 } | 2027 } |
2046 } | 2028 } |
2047 } | 2029 } |
2048 } | 2030 } |
OLD | NEW |