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: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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 void handleIdentifier(Token token, IdentifierContext context) { | 114 void handleIdentifier(Token token, IdentifierContext context) { |
| 115 debugEvent("handleIdentifier"); | 115 debugEvent("handleIdentifier"); |
| 116 String name = token.value; | 116 String name = token.value; |
| 117 SimpleIdentifier identifier = ast.simpleIdentifier(toAnalyzerToken(token)); | 117 SimpleIdentifier identifier = ast.simpleIdentifier(toAnalyzerToken(token)); |
| 118 if (context.inLibraryOrPartOfDeclaration) { | 118 if (context.inLibraryOrPartOfDeclaration) { |
| 119 if (!context.isContinuation) { | 119 if (!context.isContinuation) { |
| 120 push([identifier]); | 120 push([identifier]); |
| 121 } else { | 121 } else { |
| 122 push(identifier); | 122 push(identifier); |
| 123 } | 123 } |
| 124 } else if (context == IdentifierContext.enumValueDeclaration) { | |
| 125 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have | |
| 126 // metadata, but the spec doesn't permit it. | |
|
ahe
2017/02/23 16:47:25
I think we should accept it for error recovery.
| |
| 127 List<Annotation> metadata; | |
| 128 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | |
| 129 Comment comment = null; | |
| 130 push(ast.enumConstantDeclaration(comment, metadata, identifier)); | |
| 124 } else { | 131 } else { |
| 125 if (context.isScopeReference) { | 132 if (context.isScopeReference) { |
| 126 Builder builder = scope.lookup(name, token.charOffset, uri); | 133 Builder builder = scope.lookup(name, token.charOffset, uri); |
| 127 if (builder != null) { | 134 if (builder != null) { |
| 128 Element element = elementStore[builder]; | 135 Element element = elementStore[builder]; |
| 129 assert(element != null); | 136 assert(element != null); |
| 130 identifier.staticElement = element; | 137 identifier.staticElement = element; |
| 131 } | 138 } |
| 132 } | 139 } |
| 133 push(identifier); | 140 push(identifier); |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 comment, | 1078 comment, |
| 1072 metadata, | 1079 metadata, |
| 1073 toAnalyzerToken(typedefKeyword), | 1080 toAnalyzerToken(typedefKeyword), |
| 1074 returnType, | 1081 returnType, |
| 1075 name, | 1082 name, |
| 1076 typeParameters, | 1083 typeParameters, |
| 1077 parameters, | 1084 parameters, |
| 1078 toAnalyzerToken(endToken))); | 1085 toAnalyzerToken(endToken))); |
| 1079 } | 1086 } |
| 1080 | 1087 |
| 1088 void endEnum(Token enumKeyword, Token endBrace, int count) { | |
| 1089 debugEvent("Enum"); | |
| 1090 List<EnumConstantDeclaration> constants = popList(count); | |
| 1091 // TODO(paulberry,ahe): the parser should pass in the openBrace token. | |
| 1092 var openBrace = enumKeyword.next.next as BeginGroupToken; | |
|
ahe
2017/02/23 16:47:25
I would recommend against casts as they have to be
| |
| 1093 // TODO(paulberry): what if the '}' is missing and the parser has performed | |
| 1094 // error recovery? | |
|
ahe
2017/02/23 16:47:25
The scanner always provides a synthetic end token.
| |
| 1095 Token closeBrace = openBrace.endGroup; | |
| 1096 SimpleIdentifier name = pop(); | |
| 1097 List<Annotation> metadata = pop(); | |
| 1098 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | |
| 1099 Comment comment = null; | |
| 1100 push(ast.enumDeclaration( | |
| 1101 comment, | |
| 1102 metadata, | |
| 1103 toAnalyzerToken(enumKeyword), | |
| 1104 name, | |
| 1105 toAnalyzerToken(openBrace), | |
| 1106 constants, | |
| 1107 toAnalyzerToken(closeBrace))); | |
| 1108 } | |
| 1109 | |
| 1081 /** | 1110 /** |
| 1082 * Pop the modifiers list, if the list is empty return `null`, if the list | 1111 * Pop the modifiers list, if the list is empty return `null`, if the list |
| 1083 * has one item return it; otherwise return `null`. | 1112 * has one item return it; otherwise return `null`. |
| 1084 */ | 1113 */ |
| 1085 Token _popOptionalSingleModifier() { | 1114 Token _popOptionalSingleModifier() { |
| 1086 List<Token> modifiers = pop(); | 1115 List<Token> modifiers = pop(); |
| 1087 if (modifiers.length == 0) { | 1116 if (modifiers.length == 0) { |
| 1088 return null; | 1117 return null; |
| 1089 } else if (modifiers.length == 1) { | 1118 } else if (modifiers.length == 1) { |
| 1090 // TODO(scheglov): Verify that the modifier is valid. | 1119 // TODO(scheglov): Verify that the modifier is valid. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1120 /// [ClassDeclaration] or [ClassTypeAlias] object. | 1149 /// [ClassDeclaration] or [ClassTypeAlias] object. |
| 1121 class _MixinApplication { | 1150 class _MixinApplication { |
| 1122 final TypeName supertype; | 1151 final TypeName supertype; |
| 1123 | 1152 |
| 1124 final Token withKeyword; | 1153 final Token withKeyword; |
| 1125 | 1154 |
| 1126 final List<TypeName> mixinTypes; | 1155 final List<TypeName> mixinTypes; |
| 1127 | 1156 |
| 1128 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | 1157 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); |
| 1129 } | 1158 } |
| OLD | NEW |