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; |
11 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; | 11 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
12 import 'package:front_end/src/fasta/parser/parser.dart' | 12 import 'package:front_end/src/fasta/parser.dart' |
13 show Assert, FormalParameterType, MemberKind, Parser; | 13 show Assert, FormalParameterKind, IdentifierContext, MemberKind, Parser; |
14 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; | 14 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
15 import 'package:front_end/src/fasta/scanner/token.dart' show CommentToken; | 15 import 'package:front_end/src/fasta/scanner/token.dart' show CommentToken; |
16 import 'package:front_end/src/scanner/token.dart' as analyzer; | 16 import 'package:front_end/src/scanner/token.dart' as analyzer; |
17 | 17 |
18 import 'package:front_end/src/fasta/problems.dart' show unhandled; | 18 import 'package:front_end/src/fasta/problems.dart' show unhandled; |
19 import 'package:front_end/src/fasta/messages.dart' | 19 import 'package:front_end/src/fasta/messages.dart' |
20 show Code, Message, codeExpectedExpression, codeExpectedFunctionBody; | 20 show Code, Message, codeExpectedExpression, codeExpectedFunctionBody; |
21 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' | 21 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' |
22 show Builder, KernelLibraryBuilder, Scope; | 22 show Builder, KernelLibraryBuilder, Scope; |
23 import 'package:front_end/src/fasta/parser/identifier_context.dart' | |
24 show IdentifierContext; | |
25 import 'package:front_end/src/fasta/quote.dart'; | 23 import 'package:front_end/src/fasta/quote.dart'; |
26 import 'package:front_end/src/fasta/source/scope_listener.dart' | 24 import 'package:front_end/src/fasta/source/scope_listener.dart' |
27 show JumpTargetKind, NullValue, ScopeListener; | 25 show JumpTargetKind, NullValue, ScopeListener; |
28 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; | 26 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
29 | 27 |
30 class AstBuilder extends ScopeListener { | 28 class AstBuilder extends ScopeListener { |
31 final AstFactory ast = standard.astFactory; | 29 final AstFactory ast = standard.astFactory; |
32 | 30 |
33 final ErrorReporter errorReporter; | 31 final ErrorReporter errorReporter; |
34 final KernelLibraryBuilder library; | 32 final KernelLibraryBuilder library; |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 variableList.type, | 784 variableList.type, |
787 variableList.variables.single.name), | 785 variableList.variables.single.name), |
788 inKeyword, | 786 inKeyword, |
789 iterator, | 787 iterator, |
790 rightParenthesis, | 788 rightParenthesis, |
791 body)); | 789 body)); |
792 } | 790 } |
793 } | 791 } |
794 | 792 |
795 void endFormalParameter(Token thisKeyword, Token nameToken, | 793 void endFormalParameter(Token thisKeyword, Token nameToken, |
796 FormalParameterType kind, MemberKind memberKind) { | 794 FormalParameterKind kind, MemberKind memberKind) { |
797 debugEvent("FormalParameter"); | 795 debugEvent("FormalParameter"); |
798 _ParameterDefaultValue defaultValue = pop(); | 796 _ParameterDefaultValue defaultValue = pop(); |
799 | 797 |
800 SimpleIdentifier name = pop(); | 798 SimpleIdentifier name = pop(); |
801 | 799 |
802 AstNode typeOrFunctionTypedParameter = pop(); | 800 AstNode typeOrFunctionTypedParameter = pop(); |
803 | 801 |
804 _Modifiers modifiers = pop(); | 802 _Modifiers modifiers = pop(); |
805 Token keyword = modifiers?.finalConstOrVarKeyword; | 803 Token keyword = modifiers?.finalConstOrVarKeyword; |
806 Token covariantKeyword = modifiers?.covariantKeyword; | 804 Token covariantKeyword = modifiers?.covariantKeyword; |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 1748 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
1751 debugEvent("Metadata"); | 1749 debugEvent("Metadata"); |
1752 MethodInvocation invocation = pop(); | 1750 MethodInvocation invocation = pop(); |
1753 SimpleIdentifier constructorName = periodBeforeName != null ? pop() : null; | 1751 SimpleIdentifier constructorName = periodBeforeName != null ? pop() : null; |
1754 pop(); // Type arguments, not allowed. | 1752 pop(); // Type arguments, not allowed. |
1755 Identifier name = pop(); | 1753 Identifier name = pop(); |
1756 push(ast.annotation(beginToken, name, periodBeforeName, constructorName, | 1754 push(ast.annotation(beginToken, name, periodBeforeName, constructorName, |
1757 invocation?.argumentList)); | 1755 invocation?.argumentList)); |
1758 } | 1756 } |
1759 | 1757 |
1760 ParameterKind _toAnalyzerParameterKind(FormalParameterType type) { | 1758 ParameterKind _toAnalyzerParameterKind(FormalParameterKind type) { |
1761 if (type == FormalParameterType.POSITIONAL) { | 1759 if (type == FormalParameterKind.optionalPositional) { |
1762 return ParameterKind.POSITIONAL; | 1760 return ParameterKind.POSITIONAL; |
1763 } else if (type == FormalParameterType.NAMED) { | 1761 } else if (type == FormalParameterKind.optionalNamed) { |
1764 return ParameterKind.NAMED; | 1762 return ParameterKind.NAMED; |
1765 } else { | 1763 } else { |
1766 return ParameterKind.REQUIRED; | 1764 return ParameterKind.REQUIRED; |
1767 } | 1765 } |
1768 } | 1766 } |
1769 | 1767 |
1770 Comment _toAnalyzerComment(analyzer.Token comments) { | 1768 Comment _toAnalyzerComment(analyzer.Token comments) { |
1771 if (comments == null) return null; | 1769 if (comments == null) return null; |
1772 | 1770 |
1773 // This is temporary placeholder code to get tests to pass. | 1771 // This is temporary placeholder code to get tests to pass. |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 } else if (identical('var', s)) { | 1990 } else if (identical('var', s)) { |
1993 finalConstOrVarKeyword = token; | 1991 finalConstOrVarKeyword = token; |
1994 } else if (identical('covariant', s)) { | 1992 } else if (identical('covariant', s)) { |
1995 covariantKeyword = token; | 1993 covariantKeyword = token; |
1996 } else { | 1994 } else { |
1997 unhandled("$s", "modifier", token.charOffset, null); | 1995 unhandled("$s", "modifier", token.charOffset, null); |
1998 } | 1996 } |
1999 } | 1997 } |
2000 } | 1998 } |
2001 } | 1999 } |
OLD | NEW |