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

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

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Adjust fasta-analyzer. Created 3 years, 10 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;
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 void endLiteralSymbol(Token hashToken, int identifierCount) { 432 void endLiteralSymbol(Token hashToken, int identifierCount) {
433 debugEvent("LiteralSymbol"); 433 debugEvent("LiteralSymbol");
434 List<analyzer.Token> components = new List<analyzer.Token>(identifierCount); 434 List<analyzer.Token> components = new List<analyzer.Token>(identifierCount);
435 for (int i = identifierCount - 1; i >= 0; i--) { 435 for (int i = identifierCount - 1; i >= 0; i--) {
436 SimpleIdentifier identifier = pop(); 436 SimpleIdentifier identifier = pop();
437 components[i] = identifier.token; 437 components[i] = identifier.token;
438 } 438 }
439 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components)); 439 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components));
440 } 440 }
441 441
442 void endType(Token beginToken, Token endToken) { 442 void handleType(Token beginToken, Token endToken) {
443 debugEvent("Type"); 443 debugEvent("Type");
444 TypeArgumentList arguments = pop(); 444 TypeArgumentList arguments = pop();
445 Identifier name = pop(); 445 Identifier name = pop();
446 // TODO(paulberry,ahe): what if the type doesn't resolve to a class 446 // TODO(paulberry,ahe): what if the type doesn't resolve to a class
447 // element? 447 // element?
448 KernelClassElement cls = name.staticElement; 448 KernelClassElement cls = name.staticElement;
449 if (cls == null) { 449 if (cls == null) {
450 // TODO(paulberry): This is a kludge. Ideally we should already have 450 // TODO(paulberry): This is a kludge. Ideally we should already have
451 // set the static element at the time that handleIdentifier was called. 451 // set the static element at the time that handleIdentifier was called.
452 Builder builder = scope.lookup(name.name, beginToken.charOffset, uri); 452 Builder builder = scope.lookup(name.name, beginToken.charOffset, uri);
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 debugEvent("Member"); 1090 debugEvent("Member");
1091 } 1091 }
1092 1092
1093 @override 1093 @override
1094 void handleVoidKeyword(Token token) { 1094 void handleVoidKeyword(Token token) {
1095 debugEvent("VoidKeyword"); 1095 debugEvent("VoidKeyword");
1096 // TODO(paulberry): is this sufficient, or do we need to hook the "void" 1096 // TODO(paulberry): is this sufficient, or do we need to hook the "void"
1097 // keyword up to an element? 1097 // keyword up to an element?
1098 handleIdentifier(token); 1098 handleIdentifier(token);
1099 handleNoTypeArguments(token); 1099 handleNoTypeArguments(token);
1100 endType(token, token); 1100 handleType(token, token);
1101 } 1101 }
1102 1102
1103 @override 1103 @override
1104 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { 1104 void endFunctionTypeAlias(
1105 Token typedefKeyword, Token equals, Token endToken) {
1105 debugEvent("FunctionTypeAlias"); 1106 debugEvent("FunctionTypeAlias");
1106 FormalParameterList parameters = pop(); 1107 if (equals == null) {
1107 TypeParameterList typeParameters = pop(); 1108 FormalParameterList parameters = pop();
1108 SimpleIdentifier name = pop(); 1109 TypeParameterList typeParameters = pop();
1109 TypeAnnotation returnType = pop(); 1110 SimpleIdentifier name = pop();
1110 List<Annotation> metadata = pop(); 1111 TypeAnnotation returnType = pop();
1111 // TODO(paulberry): capture doc comments. See dartbug.com/28851. 1112 List<Annotation> metadata = pop();
1112 Comment comment = null; 1113 // TODO(paulberry): capture doc comments. See dartbug.com/28851.
1113 push(ast.functionTypeAlias( 1114 Comment comment = null;
1114 comment, 1115 push(ast.functionTypeAlias(
1115 metadata, 1116 comment,
1116 toAnalyzerToken(typedefKeyword), 1117 metadata,
1117 returnType, 1118 toAnalyzerToken(typedefKeyword),
1118 name, 1119 returnType,
1119 typeParameters, 1120 name,
1120 parameters, 1121 typeParameters,
1121 toAnalyzerToken(endToken))); 1122 parameters,
1123 toAnalyzerToken(endToken)));
1124 } else {
1125 Node type = pop();
Paul Berry 2017/02/22 18:47:25 Shouldn't the type of `type` be TypeAnnotation?
floitsch 2017/02/22 19:21:39 Maybe. I wasn't sure. Changed to TypeAnnotation.
1126 TypeParameterList templateParameters = pop();
1127 SimpleIdentifier name = pop();
1128 List<Annotation> metadata = pop();
1129
Paul Berry 2017/02/22 18:47:25 Duplicate lines 1113-1114 here.
floitsch 2017/02/22 19:21:39 Done.
1130 if (type is! GenericFunctionType) {
1131 // TODO(brianwilkerson) Generate an error and recover (better than
1132 // this).
1133 push(ast.genericTypeAlias(
1134 commentAndMetadata.comment,
Paul Berry 2017/02/22 18:47:26 Change to "comment"
floitsch 2017/02/22 19:21:40 Acknowledged.
1135 commentAndMetadata.metadata,
Paul Berry 2017/02/22 18:47:25 Change to "metadata"
floitsch 2017/02/22 19:21:39 Acknowledged.
1136 keyword,
Paul Berry 2017/02/22 18:47:26 Change to "toAnalyzerToken(typedefKeyword)"
floitsch 2017/02/22 19:21:39 Acknowledged.
1137 name,
1138 typeParameters,
1139 equals,
Paul Berry 2017/02/22 18:47:26 Change to "toAnalyzerToken(equals)"
floitsch 2017/02/22 19:21:39 Acknowledged.
1140 null,
1141 semicolon));
Paul Berry 2017/02/22 18:47:26 Change to "toAnalyzerToken(endToken)"
floitsch 2017/02/22 19:21:39 Acknowledged.
1142 } else {
1143 FunctionTypeAnnotation functionType = type;
Paul Berry 2017/02/22 18:47:26 I'm confused by this. Since the if-test on line 1
floitsch 2017/02/22 19:21:40 Changed the whole thing.
1144 push(ast.genericTypeAlias(
1145 commentAndMetadata.comment,
Paul Berry 2017/02/22 18:47:25 Change to "comment"
floitsch 2017/02/22 19:21:39 Done.
1146 commentAndMetadata.metadata,
Paul Berry 2017/02/22 18:47:25 Change to "metadata"
floitsch 2017/02/22 19:21:39 Done.
1147 keyword,
Paul Berry 2017/02/22 18:47:25 Change to "toAnalyzerToken(typedefKeyword)"
floitsch 2017/02/22 19:21:39 Done.
1148 name,
1149 typeParameters,
1150 equals,
Paul Berry 2017/02/22 18:47:26 Change to "toAnalyzerToken(equals)"
floitsch 2017/02/22 19:21:39 Done.
1151 functionType,
1152 semicolon));
Paul Berry 2017/02/22 18:47:25 Change to "toAnalyzerToken(endToken)"
floitsch 2017/02/22 19:21:39 Done.
1153 }
1154 }
1122 } 1155 }
1123 1156
1124 /** 1157 /**
1125 * Pop the modifiers list, if the list is empty return `null`, if the list 1158 * Pop the modifiers list, if the list is empty return `null`, if the list
1126 * has one item return it; otherwise return `null`. 1159 * has one item return it; otherwise return `null`.
1127 */ 1160 */
1128 Token _popOptionalSingleModifier() { 1161 Token _popOptionalSingleModifier() {
1129 List<Token> modifiers = pop(); 1162 List<Token> modifiers = pop();
1130 if (modifiers.length == 0) { 1163 if (modifiers.length == 0) {
1131 return null; 1164 return null;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 /// [ClassDeclaration] or [ClassTypeAlias] object. 1196 /// [ClassDeclaration] or [ClassTypeAlias] object.
1164 class _MixinApplication { 1197 class _MixinApplication {
1165 final TypeName supertype; 1198 final TypeName supertype;
1166 1199
1167 final Token withKeyword; 1200 final Token withKeyword;
1168 1201
1169 final List<TypeName> mixinTypes; 1202 final List<TypeName> mixinTypes;
1170 1203
1171 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); 1204 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes);
1172 } 1205 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/use_unused_api.dart ('k') | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698