Chromium Code Reviews| 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.getter( | |
| 364 node.identifier.name, converter.convertElement(currentLibrary)); | |
|
Paul Berry
2014/11/03 15:05:56
I'm confused. The only situation in which accessS
Johnni Winther
2014/11/04 12:58:53
The selector should have been a setter. Nice catch
| |
| 365 } else { | |
| 366 variableElement = converter.convertElement(accessSemantics.element); | |
|
Paul Berry
2014/11/03 15:05:56
This seems like it will break if the variable in t
Johnni Winther
2014/11/04 12:58:53
Yes. We seem to be missing a statically unresolved
| |
| 367 } | |
| 368 } else { | |
| 369 assert(invariant( | |
| 370 node, node.loopVariable != null, "Loop variable expected")); | |
| 371 variableElement = converter.convertElement(node.loopVariable.element); | |
| 372 buildVariableDeclaration = (IrBuilder builder) { | |
| 373 builder.declareLocalVariable(variableElement); | |
| 374 }; | |
| 375 } | |
| 376 // TODO(johnniwinther): Support `for-in` as a jump target. | |
| 377 irBuilder.buildForIn( | |
| 378 buildExpression: subbuild(node.iterable), | |
| 379 buildVariableDeclaration: buildVariableDeclaration, | |
| 380 variableElement: variableElement, | |
| 381 variableSelector: variableSelector, | |
| 382 buildBody: subbuild(node.body)); | |
| 383 } | |
| 346 } | 384 } |
| OLD | NEW |