| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 } | 471 } |
| 472 | 472 |
| 473 void endFormalParameter(Token thisKeyword) { | 473 void endFormalParameter(Token thisKeyword) { |
| 474 debugEvent("FormalParameter"); | 474 debugEvent("FormalParameter"); |
| 475 if (thisKeyword != null) { | 475 if (thisKeyword != null) { |
| 476 internalError("'this' can't be used here."); | 476 internalError("'this' can't be used here."); |
| 477 } | 477 } |
| 478 SimpleIdentifier name = pop(); | 478 SimpleIdentifier name = pop(); |
| 479 TypeName type = pop(); | 479 TypeName type = pop(); |
| 480 Token keyword = _popOptionalSingleModifier(); | 480 Token keyword = _popOptionalSingleModifier(); |
| 481 pop(); // Metadata. | 481 pop(); // TODO(paulberry): Metadata. |
| 482 // TODO(paulberry): handle covariant keyword. |
| 482 SimpleFormalParameter node = ast.simpleFormalParameter( | 483 SimpleFormalParameter node = ast.simpleFormalParameter( |
| 483 null, null, toAnalyzerToken(keyword), type, name); | 484 null, null, toAnalyzerToken(keyword), type, name); |
| 484 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); | 485 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); |
| 485 push(node); | 486 push(node); |
| 486 } | 487 } |
| 487 | 488 |
| 488 void endFormalParameters(int count, Token beginToken, Token endToken) { | 489 void endFormalParameters(int count, Token beginToken, Token endToken) { |
| 489 debugEvent("FormalParameters"); | 490 debugEvent("FormalParameters"); |
| 490 List<FormalParameter> parameters = popList(count) ?? <FormalParameter>[]; | 491 List<FormalParameter> parameters = popList(count) ?? <FormalParameter>[]; |
| 491 push(ast.formalParameterList(toAnalyzerToken(beginToken), parameters, null, | 492 push(ast.formalParameterList(toAnalyzerToken(beginToken), parameters, null, |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 comment, | 1079 comment, |
| 1079 metadata, | 1080 metadata, |
| 1080 toAnalyzerToken(typedefKeyword), | 1081 toAnalyzerToken(typedefKeyword), |
| 1081 returnType, | 1082 returnType, |
| 1082 name, | 1083 name, |
| 1083 typeParameters, | 1084 typeParameters, |
| 1084 parameters, | 1085 parameters, |
| 1085 toAnalyzerToken(endToken))); | 1086 toAnalyzerToken(endToken))); |
| 1086 } | 1087 } |
| 1087 | 1088 |
| 1089 @override |
| 1088 void endEnum(Token enumKeyword, Token endBrace, int count) { | 1090 void endEnum(Token enumKeyword, Token endBrace, int count) { |
| 1089 debugEvent("Enum"); | 1091 debugEvent("Enum"); |
| 1090 List<EnumConstantDeclaration> constants = popList(count); | 1092 List<EnumConstantDeclaration> constants = popList(count); |
| 1091 // TODO(paulberry,ahe): the parser should pass in the openBrace token. | 1093 // TODO(paulberry,ahe): the parser should pass in the openBrace token. |
| 1092 var openBrace = enumKeyword.next.next as BeginGroupToken; | 1094 var openBrace = enumKeyword.next.next as BeginGroupToken; |
| 1093 // TODO(paulberry): what if the '}' is missing and the parser has performed | 1095 // TODO(paulberry): what if the '}' is missing and the parser has performed |
| 1094 // error recovery? | 1096 // error recovery? |
| 1095 Token closeBrace = openBrace.endGroup; | 1097 Token closeBrace = openBrace.endGroup; |
| 1096 SimpleIdentifier name = pop(); | 1098 SimpleIdentifier name = pop(); |
| 1097 List<Annotation> metadata = pop(); | 1099 List<Annotation> metadata = pop(); |
| 1098 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1100 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1099 Comment comment = null; | 1101 Comment comment = null; |
| 1100 push(ast.enumDeclaration( | 1102 push(ast.enumDeclaration( |
| 1101 comment, | 1103 comment, |
| 1102 metadata, | 1104 metadata, |
| 1103 toAnalyzerToken(enumKeyword), | 1105 toAnalyzerToken(enumKeyword), |
| 1104 name, | 1106 name, |
| 1105 toAnalyzerToken(openBrace), | 1107 toAnalyzerToken(openBrace), |
| 1106 constants, | 1108 constants, |
| 1107 toAnalyzerToken(closeBrace))); | 1109 toAnalyzerToken(closeBrace))); |
| 1108 } | 1110 } |
| 1109 | 1111 |
| 1112 @override |
| 1113 void endTypeArguments(int count, Token beginToken, Token endToken) { |
| 1114 debugEvent("TypeArguments"); |
| 1115 List<TypeAnnotation> arguments = popList(count); |
| 1116 push(ast.typeArgumentList( |
| 1117 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); |
| 1118 } |
| 1119 |
| 1110 /** | 1120 /** |
| 1111 * Pop the modifiers list, if the list is empty return `null`, if the list | 1121 * Pop the modifiers list, if the list is empty return `null`, if the list |
| 1112 * has one item return it; otherwise return `null`. | 1122 * has one item return it; otherwise return `null`. |
| 1113 */ | 1123 */ |
| 1114 Token _popOptionalSingleModifier() { | 1124 Token _popOptionalSingleModifier() { |
| 1115 List<Token> modifiers = pop(); | 1125 List<Token> modifiers = pop(); |
| 1116 if (modifiers.length == 0) { | 1126 if (modifiers.length == 0) { |
| 1117 return null; | 1127 return null; |
| 1118 } else if (modifiers.length == 1) { | 1128 } else if (modifiers.length == 1) { |
| 1119 // TODO(scheglov): Verify that the modifier is valid. | 1129 // TODO(scheglov): Verify that the modifier is valid. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1149 /// [ClassDeclaration] or [ClassTypeAlias] object. | 1159 /// [ClassDeclaration] or [ClassTypeAlias] object. |
| 1150 class _MixinApplication { | 1160 class _MixinApplication { |
| 1151 final TypeName supertype; | 1161 final TypeName supertype; |
| 1152 | 1162 |
| 1153 final Token withKeyword; | 1163 final Token withKeyword; |
| 1154 | 1164 |
| 1155 final List<TypeName> mixinTypes; | 1165 final List<TypeName> mixinTypes; |
| 1156 | 1166 |
| 1157 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | 1167 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); |
| 1158 } | 1168 } |
| OLD | NEW |