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

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

Issue 2747583003: Parse factory constructors 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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 void handleConditionalExpression(Token question, Token colon) { 564 void handleConditionalExpression(Token question, Token colon) {
565 debugEvent("ConditionalExpression"); 565 debugEvent("ConditionalExpression");
566 Expression elseExpression = pop(); 566 Expression elseExpression = pop();
567 Expression thenExpression = pop(); 567 Expression thenExpression = pop();
568 Expression condition = pop(); 568 Expression condition = pop();
569 push(ast.conditionalExpression(condition, toAnalyzerToken(question), 569 push(ast.conditionalExpression(condition, toAnalyzerToken(question),
570 thenExpression, toAnalyzerToken(colon), elseExpression)); 570 thenExpression, toAnalyzerToken(colon), elseExpression));
571 } 571 }
572 572
573 @override 573 @override
574 void endRedirectingFactoryBody(Token equalToken, Token endToken) {
575 debugEvent("RedirectingFactoryBody");
576 ConstructorName constructorName = pop();
577 Token starToken = pop();
578 Token asyncToken = pop();
579 push(new _RedirectingFactoryBody(
580 asyncToken, starToken, equalToken, constructorName));
581 }
582
583 @override
574 void endRethrowStatement(Token rethrowToken, Token endToken) { 584 void endRethrowStatement(Token rethrowToken, Token endToken) {
575 debugEvent("RethrowStatement"); 585 debugEvent("RethrowStatement");
576 RethrowExpression expression = 586 RethrowExpression expression =
577 ast.rethrowExpression(toAnalyzerToken(rethrowToken)); 587 ast.rethrowExpression(toAnalyzerToken(rethrowToken));
578 // TODO(scheglov) According to the specification, 'rethrow' is a statement. 588 // TODO(scheglov) According to the specification, 'rethrow' is a statement.
579 push(ast.expressionStatement(expression, toAnalyzerToken(endToken))); 589 push(ast.expressionStatement(expression, toAnalyzerToken(endToken)));
580 } 590 }
581 591
582 void endThrowExpression(Token throwToken, Token endToken) { 592 void endThrowExpression(Token throwToken, Token endToken) {
583 debugEvent("ThrowExpression"); 593 debugEvent("ThrowExpression");
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 push(ast.functionExpression(typeParameters, parameters, body)); 1176 push(ast.functionExpression(typeParameters, parameters, body));
1167 } 1177 }
1168 1178
1169 @override 1179 @override
1170 void handleNoFieldInitializer(Token token) { 1180 void handleNoFieldInitializer(Token token) {
1171 debugEvent("NoFieldInitializer"); 1181 debugEvent("NoFieldInitializer");
1172 SimpleIdentifier name = pop(); 1182 SimpleIdentifier name = pop();
1173 push(ast.variableDeclaration(name, null, null)); 1183 push(ast.variableDeclaration(name, null, null));
1174 } 1184 }
1175 1185
1186 @override
1187 void endFactoryMethod(
1188 Token beginToken, Token factoryKeyword, Token semicolon) {
1189 debugEvent("FactoryMethod");
1190
1191 FunctionBody body;
1192 Token separator;
1193 ConstructorName redirectedConstructor;
1194 Object bodyObject = pop();
1195 if (bodyObject is FunctionBody) {
1196 body = bodyObject;
1197 } else if (bodyObject is _RedirectingFactoryBody) {
1198 separator = bodyObject.equalToken;
1199 redirectedConstructor = bodyObject.constructorName;
1200 body = ast.emptyFunctionBody(toAnalyzerToken(semicolon));
1201 } else {
1202 internalError('Unexpected body object: ${bodyObject.runtimeType}');
1203 }
1204
1205 FormalParameterList parameters = pop();
1206 ConstructorName constructorName = pop();
1207 _Modifiers modifiers = pop();
1208 List<Annotation> metadata = pop();
1209 Comment comment = pop();
1210 push(ast.constructorDeclaration(
1211 comment,
1212 metadata,
1213 toAnalyzerToken(modifiers?.externalKeyword),
1214 toAnalyzerToken(modifiers?.finalConstOrVarKeyword),
1215 toAnalyzerToken(factoryKeyword),
1216 constructorName.type.name,
1217 constructorName.period,
1218 constructorName.name,
1219 parameters,
1220 toAnalyzerToken(separator),
1221 null,
1222 redirectedConstructor,
1223 body));
1224 }
1225
1176 void endFieldInitializer(Token assignment) { 1226 void endFieldInitializer(Token assignment) {
1177 debugEvent("FieldInitializer"); 1227 debugEvent("FieldInitializer");
1178 Expression initializer = pop(); 1228 Expression initializer = pop();
1179 SimpleIdentifier name = pop(); 1229 SimpleIdentifier name = pop();
1180 push(ast.variableDeclaration( 1230 push(ast.variableDeclaration(
1181 name, toAnalyzerToken(assignment), initializer)); 1231 name, toAnalyzerToken(assignment), initializer));
1182 } 1232 }
1183 1233
1184 void endTopLevelFields(int count, Token beginToken, Token endToken) { 1234 void endTopLevelFields(int count, Token beginToken, Token endToken) {
1185 debugEvent("TopLevelFields"); 1235 debugEvent("TopLevelFields");
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 1513
1464 /// Data structure placed on the stack to represent the default parameter 1514 /// Data structure placed on the stack to represent the default parameter
1465 /// value with the separator token. 1515 /// value with the separator token.
1466 class _ParameterDefaultValue { 1516 class _ParameterDefaultValue {
1467 final Token separator; 1517 final Token separator;
1468 final Expression value; 1518 final Expression value;
1469 1519
1470 _ParameterDefaultValue(this.separator, this.value); 1520 _ParameterDefaultValue(this.separator, this.value);
1471 } 1521 }
1472 1522
1523 /// Data structure placed on stack to represent the redirected constructor.
1524 class _RedirectingFactoryBody {
1525 final Token asyncKeyword;
1526 final Token starKeyword;
1527 final Token equalToken;
1528 final ConstructorName constructorName;
1529
1530 _RedirectingFactoryBody(this.asyncKeyword, this.starKeyword, this.equalToken,
1531 this.constructorName);
1532 }
1533
1473 /// Data structure placed on the stack as a container for optional parameters. 1534 /// Data structure placed on the stack as a container for optional parameters.
1474 class _OptionalFormalParameters { 1535 class _OptionalFormalParameters {
1475 final List<FormalParameter> parameters; 1536 final List<FormalParameter> parameters;
1476 final Token leftDelimiter; 1537 final Token leftDelimiter;
1477 final Token rightDelimiter; 1538 final Token rightDelimiter;
1478 1539
1479 _OptionalFormalParameters( 1540 _OptionalFormalParameters(
1480 this.parameters, this.leftDelimiter, this.rightDelimiter); 1541 this.parameters, this.leftDelimiter, this.rightDelimiter);
1481 } 1542 }
1482 1543
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 } else if (identical('static', s)) { 1575 } else if (identical('static', s)) {
1515 staticKeyword = token; 1576 staticKeyword = token;
1516 } else if (identical('var', s)) { 1577 } else if (identical('var', s)) {
1517 finalConstOrVarKeyword = token; 1578 finalConstOrVarKeyword = token;
1518 } else { 1579 } else {
1519 internalError('Unhandled modifier: $s'); 1580 internalError('Unhandled modifier: $s');
1520 } 1581 }
1521 } 1582 }
1522 } 1583 }
1523 } 1584 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/parser/node_listener.dart ('k') | pkg/front_end/lib/src/fasta/parser/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698