Chromium Code Reviews| 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,ahe): 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. | |
|
ahe
2017/02/20 09:04:20
Good idea. I've filed issue https://github.com/dar
Paul Berry
2017/02/20 15:01:36
Thanks for doing that! Now that the new event is
| |
| 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. | |
|
ahe
2017/02/20 09:04:20
This is a bit tricky when it comes to handling ini
Paul Berry
2017/02/20 15:01:36
Good point. I've updated the TODO comment to make
| |
| 945 debugEvent("UnnamedFunction"); | |
| 946 var body = _endFunctionBody(); | |
| 947 FormalParameterList parameters = pop(); | |
| 948 TypeParameterList typeParameters = pop(); | |
| 949 push(ast.functionExpression(typeParameters, parameters, body)); | |
| 950 } | |
| 951 | |
| 952 @override | |
| 953 void handleNoFieldInitializer(Token token) { | |
| 954 debugEvent("NoFieldInitializer"); | |
| 955 SimpleIdentifier name = pop(); | |
| 956 push(ast.variableDeclaration(name, null, null)); | |
| 957 } | |
| 958 | |
| 959 void endFieldInitializer(Token assignment) { | |
| 960 debugEvent("FieldInitializer"); | |
| 961 Expression initializer = pop(); | |
| 962 SimpleIdentifier name = pop(); | |
| 963 push(ast.variableDeclaration( | |
| 964 name, toAnalyzerToken(assignment), initializer)); | |
| 965 } | |
| 966 | |
| 967 void endTopLevelFields(int count, Token beginToken, Token endToken) { | |
| 968 debugEvent("TopLevelFields"); | |
| 969 List<VariableDeclaration> variables = popList(count); | |
| 970 TypeAnnotation type = pop(); | |
| 971 // TODO(paulberry,ahe): the parser needs to pass the var/const/final keyword | |
|
ahe
2017/02/20 09:04:20
Those should be available in beginToken. Another o
Paul Berry
2017/02/20 15:01:36
Oh, ok. I misread the parser code and thought "be
| |
| 972 // to the listener. | |
| 973 var keyword = null; // TODO(paulberry) | |
| 974 var variableList = ast.variableDeclarationList( | |
| 975 null, null, toAnalyzerToken(keyword), type, variables); | |
| 976 var modifiers = pop(); | |
| 977 assert(modifiers == null); // TODO(paulberry) | |
| 978 List<Annotation> metadata = pop(); | |
| 979 Comment comment = null; // TODO(paulberry) | |
| 980 push(ast.topLevelVariableDeclaration( | |
| 981 comment, metadata, variableList, toAnalyzerToken(endToken))); | |
| 982 } | |
| 935 } | 983 } |
| 936 | 984 |
| 937 /// Data structure placed on the stack to represent a class body. | 985 /// Data structure placed on the stack to represent a class body. |
| 938 /// | 986 /// |
| 939 /// This is needed because analyzer has no separate AST representation of a | 987 /// 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 | 988 /// class body; it simply stores all of the relevant data in the |
| 941 /// [ClassDeclaration] object. | 989 /// [ClassDeclaration] object. |
| 942 class _ClassBody { | 990 class _ClassBody { |
| 943 final Token beginToken; | 991 final Token beginToken; |
| 944 | 992 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 957 /// [ClassDeclaration] or [ClassTypeAlias] object. | 1005 /// [ClassDeclaration] or [ClassTypeAlias] object. |
| 958 class _MixinApplication { | 1006 class _MixinApplication { |
| 959 final TypeName supertype; | 1007 final TypeName supertype; |
| 960 | 1008 |
| 961 final Token withKeyword; | 1009 final Token withKeyword; |
| 962 | 1010 |
| 963 final List<TypeName> mixinTypes; | 1011 final List<TypeName> mixinTypes; |
| 964 | 1012 |
| 965 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | 1013 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); |
| 966 } | 1014 } |
| OLD | NEW |