| 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/src/dart_types.dart' as dart2js; | 9 import 'package:compiler/src/dart_types.dart' as dart2js; |
| 10 import 'package:compiler/src/elements/elements.dart' as dart2js; | 10 import 'package:compiler/src/elements/elements.dart' as dart2js; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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; | 34 analyzer.LibraryElement get currentLibrary => element.library; |
| 35 | 35 |
| 36 ir.Node visit(AstNode node) => node.accept(this); | 36 ir.Node visit(AstNode node) => node.accept(this); |
| 37 | 37 |
| 38 @override | 38 @override |
| 39 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { | 39 ir.Primitive visitFunctionExpression(FunctionExpression node) { |
| 40 analyzer.FunctionElement function = node.element; | 40 return irBuilder.buildFunctionExpression( |
| 41 handleFunctionDeclaration(node.element, node)); |
| 42 } |
| 43 |
| 44 ir.FunctionDefinition handleFunctionDeclaration( |
| 45 analyzer.FunctionElement function, FunctionExpression node) { |
| 41 dart2js.FunctionElement element = converter.convertElement(function); | 46 dart2js.FunctionElement element = converter.convertElement(function); |
| 42 return withBuilder( | 47 return withBuilder( |
| 43 new IrBuilder(DART_CONSTANT_SYSTEM, | 48 new IrBuilder(DART_CONSTANT_SYSTEM, |
| 44 element, | 49 element, |
| 45 // TODO(johnniwinther): Supported closure variables. | 50 // TODO(johnniwinther): Supported closure variables. |
| 46 const <dart2js.Local>[]), | 51 const <dart2js.Local>[]), |
| 47 () { | 52 () { |
| 48 function.parameters.forEach((analyzer.ParameterElement parameter) { | 53 function.parameters.forEach((analyzer.ParameterElement parameter) { |
| 49 // TODO(johnniwinther): Support "closure variables", that is variables | 54 // TODO(johnniwinther): Support "closure variables", that is variables |
| 50 // accessed from an inner function. | 55 // accessed from an inner function. |
| 51 irBuilder.createParameter(converter.convertElement(parameter)); | 56 irBuilder.createParameter(converter.convertElement(parameter)); |
| 52 }); | 57 }); |
| 53 // Visit the body directly to avoid processing the signature as | 58 // Visit the body directly to avoid processing the signature as |
| 54 // expressions. | 59 // expressions. |
| 55 visit(node.functionExpression.body); | 60 visit(node.body); |
| 56 return irBuilder.buildFunctionDefinition(element, const []); | 61 return irBuilder.buildFunctionDefinition(element, const []); |
| 57 }); | 62 }); |
| 58 } | 63 } |
| 59 | 64 |
| 65 @override |
| 66 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { |
| 67 return handleFunctionDeclaration(node.element, node.functionExpression); |
| 68 } |
| 69 |
| 70 @override |
| 71 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 72 FunctionDeclaration functionDeclaration = node.functionDeclaration; |
| 73 analyzer.FunctionElement function = functionDeclaration.element; |
| 74 dart2js.FunctionElement element = converter.convertElement(function); |
| 75 ir.FunctionDefinition definition = handleFunctionDeclaration( |
| 76 function, functionDeclaration.functionExpression); |
| 77 irBuilder.declareLocalFunction(element, definition); |
| 78 } |
| 79 |
| 60 List<ir.Definition> visitArguments(ArgumentList argumentList) { | 80 List<ir.Definition> visitArguments(ArgumentList argumentList) { |
| 61 List<ir.Definition> arguments = <ir.Definition>[]; | 81 List<ir.Definition> arguments = <ir.Definition>[]; |
| 62 for (Expression argument in argumentList.arguments) { | 82 for (Expression argument in argumentList.arguments) { |
| 63 ir.Definition value = build(argument); | 83 ir.Definition value = build(argument); |
| 64 if (value == null) { | 84 if (value == null) { |
| 65 giveUp(argument, | 85 giveUp(argument, |
| 66 'Unsupported argument: $argument (${argument.runtimeType}).'); | 86 'Unsupported argument: $argument (${argument.runtimeType}).'); |
| 67 } | 87 } |
| 68 arguments.add(value); | 88 arguments.add(value); |
| 69 } | 89 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 96 dart2js.Element element = converter.convertElement(staticElement); | 116 dart2js.Element element = converter.convertElement(staticElement); |
| 97 List<ir.Definition> arguments = visitArguments(node.argumentList); | 117 List<ir.Definition> arguments = visitArguments(node.argumentList); |
| 98 return irBuilder.buildStaticInvocation( | 118 return irBuilder.buildStaticInvocation( |
| 99 element, | 119 element, |
| 100 createSelectorFromMethodInvocation( | 120 createSelectorFromMethodInvocation( |
| 101 node.argumentList, node.methodName.name), | 121 node.argumentList, node.methodName.name), |
| 102 arguments); | 122 arguments); |
| 103 } | 123 } |
| 104 | 124 |
| 105 @override | 125 @override |
| 126 ir.Node visitLocalFunctionAccess(AstNode node, AccessSemantics semantics) { |
| 127 return handleLocalAccess(node, semantics); |
| 128 } |
| 129 |
| 130 ir.Primitive handleLocalInvocation(MethodInvocation node, |
| 131 AccessSemantics semantics) { |
| 132 analyzer.Element staticElement = semantics.element; |
| 133 dart2js.Element element = converter.convertElement(staticElement); |
| 134 List<ir.Definition> arguments = visitArguments(node.argumentList); |
| 135 return irBuilder.buildLocalInvocation( |
| 136 element, |
| 137 createSelectorFromMethodInvocation( |
| 138 node.argumentList, node.methodName.name), |
| 139 arguments); |
| 140 } |
| 141 |
| 142 @override |
| 143 ir.Node visitLocalVariableInvocation(MethodInvocation node, |
| 144 AccessSemantics semantics) { |
| 145 return handleLocalInvocation(node, semantics); |
| 146 } |
| 147 |
| 148 @override |
| 149 ir.Primitive visitLocalFunctionInvocation(MethodInvocation node, |
| 150 AccessSemantics semantics) { |
| 151 return handleLocalInvocation(node, semantics); |
| 152 } |
| 153 |
| 154 @override |
| 155 ir.Primitive visitFunctionExpressionInvocation( |
| 156 FunctionExpressionInvocation node) { |
| 157 ir.Primitive target = build(node.function); |
| 158 List<ir.Definition> arguments = visitArguments(node.argumentList); |
| 159 return irBuilder.buildFunctionExpressionInvocation( |
| 160 target, |
| 161 createSelectorFromMethodInvocation(node.argumentList, 'call'), |
| 162 arguments); |
| 163 } |
| 164 |
| 165 @override |
| 106 ir.Primitive visitInstanceCreationExpression( | 166 ir.Primitive visitInstanceCreationExpression( |
| 107 InstanceCreationExpression node) { | 167 InstanceCreationExpression node) { |
| 108 analyzer.Element staticElement = node.staticElement; | 168 analyzer.Element staticElement = node.staticElement; |
| 109 if (staticElement != null) { | 169 if (staticElement != null) { |
| 110 dart2js.Element element = converter.convertElement(staticElement); | 170 dart2js.Element element = converter.convertElement(staticElement); |
| 111 dart2js.DartType type = converter.convertType(node.staticType); | 171 dart2js.DartType type = converter.convertType(node.staticType); |
| 112 List<ir.Definition> arguments = visitArguments(node.argumentList); | 172 List<ir.Definition> arguments = visitArguments(node.argumentList); |
| 113 String name = ''; | 173 String name = ''; |
| 114 if (node.constructorName.name != null) { | 174 if (node.constructorName.name != null) { |
| 115 name = node.constructorName.name.name; | 175 name = node.constructorName.name.name; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 456 } |
| 397 | 457 |
| 398 @override | 458 @override |
| 399 ir.Primitive visitAsExpression(AsExpression node) { | 459 ir.Primitive visitAsExpression(AsExpression node) { |
| 400 return irBuilder.buildTypeOperator( | 460 return irBuilder.buildTypeOperator( |
| 401 visit(node.expression), | 461 visit(node.expression), |
| 402 converter.convertType(node.type.type), | 462 converter.convertType(node.type.type), |
| 403 isTypeTest: false); | 463 isTypeTest: false); |
| 404 } | 464 } |
| 405 } | 465 } |
| OLD | NEW |