| 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/element/element.dart' show Element; | 11 import 'package:analyzer/dart/element/element.dart' show Element; |
| 12 import '../parser/parser.dart' show FormalParameterType; | 12 import '../parser/parser.dart' show FormalParameterType; |
| 13 import '../scanner/token.dart' show BeginGroupToken, Token; | 13 import '../scanner/token.dart' show BeginGroupToken, Token; |
| 14 | 14 |
| 15 import '../errors.dart' show internalError; | 15 import '../errors.dart' show internalError; |
| 16 import '../kernel/kernel_builder.dart' | 16 import '../kernel/kernel_builder.dart' |
| 17 show Builder, KernelLibraryBuilder, ProcedureBuilder; | 17 show Builder, KernelLibraryBuilder, ProcedureBuilder; |
| 18 import '../parser/identifier_context.dart' show IdentifierContext; | 18 import '../parser/identifier_context.dart' show IdentifierContext; |
| 19 import '../quote.dart'; | 19 import '../quote.dart'; |
| 20 import '../source/scope_listener.dart' | 20 import '../source/scope_listener.dart' |
| 21 show JumpTargetKind, NullValue, Scope, ScopeListener; | 21 show JumpTargetKind, NullValue, Scope, ScopeListener; |
| 22 import 'analyzer.dart' show toKernel; | 22 import 'analyzer.dart' show toKernel; |
| 23 import 'element_store.dart' | 23 import 'element_store.dart' |
| 24 show | 24 show |
| 25 AnalyzerLocalVariableElemment, | 25 AnalyzerLocalVariableElemment, |
| 26 AnalyzerParameterElement, | 26 AnalyzerParameterElement, |
| 27 ElementStore, | 27 ElementStore, |
| 28 KernelClassElement; | 28 KernelClassElement; |
| 29 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
| 30 import 'package:front_end/src/fasta/parser/error_kind.dart'; |
| 29 import 'token_utils.dart' show toAnalyzerToken, toAnalyzerCommentToken; | 31 import 'token_utils.dart' show toAnalyzerToken, toAnalyzerCommentToken; |
| 30 | 32 |
| 31 class AstBuilder extends ScopeListener { | 33 class AstBuilder extends ScopeListener { |
| 32 final AstFactory ast = standard.astFactory; | 34 final AstFactory ast = standard.astFactory; |
| 33 | 35 |
| 36 final ErrorReporter errorReporter; |
| 34 final KernelLibraryBuilder library; | 37 final KernelLibraryBuilder library; |
| 35 | |
| 36 final Builder member; | 38 final Builder member; |
| 37 | |
| 38 final ElementStore elementStore; | 39 final ElementStore elementStore; |
| 39 | 40 |
| 40 @override | 41 @override |
| 41 final Uri uri; | 42 final Uri uri; |
| 42 | 43 |
| 43 /// The name of the class currently being parsed, or `null` if no class is | 44 /// The name of the class currently being parsed, or `null` if no class is |
| 44 /// being parsed. | 45 /// being parsed. |
| 45 String className; | 46 String className; |
| 46 | 47 |
| 47 AstBuilder(this.library, this.member, this.elementStore, Scope scope, | 48 AstBuilder(this.errorReporter, this.library, this.member, this.elementStore, |
| 49 Scope scope, |
| 48 [Uri uri]) | 50 [Uri uri]) |
| 49 : uri = uri ?? library.fileUri, | 51 : uri = uri ?? library.fileUri, |
| 50 super(scope); | 52 super(scope); |
| 51 | 53 |
| 52 createJumpTarget(JumpTargetKind kind, int charOffset) { | 54 createJumpTarget(JumpTargetKind kind, int charOffset) { |
| 53 // TODO(ahe): Implement jump targets. | 55 // TODO(ahe): Implement jump targets. |
| 54 return null; | 56 return null; |
| 55 } | 57 } |
| 56 | 58 |
| 57 void beginLiteralString(Token token) { | 59 void beginLiteralString(Token token) { |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 push(expression); | 947 push(expression); |
| 946 } else { | 948 } else { |
| 947 push(ast.indexExpressionForTarget( | 949 push(ast.indexExpressionForTarget( |
| 948 target, | 950 target, |
| 949 toAnalyzerToken(openCurlyBracket), | 951 toAnalyzerToken(openCurlyBracket), |
| 950 index, | 952 index, |
| 951 toAnalyzerToken(closeCurlyBracket))); | 953 toAnalyzerToken(closeCurlyBracket))); |
| 952 } | 954 } |
| 953 } | 955 } |
| 954 | 956 |
| 957 @override |
| 958 void handleInvalidExpression(Token token) { |
| 959 debugEvent("InvalidExpression"); |
| 960 } |
| 961 |
| 962 @override |
| 963 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { |
| 964 if (kind == ErrorKind.ExpectedExpression) { |
| 965 String lexeme = token.lexeme; |
| 966 if (identical('async', lexeme) || identical('yield', lexeme)) { |
| 967 errorReporter?.reportErrorForOffset( |
| 968 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, |
| 969 token.charOffset, |
| 970 token.charCount); |
| 971 push(ast.simpleIdentifier(toAnalyzerToken(token))); |
| 972 return token; |
| 973 } |
| 974 } |
| 975 return super.handleUnrecoverableError(token, kind, arguments); |
| 976 } |
| 977 |
| 955 void handleUnaryPrefixExpression(Token token) { | 978 void handleUnaryPrefixExpression(Token token) { |
| 956 debugEvent("UnaryPrefixExpression"); | 979 debugEvent("UnaryPrefixExpression"); |
| 957 push(ast.prefixExpression(toAnalyzerToken(token), pop())); | 980 push(ast.prefixExpression(toAnalyzerToken(token), pop())); |
| 958 } | 981 } |
| 959 | 982 |
| 960 void handleUnaryPrefixAssignmentExpression(Token token) { | 983 void handleUnaryPrefixAssignmentExpression(Token token) { |
| 961 debugEvent("UnaryPrefixAssignmentExpression"); | 984 debugEvent("UnaryPrefixAssignmentExpression"); |
| 962 push(ast.prefixExpression(toAnalyzerToken(token), pop())); | 985 push(ast.prefixExpression(toAnalyzerToken(token), pop())); |
| 963 } | 986 } |
| 964 | 987 |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 } else if (identical('static', s)) { | 1791 } else if (identical('static', s)) { |
| 1769 staticKeyword = token; | 1792 staticKeyword = token; |
| 1770 } else if (identical('var', s)) { | 1793 } else if (identical('var', s)) { |
| 1771 finalConstOrVarKeyword = token; | 1794 finalConstOrVarKeyword = token; |
| 1772 } else { | 1795 } else { |
| 1773 internalError('Unhandled modifier: $s'); | 1796 internalError('Unhandled modifier: $s'); |
| 1774 } | 1797 } |
| 1775 } | 1798 } |
| 1776 } | 1799 } |
| 1777 } | 1800 } |
| OLD | NEW |