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

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

Issue 2748183002: Parse 'while' and 'do-while' statements 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
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 debugEvent("VariableInitializer"); 397 debugEvent("VariableInitializer");
398 assert(assignmentOperator.stringValue == "="); 398 assert(assignmentOperator.stringValue == "=");
399 Expression initializer = pop(); 399 Expression initializer = pop();
400 Identifier identifier = pop(); 400 Identifier identifier = pop();
401 // TODO(ahe): Don't push initializers, instead install them. 401 // TODO(ahe): Don't push initializers, instead install them.
402 push(ast.variableDeclaration( 402 push(ast.variableDeclaration(
403 identifier, toAnalyzerToken(assignmentOperator), initializer)); 403 identifier, toAnalyzerToken(assignmentOperator), initializer));
404 } 404 }
405 405
406 @override 406 @override
407 void endWhileStatement(Token whileKeyword, Token endToken) {
408 debugEvent("WhileStatement");
409 Statement body = pop();
410 ParenthesizedExpression condition = pop();
411 pop(); // continue target
412 pop(); // break target
413 push(ast.whileStatement(
414 toAnalyzerToken(whileKeyword),
415 condition.leftParenthesis,
416 condition.expression,
417 condition.rightParenthesis,
418 body));
419 }
420
421 @override
407 void handleNoVariableInitializer(Token token) { 422 void handleNoVariableInitializer(Token token) {
408 debugEvent("NoVariableInitializer"); 423 debugEvent("NoVariableInitializer");
409 } 424 }
410 425
411 void endInitializedIdentifier(Token nameToken) { 426 void endInitializedIdentifier(Token nameToken) {
412 debugEvent("InitializedIdentifier"); 427 debugEvent("InitializedIdentifier");
413 AstNode node = pop(); 428 AstNode node = pop();
414 VariableDeclaration variable; 429 VariableDeclaration variable;
415 // TODO(paulberry): This seems kludgy. It would be preferable if we 430 // TODO(paulberry): This seems kludgy. It would be preferable if we
416 // could respond to a "handleNoVariableInitializer" event by converting a 431 // could respond to a "handleNoVariableInitializer" event by converting a
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 uri, configurations, combinators, toAnalyzerToken(semicolon))); 966 uri, configurations, combinators, toAnalyzerToken(semicolon)));
952 } 967 }
953 968
954 @override 969 @override
955 void endDottedName(int count, Token firstIdentifier) { 970 void endDottedName(int count, Token firstIdentifier) {
956 debugEvent("DottedName"); 971 debugEvent("DottedName");
957 List<SimpleIdentifier> components = popList(count); 972 List<SimpleIdentifier> components = popList(count);
958 push(ast.dottedName(components)); 973 push(ast.dottedName(components));
959 } 974 }
960 975
976 @override
977 void endDoWhileStatement(
978 Token doKeyword, Token whileKeyword, Token semicolon) {
979 debugEvent("DoWhileStatement");
980 ParenthesizedExpression condition = pop();
981 Statement body = pop();
982 pop(); // continue target
983 pop(); // break target
984 push(ast.doStatement(
985 toAnalyzerToken(doKeyword),
986 body,
987 toAnalyzerToken(whileKeyword),
988 condition.leftParenthesis,
989 condition.expression,
990 condition.rightParenthesis,
991 toAnalyzerToken(semicolon)));
992 }
993
961 void endConditionalUri(Token ifKeyword, Token equalitySign) { 994 void endConditionalUri(Token ifKeyword, Token equalitySign) {
962 debugEvent("ConditionalUri"); 995 debugEvent("ConditionalUri");
963 StringLiteral libraryUri = pop(); 996 StringLiteral libraryUri = pop();
964 // TODO(paulberry,ahe): the parser should report the right paren token to 997 // TODO(paulberry,ahe): the parser should report the right paren token to
965 // the listener. 998 // the listener.
966 Token rightParen = null; 999 Token rightParen = null;
967 StringLiteral value; 1000 StringLiteral value;
968 if (equalitySign != null) { 1001 if (equalitySign != null) {
969 value = pop(); 1002 value = pop();
970 } 1003 }
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 } else if (identical('static', s)) { 1637 } else if (identical('static', s)) {
1605 staticKeyword = token; 1638 staticKeyword = token;
1606 } else if (identical('var', s)) { 1639 } else if (identical('var', s)) {
1607 finalConstOrVarKeyword = token; 1640 finalConstOrVarKeyword = token;
1608 } else { 1641 } else {
1609 internalError('Unhandled modifier: $s'); 1642 internalError('Unhandled modifier: $s');
1610 } 1643 }
1611 } 1644 }
1612 } 1645 }
1613 } 1646 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698