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

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

Issue 2776743002: Parse LabeledStatement and SwitchStatement with Fasta. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_fasta_test.dart » ('j') | 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 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 } 895 }
896 } 896 }
897 push(ast.formalParameterList( 897 push(ast.formalParameterList(
898 toAnalyzerToken(beginToken), 898 toAnalyzerToken(beginToken),
899 parameters, 899 parameters,
900 toAnalyzerToken(leftDelimiter), 900 toAnalyzerToken(leftDelimiter),
901 toAnalyzerToken(rightDelimiter), 901 toAnalyzerToken(rightDelimiter),
902 toAnalyzerToken(endToken))); 902 toAnalyzerToken(endToken)));
903 } 903 }
904 904
905 @override
906 void endSwitchBlock(int caseCount, Token leftBracket, Token rightBracket) {
907 debugEvent("SwitchBlock");
908 List<List<SwitchMember>> membersList = popList(caseCount);
909 exitBreakTarget();
910 exitLocalScope();
911 List<SwitchMember> members =
912 membersList?.expand((members) => members)?.toList() ?? <SwitchMember>[];
913 push(leftBracket);
914 push(members);
915 push(rightBracket);
916 }
917
918 @override
919 void handleSwitchCase(
920 int labelCount,
921 int expressionCount,
922 Token defaultKeyword,
923 int statementCount,
924 Token firstToken,
925 Token endToken) {
926 debugEvent("SwitchCase");
927 List<Statement> statements = popList(statementCount);
928 List<SwitchMember> members = popList(expressionCount) ?? [];
929 List<Label> labels = popList(labelCount);
930 if (defaultKeyword != null) {
931 members.add(ast.switchDefault(
932 <Label>[], defaultKeyword, defaultKeyword.next, <Statement>[]));
933 }
934 members.last.statements.addAll(statements);
935 members.first.labels.addAll(labels);
936 push(members);
937 }
938
939 @override
940 void handleCaseMatch(Token caseKeyword, Token colon) {
941 debugEvent("CaseMatch");
942 Expression expression = pop();
943 push(ast.switchCase(
944 <Label>[], caseKeyword, expression, colon, <Statement>[]));
945 }
946
947 @override
948 void endSwitchStatement(Token switchKeyword, Token endToken) {
949 debugEvent("SwitchStatement");
950 Token rightBracket = pop();
951 List<SwitchMember> members = pop();
952 Token leftBracket = pop();
953 ParenthesizedExpression expression = pop();
954 push(ast.switchStatement(
955 switchKeyword,
956 expression.leftParenthesis,
957 expression.expression,
958 expression.rightParenthesis,
959 leftBracket,
960 members,
961 rightBracket));
962 }
963
905 void handleCatchBlock(Token onKeyword, Token catchKeyword) { 964 void handleCatchBlock(Token onKeyword, Token catchKeyword) {
906 debugEvent("CatchBlock"); 965 debugEvent("CatchBlock");
907 Block body = pop(); 966 Block body = pop();
908 FormalParameterList catchParameterList = popIfNotNull(catchKeyword); 967 FormalParameterList catchParameterList = popIfNotNull(catchKeyword);
909 TypeAnnotation type = popIfNotNull(onKeyword); 968 TypeAnnotation type = popIfNotNull(onKeyword);
910 SimpleIdentifier exception; 969 SimpleIdentifier exception;
911 SimpleIdentifier stackTrace; 970 SimpleIdentifier stackTrace;
912 if (catchParameterList != null) { 971 if (catchParameterList != null) {
913 List<FormalParameter> catchParameters = catchParameterList.parameters; 972 List<FormalParameter> catchParameters = catchParameterList.parameters;
914 if (catchParameters.length > 0) { 973 if (catchParameters.length > 0) {
(...skipping 22 matching lines...) Expand all
937 } 996 }
938 997
939 void endTryStatement(int catchCount, Token tryKeyword, Token finallyKeyword) { 998 void endTryStatement(int catchCount, Token tryKeyword, Token finallyKeyword) {
940 Block finallyBlock = popIfNotNull(finallyKeyword); 999 Block finallyBlock = popIfNotNull(finallyKeyword);
941 List<CatchClause> catchClauses = popList(catchCount); 1000 List<CatchClause> catchClauses = popList(catchCount);
942 Block body = pop(); 1001 Block body = pop();
943 push(ast.tryStatement(toAnalyzerToken(tryKeyword), body, catchClauses, 1002 push(ast.tryStatement(toAnalyzerToken(tryKeyword), body, catchClauses,
944 toAnalyzerToken(finallyKeyword), finallyBlock)); 1003 toAnalyzerToken(finallyKeyword), finallyBlock));
945 } 1004 }
946 1005
1006 @override
1007 void handleLabel(Token colon) {
1008 debugEvent("Label");
1009 SimpleIdentifier name = pop();
1010 push(ast.label(name, colon));
1011 }
1012
947 void handleNoExpression(Token token) { 1013 void handleNoExpression(Token token) {
948 debugEvent("NoExpression"); 1014 debugEvent("NoExpression");
949 push(NullValue.Expression); 1015 push(NullValue.Expression);
950 } 1016 }
951 1017
952 void handleIndexedExpression( 1018 void handleIndexedExpression(
953 Token openCurlyBracket, Token closeCurlyBracket) { 1019 Token openCurlyBracket, Token closeCurlyBracket) {
954 debugEvent("IndexedExpression"); 1020 debugEvent("IndexedExpression");
955 Expression index = pop(); 1021 Expression index = pop();
956 Expression target = pop(); 1022 Expression target = pop();
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 typeParameters, 1365 typeParameters,
1300 equals, 1366 equals,
1301 toAnalyzerToken(abstractKeyword), 1367 toAnalyzerToken(abstractKeyword),
1302 superclass, 1368 superclass,
1303 withClause, 1369 withClause,
1304 implementsClause, 1370 implementsClause,
1305 toAnalyzerToken(endToken))); 1371 toAnalyzerToken(endToken)));
1306 } 1372 }
1307 1373
1308 @override 1374 @override
1375 void endLabeledStatement(int labelCount) {
1376 debugEvent("LabeledStatement");
1377 Statement statement = pop();
1378 List<Label> labels = popList(labelCount);
1379 push(ast.labeledStatement(labels, statement));
1380 }
1381
1382 @override
1309 void endLibraryName(Token libraryKeyword, Token semicolon) { 1383 void endLibraryName(Token libraryKeyword, Token semicolon) {
1310 debugEvent("LibraryName"); 1384 debugEvent("LibraryName");
1311 List<SimpleIdentifier> libraryName = pop(); 1385 List<SimpleIdentifier> libraryName = pop();
1312 var name = ast.libraryIdentifier(libraryName); 1386 var name = ast.libraryIdentifier(libraryName);
1313 List<Annotation> metadata = pop(); 1387 List<Annotation> metadata = pop();
1314 Comment comment = pop(); 1388 Comment comment = pop();
1315 push(ast.libraryDirective(comment, metadata, 1389 push(ast.libraryDirective(comment, metadata,
1316 toAnalyzerToken(libraryKeyword), name, toAnalyzerToken(semicolon))); 1390 toAnalyzerToken(libraryKeyword), name, toAnalyzerToken(semicolon)));
1317 } 1391 }
1318 1392
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 } else if (identical('static', s)) { 1938 } else if (identical('static', s)) {
1865 staticKeyword = token; 1939 staticKeyword = token;
1866 } else if (identical('var', s)) { 1940 } else if (identical('var', s)) {
1867 finalConstOrVarKeyword = token; 1941 finalConstOrVarKeyword = token;
1868 } else { 1942 } else {
1869 internalError('Unhandled modifier: $s'); 1943 internalError('Unhandled modifier: $s');
1870 } 1944 }
1871 } 1945 }
1872 } 1946 }
1873 } 1947 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_fasta_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698