Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: pkg/analyzer/lib/src/fasta/ast_builder.dart

Issue 2832403002: merge PrecedenceInfo into TokenType and update all refs (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/precedence.dart';
16 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; 15 import 'package:front_end/src/fasta/scanner/string_scanner.dart';
17 import 'package:front_end/src/fasta/scanner/token.dart' 16 import 'package:front_end/src/fasta/scanner/token.dart'
18 show BeginGroupToken, CommentToken, Token; 17 show BeginGroupToken, CommentToken, Token;
19 18
20 import 'package:front_end/src/fasta/errors.dart' show internalError; 19 import 'package:front_end/src/fasta/errors.dart' show internalError;
21 import 'package:front_end/src/fasta/fasta_codes.dart' 20 import 'package:front_end/src/fasta/fasta_codes.dart'
22 show FastaMessage, codeExpectedExpression, codeExpectedFunctionBody; 21 show FastaMessage, codeExpectedExpression, codeExpectedFunctionBody;
23 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' 22 import 'package:front_end/src/fasta/kernel/kernel_builder.dart'
24 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope; 23 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope;
25 import 'package:front_end/src/fasta/parser/identifier_context.dart' 24 import 'package:front_end/src/fasta/parser/identifier_context.dart'
(...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 1909
1911 @override 1910 @override
1912 void debugEvent(String name) { 1911 void debugEvent(String name) {
1913 // printEvent(name); 1912 // printEvent(name);
1914 } 1913 }
1915 1914
1916 @override 1915 @override
1917 Token injectGenericCommentTypeAssign(Token token) { 1916 Token injectGenericCommentTypeAssign(Token token) {
1918 // TODO(paulberry,scheglov,ahe): figure out how to share these generic 1917 // TODO(paulberry,scheglov,ahe): figure out how to share these generic
1919 // comment methods with BodyBuilder. 1918 // comment methods with BodyBuilder.
1920 return _injectGenericComment(token, GENERIC_METHOD_TYPE_ASSIGN, 3); 1919 return _injectGenericComment(
1920 token, TokenType.GENERIC_METHOD_TYPE_ASSIGN, 3);
1921 } 1921 }
1922 1922
1923 @override 1923 @override
1924 Token injectGenericCommentTypeList(Token token) { 1924 Token injectGenericCommentTypeList(Token token) {
1925 return _injectGenericComment(token, GENERIC_METHOD_TYPE_LIST, 2); 1925 return _injectGenericComment(token, TokenType.GENERIC_METHOD_TYPE_LIST, 2);
1926 } 1926 }
1927 1927
1928 @override 1928 @override
1929 Token replaceTokenWithGenericCommentTypeAssign( 1929 Token replaceTokenWithGenericCommentTypeAssign(
1930 Token tokenToStartReplacing, Token tokenWithComment) { 1930 Token tokenToStartReplacing, Token tokenWithComment) {
1931 Token injected = injectGenericCommentTypeAssign(tokenWithComment); 1931 Token injected = injectGenericCommentTypeAssign(tokenWithComment);
1932 if (!identical(injected, tokenWithComment)) { 1932 if (!identical(injected, tokenWithComment)) {
1933 Token prev = tokenToStartReplacing.previous; 1933 Token prev = tokenToStartReplacing.previous;
1934 prev.setNextWithoutSettingPrevious(injected); 1934 prev.setNextWithoutSettingPrevious(injected);
1935 tokenToStartReplacing = injected; 1935 tokenToStartReplacing = injected;
1936 tokenToStartReplacing.previous = prev; 1936 tokenToStartReplacing.previous = prev;
1937 } 1937 }
1938 return tokenToStartReplacing; 1938 return tokenToStartReplacing;
1939 } 1939 }
1940 1940
1941 /// Check if the given [token] has a comment token with the given [info], 1941 /// Check if the given [token] has a comment token with the given [info],
1942 /// which should be either [GENERIC_METHOD_TYPE_ASSIGN] or 1942 /// which should be either [TokenType.GENERIC_METHOD_TYPE_ASSIGN] or
1943 /// [GENERIC_METHOD_TYPE_LIST]. If found, parse the comment into tokens and 1943 /// [TokenType.GENERIC_METHOD_TYPE_LIST]. If found, parse the comment
1944 /// inject into the token stream before the [token]. 1944 /// into tokens and inject into the token stream before the [token].
1945 Token _injectGenericComment(Token token, TokenType info, int prefixLen) { 1945 Token _injectGenericComment(Token token, TokenType info, int prefixLen) {
1946 if (parseGenericMethodComments) { 1946 if (parseGenericMethodComments) {
1947 CommentToken t = token.precedingCommentTokens; 1947 CommentToken t = token.precedingCommentTokens;
1948 for (; t != null; t = t.next) { 1948 for (; t != null; t = t.next) {
1949 if (t.info == info) { 1949 if (t.info == info) {
1950 String code = t.lexeme.substring(prefixLen, t.lexeme.length - 2); 1950 String code = t.lexeme.substring(prefixLen, t.lexeme.length - 2);
1951 Token tokens = _scanGenericMethodComment(code, t.offset + prefixLen); 1951 Token tokens = _scanGenericMethodComment(code, t.offset + prefixLen);
1952 if (tokens != null) { 1952 if (tokens != null) {
1953 // Remove the token from the comment stream. 1953 // Remove the token from the comment stream.
1954 t.remove(); 1954 t.remove();
1955 // Insert the tokens into the stream. 1955 // Insert the tokens into the stream.
1956 _injectTokenList(token, tokens); 1956 _injectTokenList(token, tokens);
1957 return tokens; 1957 return tokens;
1958 } 1958 }
1959 } 1959 }
1960 } 1960 }
1961 } 1961 }
1962 return token; 1962 return token;
1963 } 1963 }
1964 1964
1965 void _injectTokenList(Token beforeToken, Token firstToken) { 1965 void _injectTokenList(Token beforeToken, Token firstToken) {
1966 // Scanner creates a cyclic EOF token. 1966 // Scanner creates a cyclic EOF token.
1967 Token lastToken = firstToken; 1967 Token lastToken = firstToken;
1968 while (lastToken.next.info != EOF_INFO) { 1968 while (lastToken.next.info != TokenType.EOF) {
1969 lastToken = lastToken.next; 1969 lastToken = lastToken.next;
1970 } 1970 }
1971 // Inject these new tokens into the stream. 1971 // Inject these new tokens into the stream.
1972 Token previous = beforeToken.previous; 1972 Token previous = beforeToken.previous;
1973 lastToken.setNext(beforeToken); 1973 lastToken.setNext(beforeToken);
1974 previous.setNext(firstToken); 1974 previous.setNext(firstToken);
1975 beforeToken = firstToken; 1975 beforeToken = firstToken;
1976 } 1976 }
1977 1977
1978 /// Scans the given [code], and returns the tokens, otherwise returns `null`. 1978 /// Scans the given [code], and returns the tokens, otherwise returns `null`.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 } else if (identical('static', s)) { 2081 } else if (identical('static', s)) {
2082 staticKeyword = token; 2082 staticKeyword = token;
2083 } else if (identical('var', s)) { 2083 } else if (identical('var', s)) {
2084 finalConstOrVarKeyword = token; 2084 finalConstOrVarKeyword = token;
2085 } else { 2085 } else {
2086 internalError('Unhandled modifier: $s'); 2086 internalError('Unhandled modifier: $s');
2087 } 2087 }
2088 } 2088 }
2089 } 2089 }
2090 } 2090 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/scanner/scanner.dart ('k') | pkg/analyzer/lib/src/fasta/token_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698