| 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:front_end/src/fasta/scanner/token.dart' | 7 import 'package:front_end/src/fasta/scanner/token.dart' |
| 8 show BeginGroupToken, Token; | 8 show BeginGroupToken, Token; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 Identifier identifier = pop(); | 306 Identifier identifier = pop(); |
| 307 // TODO(ahe): Don't push initializers, instead install them. | 307 // TODO(ahe): Don't push initializers, instead install them. |
| 308 push(ast.variableDeclaration( | 308 push(ast.variableDeclaration( |
| 309 identifier, toAnalyzerToken(assignmentOperator), initializer)); | 309 identifier, toAnalyzerToken(assignmentOperator), initializer)); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void endInitializedIdentifier() { | 312 void endInitializedIdentifier() { |
| 313 debugEvent("InitializedIdentifier"); | 313 debugEvent("InitializedIdentifier"); |
| 314 AstNode node = pop(); | 314 AstNode node = pop(); |
| 315 VariableDeclaration variable; | 315 VariableDeclaration variable; |
| 316 // TODO(paulberry): This seems kludgy. It would be preferable if we |
| 317 // could respond to a "handleNoVariableInitializer" event by converting a |
| 318 // SimpleIdentifier into a VariableDeclaration, and then when this code was |
| 319 // reached, node would always be a VariableDeclaration. |
| 316 if (node is VariableDeclaration) { | 320 if (node is VariableDeclaration) { |
| 317 variable = node; | 321 variable = node; |
| 318 } else if (node is SimpleIdentifier) { | 322 } else if (node is SimpleIdentifier) { |
| 319 variable = ast.variableDeclaration(node, null, null); | 323 variable = ast.variableDeclaration(node, null, null); |
| 320 } else { | 324 } else { |
| 321 internalError("unhandled identifier: ${node.runtimeType}"); | 325 internalError("unhandled identifier: ${node.runtimeType}"); |
| 322 } | 326 } |
| 323 push(variable); | 327 push(variable); |
| 324 scope[variable.name.name] = variable.name.staticElement = | 328 scope[variable.name.name] = variable.name.staticElement = |
| 325 new AnalyzerLocalVariableElemment(variable); | 329 new AnalyzerLocalVariableElemment(variable); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 assert(star == null); | 623 assert(star == null); |
| 620 return ast.expressionFunctionBody( | 624 return ast.expressionFunctionBody( |
| 621 asyncKeyword, body.returnKeyword, body.expression, body.semicolon); | 625 asyncKeyword, body.returnKeyword, body.expression, body.semicolon); |
| 622 } else { | 626 } else { |
| 623 return internalError( | 627 return internalError( |
| 624 'Unexpected function body type: ${body.runtimeType}'); | 628 'Unexpected function body type: ${body.runtimeType}'); |
| 625 } | 629 } |
| 626 } | 630 } |
| 627 | 631 |
| 628 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 632 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
| 633 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 634 // variables. |
| 629 debugEvent("TopLevelMethod"); | 635 debugEvent("TopLevelMethod"); |
| 630 FunctionBody body = _endFunctionBody(); | 636 FunctionBody body = _endFunctionBody(); |
| 631 FormalParameterList parameters = pop(); | 637 FormalParameterList parameters = pop(); |
| 632 TypeParameterList typeParameters = pop(); | 638 TypeParameterList typeParameters = pop(); |
| 633 SimpleIdentifier name = pop(); | 639 SimpleIdentifier name = pop(); |
| 634 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); | 640 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); |
| 635 TypeAnnotation returnType = pop(); | 641 TypeAnnotation returnType = pop(); |
| 636 // TODO(paulberry): handle modifiers. | 642 // TODO(paulberry): handle modifiers. |
| 637 var modifiers = pop(); | 643 var modifiers = pop(); |
| 638 assert(modifiers == null); | 644 assert(modifiers == null); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 StringLiteral uri = null; // TODO(paulberry) | 931 StringLiteral uri = null; // TODO(paulberry) |
| 926 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed | 932 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed |
| 927 // in a reference to the "of" keyword. | 933 // in a reference to the "of" keyword. |
| 928 var ofKeyword = partKeyword.next; | 934 var ofKeyword = partKeyword.next; |
| 929 List<Annotation> metadata = pop(); | 935 List<Annotation> metadata = pop(); |
| 930 Comment comment = null; // TODO(paulberry) | 936 Comment comment = null; // TODO(paulberry) |
| 931 push(ast.partOfDirective(comment, metadata, toAnalyzerToken(partKeyword), | 937 push(ast.partOfDirective(comment, metadata, toAnalyzerToken(partKeyword), |
| 932 toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon))); | 938 toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon))); |
| 933 accumulateIdentifierComponents = false; | 939 accumulateIdentifierComponents = false; |
| 934 } | 940 } |
| 941 |
| 942 void endUnnamedFunction(Token token) { |
| 943 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 944 // variables. Note that this is tricky due to the handling of initializers |
| 945 // in constructors, so the logic should be shared with BodyBuilder as much |
| 946 // as possible. |
| 947 debugEvent("UnnamedFunction"); |
| 948 var body = _endFunctionBody(); |
| 949 FormalParameterList parameters = pop(); |
| 950 TypeParameterList typeParameters = pop(); |
| 951 push(ast.functionExpression(typeParameters, parameters, body)); |
| 952 } |
| 953 |
| 954 @override |
| 955 void handleNoFieldInitializer(Token token) { |
| 956 debugEvent("NoFieldInitializer"); |
| 957 SimpleIdentifier name = pop(); |
| 958 push(ast.variableDeclaration(name, null, null)); |
| 959 } |
| 960 |
| 961 void endFieldInitializer(Token assignment) { |
| 962 debugEvent("FieldInitializer"); |
| 963 Expression initializer = pop(); |
| 964 SimpleIdentifier name = pop(); |
| 965 push(ast.variableDeclaration( |
| 966 name, toAnalyzerToken(assignment), initializer)); |
| 967 } |
| 968 |
| 969 void endTopLevelFields(int count, Token beginToken, Token endToken) { |
| 970 debugEvent("TopLevelFields"); |
| 971 List<VariableDeclaration> variables = popList(count); |
| 972 TypeAnnotation type = pop(); |
| 973 // TODO(paulberry): the var/const/final keyword should be pointed to by |
| 974 // beginToken. |
| 975 var keyword = null; // TODO(paulberry) |
| 976 var variableList = ast.variableDeclarationList( |
| 977 null, null, toAnalyzerToken(keyword), type, variables); |
| 978 var modifiers = pop(); |
| 979 assert(modifiers == null); // TODO(paulberry) |
| 980 List<Annotation> metadata = pop(); |
| 981 Comment comment = null; // TODO(paulberry) |
| 982 push(ast.topLevelVariableDeclaration( |
| 983 comment, metadata, variableList, toAnalyzerToken(endToken))); |
| 984 } |
| 935 } | 985 } |
| 936 | 986 |
| 937 /// Data structure placed on the stack to represent a class body. | 987 /// Data structure placed on the stack to represent a class body. |
| 938 /// | 988 /// |
| 939 /// This is needed because analyzer has no separate AST representation of a | 989 /// This is needed because analyzer has no separate AST representation of a |
| 940 /// class body; it simply stores all of the relevant data in the | 990 /// class body; it simply stores all of the relevant data in the |
| 941 /// [ClassDeclaration] object. | 991 /// [ClassDeclaration] object. |
| 942 class _ClassBody { | 992 class _ClassBody { |
| 943 final Token beginToken; | 993 final Token beginToken; |
| 944 | 994 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 957 /// [ClassDeclaration] or [ClassTypeAlias] object. | 1007 /// [ClassDeclaration] or [ClassTypeAlias] object. |
| 958 class _MixinApplication { | 1008 class _MixinApplication { |
| 959 final TypeName supertype; | 1009 final TypeName supertype; |
| 960 | 1010 |
| 961 final Token withKeyword; | 1011 final Token withKeyword; |
| 962 | 1012 |
| 963 final List<TypeName> mixinTypes; | 1013 final List<TypeName> mixinTypes; |
| 964 | 1014 |
| 965 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | 1015 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); |
| 966 } | 1016 } |
| OLD | NEW |