OLD | NEW |
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 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 StringLiteral uri = null; // TODO(paulberry) | 1474 StringLiteral uri = null; // TODO(paulberry) |
1475 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed | 1475 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed |
1476 // in a reference to the "of" keyword. | 1476 // in a reference to the "of" keyword. |
1477 var ofKeyword = partKeyword.next; | 1477 var ofKeyword = partKeyword.next; |
1478 List<Annotation> metadata = pop(); | 1478 List<Annotation> metadata = pop(); |
1479 Comment comment = pop(); | 1479 Comment comment = pop(); |
1480 push(ast.partOfDirective( | 1480 push(ast.partOfDirective( |
1481 comment, metadata, partKeyword, ofKeyword, uri, name, semicolon)); | 1481 comment, metadata, partKeyword, ofKeyword, uri, name, semicolon)); |
1482 } | 1482 } |
1483 | 1483 |
1484 void endUnnamedFunction(Token beginToken, Token token) { | 1484 @override |
| 1485 void endFunctionExpression(Token beginToken, Token token) { |
1485 // TODO(paulberry): set up scopes properly to resolve parameters and type | 1486 // TODO(paulberry): set up scopes properly to resolve parameters and type |
1486 // variables. Note that this is tricky due to the handling of initializers | 1487 // variables. Note that this is tricky due to the handling of initializers |
1487 // in constructors, so the logic should be shared with BodyBuilder as much | 1488 // in constructors, so the logic should be shared with BodyBuilder as much |
1488 // as possible. | 1489 // as possible. |
1489 debugEvent("UnnamedFunction"); | 1490 debugEvent("FunctionExpression"); |
1490 FunctionBody body = pop(); | 1491 FunctionBody body = pop(); |
1491 FormalParameterList parameters = pop(); | 1492 FormalParameterList parameters = pop(); |
1492 TypeParameterList typeParameters = pop(); | 1493 TypeParameterList typeParameters = pop(); |
1493 push(ast.functionExpression(typeParameters, parameters, body)); | 1494 push(ast.functionExpression(typeParameters, parameters, body)); |
1494 } | 1495 } |
1495 | 1496 |
1496 @override | 1497 @override |
1497 void handleNoFieldInitializer(Token token) { | 1498 void handleNoFieldInitializer(Token token) { |
1498 debugEvent("NoFieldInitializer"); | 1499 debugEvent("NoFieldInitializer"); |
1499 SimpleIdentifier name = pop(); | 1500 SimpleIdentifier name = pop(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 } | 1558 } |
1558 | 1559 |
1559 void endFieldInitializer(Token assignment, Token token) { | 1560 void endFieldInitializer(Token assignment, Token token) { |
1560 debugEvent("FieldInitializer"); | 1561 debugEvent("FieldInitializer"); |
1561 Expression initializer = pop(); | 1562 Expression initializer = pop(); |
1562 SimpleIdentifier name = pop(); | 1563 SimpleIdentifier name = pop(); |
1563 push(ast.variableDeclaration(name, assignment, initializer)); | 1564 push(ast.variableDeclaration(name, assignment, initializer)); |
1564 } | 1565 } |
1565 | 1566 |
1566 @override | 1567 @override |
1567 void endFunction(Token getOrSet, Token endToken) { | 1568 void endNamedFunctionExpression(Token endToken) { |
1568 debugEvent("Function"); | 1569 logEvent("NamedFunctionExpression"); |
| 1570 } |
| 1571 |
| 1572 @override |
| 1573 void endFunctionDeclaration(Token endToken) { |
| 1574 debugEvent("FunctionDeclaration"); |
1569 FunctionBody body = pop(); | 1575 FunctionBody body = pop(); |
1570 pop(); // constructor initializers | 1576 pop(); // constructor initializers |
1571 pop(); // separator before constructor initializers | 1577 pop(); // separator before constructor initializers |
1572 FormalParameterList parameters = pop(); | 1578 FormalParameterList parameters = pop(); |
1573 TypeParameterList typeParameters = pop(); | 1579 TypeParameterList typeParameters = pop(); |
1574 // TODO(scheglov) It is an error if "getOrSet" is not null. | 1580 FunctionExpression functionExpression = |
1575 push(ast.functionExpression(typeParameters, parameters, body)); | 1581 ast.functionExpression(typeParameters, parameters, body); |
1576 } | |
1577 | |
1578 @override | |
1579 void endFunctionDeclaration(Token token) { | |
1580 debugEvent("FunctionDeclaration"); | |
1581 FunctionExpression functionExpression = pop(); | |
1582 SimpleIdentifier name = pop(); | 1582 SimpleIdentifier name = pop(); |
1583 TypeAnnotation returnType = pop(); | 1583 TypeAnnotation returnType = pop(); |
1584 pop(); // modifiers | 1584 pop(); // modifiers |
1585 push(ast.functionDeclarationStatement(ast.functionDeclaration( | 1585 push(ast.functionDeclarationStatement(ast.functionDeclaration( |
1586 null, null, null, returnType, null, name, functionExpression))); | 1586 null, null, null, returnType, null, name, functionExpression))); |
1587 } | 1587 } |
1588 | 1588 |
1589 @override | 1589 @override |
1590 void endFunctionName(Token beginToken, Token token) { | 1590 void endFunctionName(Token beginToken, Token token) { |
1591 debugEvent("FunctionName"); | 1591 debugEvent("FunctionName"); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2024 } else if (identical('var', s)) { | 2024 } else if (identical('var', s)) { |
2025 finalConstOrVarKeyword = token; | 2025 finalConstOrVarKeyword = token; |
2026 } else if (identical('covariant', s)) { | 2026 } else if (identical('covariant', s)) { |
2027 covariantKeyword = token; | 2027 covariantKeyword = token; |
2028 } else { | 2028 } else { |
2029 internalError('Unhandled modifier: $s'); | 2029 internalError('Unhandled modifier: $s'); |
2030 } | 2030 } |
2031 } | 2031 } |
2032 } | 2032 } |
2033 } | 2033 } |
OLD | NEW |