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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 toAnalyzerToken(elseToken), | 385 toAnalyzerToken(elseToken), |
386 elsePart)); | 386 elsePart)); |
387 } | 387 } |
388 | 388 |
389 void prepareInitializers() { | 389 void prepareInitializers() { |
390 debugEvent("prepareInitializers"); | 390 debugEvent("prepareInitializers"); |
391 } | 391 } |
392 | 392 |
393 void handleNoInitializers() { | 393 void handleNoInitializers() { |
394 debugEvent("NoInitializers"); | 394 debugEvent("NoInitializers"); |
| 395 push(NullValue.ConstructorInitializers); |
395 } | 396 } |
396 | 397 |
397 void endInitializers(int count, Token beginToken, Token endToken) { | 398 void endInitializers(int count, Token beginToken, Token endToken) { |
398 debugEvent("Initializers"); | 399 debugEvent("Initializers"); |
399 popList(count); | 400 push(popList(count)); |
400 } | 401 } |
401 | 402 |
402 void endVariableInitializer(Token assignmentOperator) { | 403 void endVariableInitializer(Token assignmentOperator) { |
403 debugEvent("VariableInitializer"); | 404 debugEvent("VariableInitializer"); |
404 assert(assignmentOperator.stringValue == "="); | 405 assert(assignmentOperator.stringValue == "="); |
405 Expression initializer = pop(); | 406 Expression initializer = pop(); |
406 Identifier identifier = pop(); | 407 Identifier identifier = pop(); |
407 // TODO(ahe): Don't push initializers, instead install them. | 408 // TODO(ahe): Don't push initializers, instead install them. |
408 push(ast.variableDeclaration( | 409 push(ast.variableDeclaration( |
409 identifier, toAnalyzerToken(assignmentOperator), initializer)); | 410 identifier, toAnalyzerToken(assignmentOperator), initializer)); |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 List<TypeParameter> typeParameters = popList(count); | 1401 List<TypeParameter> typeParameters = popList(count); |
1401 push(ast.typeParameterList(toAnalyzerToken(beginToken), typeParameters, | 1402 push(ast.typeParameterList(toAnalyzerToken(beginToken), typeParameters, |
1402 toAnalyzerToken(endToken))); | 1403 toAnalyzerToken(endToken))); |
1403 } | 1404 } |
1404 | 1405 |
1405 @override | 1406 @override |
1406 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 1407 void endMethod(Token getOrSet, Token beginToken, Token endToken) { |
1407 debugEvent("Method"); | 1408 debugEvent("Method"); |
1408 FunctionBody body = pop(); | 1409 FunctionBody body = pop(); |
1409 ConstructorName redirectedConstructor = null; // TODO(paulberry) | 1410 ConstructorName redirectedConstructor = null; // TODO(paulberry) |
1410 List<ConstructorInitializer> initializers = null; // TODO(paulberry) | 1411 List<Object> initializerObjects = pop() ?? const []; |
1411 Token separator = null; // TODO(paulberry) | 1412 Token separator = null; // TODO(paulberry) |
1412 FormalParameterList parameters = pop(); | 1413 FormalParameterList parameters = pop(); |
1413 TypeParameterList typeParameters = pop(); // TODO(paulberry) | 1414 TypeParameterList typeParameters = pop(); // TODO(paulberry) |
1414 var name = pop(); | 1415 var name = pop(); |
1415 TypeAnnotation returnType = pop(); // TODO(paulberry) | 1416 TypeAnnotation returnType = pop(); // TODO(paulberry) |
1416 _Modifiers modifiers = pop(); | 1417 _Modifiers modifiers = pop(); |
1417 List<Annotation> metadata = pop(); | 1418 List<Annotation> metadata = pop(); |
1418 Comment comment = pop(); | 1419 Comment comment = pop(); |
1419 | 1420 |
| 1421 var initializers = <ConstructorInitializer>[]; |
| 1422 for (Object initializerObject in initializerObjects) { |
| 1423 if (initializerObject is AssignmentExpression) { |
| 1424 analyzer.Token thisKeyword; |
| 1425 analyzer.Token period; |
| 1426 SimpleIdentifier fieldName; |
| 1427 Expression left = initializerObject.leftHandSide; |
| 1428 if (left is PropertyAccess) { |
| 1429 var thisExpression = left.target as ThisExpression; |
| 1430 thisKeyword = thisExpression.thisKeyword; |
| 1431 period = left.operator; |
| 1432 fieldName = left.propertyName; |
| 1433 } else { |
| 1434 fieldName = left as SimpleIdentifier; |
| 1435 } |
| 1436 initializers.add(ast.constructorFieldInitializer( |
| 1437 thisKeyword, |
| 1438 period, |
| 1439 fieldName, |
| 1440 initializerObject.operator, |
| 1441 initializerObject.rightHandSide)); |
| 1442 } |
| 1443 } |
| 1444 |
1420 void constructor(SimpleIdentifier returnType, analyzer.Token period, | 1445 void constructor(SimpleIdentifier returnType, analyzer.Token period, |
1421 SimpleIdentifier name) { | 1446 SimpleIdentifier name) { |
1422 push(ast.constructorDeclaration( | 1447 push(ast.constructorDeclaration( |
1423 comment, | 1448 comment, |
1424 metadata, | 1449 metadata, |
1425 toAnalyzerToken(modifiers?.externalKeyword), | 1450 toAnalyzerToken(modifiers?.externalKeyword), |
1426 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), | 1451 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), |
1427 null, // TODO(paulberry): factoryKeyword | 1452 null, // TODO(paulberry): factoryKeyword |
1428 ast.simpleIdentifier(returnType.token), | 1453 ast.simpleIdentifier(returnType.token), |
1429 period, | 1454 period, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 } else if (identical('static', s)) { | 1750 } else if (identical('static', s)) { |
1726 staticKeyword = token; | 1751 staticKeyword = token; |
1727 } else if (identical('var', s)) { | 1752 } else if (identical('var', s)) { |
1728 finalConstOrVarKeyword = token; | 1753 finalConstOrVarKeyword = token; |
1729 } else { | 1754 } else { |
1730 internalError('Unhandled modifier: $s'); | 1755 internalError('Unhandled modifier: $s'); |
1731 } | 1756 } |
1732 } | 1757 } |
1733 } | 1758 } |
1734 } | 1759 } |
OLD | NEW |