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

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

Issue 2742233002: Fix for parsing EmptyFunctionBody with Fasta. (Closed)
Patch Set: Created 3 years, 9 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 } 227 }
228 228
229 void doPropertyGet(Token token) {} 229 void doPropertyGet(Token token) {}
230 230
231 void endExpressionStatement(Token token) { 231 void endExpressionStatement(Token token) {
232 debugEvent("ExpressionStatement"); 232 debugEvent("ExpressionStatement");
233 push(ast.expressionStatement(pop(), toAnalyzerToken(token))); 233 push(ast.expressionStatement(pop(), toAnalyzerToken(token)));
234 } 234 }
235 235
236 @override
237 void endEmptyFunctionBody(Token semicolon) {
238 debugEvent("EmptyFunctionBody");
239 // TODO(scheglov) Change the parser to not produce these modifiers.
240 pop(); // star
241 pop(); // async
242 push(ast.emptyFunctionBody(toAnalyzerToken(semicolon)));
243 }
244
236 void endFunctionBody(int count, Token beginToken, Token endToken) { 245 void endFunctionBody(int count, Token beginToken, Token endToken) {
237 debugEvent("FunctionBody"); 246 debugEvent("FunctionBody");
238 List statements = popList(count); 247 List statements = popList(count);
239 if (beginToken != null) { 248 if (beginToken != null) {
240 exitLocalScope(); 249 exitLocalScope();
241 } 250 }
242 Block block = ast.block( 251 Block block = ast.block(
243 toAnalyzerToken(beginToken), statements, toAnalyzerToken(endToken)); 252 toAnalyzerToken(beginToken), statements, toAnalyzerToken(endToken));
244 analyzer.Token star = pop(); 253 analyzer.Token star = pop();
245 analyzer.Token asyncKeyword = pop(); 254 analyzer.Token asyncKeyword = pop();
246 push(ast.blockFunctionBody(asyncKeyword, star, block)); 255 push(ast.blockFunctionBody(asyncKeyword, star, block));
247 } 256 }
248 257
249 void finishFunction(formals, asyncModifier, FunctionBody body) { 258 void finishFunction(formals, asyncModifier, FunctionBody body) {
250 debugEvent("finishFunction"); 259 debugEvent("finishFunction");
251 Statement bodyStatement; 260 Statement bodyStatement;
252 if (body is ExpressionFunctionBody) { 261 if (body is EmptyFunctionBody) {
262 bodyStatement = ast.emptyStatement(body.semicolon);
263 } else if (body is ExpressionFunctionBody) {
253 bodyStatement = ast.returnStatement(null, body.expression, null); 264 bodyStatement = ast.returnStatement(null, body.expression, null);
254 } else { 265 } else {
255 bodyStatement = (body as BlockFunctionBody).block; 266 bodyStatement = (body as BlockFunctionBody).block;
256 } 267 }
257 var kernel = toKernel(bodyStatement, elementStore, library.library, scope); 268 var kernel = toKernel(bodyStatement, elementStore, library.library, scope);
258 if (member is ProcedureBuilder) { 269 if (member is ProcedureBuilder) {
259 ProcedureBuilder builder = member; 270 ProcedureBuilder builder = member;
260 builder.body = kernel; 271 builder.body = kernel;
261 } else { 272 } else {
262 internalError("Internal error: expected procedure, but got: $member"); 273 internalError("Internal error: expected procedure, but got: $member");
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 } else if (identical('static', s)) { 1586 } else if (identical('static', s)) {
1576 staticKeyword = token; 1587 staticKeyword = token;
1577 } else if (identical('var', s)) { 1588 } else if (identical('var', s)) {
1578 finalConstOrVarKeyword = token; 1589 finalConstOrVarKeyword = token;
1579 } else { 1590 } else {
1580 internalError('Unhandled modifier: $s'); 1591 internalError('Unhandled modifier: $s');
1581 } 1592 }
1582 } 1593 }
1583 } 1594 }
1584 } 1595 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698