| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 void endArguments(int count, Token beginToken, Token endToken) { | 142 void endArguments(int count, Token beginToken, Token endToken) { |
| 143 debugEvent("Arguments"); | 143 debugEvent("Arguments"); |
| 144 List expressions = popList(count); | 144 List expressions = popList(count); |
| 145 ArgumentList arguments = ast.argumentList( | 145 ArgumentList arguments = ast.argumentList( |
| 146 toAnalyzerToken(beginToken), expressions, toAnalyzerToken(endToken)); | 146 toAnalyzerToken(beginToken), expressions, toAnalyzerToken(endToken)); |
| 147 push(ast.methodInvocation(null, null, null, null, arguments)); | 147 push(ast.methodInvocation(null, null, null, null, arguments)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void handleIdentifier(Token token, IdentifierContext context) { | 150 void handleIdentifier(Token token, IdentifierContext context) { |
| 151 debugEvent("handleIdentifier"); | 151 debugEvent("handleIdentifier"); |
| 152 String name = token.value; | 152 analyzer.Token analyzerToken = toAnalyzerToken(token); |
| 153 SimpleIdentifier identifier = ast.simpleIdentifier(toAnalyzerToken(token)); | 153 |
| 154 if (context.inSymbol) { |
| 155 push(analyzerToken); |
| 156 return; |
| 157 } |
| 158 |
| 159 SimpleIdentifier identifier = ast.simpleIdentifier(analyzerToken); |
| 154 if (context.inLibraryOrPartOfDeclaration) { | 160 if (context.inLibraryOrPartOfDeclaration) { |
| 155 if (!context.isContinuation) { | 161 if (!context.isContinuation) { |
| 156 push([identifier]); | 162 push([identifier]); |
| 157 } else { | 163 } else { |
| 158 push(identifier); | 164 push(identifier); |
| 159 } | 165 } |
| 160 } else if (context == IdentifierContext.enumValueDeclaration) { | 166 } else if (context == IdentifierContext.enumValueDeclaration) { |
| 161 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have | 167 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have |
| 162 // metadata, but the spec doesn't permit it. | 168 // metadata, but the spec doesn't permit it. |
| 163 List<Annotation> metadata; | 169 List<Annotation> metadata; |
| 164 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 170 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 165 Comment comment = null; | 171 Comment comment = null; |
| 166 push(ast.enumConstantDeclaration(comment, metadata, identifier)); | 172 push(ast.enumConstantDeclaration(comment, metadata, identifier)); |
| 167 } else { | 173 } else { |
| 168 if (context.isScopeReference) { | 174 if (context.isScopeReference) { |
| 175 String name = token.value; |
| 169 Builder builder = scope.lookup(name, token.charOffset, uri); | 176 Builder builder = scope.lookup(name, token.charOffset, uri); |
| 170 if (builder != null) { | 177 if (builder != null) { |
| 171 Element element = elementStore[builder]; | 178 Element element = elementStore[builder]; |
| 172 assert(element != null); | 179 assert(element != null); |
| 173 identifier.staticElement = element; | 180 identifier.staticElement = element; |
| 174 } | 181 } |
| 175 } else if (context == IdentifierContext.classDeclaration) { | 182 } else if (context == IdentifierContext.classDeclaration) { |
| 176 className = identifier.name; | 183 className = identifier.name; |
| 177 } | 184 } |
| 178 push(identifier); | 185 push(identifier); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 263 |
| 257 void endCascade() { | 264 void endCascade() { |
| 258 debugEvent("Cascade"); | 265 debugEvent("Cascade"); |
| 259 Expression expression = pop(); | 266 Expression expression = pop(); |
| 260 CascadeExpression receiver = pop(); | 267 CascadeExpression receiver = pop(); |
| 261 pop(); // Token. | 268 pop(); // Token. |
| 262 receiver.cascadeSections.add(expression); | 269 receiver.cascadeSections.add(expression); |
| 263 push(receiver); | 270 push(receiver); |
| 264 } | 271 } |
| 265 | 272 |
| 273 void handleOperator(Token token) { |
| 274 debugEvent("Operator"); |
| 275 push(toAnalyzerToken(token)); |
| 276 } |
| 277 |
| 266 void handleBinaryExpression(Token token) { | 278 void handleBinaryExpression(Token token) { |
| 267 debugEvent("BinaryExpression"); | 279 debugEvent("BinaryExpression"); |
| 268 if (identical(".", token.stringValue) || | 280 if (identical(".", token.stringValue) || |
| 269 identical("?.", token.stringValue) || | 281 identical("?.", token.stringValue) || |
| 270 identical("..", token.stringValue)) { | 282 identical("..", token.stringValue)) { |
| 271 doDotExpression(token); | 283 doDotExpression(token); |
| 272 } else { | 284 } else { |
| 273 Expression right = pop(); | 285 Expression right = pop(); |
| 274 Expression left = pop(); | 286 Expression left = pop(); |
| 275 push(ast.binaryExpression(left, toAnalyzerToken(token), right)); | 287 push(ast.binaryExpression(left, toAnalyzerToken(token), right)); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 toAnalyzerToken(beginToken), entries, toAnalyzerToken(endToken))); | 492 toAnalyzerToken(beginToken), entries, toAnalyzerToken(endToken))); |
| 481 } | 493 } |
| 482 | 494 |
| 483 void endLiteralMapEntry(Token colon, Token endToken) { | 495 void endLiteralMapEntry(Token colon, Token endToken) { |
| 484 debugEvent("LiteralMapEntry"); | 496 debugEvent("LiteralMapEntry"); |
| 485 Expression value = pop(); | 497 Expression value = pop(); |
| 486 Expression key = pop(); | 498 Expression key = pop(); |
| 487 push(ast.mapLiteralEntry(key, toAnalyzerToken(colon), value)); | 499 push(ast.mapLiteralEntry(key, toAnalyzerToken(colon), value)); |
| 488 } | 500 } |
| 489 | 501 |
| 490 void endLiteralSymbol(Token hashToken, int identifierCount) { | 502 void endLiteralSymbol(Token hashToken, int tokenCount) { |
| 491 debugEvent("LiteralSymbol"); | 503 debugEvent("LiteralSymbol"); |
| 492 List<analyzer.Token> components = new List<analyzer.Token>(identifierCount); | 504 List<analyzer.Token> components = popList(tokenCount); |
| 493 for (int i = identifierCount - 1; i >= 0; i--) { | |
| 494 SimpleIdentifier identifier = pop(); | |
| 495 components[i] = identifier.token; | |
| 496 } | |
| 497 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components)); | 505 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components)); |
| 498 } | 506 } |
| 499 | 507 |
| 500 @override | 508 @override |
| 501 void handleSuperExpression(Token token) { | 509 void handleSuperExpression(Token token) { |
| 502 debugEvent("SuperExpression"); | 510 debugEvent("SuperExpression"); |
| 503 push(ast.superExpression(toAnalyzerToken(token))); | 511 push(ast.superExpression(toAnalyzerToken(token))); |
| 504 } | 512 } |
| 505 | 513 |
| 506 @override | 514 @override |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 } else if (identical('static', s)) { | 1456 } else if (identical('static', s)) { |
| 1449 staticKeyword = token; | 1457 staticKeyword = token; |
| 1450 } else if (identical('var', s)) { | 1458 } else if (identical('var', s)) { |
| 1451 finalConstOrVarKeyword = token; | 1459 finalConstOrVarKeyword = token; |
| 1452 } else { | 1460 } else { |
| 1453 internalError('Unhandled modifier: $s'); | 1461 internalError('Unhandled modifier: $s'); |
| 1454 } | 1462 } |
| 1455 } | 1463 } |
| 1456 } | 1464 } |
| 1457 } | 1465 } |
| OLD | NEW |