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

Side by Side Diff: pkg/analyzer/tool/summary/mini_ast.dart

Issue 2872433005: more work aligning fasta.Token with analyzer.Token (Closed)
Patch Set: Created 3 years, 7 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:front_end/src/fasta/errors.dart'; 5 import 'package:front_end/src/fasta/errors.dart';
6 import 'package:front_end/src/fasta/parser/identifier_context.dart'; 6 import 'package:front_end/src/fasta/parser/identifier_context.dart';
7 import 'package:front_end/src/fasta/parser/parser.dart'; 7 import 'package:front_end/src/fasta/parser/parser.dart';
8 import 'package:front_end/src/fasta/scanner/token.dart'; 8 import 'package:front_end/src/fasta/scanner/token.dart';
9 import 'package:front_end/src/fasta/source/stack_listener.dart'; 9 import 'package:front_end/src/fasta/source/stack_listener.dart';
10 import 'package:front_end/src/scanner/token.dart' as analyzer;
10 11
11 /// "Mini AST" representation of a declaration which can accept annotations. 12 /// "Mini AST" representation of a declaration which can accept annotations.
12 class AnnotatedNode { 13 class AnnotatedNode {
13 final Comment documentationComment; 14 final Comment documentationComment;
14 15
15 final List<Annotation> metadata; 16 final List<Annotation> metadata;
16 17
17 AnnotatedNode(this.documentationComment, List<Annotation> metadata) 18 AnnotatedNode(this.documentationComment, List<Annotation> metadata)
18 : metadata = metadata ?? const []; 19 : metadata = metadata ?? const [];
19 } 20 }
(...skipping 27 matching lines...) Expand all
47 ClassMember(Comment documentationComment, List<Annotation> metadata) 48 ClassMember(Comment documentationComment, List<Annotation> metadata)
48 : super(documentationComment, metadata); 49 : super(documentationComment, metadata);
49 } 50 }
50 51
51 /// "Mini AST" representation of a comment. 52 /// "Mini AST" representation of a comment.
52 class Comment { 53 class Comment {
53 final bool isDocumentation; 54 final bool isDocumentation;
54 55
55 final List<Token> tokens; 56 final List<Token> tokens;
56 57
57 factory Comment(Token commentToken) { 58 factory Comment(analyzer.Token commentToken) {
58 var tokens = <Token>[]; 59 var tokens = <Token>[];
59 bool isDocumentation = false; 60 bool isDocumentation = false;
60 while (commentToken != null) { 61 while (commentToken != null) {
61 if (commentToken.lexeme.startsWith('/**') || 62 if (commentToken.lexeme.startsWith('/**') ||
62 commentToken.lexeme.startsWith('///')) { 63 commentToken.lexeme.startsWith('///')) {
63 isDocumentation = true; 64 isDocumentation = true;
64 } 65 }
65 tokens.add(commentToken); 66 tokens.add(commentToken);
66 commentToken = commentToken.next; 67 commentToken = commentToken.next;
67 } 68 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 157
157 @override 158 @override
158 void beginMetadata(Token token) { 159 void beginMetadata(Token token) {
159 inMetadata = true; 160 inMetadata = true;
160 } 161 }
161 162
162 @override 163 @override
163 void beginMetadataStar(Token token) { 164 void beginMetadataStar(Token token) {
164 debugEvent("beginMetadataStar"); 165 debugEvent("beginMetadataStar");
165 if (token.precedingComments != null) { 166 if (token.precedingComments != null) {
166 push(new Comment(token.precedingCommentTokens)); 167 push(new Comment(token.precedingComments));
167 } else { 168 } else {
168 push(NullValue.Comments); 169 push(NullValue.Comments);
169 } 170 }
170 } 171 }
171 172
172 @override 173 @override
173 void endArguments(int count, Token beginToken, Token endToken) { 174 void endArguments(int count, Token beginToken, Token endToken) {
174 debugEvent("Arguments"); 175 debugEvent("Arguments");
175 push(popList(count)); 176 push(popList(count));
176 } 177 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 383 }
383 384
384 @override 385 @override
385 void handleFunctionBodySkipped(Token token, bool isExpressionBody) { 386 void handleFunctionBodySkipped(Token token, bool isExpressionBody) {
386 if (isExpressionBody) pop(); 387 if (isExpressionBody) pop();
387 push(NullValue.FunctionBody); 388 push(NullValue.FunctionBody);
388 } 389 }
389 390
390 void handleIdentifier(Token token, IdentifierContext context) { 391 void handleIdentifier(Token token, IdentifierContext context) {
391 if (context == IdentifierContext.enumValueDeclaration) { 392 if (context == IdentifierContext.enumValueDeclaration) {
392 var comment = new Comment(token.precedingCommentTokens); 393 var comment = new Comment(token.precedingComments);
393 push(new EnumConstantDeclaration(comment, null, token.lexeme)); 394 push(new EnumConstantDeclaration(comment, null, token.lexeme));
394 } else { 395 } else {
395 push(token.lexeme); 396 push(token.lexeme);
396 } 397 }
397 } 398 }
398 399
399 void handleLiteralInt(Token token) { 400 void handleLiteralInt(Token token) {
400 debugEvent("LiteralInt"); 401 debugEvent("LiteralInt");
401 push(new IntegerLiteral(int.parse(token.lexeme))); 402 push(new IntegerLiteral(int.parse(token.lexeme)));
402 } 403 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 final String name; 464 final String name;
464 465
465 final List<TypeName> typeArguments; 466 final List<TypeName> typeArguments;
466 467
467 TypeName(this.name, this.typeArguments); 468 TypeName(this.name, this.typeArguments);
468 } 469 }
469 470
470 /// "Mini AST" representation of an expression which summary code generation 471 /// "Mini AST" representation of an expression which summary code generation
471 /// need not be concerned about. 472 /// need not be concerned about.
472 class UnknownExpression extends Expression {} 473 class UnknownExpression extends Expression {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698