OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer2dart.cps_generator; | 5 library analyzer2dart.cps_generator; |
6 | 6 |
7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
8 | 8 |
9 import 'package:compiler/implementation/dart_types.dart' as dart2js; | 9 import 'package:compiler/implementation/dart_types.dart' as dart2js; |
10 import 'package:compiler/implementation/elements/elements.dart' as dart2js; | 10 import 'package:compiler/implementation/elements/elements.dart' as dart2js; |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> | 25 class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
26 with IrBuilderMixin<AstNode> { | 26 with IrBuilderMixin<AstNode> { |
27 final analyzer.Element element; | 27 final analyzer.Element element; |
28 final ElementConverter converter; | 28 final ElementConverter converter; |
29 | 29 |
30 CpsGeneratingVisitor(this.converter, this.element); | 30 CpsGeneratingVisitor(this.converter, this.element); |
31 | 31 |
32 Source get currentSource => element.source; | 32 Source get currentSource => element.source; |
33 | 33 |
| 34 analyzer.LibraryElement get currentLibrary => element.library; |
| 35 |
34 ir.Node visit(AstNode node) => node.accept(this); | 36 ir.Node visit(AstNode node) => node.accept(this); |
35 | 37 |
36 @override | 38 @override |
37 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { | 39 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { |
38 analyzer.FunctionElement function = node.element; | 40 analyzer.FunctionElement function = node.element; |
39 dart2js.FunctionElement element = converter.convertElement(function); | 41 dart2js.FunctionElement element = converter.convertElement(function); |
40 return withBuilder( | 42 return withBuilder( |
41 new IrBuilder(DART_CONSTANT_SYSTEM, | 43 new IrBuilder(DART_CONSTANT_SYSTEM, |
42 element, | 44 element, |
43 // TODO(johnniwinther): Supported closure variables. | 45 // TODO(johnniwinther): Supported closure variables. |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 buildBody: subbuild(node.body), | 338 buildBody: subbuild(node.body), |
337 buildUpdate: subbuildSequence(node.updaters)); | 339 buildUpdate: subbuildSequence(node.updaters)); |
338 } | 340 } |
339 | 341 |
340 @override | 342 @override |
341 visitWhileStatement(WhileStatement node) { | 343 visitWhileStatement(WhileStatement node) { |
342 // TODO(johnniwinther): Support `while` as a jump target. | 344 // TODO(johnniwinther): Support `while` as a jump target. |
343 irBuilder.buildWhile(buildCondition: subbuild(node.condition), | 345 irBuilder.buildWhile(buildCondition: subbuild(node.condition), |
344 buildBody: subbuild(node.body)); | 346 buildBody: subbuild(node.body)); |
345 } | 347 } |
| 348 |
| 349 @override |
| 350 visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 351 giveUp(node, "Unexpected node: DeclaredIdentifier"); |
| 352 } |
| 353 |
| 354 @override |
| 355 visitForEachStatement(ForEachStatement node) { |
| 356 SubbuildFunction buildVariableDeclaration; |
| 357 dart2js.Element variableElement; |
| 358 Selector variableSelector; |
| 359 if (node.identifier != null) { |
| 360 AccessSemantics accessSemantics = |
| 361 node.identifier.accept(ACCESS_SEMANTICS_VISITOR); |
| 362 if (accessSemantics.kind == AccessKind.DYNAMIC) { |
| 363 variableSelector = new Selector.setter( |
| 364 node.identifier.name, converter.convertElement(currentLibrary)); |
| 365 } else if (accessSemantics.element != null) { |
| 366 variableElement = converter.convertElement(accessSemantics.element); |
| 367 variableSelector = new Selector.setter( |
| 368 variableElement.name, |
| 369 converter.convertElement(accessSemantics.element.library)); |
| 370 } else { |
| 371 giveUp(node, 'For-in of unresolved variable: $accessSemantics'); |
| 372 } |
| 373 } else { |
| 374 assert(invariant( |
| 375 node, node.loopVariable != null, "Loop variable expected")); |
| 376 variableElement = converter.convertElement(node.loopVariable.element); |
| 377 buildVariableDeclaration = (IrBuilder builder) { |
| 378 builder.declareLocalVariable(variableElement); |
| 379 }; |
| 380 } |
| 381 // TODO(johnniwinther): Support `for-in` as a jump target. |
| 382 irBuilder.buildForIn( |
| 383 buildExpression: subbuild(node.iterable), |
| 384 buildVariableDeclaration: buildVariableDeclaration, |
| 385 variableElement: variableElement, |
| 386 variableSelector: variableSelector, |
| 387 buildBody: subbuild(node.body)); |
| 388 } |
346 } | 389 } |
OLD | NEW |