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

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

Issue 2793113002: Convert constructor initializers in endInitializers() and other tweaks. (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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 debugEvent("prepareInitializers"); 404 debugEvent("prepareInitializers");
405 } 405 }
406 406
407 void handleNoInitializers() { 407 void handleNoInitializers() {
408 debugEvent("NoInitializers"); 408 debugEvent("NoInitializers");
409 push(NullValue.ConstructorInitializers); 409 push(NullValue.ConstructorInitializers);
410 } 410 }
411 411
412 void endInitializers(int count, Token beginToken, Token endToken) { 412 void endInitializers(int count, Token beginToken, Token endToken) {
413 debugEvent("Initializers"); 413 debugEvent("Initializers");
414 push(popList(count)); 414 List<Object> initializerObjects = popList(count) ?? const [];
415
416 var initializers = <ConstructorInitializer>[];
417 for (Object initializerObject in initializerObjects) {
418 if (initializerObject is FunctionExpressionInvocation) {
419 Expression function = initializerObject.function;
420 if (function is SuperExpression) {
421 initializers.add(ast.superConstructorInvocation(function.superKeyword,
422 null, null, initializerObject.argumentList));
423 } else {
424 initializers.add(ast.redirectingConstructorInvocation(
425 (function as ThisExpression).thisKeyword,
426 null,
427 null,
428 initializerObject.argumentList));
429 }
430 } else if (initializerObject is MethodInvocation) {
431 Expression target = initializerObject.target;
432 if (target is SuperExpression) {
433 initializers.add(ast.superConstructorInvocation(
434 target.superKeyword,
435 initializerObject.operator,
436 initializerObject.methodName,
437 initializerObject.argumentList));
438 } else {
439 initializers.add(ast.redirectingConstructorInvocation(
440 (target as ThisExpression).thisKeyword,
441 initializerObject.operator,
442 initializerObject.methodName,
443 initializerObject.argumentList));
444 }
445 } else if (initializerObject is AssignmentExpression) {
446 analyzer.Token thisKeyword;
447 analyzer.Token period;
448 SimpleIdentifier fieldName;
449 Expression left = initializerObject.leftHandSide;
450 if (left is PropertyAccess) {
451 var thisExpression = left.target as ThisExpression;
452 thisKeyword = thisExpression.thisKeyword;
453 period = left.operator;
454 fieldName = left.propertyName;
455 } else {
456 fieldName = left as SimpleIdentifier;
457 }
458 initializers.add(ast.constructorFieldInitializer(
459 thisKeyword,
460 period,
461 fieldName,
462 initializerObject.operator,
463 initializerObject.rightHandSide));
464 }
465 }
466
467 push(initializers);
415 } 468 }
416 469
417 void endVariableInitializer(Token assignmentOperator) { 470 void endVariableInitializer(Token assignmentOperator) {
418 debugEvent("VariableInitializer"); 471 debugEvent("VariableInitializer");
419 assert(assignmentOperator.stringValue == "="); 472 assert(assignmentOperator.stringValue == "=");
420 Expression initializer = pop(); 473 Expression initializer = pop();
421 Identifier identifier = pop(); 474 Identifier identifier = pop();
422 // TODO(ahe): Don't push initializers, instead install them. 475 // TODO(ahe): Don't push initializers, instead install them.
423 push(ast.variableDeclaration( 476 push(ast.variableDeclaration(
424 identifier, toAnalyzerToken(assignmentOperator), initializer)); 477 identifier, toAnalyzerToken(assignmentOperator), initializer));
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 List<TypeParameter> typeParameters = popList(count); 1622 List<TypeParameter> typeParameters = popList(count);
1570 push(ast.typeParameterList(toAnalyzerToken(beginToken), typeParameters, 1623 push(ast.typeParameterList(toAnalyzerToken(beginToken), typeParameters,
1571 toAnalyzerToken(endToken))); 1624 toAnalyzerToken(endToken)));
1572 } 1625 }
1573 1626
1574 @override 1627 @override
1575 void endMethod(Token getOrSet, Token beginToken, Token endToken) { 1628 void endMethod(Token getOrSet, Token beginToken, Token endToken) {
1576 debugEvent("Method"); 1629 debugEvent("Method");
1577 FunctionBody body = pop(); 1630 FunctionBody body = pop();
1578 ConstructorName redirectedConstructor = null; // TODO(paulberry) 1631 ConstructorName redirectedConstructor = null; // TODO(paulberry)
1579 List<Object> initializerObjects = pop() ?? const []; 1632 List<ConstructorInitializer> initializers = pop() ?? const [];
1580 Token separator = null; // TODO(paulberry) 1633 Token separator = null; // TODO(paulberry)
1581 FormalParameterList parameters = pop(); 1634 FormalParameterList parameters = pop();
1582 TypeParameterList typeParameters = pop(); // TODO(paulberry) 1635 TypeParameterList typeParameters = pop(); // TODO(paulberry)
1583 var name = pop(); 1636 var name = pop();
1584 TypeAnnotation returnType = pop(); // TODO(paulberry) 1637 TypeAnnotation returnType = pop(); // TODO(paulberry)
1585 _Modifiers modifiers = pop(); 1638 _Modifiers modifiers = pop();
1586 List<Annotation> metadata = pop(); 1639 List<Annotation> metadata = pop();
1587 Comment comment = pop(); 1640 Comment comment = pop();
1588 1641
1589 var initializers = <ConstructorInitializer>[];
1590 for (Object initializerObject in initializerObjects) {
1591 if (initializerObject is FunctionExpressionInvocation) {
1592 Expression function = initializerObject.function;
1593 if (function is SuperExpression) {
1594 initializers.add(ast.superConstructorInvocation(function.superKeyword,
1595 null, null, initializerObject.argumentList));
1596 } else {
1597 initializers.add(ast.redirectingConstructorInvocation(
1598 (function as ThisExpression).thisKeyword,
1599 null,
1600 null,
1601 initializerObject.argumentList));
1602 }
1603 } else if (initializerObject is MethodInvocation) {
1604 Expression target = initializerObject.target;
1605 if (target is SuperExpression) {
1606 initializers.add(ast.superConstructorInvocation(
1607 target.superKeyword,
1608 initializerObject.operator,
1609 initializerObject.methodName,
1610 initializerObject.argumentList));
1611 } else {
1612 initializers.add(ast.redirectingConstructorInvocation(
1613 (target as ThisExpression).thisKeyword,
1614 initializerObject.operator,
1615 initializerObject.methodName,
1616 initializerObject.argumentList));
1617 }
1618 } else if (initializerObject is AssignmentExpression) {
1619 analyzer.Token thisKeyword;
1620 analyzer.Token period;
1621 SimpleIdentifier fieldName;
1622 Expression left = initializerObject.leftHandSide;
1623 if (left is PropertyAccess) {
1624 var thisExpression = left.target as ThisExpression;
1625 thisKeyword = thisExpression.thisKeyword;
1626 period = left.operator;
1627 fieldName = left.propertyName;
1628 } else {
1629 fieldName = left as SimpleIdentifier;
1630 }
1631 initializers.add(ast.constructorFieldInitializer(
1632 thisKeyword,
1633 period,
1634 fieldName,
1635 initializerObject.operator,
1636 initializerObject.rightHandSide));
1637 }
1638 }
1639
1640 void constructor(SimpleIdentifier returnType, analyzer.Token period, 1642 void constructor(SimpleIdentifier returnType, analyzer.Token period,
1641 SimpleIdentifier name) { 1643 SimpleIdentifier name) {
1642 push(ast.constructorDeclaration( 1644 push(ast.constructorDeclaration(
1643 comment, 1645 comment,
1644 metadata, 1646 metadata,
1645 toAnalyzerToken(modifiers?.externalKeyword), 1647 toAnalyzerToken(modifiers?.externalKeyword),
1646 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), 1648 toAnalyzerToken(modifiers?.finalConstOrVarKeyword),
1647 null, // TODO(paulberry): factoryKeyword 1649 null, // TODO(paulberry): factoryKeyword
1648 ast.simpleIdentifier(returnType.token), 1650 ast.simpleIdentifier(returnType.token),
1649 period, 1651 period,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 } else if (identical('static', s)) { 1947 } else if (identical('static', s)) {
1946 staticKeyword = token; 1948 staticKeyword = token;
1947 } else if (identical('var', s)) { 1949 } else if (identical('var', s)) {
1948 finalConstOrVarKeyword = token; 1950 finalConstOrVarKeyword = token;
1949 } else { 1951 } else {
1950 internalError('Unhandled modifier: $s'); 1952 internalError('Unhandled modifier: $s');
1951 } 1953 }
1952 } 1954 }
1953 } 1955 }
1954 } 1956 }
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