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' show | 7 import 'package:front_end/src/fasta/scanner/token.dart' |
| 8 BeginGroupToken, | 8 show BeginGroupToken, Token; |
|
ahe
2017/02/17 09:02:02
FYI: I'm really happy to see that dartfmt doesn't
| |
| 9 Token; | |
| 10 | 9 |
| 11 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
| 12 | 11 |
| 13 import 'package:analyzer/dart/ast/token.dart' as analyzer show | 12 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; |
| 14 Token; | |
| 15 | 13 |
| 16 import 'package:analyzer/dart/element/element.dart' show | 14 import 'package:analyzer/dart/element/element.dart' show Element; |
| 17 Element; | |
| 18 | 15 |
| 19 import 'package:analyzer/dart/ast/ast_factory.dart' show | 16 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; |
| 20 AstFactory; | |
| 21 | 17 |
| 22 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; | 18 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; |
| 23 | 19 |
| 24 import '../errors.dart' show | 20 import 'package:kernel/ast.dart' show AsyncMarker; |
| 25 internalError; | |
| 26 | 21 |
| 27 import '../source/scope_listener.dart' show | 22 import '../errors.dart' show internalError; |
| 28 JumpTargetKind, | |
| 29 NullValue, | |
| 30 Scope, | |
| 31 ScopeListener; | |
| 32 | 23 |
| 33 import '../kernel/kernel_builder.dart' show | 24 import '../source/scope_listener.dart' |
| 34 Builder, | 25 show JumpTargetKind, NullValue, Scope, ScopeListener; |
| 35 KernelLibraryBuilder, | 26 |
| 36 ProcedureBuilder; | 27 import '../kernel/kernel_builder.dart' |
| 28 show Builder, KernelLibraryBuilder, ProcedureBuilder; | |
| 37 | 29 |
| 38 import '../quote.dart'; | 30 import '../quote.dart'; |
| 39 | 31 |
| 40 import '../source/outline_builder.dart' show | 32 import '../source/outline_builder.dart' show asyncMarkerFromTokens; |
| 41 asyncMarkerFromTokens; | |
| 42 | 33 |
| 43 import 'element_store.dart' show | 34 import 'element_store.dart' |
| 44 AnalyzerLocalVariableElemment, | 35 show |
| 45 AnalyzerParameterElement, | 36 AnalyzerLocalVariableElemment, |
| 46 ElementStore, | 37 AnalyzerParameterElement, |
| 47 KernelClassElement; | 38 ElementStore, |
| 39 KernelClassElement; | |
| 48 | 40 |
| 49 import 'token_utils.dart' show | 41 import 'token_utils.dart' show toAnalyzerToken; |
| 50 toAnalyzerToken; | |
| 51 | 42 |
| 52 import 'analyzer.dart' show | 43 import 'analyzer.dart' show toKernel; |
| 53 toKernel; | |
| 54 | 44 |
| 55 class AstBuilder extends ScopeListener { | 45 class AstBuilder extends ScopeListener { |
| 56 final AstFactory ast = standard.astFactory; | 46 final AstFactory ast = standard.astFactory; |
| 57 | 47 |
| 58 final KernelLibraryBuilder library; | 48 final KernelLibraryBuilder library; |
| 59 | 49 |
| 60 final Builder member; | 50 final Builder member; |
| 61 | 51 |
| 62 final ElementStore elementStore; | 52 final ElementStore elementStore; |
| 63 | 53 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 93 Token token = pop(); | 83 Token token = pop(); |
| 94 String value = unescapeString(token.value); | 84 String value = unescapeString(token.value); |
| 95 push(ast.simpleStringLiteral(toAnalyzerToken(token), value)); | 85 push(ast.simpleStringLiteral(toAnalyzerToken(token), value)); |
| 96 } else { | 86 } else { |
| 97 List parts = popList(1 + interpolationCount * 2); | 87 List parts = popList(1 + interpolationCount * 2); |
| 98 Token first = parts.first; | 88 Token first = parts.first; |
| 99 Token last = parts.last; | 89 Token last = parts.last; |
| 100 Quote quote = analyzeQuote(first.value); | 90 Quote quote = analyzeQuote(first.value); |
| 101 List<InterpolationElement> elements = <InterpolationElement>[]; | 91 List<InterpolationElement> elements = <InterpolationElement>[]; |
| 102 elements.add(ast.interpolationString( | 92 elements.add(ast.interpolationString( |
| 103 toAnalyzerToken(first), | 93 toAnalyzerToken(first), unescapeFirstStringPart(first.value, quote))); |
| 104 unescapeFirstStringPart(first.value, quote))); | |
| 105 for (int i = 1; i < parts.length - 1; i++) { | 94 for (int i = 1; i < parts.length - 1; i++) { |
| 106 var part = parts[i]; | 95 var part = parts[i]; |
| 107 if (part is Token) { | 96 if (part is Token) { |
| 108 elements.add(ast.interpolationString( | 97 elements |
| 109 toAnalyzerToken(part), part.value)); | 98 .add(ast.interpolationString(toAnalyzerToken(part), part.value)); |
| 110 } else if (part is Expression) { | 99 } else if (part is Expression) { |
| 111 elements.add(ast.interpolationExpression(null, part, null)); | 100 elements.add(ast.interpolationExpression(null, part, null)); |
| 112 } else { | 101 } else { |
| 113 internalError( | 102 internalError( |
| 114 "Unexpected part in string interpolation: ${part.runtimeType}"); | 103 "Unexpected part in string interpolation: ${part.runtimeType}"); |
| 115 } | 104 } |
| 116 } | 105 } |
| 117 elements.add(ast.interpolationString(toAnalyzerToken(last), | 106 elements.add(ast.interpolationString( |
| 118 unescapeLastStringPart(last.value, quote))); | 107 toAnalyzerToken(last), unescapeLastStringPart(last.value, quote))); |
| 119 push(ast.stringInterpolation(elements)); | 108 push(ast.stringInterpolation(elements)); |
| 120 } | 109 } |
| 121 } | 110 } |
| 122 | 111 |
| 123 void handleStringJuxtaposition(int literalCount) { | 112 void handleStringJuxtaposition(int literalCount) { |
| 124 debugEvent("StringJuxtaposition"); | 113 debugEvent("StringJuxtaposition"); |
| 125 push(ast.adjacentStrings(popList(literalCount))); | 114 push(ast.adjacentStrings(popList(literalCount))); |
| 126 } | 115 } |
| 127 | 116 |
| 128 void endArguments(int count, Token beginToken, Token endToken) { | 117 void endArguments(int count, Token beginToken, Token endToken) { |
| 129 debugEvent("Arguments"); | 118 debugEvent("Arguments"); |
| 130 List expressions = popList(count); | 119 List expressions = popList(count); |
| 131 ArgumentList arguments = ast.argumentList(toAnalyzerToken(beginToken), | 120 ArgumentList arguments = ast.argumentList( |
| 132 expressions, toAnalyzerToken(endToken)); | 121 toAnalyzerToken(beginToken), expressions, toAnalyzerToken(endToken)); |
| 133 push(ast.methodInvocation(null, null, null, null, arguments)); | 122 push(ast.methodInvocation(null, null, null, null, arguments)); |
| 134 } | 123 } |
| 135 | 124 |
| 136 void beginExpression(Token token) { | 125 void beginExpression(Token token) { |
| 137 isFirstIdentifier = true; | 126 isFirstIdentifier = true; |
| 138 } | 127 } |
| 139 | 128 |
| 140 void handleIdentifier(Token token) { | 129 void handleIdentifier(Token token) { |
| 141 debugEvent("handleIdentifier"); | 130 debugEvent("handleIdentifier"); |
| 142 String name = token.value; | 131 String name = token.value; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 170 void doInvocation(Token token, MethodInvocation arguments) { | 159 void doInvocation(Token token, MethodInvocation arguments) { |
| 171 Expression receiver = pop(); | 160 Expression receiver = pop(); |
| 172 if (receiver is SimpleIdentifier) { | 161 if (receiver is SimpleIdentifier) { |
| 173 arguments.methodName = receiver; | 162 arguments.methodName = receiver; |
| 174 push(arguments); | 163 push(arguments); |
| 175 } else { | 164 } else { |
| 176 internalError("Unhandled receiver in send: ${receiver.runtimeType}"); | 165 internalError("Unhandled receiver in send: ${receiver.runtimeType}"); |
| 177 } | 166 } |
| 178 } | 167 } |
| 179 | 168 |
| 180 void doPropertyGet(Token token) { | 169 void doPropertyGet(Token token) {} |
| 181 } | |
| 182 | 170 |
| 183 void endExpressionStatement(Token token) { | 171 void endExpressionStatement(Token token) { |
| 184 debugEvent("ExpressionStatement"); | 172 debugEvent("ExpressionStatement"); |
| 185 push(ast.expressionStatement(pop(), toAnalyzerToken(token))); | 173 push(ast.expressionStatement(pop(), toAnalyzerToken(token))); |
| 186 } | 174 } |
| 187 | 175 |
| 188 void endFunctionBody(int count, Token beginToken, Token endToken) { | 176 void endFunctionBody(int count, Token beginToken, Token endToken) { |
| 189 debugEvent("FunctionBody"); | 177 debugEvent("FunctionBody"); |
| 190 List statements = popList(count); | 178 List statements = popList(count); |
| 191 if (beginToken != null) { | 179 if (beginToken != null) { |
| 192 exitLocalScope(); | 180 exitLocalScope(); |
| 193 } | 181 } |
| 194 push(ast.block(toAnalyzerToken(beginToken), statements, | 182 push(ast.block( |
| 195 toAnalyzerToken(endToken))); | 183 toAnalyzerToken(beginToken), statements, toAnalyzerToken(endToken))); |
| 196 } | 184 } |
| 197 | 185 |
| 198 void finishFunction(formals, asyncModifier, Statement body) { | 186 void finishFunction(formals, asyncModifier, Statement body) { |
| 199 debugEvent("finishFunction"); | 187 debugEvent("finishFunction"); |
| 200 var kernel = toKernel(body, elementStore, library.library, scope); | 188 var kernel = toKernel(body, elementStore, library.library, scope); |
| 201 if (member is ProcedureBuilder) { | 189 if (member is ProcedureBuilder) { |
| 202 ProcedureBuilder builder = member; | 190 ProcedureBuilder builder = member; |
| 203 builder.body = kernel; | 191 builder.body = kernel; |
| 204 } else { | 192 } else { |
| 205 internalError("Internal error: expected procedure, but got: $member"); | 193 internalError("Internal error: expected procedure, but got: $member"); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 236 Expression right = pop(); | 224 Expression right = pop(); |
| 237 Expression left = pop(); | 225 Expression left = pop(); |
| 238 push(ast.binaryExpression(left, toAnalyzerToken(token), right)); | 226 push(ast.binaryExpression(left, toAnalyzerToken(token), right)); |
| 239 } | 227 } |
| 240 } | 228 } |
| 241 | 229 |
| 242 void doDotExpression(Token token) { | 230 void doDotExpression(Token token) { |
| 243 Expression identifierOrInvoke = pop(); | 231 Expression identifierOrInvoke = pop(); |
| 244 Expression receiver = pop(); | 232 Expression receiver = pop(); |
| 245 if (identifierOrInvoke is SimpleIdentifier) { | 233 if (identifierOrInvoke is SimpleIdentifier) { |
| 246 push(ast.propertyAccess(receiver, toAnalyzerToken(token), | 234 push(ast.propertyAccess( |
| 247 identifierOrInvoke)); | 235 receiver, toAnalyzerToken(token), identifierOrInvoke)); |
| 248 } else if (identifierOrInvoke is MethodInvocation) { | 236 } else if (identifierOrInvoke is MethodInvocation) { |
| 249 assert(identifierOrInvoke.target == null); | 237 assert(identifierOrInvoke.target == null); |
| 250 identifierOrInvoke | 238 identifierOrInvoke |
| 251 ..target = receiver | 239 ..target = receiver |
| 252 ..operator = toAnalyzerToken(token); | 240 ..operator = toAnalyzerToken(token); |
| 253 push(identifierOrInvoke); | 241 push(identifierOrInvoke); |
| 254 } else { | 242 } else { |
| 255 internalError( | 243 internalError( |
| 256 "Unhandled property access: ${identifierOrInvoke.runtimeType}"); | 244 "Unhandled property access: ${identifierOrInvoke.runtimeType}"); |
| 257 } | 245 } |
| 258 } | 246 } |
| 259 | 247 |
| 260 void handleLiteralInt(Token token) { | 248 void handleLiteralInt(Token token) { |
| 261 debugEvent("LiteralInt"); | 249 debugEvent("LiteralInt"); |
| 262 push(ast.integerLiteral(toAnalyzerToken(token), int.parse(token.value))); | 250 push(ast.integerLiteral(toAnalyzerToken(token), int.parse(token.value))); |
| 263 } | 251 } |
| 264 | 252 |
| 265 void endReturnStatement( | 253 void endReturnStatement( |
| 266 bool hasExpression, Token beginToken, Token endToken) { | 254 bool hasExpression, Token beginToken, Token endToken) { |
| 267 debugEvent("ReturnStatement"); | 255 debugEvent("ReturnStatement"); |
| 268 Expression expression = hasExpression ? pop() : null; | 256 Expression expression = hasExpression ? pop() : null; |
| 269 push(ast.returnStatement(toAnalyzerToken(beginToken), expression, | 257 push(ast.returnStatement( |
| 270 toAnalyzerToken(endToken))); | 258 toAnalyzerToken(beginToken), expression, toAnalyzerToken(endToken))); |
| 271 } | 259 } |
| 272 | 260 |
| 273 void endIfStatement(Token ifToken, Token elseToken) { | 261 void endIfStatement(Token ifToken, Token elseToken) { |
| 274 Statement elsePart = popIfNotNull(elseToken); | 262 Statement elsePart = popIfNotNull(elseToken); |
| 275 Statement thenPart = pop(); | 263 Statement thenPart = pop(); |
| 276 Expression condition = pop(); | 264 Expression condition = pop(); |
| 277 BeginGroupToken leftParenthesis = ifToken.next; | 265 BeginGroupToken leftParenthesis = ifToken.next; |
| 278 push(ast.ifStatement( | 266 push(ast.ifStatement( |
| 279 toAnalyzerToken(ifToken), toAnalyzerToken(ifToken.next), condition, | 267 toAnalyzerToken(ifToken), |
| 280 toAnalyzerToken(leftParenthesis.endGroup), thenPart, | 268 toAnalyzerToken(ifToken.next), |
| 281 toAnalyzerToken(elseToken), elsePart)); | 269 condition, |
| 270 toAnalyzerToken(leftParenthesis.endGroup), | |
| 271 thenPart, | |
| 272 toAnalyzerToken(elseToken), | |
| 273 elsePart)); | |
| 282 } | 274 } |
| 283 | 275 |
| 284 void prepareInitializers() { | 276 void prepareInitializers() { |
| 285 debugEvent("prepareInitializers"); | 277 debugEvent("prepareInitializers"); |
| 286 } | 278 } |
| 287 | 279 |
| 288 void handleNoInitializers() { | 280 void handleNoInitializers() { |
| 289 debugEvent("NoInitializers"); | 281 debugEvent("NoInitializers"); |
| 290 } | 282 } |
| 291 | 283 |
| 292 void endInitializers(int count, Token beginToken, Token endToken) { | 284 void endInitializers(int count, Token beginToken, Token endToken) { |
| 293 debugEvent("Initializers"); | 285 debugEvent("Initializers"); |
| 294 popList(count); | 286 popList(count); |
| 295 } | 287 } |
| 296 | 288 |
| 297 void endVariableInitializer(Token assignmentOperator) { | 289 void endVariableInitializer(Token assignmentOperator) { |
| 298 debugEvent("VariableInitializer"); | 290 debugEvent("VariableInitializer"); |
| 299 assert(assignmentOperator.stringValue == "="); | 291 assert(assignmentOperator.stringValue == "="); |
| 300 Expression initializer = pop(); | 292 Expression initializer = pop(); |
| 301 Identifier identifier = pop(); | 293 Identifier identifier = pop(); |
| 302 // TODO(ahe): Don't push initializers, instead install them. | 294 // TODO(ahe): Don't push initializers, instead install them. |
| 303 push(ast.variableDeclaration( | 295 push(ast.variableDeclaration( |
| 304 identifier, toAnalyzerToken(assignmentOperator), initializer)); | 296 identifier, toAnalyzerToken(assignmentOperator), initializer)); |
| 305 } | 297 } |
| 306 | 298 |
| 307 void endInitializedIdentifier() { | 299 void endInitializedIdentifier() { |
| 308 debugEvent("InitializedIdentifier"); | 300 debugEvent("InitializedIdentifier"); |
| 309 AstNode node = pop(); | 301 AstNode node = pop(); |
| 310 VariableDeclaration variable; | 302 VariableDeclaration variable; |
| 311 if (node is VariableDeclaration) { | 303 if (node is VariableDeclaration) { |
| 312 variable = node; | 304 variable = node; |
| 313 } else if (node is SimpleIdentifier) { | 305 } else if (node is SimpleIdentifier) { |
| 314 variable = ast.variableDeclaration(node, null, null); | 306 variable = ast.variableDeclaration(node, null, null); |
| 315 } else { | 307 } else { |
| 316 internalError("unhandled identifier: ${node.runtimeType}"); | 308 internalError("unhandled identifier: ${node.runtimeType}"); |
| 317 } | 309 } |
| 318 push(variable); | 310 push(variable); |
| 319 scope[variable.name.name] = variable.name.staticElement = | 311 scope[variable.name.name] = variable.name.staticElement = |
| 320 new AnalyzerLocalVariableElemment(variable); | 312 new AnalyzerLocalVariableElemment(variable); |
| 321 } | 313 } |
| 322 | 314 |
| 323 void endVariablesDeclaration(int count, Token endToken) { | 315 void endVariablesDeclaration(int count, Token endToken) { |
| 324 debugEvent("VariablesDeclaration"); | 316 debugEvent("VariablesDeclaration"); |
| 325 List<VariableDeclaration> variables = popList(count); | 317 List<VariableDeclaration> variables = popList(count); |
| 326 TypeName type = pop(); | 318 TypeName type = pop(); |
| 327 pop(); // Modifiers. | 319 pop(); // Modifiers. |
| 328 push(ast.variableDeclarationStatement( | 320 push(ast.variableDeclarationStatement( |
| 329 ast.variableDeclarationList(null, null, null, type, variables), | 321 ast.variableDeclarationList(null, null, null, type, variables), |
| 330 toAnalyzerToken(endToken))); | 322 toAnalyzerToken(endToken))); |
| 331 } | 323 } |
| 332 | 324 |
| 333 void handleAssignmentExpression(Token token) { | 325 void handleAssignmentExpression(Token token) { |
| 334 debugEvent("AssignmentExpression"); | 326 debugEvent("AssignmentExpression"); |
| 335 Expression rhs = pop(); | 327 Expression rhs = pop(); |
| 336 Expression lhs = pop(); | 328 Expression lhs = pop(); |
| 337 push(ast.assignmentExpression(lhs, toAnalyzerToken(token), rhs)); | 329 push(ast.assignmentExpression(lhs, toAnalyzerToken(token), rhs)); |
| 338 } | 330 } |
| 339 | 331 |
| 340 void endBlock(int count, Token beginToken, Token endToken) { | 332 void endBlock(int count, Token beginToken, Token endToken) { |
| 341 debugEvent("Block"); | 333 debugEvent("Block"); |
| 342 List<Statement> statements = popList(count) ?? <Statement>[]; | 334 List<Statement> statements = popList(count) ?? <Statement>[]; |
| 343 exitLocalScope(); | 335 exitLocalScope(); |
| 344 push(ast.block(toAnalyzerToken(beginToken), statements, | 336 push(ast.block( |
| 345 toAnalyzerToken(endToken))); | 337 toAnalyzerToken(beginToken), statements, toAnalyzerToken(endToken))); |
| 346 } | 338 } |
| 347 | 339 |
| 348 void endForStatement( | 340 void endForStatement( |
| 349 int updateExpressionCount, Token beginToken, Token endToken) { | 341 int updateExpressionCount, Token beginToken, Token endToken) { |
| 350 debugEvent("ForStatement"); | 342 debugEvent("ForStatement"); |
| 351 Statement body = pop(); | 343 Statement body = pop(); |
| 352 List<Expression> updates = popList(updateExpressionCount); | 344 List<Expression> updates = popList(updateExpressionCount); |
| 353 ExpressionStatement condition = pop(); | 345 ExpressionStatement condition = pop(); |
| 354 VariableDeclarationStatement variables = pop(); | 346 VariableDeclarationStatement variables = pop(); |
| 355 exitContinueTarget(); | 347 exitContinueTarget(); |
| 356 exitBreakTarget(); | 348 exitBreakTarget(); |
| 357 exitLocalScope(); | 349 exitLocalScope(); |
| 358 BeginGroupToken leftParenthesis = beginToken.next; | 350 BeginGroupToken leftParenthesis = beginToken.next; |
| 359 push(ast.forStatement( | 351 push(ast.forStatement( |
| 360 toAnalyzerToken(beginToken), | 352 toAnalyzerToken(beginToken), |
| 361 toAnalyzerToken(leftParenthesis), | 353 toAnalyzerToken(leftParenthesis), |
| 362 variables?.variables, | 354 variables?.variables, |
| 363 null, // initialization. | 355 null, // initialization. |
| 364 variables?.semicolon, | 356 variables?.semicolon, |
| 365 condition.expression, | 357 condition.expression, |
| 366 condition.semicolon, | 358 condition.semicolon, |
| 367 updates, | 359 updates, |
| 368 toAnalyzerToken(leftParenthesis.endGroup), | 360 toAnalyzerToken(leftParenthesis.endGroup), |
| 369 body)); | 361 body)); |
| 370 } | 362 } |
| 371 | 363 |
| 372 void handleLiteralList( | 364 void handleLiteralList( |
| 373 int count, Token beginToken, Token constKeyword, Token endToken) { | 365 int count, Token beginToken, Token constKeyword, Token endToken) { |
| 374 debugEvent("LiteralList"); | 366 debugEvent("LiteralList"); |
| 375 List<Expression> expressions = popList(count); | 367 List<Expression> expressions = popList(count); |
| 376 TypeArgumentList typeArguments = pop(); | 368 TypeArgumentList typeArguments = pop(); |
| 377 push(ast.listLiteral( | 369 push(ast.listLiteral(toAnalyzerToken(constKeyword), typeArguments, |
| 378 toAnalyzerToken(constKeyword), | 370 toAnalyzerToken(beginToken), expressions, toAnalyzerToken(endToken))); |
| 379 typeArguments, | |
| 380 toAnalyzerToken(beginToken), | |
| 381 expressions, | |
| 382 toAnalyzerToken(endToken))); | |
| 383 } | 371 } |
| 384 | 372 |
| 385 void handleAsyncModifier(Token asyncToken, Token starToken) { | 373 void handleAsyncModifier(Token asyncToken, Token starToken) { |
| 386 debugEvent("AsyncModifier"); | 374 debugEvent("AsyncModifier"); |
| 387 push(asyncMarkerFromTokens(asyncToken, starToken)); | 375 push(asyncMarkerFromTokens(asyncToken, starToken)); |
| 388 } | 376 } |
| 389 | 377 |
| 390 void endAwaitExpression(Token beginToken, Token endToken) { | 378 void endAwaitExpression(Token beginToken, Token endToken) { |
| 391 debugEvent("AwaitExpression"); | 379 debugEvent("AwaitExpression"); |
| 392 push(ast.awaitExpression(toAnalyzerToken(beginToken), pop())); | 380 push(ast.awaitExpression(toAnalyzerToken(beginToken), pop())); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 412 debugEvent("LiteralNull"); | 400 debugEvent("LiteralNull"); |
| 413 push(ast.nullLiteral(toAnalyzerToken(token))); | 401 push(ast.nullLiteral(toAnalyzerToken(token))); |
| 414 } | 402 } |
| 415 | 403 |
| 416 void handleLiteralMap( | 404 void handleLiteralMap( |
| 417 int count, Token beginToken, Token constKeyword, Token endToken) { | 405 int count, Token beginToken, Token constKeyword, Token endToken) { |
| 418 debugEvent("LiteralMap"); | 406 debugEvent("LiteralMap"); |
| 419 List<MapLiteralEntry> entries = popList(count) ?? <MapLiteralEntry>[]; | 407 List<MapLiteralEntry> entries = popList(count) ?? <MapLiteralEntry>[]; |
| 420 TypeArgumentList typeArguments = pop(); | 408 TypeArgumentList typeArguments = pop(); |
| 421 push(ast.mapLiteral(toAnalyzerToken(constKeyword), typeArguments, | 409 push(ast.mapLiteral(toAnalyzerToken(constKeyword), typeArguments, |
| 422 toAnalyzerToken(beginToken), entries, toAnalyzerToken(endToken))); | 410 toAnalyzerToken(beginToken), entries, toAnalyzerToken(endToken))); |
| 423 } | 411 } |
| 424 | 412 |
| 425 void endLiteralMapEntry(Token colon, Token endToken) { | 413 void endLiteralMapEntry(Token colon, Token endToken) { |
| 426 debugEvent("LiteralMapEntry"); | 414 debugEvent("LiteralMapEntry"); |
| 427 Expression value = pop(); | 415 Expression value = pop(); |
| 428 Expression key = pop(); | 416 Expression key = pop(); |
| 429 push(ast.mapLiteralEntry(key, toAnalyzerToken(colon), value)); | 417 push(ast.mapLiteralEntry(key, toAnalyzerToken(colon), value)); |
| 430 } | 418 } |
| 431 | 419 |
| 432 void endLiteralSymbol(Token hashToken, int identifierCount) { | 420 void endLiteralSymbol(Token hashToken, int identifierCount) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 462 debugEvent("AsOperator"); | 450 debugEvent("AsOperator"); |
| 463 TypeName type = pop(); | 451 TypeName type = pop(); |
| 464 Expression expression = pop(); | 452 Expression expression = pop(); |
| 465 push(ast.asExpression(expression, toAnalyzerToken(operator), type)); | 453 push(ast.asExpression(expression, toAnalyzerToken(operator), type)); |
| 466 } | 454 } |
| 467 | 455 |
| 468 void handleIsOperator(Token operator, Token not, Token endToken) { | 456 void handleIsOperator(Token operator, Token not, Token endToken) { |
| 469 debugEvent("IsOperator"); | 457 debugEvent("IsOperator"); |
| 470 TypeName type = pop(); | 458 TypeName type = pop(); |
| 471 Expression expression = pop(); | 459 Expression expression = pop(); |
| 472 push(ast.isExpression(expression, toAnalyzerToken(operator), | 460 push(ast.isExpression( |
| 473 toAnalyzerToken(not), type)); | 461 expression, toAnalyzerToken(operator), toAnalyzerToken(not), type)); |
| 474 } | 462 } |
| 475 | 463 |
| 476 void handleConditionalExpression(Token question, Token colon) { | 464 void handleConditionalExpression(Token question, Token colon) { |
| 477 debugEvent("ConditionalExpression"); | 465 debugEvent("ConditionalExpression"); |
| 478 Expression elseExpression = pop(); | 466 Expression elseExpression = pop(); |
| 479 Expression thenExpression = pop(); | 467 Expression thenExpression = pop(); |
| 480 Expression condition = pop(); | 468 Expression condition = pop(); |
| 481 push(ast.conditionalExpression(condition, toAnalyzerToken(question), | 469 push(ast.conditionalExpression(condition, toAnalyzerToken(question), |
| 482 thenExpression, toAnalyzerToken(colon), elseExpression)); | 470 thenExpression, toAnalyzerToken(colon), elseExpression)); |
| 483 } | 471 } |
| 484 | 472 |
| 485 void endThrowExpression(Token throwToken, Token endToken) { | 473 void endThrowExpression(Token throwToken, Token endToken) { |
| 486 debugEvent("ThrowExpression"); | 474 debugEvent("ThrowExpression"); |
| 487 push(ast.throwExpression(toAnalyzerToken(throwToken), pop())); | 475 push(ast.throwExpression(toAnalyzerToken(throwToken), pop())); |
| 488 } | 476 } |
| 489 | 477 |
| 490 void endFormalParameter(Token thisKeyword) { | 478 void endFormalParameter(Token thisKeyword) { |
| 491 debugEvent("FormalParameter"); | 479 debugEvent("FormalParameter"); |
| 492 if (thisKeyword != null) { | 480 if (thisKeyword != null) { |
| 493 internalError("'this' can't be used here."); | 481 internalError("'this' can't be used here."); |
| 494 } | 482 } |
| 495 SimpleIdentifier name = pop(); | 483 SimpleIdentifier name = pop(); |
| 496 TypeName type = pop(); | 484 TypeName type = pop(); |
| 497 pop(); // Modifiers. | 485 pop(); // Modifiers. |
| 498 pop(); // Metadata. | 486 pop(); // Metadata. |
| 499 SimpleFormalParameter node = ast.simpleFormalParameter(null, null, | 487 SimpleFormalParameter node = ast.simpleFormalParameter( |
| 500 toAnalyzerToken(thisKeyword), type, name); | 488 null, null, toAnalyzerToken(thisKeyword), type, name); |
| 501 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); | 489 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); |
| 502 push(node); | 490 push(node); |
| 503 } | 491 } |
| 504 | 492 |
| 505 void endFormalParameters(int count, Token beginToken, Token endToken) { | 493 void endFormalParameters(int count, Token beginToken, Token endToken) { |
| 506 debugEvent("FormalParameters"); | 494 debugEvent("FormalParameters"); |
| 507 List<FormalParameter> parameters = popList(count) ?? <FormalParameter>[]; | 495 List<FormalParameter> parameters = popList(count) ?? <FormalParameter>[]; |
| 508 push(ast.formalParameterList(toAnalyzerToken(beginToken), parameters, | 496 push(ast.formalParameterList(toAnalyzerToken(beginToken), parameters, null, |
| 509 null, null, toAnalyzerToken(endToken))); | 497 null, toAnalyzerToken(endToken))); |
| 510 } | 498 } |
| 511 | 499 |
| 512 void handleCatchBlock(Token onKeyword, Token catchKeyword) { | 500 void handleCatchBlock(Token onKeyword, Token catchKeyword) { |
| 513 debugEvent("CatchBlock"); | 501 debugEvent("CatchBlock"); |
| 514 Block body = pop(); | 502 Block body = pop(); |
| 515 FormalParameterList catchParameters = popIfNotNull(catchKeyword); | 503 FormalParameterList catchParameters = popIfNotNull(catchKeyword); |
| 516 if (catchKeyword != null) { | 504 if (catchKeyword != null) { |
| 517 exitLocalScope(); | 505 exitLocalScope(); |
| 518 } | 506 } |
| 519 TypeName type = popIfNotNull(onKeyword); | 507 TypeName type = popIfNotNull(onKeyword); |
| 520 SimpleIdentifier exception; | 508 SimpleIdentifier exception; |
| 521 SimpleIdentifier stackTrace; | 509 SimpleIdentifier stackTrace; |
| 522 if (catchParameters != null) { | 510 if (catchParameters != null) { |
| 523 if (catchParameters.length > 0) { | 511 if (catchParameters.length > 0) { |
| 524 exception = catchParameters.parameters[0].identifier; | 512 exception = catchParameters.parameters[0].identifier; |
| 525 } | 513 } |
| 526 if (catchParameters.length > 1) { | 514 if (catchParameters.length > 1) { |
| 527 stackTrace = catchParameters.parameters[1].identifier; | 515 stackTrace = catchParameters.parameters[1].identifier; |
| 528 } | 516 } |
| 529 } | 517 } |
| 530 BeginGroupToken leftParenthesis = catchKeyword.next; | 518 BeginGroupToken leftParenthesis = catchKeyword.next; |
| 531 push(ast.catchClause(toAnalyzerToken(onKeyword), type, | 519 push(ast.catchClause( |
| 532 toAnalyzerToken(catchKeyword), toAnalyzerToken(leftParenthesis), | 520 toAnalyzerToken(onKeyword), |
| 533 exception, null, stackTrace, | 521 type, |
| 534 toAnalyzerToken(leftParenthesis.endGroup), body)); | 522 toAnalyzerToken(catchKeyword), |
| 523 toAnalyzerToken(leftParenthesis), | |
| 524 exception, | |
| 525 null, | |
| 526 stackTrace, | |
| 527 toAnalyzerToken(leftParenthesis.endGroup), | |
| 528 body)); | |
| 535 } | 529 } |
| 536 | 530 |
| 537 void endTryStatement( | 531 void endTryStatement(int catchCount, Token tryKeyword, Token finallyKeyword) { |
| 538 int catchCount, Token tryKeyword, Token finallyKeyword) { | |
| 539 Block finallyBlock = popIfNotNull(finallyKeyword); | 532 Block finallyBlock = popIfNotNull(finallyKeyword); |
| 540 List<CatchClause> catchClauses = popList(catchCount); | 533 List<CatchClause> catchClauses = popList(catchCount); |
| 541 Block body = pop(); | 534 Block body = pop(); |
| 542 push(ast.tryStatement(toAnalyzerToken(tryKeyword), body, catchClauses, | 535 push(ast.tryStatement(toAnalyzerToken(tryKeyword), body, catchClauses, |
| 543 toAnalyzerToken(finallyKeyword), finallyBlock)); | 536 toAnalyzerToken(finallyKeyword), finallyBlock)); |
| 544 } | 537 } |
| 545 | 538 |
| 546 void handleNoExpression(Token token) { | 539 void handleNoExpression(Token token) { |
| 547 debugEvent("NoExpression"); | 540 debugEvent("NoExpression"); |
| 548 push(NullValue.Expression); | 541 push(NullValue.Expression); |
| 549 } | 542 } |
| 550 | 543 |
| 551 void handleIndexedExpression( | 544 void handleIndexedExpression( |
| 552 Token openCurlyBracket, Token closeCurlyBracket) { | 545 Token openCurlyBracket, Token closeCurlyBracket) { |
| 553 debugEvent("IndexedExpression"); | 546 debugEvent("IndexedExpression"); |
| 554 Expression index = pop(); | 547 Expression index = pop(); |
| 555 Expression target = pop(); | 548 Expression target = pop(); |
| 556 if (target == null) { | 549 if (target == null) { |
| 557 CascadeExpression receiver = pop(); | 550 CascadeExpression receiver = pop(); |
| 558 Token token = peek(); | 551 Token token = peek(); |
| 559 push(receiver); | 552 push(receiver); |
| 560 IndexExpression expression = ast.indexExpressionForCascade( | 553 IndexExpression expression = ast.indexExpressionForCascade( |
| 561 toAnalyzerToken(token), toAnalyzerToken(openCurlyBracket), index, | 554 toAnalyzerToken(token), |
| 555 toAnalyzerToken(openCurlyBracket), | |
| 556 index, | |
| 562 toAnalyzerToken(closeCurlyBracket)); | 557 toAnalyzerToken(closeCurlyBracket)); |
| 563 assert(expression.isCascaded); | 558 assert(expression.isCascaded); |
| 564 push(expression); | 559 push(expression); |
| 565 } else { | 560 } else { |
| 566 push(ast.indexExpressionForTarget(target, | 561 push(ast.indexExpressionForTarget( |
| 567 toAnalyzerToken(openCurlyBracket), index, | 562 target, |
| 568 toAnalyzerToken(closeCurlyBracket))); | 563 toAnalyzerToken(openCurlyBracket), |
| 564 index, | |
| 565 toAnalyzerToken(closeCurlyBracket))); | |
| 569 } | 566 } |
| 570 } | 567 } |
| 571 | 568 |
| 572 void handleUnaryPrefixExpression(Token token) { | 569 void handleUnaryPrefixExpression(Token token) { |
| 573 debugEvent("UnaryPrefixExpression"); | 570 debugEvent("UnaryPrefixExpression"); |
| 574 push(ast.prefixExpression(toAnalyzerToken(token), pop())); | 571 push(ast.prefixExpression(toAnalyzerToken(token), pop())); |
| 575 } | 572 } |
| 576 | 573 |
| 577 void handleUnaryPrefixAssignmentExpression(Token token) { | 574 void handleUnaryPrefixAssignmentExpression(Token token) { |
| 578 debugEvent("UnaryPrefixAssignmentExpression"); | 575 debugEvent("UnaryPrefixAssignmentExpression"); |
| 579 push(ast.prefixExpression(toAnalyzerToken(token), pop())); | 576 push(ast.prefixExpression(toAnalyzerToken(token), pop())); |
| 580 } | 577 } |
| 581 | 578 |
| 582 void handleUnaryPostfixAssignmentExpression(Token token) { | 579 void handleUnaryPostfixAssignmentExpression(Token token) { |
| 583 debugEvent("UnaryPostfixAssignmentExpression"); | 580 debugEvent("UnaryPostfixAssignmentExpression"); |
| 584 push(ast.postfixExpression(pop(), toAnalyzerToken(token))); | 581 push(ast.postfixExpression(pop(), toAnalyzerToken(token))); |
| 585 } | 582 } |
| 586 | 583 |
| 587 void handleModifier(Token token) { | 584 void handleModifier(Token token) { |
| 588 debugEvent("Modifier"); | 585 debugEvent("Modifier"); |
| 589 // TODO(ahe): Don't ignore modifiers. | 586 // TODO(ahe): Don't ignore modifiers. |
| 590 } | 587 } |
| 591 | 588 |
| 592 void handleModifiers(int count) { | 589 void handleModifiers(int count) { |
| 593 debugEvent("Modifiers"); | 590 debugEvent("Modifiers"); |
| 594 // TODO(ahe): Don't ignore modifiers. | 591 // TODO(ahe): Don't ignore modifiers. |
| 595 push(NullValue.Modifiers); | 592 push(NullValue.Modifiers); |
| 596 } | 593 } |
| 594 | |
| 595 FunctionBody _endFunctionBody() { | |
| 596 AstNode body = pop(); | |
| 597 // TODO(paulberry): asyncMarker should have a type that allows constructing | |
| 598 // the necessary analyzer AST data structures. | |
|
ahe
2017/02/17 09:02:02
What's missing? Position information?
Paul Berry
2017/02/17 16:14:26
Yes. The analyzer ASTs expect to be able to point
ahe
2017/02/17 18:05:50
OK. handleAsyncModifier should probably just creat
| |
| 599 AsyncMarker asyncMarker = pop(); | |
| 600 assert(asyncMarker == AsyncMarker.Sync); | |
| 601 analyzer.Token asyncKeyword = null; | |
| 602 analyzer.Token star = null; | |
| 603 if (body is Block) { | |
| 604 return ast.blockFunctionBody(asyncKeyword, star, body); | |
| 605 } else if (body is ReturnStatement) { | |
| 606 assert(star == null); | |
| 607 return ast.expressionFunctionBody( | |
| 608 asyncKeyword, body.returnKeyword, body.expression, body.semicolon); | |
| 609 } else { | |
| 610 return internalError( | |
| 611 'Unexpected function body type: ${body.runtimeType}'); | |
| 612 } | |
| 613 } | |
| 614 | |
| 615 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | |
| 616 debugEvent("TopLevelMethod"); | |
| 617 FunctionBody body = _endFunctionBody(); | |
| 618 FormalParameterList parameters = pop(); | |
| 619 TypeParameterList typeParameters = pop(); | |
| 620 SimpleIdentifier name = pop(); | |
| 621 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); | |
| 622 TypeAnnotation returnType = pop(); | |
| 623 // TODO(paulberry): handle modifiers. | |
| 624 var modifiers = pop(); | |
| 625 assert(modifiers == null); | |
| 626 analyzer.Token externalKeyword = null; | |
| 627 List<Annotation> metadata = pop(); | |
| 628 // TODO(paulberry): capture doc comments. | |
| 629 Comment comment = null; | |
| 630 push(ast.functionDeclaration( | |
| 631 comment, | |
| 632 metadata, | |
| 633 externalKeyword, | |
| 634 returnType, | |
| 635 propertyKeyword, | |
| 636 name, | |
| 637 ast.functionExpression(typeParameters, parameters, body))); | |
| 638 } | |
| 639 | |
| 640 @override | |
| 641 void endTopLevelDeclaration(Token token) { | |
| 642 debugEvent("TopLevelDeclaration"); | |
| 643 } | |
| 644 | |
| 645 @override | |
| 646 void endCompilationUnit(int count, Token token) { | |
| 647 debugEvent("CompilationUnit"); | |
| 648 analyzer.Token beginToken = null; // TODO(paulberry) | |
|
ahe
2017/02/17 09:02:02
Here's a suggestion for when you get to this:
@ov
Paul Berry
2017/02/17 16:14:26
Thanks!
| |
| 649 ScriptTag scriptTag = null; // TODO(paulberry) | |
|
ahe
2017/02/17 09:02:02
What are script tags?
Paul Berry
2017/02/17 16:14:26
"script tag" is the Dart spec's name for the initi
ahe
2017/02/17 18:05:50
Ah. Shebang :-)
Assuming this is just the first l
| |
| 650 var directives = <Directive>[]; | |
| 651 var declarations = <CompilationUnitMember>[]; | |
| 652 analyzer.Token endToken = null; // TODO(paulberry) | |
| 653 for (AstNode node in popList(count)) { | |
| 654 if (node is Directive) { | |
| 655 directives.add(node); | |
| 656 } else if (node is CompilationUnitMember) { | |
| 657 declarations.add(node); | |
| 658 } else { | |
| 659 internalError( | |
| 660 'Unrecognized compilation unit member: ${node.runtimeType}'); | |
| 661 } | |
| 662 } | |
| 663 push(ast.compilationUnit( | |
| 664 beginToken, scriptTag, directives, declarations, endToken)); | |
| 665 } | |
| 597 } | 666 } |
| OLD | NEW |