| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // accessed from an inner function. | 50 // accessed from an inner function. |
| 51 irBuilder.createParameter(converter.convertElement(parameter)); | 51 irBuilder.createParameter(converter.convertElement(parameter)); |
| 52 }); | 52 }); |
| 53 // Visit the body directly to avoid processing the signature as | 53 // Visit the body directly to avoid processing the signature as |
| 54 // expressions. | 54 // expressions. |
| 55 visit(node.functionExpression.body); | 55 visit(node.functionExpression.body); |
| 56 return irBuilder.buildFunctionDefinition(element, const []); | 56 return irBuilder.buildFunctionDefinition(element, const []); |
| 57 }); | 57 }); |
| 58 } | 58 } |
| 59 | 59 |
| 60 List<ir.Definition> visitArguments(ArgumentList argumentList) { | 60 List<ir.Primitive> visitArguments(ArgumentList argumentList) { |
| 61 List<ir.Definition> arguments = <ir.Definition>[]; | 61 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 62 for (Expression argument in argumentList.arguments) { | 62 for (Expression argument in argumentList.arguments) { |
| 63 ir.Definition value = build(argument); | 63 ir.Primitive value = build(argument); |
| 64 if (value == null) { | 64 if (value == null) { |
| 65 giveUp(argument, | 65 giveUp(argument, |
| 66 'Unsupported argument: $argument (${argument.runtimeType}).'); | 66 'Unsupported argument: $argument (${argument.runtimeType}).'); |
| 67 } | 67 } |
| 68 arguments.add(value); | 68 arguments.add(value); |
| 69 } | 69 } |
| 70 return arguments; | 70 return arguments; |
| 71 } | 71 } |
| 72 | 72 |
| 73 @override | 73 @override |
| 74 ir.Node visitMethodInvocation(MethodInvocation node) { | 74 ir.Node visitMethodInvocation(MethodInvocation node) { |
| 75 // Overridden to avoid eager visits of the receiver and arguments. | 75 // Overridden to avoid eager visits of the receiver and arguments. |
| 76 return handleMethodInvocation(node); | 76 return handleMethodInvocation(node); |
| 77 } | 77 } |
| 78 | 78 |
| 79 @override | 79 @override |
| 80 ir.Primitive visitDynamicInvocation(MethodInvocation node, | 80 ir.Primitive visitDynamicInvocation(MethodInvocation node, |
| 81 AccessSemantics semantics) { | 81 AccessSemantics semantics) { |
| 82 // TODO(johnniwinther): Handle implicit `this`. | 82 // TODO(johnniwinther): Handle implicit `this`. |
| 83 ir.Primitive receiver = build(semantics.target); | 83 ir.Primitive receiver = build(semantics.target); |
| 84 List<ir.Definition> arguments = visitArguments(node.argumentList); | 84 List<ir.Primitive> arguments = visitArguments(node.argumentList); |
| 85 return irBuilder.buildDynamicInvocation( | 85 return irBuilder.buildDynamicInvocation( |
| 86 receiver, | 86 receiver, |
| 87 createSelectorFromMethodInvocation( | 87 createSelectorFromMethodInvocation( |
| 88 node.argumentList, node.methodName.name), | 88 node.argumentList, node.methodName.name), |
| 89 arguments); | 89 arguments); |
| 90 } | 90 } |
| 91 | 91 |
| 92 @override | 92 @override |
| 93 ir.Primitive visitStaticMethodInvocation(MethodInvocation node, | 93 ir.Primitive visitStaticMethodInvocation(MethodInvocation node, |
| 94 AccessSemantics semantics) { | 94 AccessSemantics semantics) { |
| 95 analyzer.Element staticElement = semantics.element; | 95 analyzer.Element staticElement = semantics.element; |
| 96 dart2js.Element element = converter.convertElement(staticElement); | 96 dart2js.Element element = converter.convertElement(staticElement); |
| 97 List<ir.Definition> arguments = visitArguments(node.argumentList); | 97 List<ir.Primitive> arguments = visitArguments(node.argumentList); |
| 98 return irBuilder.buildStaticInvocation( | 98 return irBuilder.buildStaticInvocation( |
| 99 element, | 99 element, |
| 100 createSelectorFromMethodInvocation( | 100 createSelectorFromMethodInvocation( |
| 101 node.argumentList, node.methodName.name), | 101 node.argumentList, node.methodName.name), |
| 102 arguments); | 102 arguments); |
| 103 } | 103 } |
| 104 | 104 |
| 105 @override | 105 @override |
| 106 ir.Primitive visitInstanceCreationExpression( | 106 ir.Primitive visitInstanceCreationExpression( |
| 107 InstanceCreationExpression node) { | 107 InstanceCreationExpression node) { |
| 108 analyzer.Element staticElement = node.staticElement; | 108 analyzer.Element staticElement = node.staticElement; |
| 109 if (staticElement != null) { | 109 if (staticElement != null) { |
| 110 dart2js.Element element = converter.convertElement(staticElement); | 110 dart2js.Element element = converter.convertElement(staticElement); |
| 111 dart2js.DartType type = converter.convertType(node.staticType); | 111 dart2js.DartType type = converter.convertType(node.staticType); |
| 112 List<ir.Definition> arguments = visitArguments(node.argumentList); | 112 List<ir.Primitive> arguments = visitArguments(node.argumentList); |
| 113 String name = ''; | 113 String name = ''; |
| 114 if (node.constructorName.name != null) { | 114 if (node.constructorName.name != null) { |
| 115 name = node.constructorName.name.name; | 115 name = node.constructorName.name.name; |
| 116 } | 116 } |
| 117 return irBuilder.buildConstructorInvocation( | 117 return irBuilder.buildConstructorInvocation( |
| 118 element, | 118 element, |
| 119 createSelectorFromMethodInvocation(node.argumentList, name), | 119 createSelectorFromMethodInvocation(node.argumentList, name), |
| 120 type, | 120 type, |
| 121 arguments); | 121 arguments); |
| 122 } | 122 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 return irBuilder.buildStaticGet(target, | 251 return irBuilder.buildStaticGet(target, |
| 252 new Selector.getter(target.name, target.library)); | 252 new Selector.getter(target.name, target.library)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 ir.Primitive handleBinaryExpression(BinaryExpression node, | 255 ir.Primitive handleBinaryExpression(BinaryExpression node, |
| 256 String op) { | 256 String op) { |
| 257 ir.Primitive left = build(node.leftOperand); | 257 ir.Primitive left = build(node.leftOperand); |
| 258 ir.Primitive right = build(node.rightOperand); | 258 ir.Primitive right = build(node.rightOperand); |
| 259 Selector selector = new Selector.binaryOperator(op); | 259 Selector selector = new Selector.binaryOperator(op); |
| 260 return irBuilder.buildDynamicInvocation( | 260 return irBuilder.buildDynamicInvocation( |
| 261 left, selector, <ir.Definition>[right]); | 261 left, selector, <ir.Primitive>[right]); |
| 262 } | 262 } |
| 263 | 263 |
| 264 ir.Node handleLazyOperator(BinaryExpression node, {bool isLazyOr: false}) { | 264 ir.Node handleLazyOperator(BinaryExpression node, {bool isLazyOr: false}) { |
| 265 return irBuilder.buildLogicalOperator( | 265 return irBuilder.buildLogicalOperator( |
| 266 build(node.leftOperand), | 266 build(node.leftOperand), |
| 267 subbuild(node.rightOperand), | 267 subbuild(node.rightOperand), |
| 268 isLazyOr: isLazyOr); | 268 isLazyOr: isLazyOr); |
| 269 } | 269 } |
| 270 | 270 |
| 271 @override | 271 @override |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 396 } |
| 397 | 397 |
| 398 @override | 398 @override |
| 399 ir.Primitive visitAsExpression(AsExpression node) { | 399 ir.Primitive visitAsExpression(AsExpression node) { |
| 400 return irBuilder.buildTypeOperator( | 400 return irBuilder.buildTypeOperator( |
| 401 visit(node.expression), | 401 visit(node.expression), |
| 402 converter.convertType(node.type.type), | 402 converter.convertType(node.type.type), |
| 403 isTypeTest: false); | 403 isTypeTest: false); |
| 404 } | 404 } |
| 405 } | 405 } |
| OLD | NEW |