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; |
11 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; | 11 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
12 import 'package:analyzer/dart/element/element.dart' show Element; | 12 import 'package:analyzer/dart/element/element.dart' show Element; |
13 import 'package:front_end/src/fasta/parser/parser.dart' | 13 import 'package:front_end/src/fasta/parser/parser.dart' |
14 show Assert, FormalParameterType, MemberKind, Parser; | 14 show Assert, FormalParameterType, MemberKind, Parser; |
15 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; | 15 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
16 import 'package:front_end/src/fasta/scanner/token.dart' show CommentToken; | 16 import 'package:front_end/src/fasta/scanner/token.dart' show CommentToken; |
17 import 'package:front_end/src/scanner/token.dart' as analyzer; | 17 import 'package:front_end/src/scanner/token.dart' as analyzer; |
18 | 18 |
19 import 'package:front_end/src/fasta/errors.dart' show internalError; | 19 import 'package:front_end/src/fasta/deprecated_problems.dart' |
| 20 show deprecated_internalProblem; |
20 import 'package:front_end/src/fasta/fasta_codes.dart' | 21 import 'package:front_end/src/fasta/fasta_codes.dart' |
21 show | 22 show |
22 FastaCode, | 23 FastaCode, |
23 FastaMessage, | 24 FastaMessage, |
24 codeExpectedExpression, | 25 codeExpectedExpression, |
25 codeExpectedFunctionBody; | 26 codeExpectedFunctionBody; |
26 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' | 27 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' |
27 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope; | 28 show Builder, KernelLibraryBuilder, ProcedureBuilder, Scope; |
28 import 'package:front_end/src/fasta/parser/identifier_context.dart' | 29 import 'package:front_end/src/fasta/parser/identifier_context.dart' |
29 show IdentifierContext; | 30 show IdentifierContext; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 List<InterpolationElement> elements = <InterpolationElement>[]; | 161 List<InterpolationElement> elements = <InterpolationElement>[]; |
161 elements.add(ast.interpolationString( | 162 elements.add(ast.interpolationString( |
162 first, unescapeFirstStringPart(first.lexeme, quote))); | 163 first, unescapeFirstStringPart(first.lexeme, quote))); |
163 for (int i = 1; i < parts.length - 1; i++) { | 164 for (int i = 1; i < parts.length - 1; i++) { |
164 var part = parts[i]; | 165 var part = parts[i]; |
165 if (part is Token) { | 166 if (part is Token) { |
166 elements.add(ast.interpolationString(part, part.lexeme)); | 167 elements.add(ast.interpolationString(part, part.lexeme)); |
167 } else if (part is Expression) { | 168 } else if (part is Expression) { |
168 elements.add(ast.interpolationExpression(null, part, null)); | 169 elements.add(ast.interpolationExpression(null, part, null)); |
169 } else { | 170 } else { |
170 internalError( | 171 deprecated_internalProblem( |
171 "Unexpected part in string interpolation: ${part.runtimeType}"); | 172 "Unexpected part in string interpolation: ${part.runtimeType}"); |
172 } | 173 } |
173 } | 174 } |
174 elements.add(ast.interpolationString( | 175 elements.add(ast.interpolationString( |
175 last, unescapeLastStringPart(last.lexeme, quote))); | 176 last, unescapeLastStringPart(last.lexeme, quote))); |
176 push(ast.stringInterpolation(elements)); | 177 push(ast.stringInterpolation(elements)); |
177 } | 178 } |
178 } | 179 } |
179 | 180 |
180 void handleScript(Token token) { | 181 void handleScript(Token token) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } else if (body is ExpressionFunctionBody) { | 301 } else if (body is ExpressionFunctionBody) { |
301 bodyStatement = ast.returnStatement(null, body.expression, null); | 302 bodyStatement = ast.returnStatement(null, body.expression, null); |
302 } else { | 303 } else { |
303 bodyStatement = (body as BlockFunctionBody).block; | 304 bodyStatement = (body as BlockFunctionBody).block; |
304 } | 305 } |
305 var kernel = toKernel(bodyStatement, elementStore, library.library, scope); | 306 var kernel = toKernel(bodyStatement, elementStore, library.library, scope); |
306 if (member is ProcedureBuilder) { | 307 if (member is ProcedureBuilder) { |
307 ProcedureBuilder builder = member; | 308 ProcedureBuilder builder = member; |
308 builder.body = kernel; | 309 builder.body = kernel; |
309 } else { | 310 } else { |
310 internalError("Internal error: expected procedure, but got: $member"); | 311 deprecated_internalProblem( |
| 312 "Internal error: expected procedure, but got: $member"); |
311 } | 313 } |
312 } | 314 } |
313 | 315 |
314 void beginCascade(Token token) { | 316 void beginCascade(Token token) { |
315 debugEvent("beginCascade"); | 317 debugEvent("beginCascade"); |
316 Expression expression = pop(); | 318 Expression expression = pop(); |
317 push(token); | 319 push(token); |
318 if (expression is CascadeExpression) { | 320 if (expression is CascadeExpression) { |
319 push(expression); | 321 push(expression); |
320 } else { | 322 } else { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } else { | 366 } else { |
365 push(ast.propertyAccess(receiver, token, identifierOrInvoke)); | 367 push(ast.propertyAccess(receiver, token, identifierOrInvoke)); |
366 } | 368 } |
367 } else if (identifierOrInvoke is MethodInvocation) { | 369 } else if (identifierOrInvoke is MethodInvocation) { |
368 assert(identifierOrInvoke.target == null); | 370 assert(identifierOrInvoke.target == null); |
369 identifierOrInvoke | 371 identifierOrInvoke |
370 ..target = receiver | 372 ..target = receiver |
371 ..operator = token; | 373 ..operator = token; |
372 push(identifierOrInvoke); | 374 push(identifierOrInvoke); |
373 } else { | 375 } else { |
374 internalError( | 376 deprecated_internalProblem( |
375 "Unhandled property access: ${identifierOrInvoke.runtimeType}"); | 377 "Unhandled property access: ${identifierOrInvoke.runtimeType}"); |
376 } | 378 } |
377 } | 379 } |
378 | 380 |
379 void handleLiteralInt(Token token) { | 381 void handleLiteralInt(Token token) { |
380 debugEvent("LiteralInt"); | 382 debugEvent("LiteralInt"); |
381 push(ast.integerLiteral(token, int.parse(token.lexeme))); | 383 push(ast.integerLiteral(token, int.parse(token.lexeme))); |
382 } | 384 } |
383 | 385 |
384 void handleExpressionFunctionBody(Token arrowToken, Token endToken) { | 386 void handleExpressionFunctionBody(Token arrowToken, Token endToken) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 VariableDeclaration variable; | 516 VariableDeclaration variable; |
515 // TODO(paulberry): This seems kludgy. It would be preferable if we | 517 // TODO(paulberry): This seems kludgy. It would be preferable if we |
516 // could respond to a "handleNoVariableInitializer" event by converting a | 518 // could respond to a "handleNoVariableInitializer" event by converting a |
517 // SimpleIdentifier into a VariableDeclaration, and then when this code was | 519 // SimpleIdentifier into a VariableDeclaration, and then when this code was |
518 // reached, node would always be a VariableDeclaration. | 520 // reached, node would always be a VariableDeclaration. |
519 if (node is VariableDeclaration) { | 521 if (node is VariableDeclaration) { |
520 variable = node; | 522 variable = node; |
521 } else if (node is SimpleIdentifier) { | 523 } else if (node is SimpleIdentifier) { |
522 variable = ast.variableDeclaration(node, null, null); | 524 variable = ast.variableDeclaration(node, null, null); |
523 } else { | 525 } else { |
524 internalError("unhandled identifier: ${node.runtimeType}"); | 526 deprecated_internalProblem("unhandled identifier: ${node.runtimeType}"); |
525 } | 527 } |
526 push(variable); | 528 push(variable); |
527 scope.declare( | 529 scope.declare( |
528 variable.name.name, | 530 variable.name.name, |
529 variable.name.staticElement = | 531 variable.name.staticElement = |
530 new AnalyzerLocalVariableElemment(variable), | 532 new AnalyzerLocalVariableElemment(variable), |
531 nameToken.charOffset, | 533 nameToken.charOffset, |
532 uri); | 534 uri); |
533 } | 535 } |
534 | 536 |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 var declarations = <CompilationUnitMember>[]; | 1186 var declarations = <CompilationUnitMember>[]; |
1185 if (elements != null) { | 1187 if (elements != null) { |
1186 for (AstNode node in elements) { | 1188 for (AstNode node in elements) { |
1187 if (node is ScriptTag) { | 1189 if (node is ScriptTag) { |
1188 scriptTag = node; | 1190 scriptTag = node; |
1189 } else if (node is Directive) { | 1191 } else if (node is Directive) { |
1190 directives.add(node); | 1192 directives.add(node); |
1191 } else if (node is CompilationUnitMember) { | 1193 } else if (node is CompilationUnitMember) { |
1192 declarations.add(node); | 1194 declarations.add(node); |
1193 } else { | 1195 } else { |
1194 internalError( | 1196 deprecated_internalProblem( |
1195 'Unrecognized compilation unit member: ${node.runtimeType}'); | 1197 'Unrecognized compilation unit member: ${node.runtimeType}'); |
1196 } | 1198 } |
1197 } | 1199 } |
1198 } | 1200 } |
1199 | 1201 |
1200 push(ast.compilationUnit( | 1202 push(ast.compilationUnit( |
1201 beginToken, scriptTag, directives, declarations, endToken)); | 1203 beginToken, scriptTag, directives, declarations, endToken)); |
1202 } | 1204 } |
1203 | 1205 |
1204 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, | 1206 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 WithClause withClause; | 1348 WithClause withClause; |
1347 var supertype = pop(); | 1349 var supertype = pop(); |
1348 if (supertype == null) { | 1350 if (supertype == null) { |
1349 // No extends clause | 1351 // No extends clause |
1350 } else if (supertype is TypeName) { | 1352 } else if (supertype is TypeName) { |
1351 extendsClause = ast.extendsClause(extendsKeyword, supertype); | 1353 extendsClause = ast.extendsClause(extendsKeyword, supertype); |
1352 } else if (supertype is _MixinApplication) { | 1354 } else if (supertype is _MixinApplication) { |
1353 extendsClause = ast.extendsClause(extendsKeyword, supertype.supertype); | 1355 extendsClause = ast.extendsClause(extendsKeyword, supertype.supertype); |
1354 withClause = ast.withClause(supertype.withKeyword, supertype.mixinTypes); | 1356 withClause = ast.withClause(supertype.withKeyword, supertype.mixinTypes); |
1355 } else { | 1357 } else { |
1356 internalError('Unexpected kind of supertype ${supertype.runtimeType}'); | 1358 deprecated_internalProblem( |
| 1359 'Unexpected kind of supertype ${supertype.runtimeType}'); |
1357 } | 1360 } |
1358 TypeParameterList typeParameters = pop(); | 1361 TypeParameterList typeParameters = pop(); |
1359 SimpleIdentifier name = pop(); | 1362 SimpleIdentifier name = pop(); |
1360 assert(className == name.name); | 1363 assert(className == name.name); |
1361 className = null; | 1364 className = null; |
1362 _Modifiers modifiers = pop(); | 1365 _Modifiers modifiers = pop(); |
1363 Token abstractKeyword = modifiers?.abstractKeyword; | 1366 Token abstractKeyword = modifiers?.abstractKeyword; |
1364 List<Annotation> metadata = pop(); | 1367 List<Annotation> metadata = pop(); |
1365 Comment comment = pop(); | 1368 Comment comment = pop(); |
1366 push(ast.classDeclaration( | 1369 push(ast.classDeclaration( |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 Token separator; | 1512 Token separator; |
1510 ConstructorName redirectedConstructor; | 1513 ConstructorName redirectedConstructor; |
1511 Object bodyObject = pop(); | 1514 Object bodyObject = pop(); |
1512 if (bodyObject is FunctionBody) { | 1515 if (bodyObject is FunctionBody) { |
1513 body = bodyObject; | 1516 body = bodyObject; |
1514 } else if (bodyObject is _RedirectingFactoryBody) { | 1517 } else if (bodyObject is _RedirectingFactoryBody) { |
1515 separator = bodyObject.equalToken; | 1518 separator = bodyObject.equalToken; |
1516 redirectedConstructor = bodyObject.constructorName; | 1519 redirectedConstructor = bodyObject.constructorName; |
1517 body = ast.emptyFunctionBody(semicolon); | 1520 body = ast.emptyFunctionBody(semicolon); |
1518 } else { | 1521 } else { |
1519 internalError('Unexpected body object: ${bodyObject.runtimeType}'); | 1522 deprecated_internalProblem( |
| 1523 'Unexpected body object: ${bodyObject.runtimeType}'); |
1520 } | 1524 } |
1521 | 1525 |
1522 FormalParameterList parameters = pop(); | 1526 FormalParameterList parameters = pop(); |
1523 ConstructorName constructorName = pop(); | 1527 ConstructorName constructorName = pop(); |
1524 _Modifiers modifiers = pop(); | 1528 _Modifiers modifiers = pop(); |
1525 List<Annotation> metadata = pop(); | 1529 List<Annotation> metadata = pop(); |
1526 Comment comment = pop(); | 1530 Comment comment = pop(); |
1527 | 1531 |
1528 // Decompose the preliminary ConstructorName into the type name and | 1532 // Decompose the preliminary ConstructorName into the type name and |
1529 // the actual constructor name. | 1533 // the actual constructor name. |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 void addCompileTimeErrorFromMessage(FastaMessage message) { | 1918 void addCompileTimeErrorFromMessage(FastaMessage message) { |
1915 FastaCode code = message.code; | 1919 FastaCode code = message.code; |
1916 switch (code.analyzerCode) { | 1920 switch (code.analyzerCode) { |
1917 case "EXPECTED_TYPE_NAME": | 1921 case "EXPECTED_TYPE_NAME": |
1918 errorReporter?.reportErrorForOffset( | 1922 errorReporter?.reportErrorForOffset( |
1919 ParserErrorCode.EXPECTED_TYPE_NAME, message.charOffset, 1); | 1923 ParserErrorCode.EXPECTED_TYPE_NAME, message.charOffset, 1); |
1920 return; | 1924 return; |
1921 default: | 1925 default: |
1922 // fall through | 1926 // fall through |
1923 } | 1927 } |
1924 library.addCompileTimeError(message.charOffset, message.message, | 1928 library.deprecated_addCompileTimeError(message.charOffset, message.message, |
1925 fileUri: message.uri); | 1929 fileUri: message.uri); |
1926 } | 1930 } |
1927 } | 1931 } |
1928 | 1932 |
1929 /// Data structure placed on the stack to represent a class body. | 1933 /// Data structure placed on the stack to represent a class body. |
1930 /// | 1934 /// |
1931 /// This is needed because analyzer has no separate AST representation of a | 1935 /// This is needed because analyzer has no separate AST representation of a |
1932 /// class body; it simply stores all of the relevant data in the | 1936 /// class body; it simply stores all of the relevant data in the |
1933 /// [ClassDeclaration] object. | 1937 /// [ClassDeclaration] object. |
1934 class _ClassBody { | 1938 class _ClassBody { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 externalKeyword = token; | 2023 externalKeyword = token; |
2020 } else if (identical('final', s)) { | 2024 } else if (identical('final', s)) { |
2021 finalConstOrVarKeyword = token; | 2025 finalConstOrVarKeyword = token; |
2022 } else if (identical('static', s)) { | 2026 } else if (identical('static', s)) { |
2023 staticKeyword = token; | 2027 staticKeyword = token; |
2024 } else if (identical('var', s)) { | 2028 } else if (identical('var', s)) { |
2025 finalConstOrVarKeyword = token; | 2029 finalConstOrVarKeyword = token; |
2026 } else if (identical('covariant', s)) { | 2030 } else if (identical('covariant', s)) { |
2027 covariantKeyword = token; | 2031 covariantKeyword = token; |
2028 } else { | 2032 } else { |
2029 internalError('Unhandled modifier: $s'); | 2033 deprecated_internalProblem('Unhandled modifier: $s'); |
2030 } | 2034 } |
2031 } | 2035 } |
2032 } | 2036 } |
2033 } | 2037 } |
OLD | NEW |