| 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/elements/elements.dart' as dart2js; | 9 import 'package:compiler/implementation/elements/elements.dart' as dart2js; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 analyzer.FunctionElement function = node.element; | 33 analyzer.FunctionElement function = node.element; |
| 34 function.parameters.forEach((analyzer.ParameterElement parameter) { | 34 function.parameters.forEach((analyzer.ParameterElement parameter) { |
| 35 // TODO(johnniwinther): Support "closure variables", that is variables | 35 // TODO(johnniwinther): Support "closure variables", that is variables |
| 36 // accessed from an inner function. | 36 // accessed from an inner function. |
| 37 irBuilder.createParameter(converter.convertElement(parameter), | 37 irBuilder.createParameter(converter.convertElement(parameter), |
| 38 isClosureVariable: false); | 38 isClosureVariable: false); |
| 39 }); | 39 }); |
| 40 // Visit the body directly to avoid processing the signature as expressions. | 40 // Visit the body directly to avoid processing the signature as expressions. |
| 41 node.functionExpression.body.accept(this); | 41 node.functionExpression.body.accept(this); |
| 42 return irBuilder.buildFunctionDefinition( | 42 return irBuilder.buildFunctionDefinition( |
| 43 converter.convertElement(function), const [], const []); | 43 converter.convertElement(function), const []); |
| 44 } | 44 } |
| 45 | 45 |
| 46 @override | 46 @override |
| 47 visitStaticMethodInvocation(MethodInvocation node, | 47 visitStaticMethodInvocation(MethodInvocation node, |
| 48 AccessSemantics semantics) { | 48 AccessSemantics semantics) { |
| 49 analyzer.Element staticElement = semantics.element; | 49 analyzer.Element staticElement = semantics.element; |
| 50 dart2js.Element element = converter.convertElement(staticElement); | 50 dart2js.Element element = converter.convertElement(staticElement); |
| 51 List<ir.Definition> arguments = <ir.Definition>[]; | 51 List<ir.Definition> arguments = <ir.Definition>[]; |
| 52 for (Expression argument in node.argumentList.arguments) { | 52 for (Expression argument in node.argumentList.arguments) { |
| 53 ir.Definition value = argument.accept(this); | 53 ir.Definition value = argument.accept(this); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 @override | 114 @override |
| 115 ir.Node visitLocalVariableAccess(AstNode node, AccessSemantics semantics) { | 115 ir.Node visitLocalVariableAccess(AstNode node, AccessSemantics semantics) { |
| 116 return handleLocalAccess(node, semantics); | 116 return handleLocalAccess(node, semantics); |
| 117 } | 117 } |
| 118 | 118 |
| 119 @override | 119 @override |
| 120 ir.Node visitParameterAccess(AstNode node, AccessSemantics semantics) { | 120 ir.Node visitParameterAccess(AstNode node, AccessSemantics semantics) { |
| 121 return handleLocalAccess(node, semantics); | 121 return handleLocalAccess(node, semantics); |
| 122 } | 122 } |
| 123 | 123 |
| 124 @override |
| 125 visitVariableDeclaration(VariableDeclaration node) { |
| 126 // TODO(johnniwinther): Handle constant local variables. |
| 127 ir.Node initialValue; |
| 128 if (node.initializer != null) { |
| 129 initialValue = node.initializer.accept(this); |
| 130 } |
| 131 irBuilder.declareLocalVariable( |
| 132 converter.convertElement(node.element), |
| 133 initialValue: initialValue); |
| 134 } |
| 135 |
| 124 ir.Primitive handleLocalAccess(AstNode node, AccessSemantics semantics) { | 136 ir.Primitive handleLocalAccess(AstNode node, AccessSemantics semantics) { |
| 125 analyzer.Element element = semantics.element; | 137 analyzer.Element element = semantics.element; |
| 126 dart2js.Element target = converter.convertElement(element); | 138 dart2js.Element target = converter.convertElement(element); |
| 127 assert(invariant(node, target.isLocal, '$target expected to be local.')); | 139 assert(invariant(node, target.isLocal, '$target expected to be local.')); |
| 128 return irBuilder.buildGetLocal(target); | 140 return irBuilder.buildGetLocal(target); |
| 129 } | 141 } |
| 130 | 142 |
| 131 @override | 143 @override |
| 132 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) { | 144 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) { |
| 133 analyzer.Element element = semantics.element; | 145 analyzer.Element element = semantics.element; |
| 134 dart2js.Element target = converter.convertElement(element); | 146 dart2js.Element target = converter.convertElement(element); |
| 135 // TODO(johnniwinther): Selector information should be computed in the | 147 // TODO(johnniwinther): Selector information should be computed in the |
| 136 // [TreeShaker] and shared with the [CpsGeneratingVisitor]. | 148 // [TreeShaker] and shared with the [CpsGeneratingVisitor]. |
| 137 assert(invariant(node, target.isTopLevel || target.isStatic, | 149 assert(invariant(node, target.isTopLevel || target.isStatic, |
| 138 '$target expected to be top-level or static.')); | 150 '$target expected to be top-level or static.')); |
| 139 return irBuilder.buildGetStatic(target, | 151 return irBuilder.buildGetStatic(target, |
| 140 new Selector.getter(target.name, target.library)); | 152 new Selector.getter(target.name, target.library)); |
| 141 } | 153 } |
| 142 } | 154 } |
| OLD | NEW |