| 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 TokenType; | 11 import 'package:analyzer/dart/ast/token.dart' show TokenType; |
| 12 import 'package:analyzer/dart/element/element.dart' show Element; | 12 import 'package:analyzer/dart/element/element.dart' show Element; |
| 13 import 'package:front_end/src/fasta/parser/parser.dart' | 13 import 'package:front_end/src/fasta/parser/parser.dart' |
| 14 show FormalParameterType, Parser; | 14 show FormalParameterType, Parser; |
| 15 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; | 15 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
| 16 import 'package:front_end/src/fasta/scanner/token.dart' | 16 import 'package:front_end/src/fasta/scanner/token.dart' |
| 17 show BeginGroupToken, CommentToken, Token; | 17 show BeginGroupToken, CommentToken, Token; |
| 18 import 'package:front_end/src/scanner/token.dart' as analyzer; |
| 18 | 19 |
| 19 import 'package:front_end/src/fasta/errors.dart' show internalError; | 20 import 'package:front_end/src/fasta/errors.dart' show internalError; |
| 20 import 'package:front_end/src/fasta/fasta_codes.dart' | 21 import 'package:front_end/src/fasta/fasta_codes.dart' |
| 21 show FastaMessage, codeExpectedExpression, codeExpectedFunctionBody; | 22 show FastaMessage, codeExpectedExpression, codeExpectedFunctionBody; |
| 22 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' | 23 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' |
| 23 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope; | 24 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope; |
| 24 import 'package:front_end/src/fasta/parser/identifier_context.dart' | 25 import 'package:front_end/src/fasta/parser/identifier_context.dart' |
| 25 show IdentifierContext; | 26 show IdentifierContext; |
| 26 import 'package:front_end/src/fasta/quote.dart'; | 27 import 'package:front_end/src/fasta/quote.dart'; |
| 27 import 'package:front_end/src/fasta/source/scope_listener.dart' | 28 import 'package:front_end/src/fasta/source/scope_listener.dart' |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (context.inLibraryOrPartOfDeclaration) { | 206 if (context.inLibraryOrPartOfDeclaration) { |
| 206 if (!context.isContinuation) { | 207 if (!context.isContinuation) { |
| 207 push([identifier]); | 208 push([identifier]); |
| 208 } else { | 209 } else { |
| 209 push(identifier); | 210 push(identifier); |
| 210 } | 211 } |
| 211 } else if (context == IdentifierContext.enumValueDeclaration) { | 212 } else if (context == IdentifierContext.enumValueDeclaration) { |
| 212 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have | 213 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have |
| 213 // metadata, but the spec doesn't permit it. | 214 // metadata, but the spec doesn't permit it. |
| 214 List<Annotation> metadata; | 215 List<Annotation> metadata; |
| 215 Comment comment = _toAnalyzerComment(token.precedingCommentTokens); | 216 Comment comment = _toAnalyzerComment(token.precedingComments); |
| 216 push(ast.enumConstantDeclaration(comment, metadata, identifier)); | 217 push(ast.enumConstantDeclaration(comment, metadata, identifier)); |
| 217 } else { | 218 } else { |
| 218 if (context.isScopeReference) { | 219 if (context.isScopeReference) { |
| 219 String name = token.lexeme; | 220 String name = token.lexeme; |
| 220 Builder builder = scope.lookup(name, token.charOffset, uri); | 221 Builder builder = scope.lookup(name, token.charOffset, uri); |
| 221 if (builder != null) { | 222 if (builder != null) { |
| 222 Element element = elementStore[builder]; | 223 Element element = elementStore[builder]; |
| 223 assert(element != null); | 224 assert(element != null); |
| 224 identifier.staticElement = element; | 225 identifier.staticElement = element; |
| 225 } | 226 } |
| (...skipping 1630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1856 void handleOperatorName(Token operatorKeyword, Token token) { | 1857 void handleOperatorName(Token operatorKeyword, Token token) { |
| 1857 debugEvent("OperatorName"); | 1858 debugEvent("OperatorName"); |
| 1858 push(new _OperatorName(operatorKeyword, | 1859 push(new _OperatorName(operatorKeyword, |
| 1859 ast.simpleIdentifier(toAnalyzerToken(token), isDeclaration: true))); | 1860 ast.simpleIdentifier(toAnalyzerToken(token), isDeclaration: true))); |
| 1860 } | 1861 } |
| 1861 | 1862 |
| 1862 @override | 1863 @override |
| 1863 void beginMetadataStar(Token token) { | 1864 void beginMetadataStar(Token token) { |
| 1864 debugEvent("beginMetadataStar"); | 1865 debugEvent("beginMetadataStar"); |
| 1865 if (token.precedingComments != null) { | 1866 if (token.precedingComments != null) { |
| 1866 push(_toAnalyzerComment(token.precedingCommentTokens)); | 1867 push(_toAnalyzerComment(token.precedingComments)); |
| 1867 } else { | 1868 } else { |
| 1868 push(NullValue.Comments); | 1869 push(NullValue.Comments); |
| 1869 } | 1870 } |
| 1870 } | 1871 } |
| 1871 | 1872 |
| 1872 @override | 1873 @override |
| 1873 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 1874 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
| 1874 debugEvent("Metadata"); | 1875 debugEvent("Metadata"); |
| 1875 MethodInvocation invocation = pop(); | 1876 MethodInvocation invocation = pop(); |
| 1876 SimpleIdentifier constructorName = periodBeforeName != null ? pop() : null; | 1877 SimpleIdentifier constructorName = periodBeforeName != null ? pop() : null; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1887 ParameterKind _toAnalyzerParameterKind(FormalParameterType type) { | 1888 ParameterKind _toAnalyzerParameterKind(FormalParameterType type) { |
| 1888 if (type == FormalParameterType.POSITIONAL) { | 1889 if (type == FormalParameterType.POSITIONAL) { |
| 1889 return ParameterKind.POSITIONAL; | 1890 return ParameterKind.POSITIONAL; |
| 1890 } else if (type == FormalParameterType.NAMED) { | 1891 } else if (type == FormalParameterType.NAMED) { |
| 1891 return ParameterKind.NAMED; | 1892 return ParameterKind.NAMED; |
| 1892 } else { | 1893 } else { |
| 1893 return ParameterKind.REQUIRED; | 1894 return ParameterKind.REQUIRED; |
| 1894 } | 1895 } |
| 1895 } | 1896 } |
| 1896 | 1897 |
| 1897 Comment _toAnalyzerComment(Token comments) { | 1898 Comment _toAnalyzerComment(analyzer.Token comments) { |
| 1898 if (comments == null) return null; | 1899 if (comments == null) return null; |
| 1899 | 1900 |
| 1900 // This is temporary placeholder code to get tests to pass. | 1901 // This is temporary placeholder code to get tests to pass. |
| 1901 // TODO(paulberry): after analyzer and fasta token representations are | 1902 // TODO(paulberry): after analyzer and fasta token representations are |
| 1902 // unified, refactor the code in analyzer's parser that handles | 1903 // unified, refactor the code in analyzer's parser that handles |
| 1903 // documentation comments so that it is reusable, and reuse it here. | 1904 // documentation comments so that it is reusable, and reuse it here. |
| 1904 // See Parser.parseCommentAndMetadata | 1905 // See Parser.parseCommentAndMetadata |
| 1905 var tokens = <analyzer.Token>[toAnalyzerCommentToken(comments)]; | 1906 var tokens = <analyzer.Token>[toAnalyzerCommentToken(comments)]; |
| 1906 var references = <CommentReference>[]; | 1907 var references = <CommentReference>[]; |
| 1907 return ast.documentationComment(tokens, references); | 1908 return ast.documentationComment(tokens, references); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 void discardTypeReplacedWithCommentTypeAssign() { | 1943 void discardTypeReplacedWithCommentTypeAssign() { |
| 1943 pop(); | 1944 pop(); |
| 1944 } | 1945 } |
| 1945 | 1946 |
| 1946 /// Check if the given [token] has a comment token with the given [type], | 1947 /// Check if the given [token] has a comment token with the given [type], |
| 1947 /// which should be either [TokenType.GENERIC_METHOD_TYPE_ASSIGN] or | 1948 /// which should be either [TokenType.GENERIC_METHOD_TYPE_ASSIGN] or |
| 1948 /// [TokenType.GENERIC_METHOD_TYPE_LIST]. If found, parse the comment | 1949 /// [TokenType.GENERIC_METHOD_TYPE_LIST]. If found, parse the comment |
| 1949 /// into tokens and inject into the token stream before the [token]. | 1950 /// into tokens and inject into the token stream before the [token]. |
| 1950 Token _injectGenericComment(Token token, TokenType type, int prefixLen) { | 1951 Token _injectGenericComment(Token token, TokenType type, int prefixLen) { |
| 1951 if (parseGenericMethodComments) { | 1952 if (parseGenericMethodComments) { |
| 1952 CommentToken t = token.precedingCommentTokens; | 1953 CommentToken t = token.precedingComments; |
| 1953 for (; t != null; t = t.next) { | 1954 for (; t != null; t = t.next) { |
| 1954 if (t.type == type) { | 1955 if (t.type == type) { |
| 1955 String code = t.lexeme.substring(prefixLen, t.lexeme.length - 2); | 1956 String code = t.lexeme.substring(prefixLen, t.lexeme.length - 2); |
| 1956 Token tokens = _scanGenericMethodComment(code, t.offset + prefixLen); | 1957 Token tokens = _scanGenericMethodComment(code, t.offset + prefixLen); |
| 1957 if (tokens != null) { | 1958 if (tokens != null) { |
| 1958 // Remove the token from the comment stream. | 1959 // Remove the token from the comment stream. |
| 1959 t.remove(); | 1960 t.remove(); |
| 1960 // Insert the tokens into the stream. | 1961 // Insert the tokens into the stream. |
| 1961 _injectTokenList(token, tokens); | 1962 _injectTokenList(token, tokens); |
| 1962 return tokens; | 1963 return tokens; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2086 } else if (identical('static', s)) { | 2087 } else if (identical('static', s)) { |
| 2087 staticKeyword = token; | 2088 staticKeyword = token; |
| 2088 } else if (identical('var', s)) { | 2089 } else if (identical('var', s)) { |
| 2089 finalConstOrVarKeyword = token; | 2090 finalConstOrVarKeyword = token; |
| 2090 } else { | 2091 } else { |
| 2091 internalError('Unhandled modifier: $s'); | 2092 internalError('Unhandled modifier: $s'); |
| 2092 } | 2093 } |
| 2093 } | 2094 } |
| 2094 } | 2095 } |
| 2095 } | 2096 } |
| OLD | NEW |