OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
6 | 6 |
7 class SsaCodeGeneratorTask extends CompilerTask { | 7 class SsaCodeGeneratorTask extends CompilerTask { |
8 | 8 |
9 final JavaScriptBackend backend; | 9 final JavaScriptBackend backend; |
10 | 10 |
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 } | 1513 } |
1514 } | 1514 } |
1515 | 1515 |
1516 js.Call jsPropertyCall(js.Expression receiver, | 1516 js.Call jsPropertyCall(js.Expression receiver, |
1517 String fieldName, | 1517 String fieldName, |
1518 List<js.Expression> arguments) { | 1518 List<js.Expression> arguments) { |
1519 return new js.Call(new js.PropertyAccess.field(receiver, fieldName), | 1519 return new js.Call(new js.PropertyAccess.field(receiver, fieldName), |
1520 arguments); | 1520 arguments); |
1521 } | 1521 } |
1522 | 1522 |
| 1523 // TODO(ngeoffray): Once we remove the old interceptors, we can |
| 1524 // start using HInvokeInterceptor to represent interceptor calls on |
| 1525 // an Interceptor class. Currently we recognize if a call is a call |
| 1526 // on an interceptor by checking if the arguments in the inputs list |
| 1527 // is one more than the arguments in the selector. The extra |
| 1528 // argument in an interceptor call is the actual receiver. |
| 1529 bool isInterceptorCall(HInvokeDynamicMethod node) { |
| 1530 return node.inputs.length - 1 != node.selector.argumentCount; |
| 1531 } |
| 1532 |
1523 visitInvokeDynamicMethod(HInvokeDynamicMethod node) { | 1533 visitInvokeDynamicMethod(HInvokeDynamicMethod node) { |
1524 use(node.receiver); | 1534 use(node.receiver); |
1525 js.Expression object = pop(); | 1535 js.Expression object = pop(); |
1526 SourceString name = node.selector.name; | 1536 SourceString name = node.selector.name; |
1527 String methodName; | 1537 String methodName; |
1528 List<js.Expression> arguments; | 1538 List<js.Expression> arguments; |
1529 Element target = node.element; | 1539 Element target = node.element; |
1530 | 1540 |
1531 // Avoid adding the generative constructor name to the list of | 1541 // Avoid adding the generative constructor name to the list of |
1532 // seen selectors. | 1542 // seen selectors. |
1533 if (target != null && target.isGenerativeConstructorBody()) { | 1543 if (target != null && target.isGenerativeConstructorBody()) { |
1534 methodName = name.slowToString(); | 1544 methodName = name.slowToString(); |
1535 arguments = visitArguments(node.inputs); | 1545 arguments = visitArguments(node.inputs); |
1536 } else { | 1546 } else { |
1537 methodName = backend.namer.instanceMethodInvocationName( | 1547 methodName = backend.namer.instanceMethodInvocationName( |
1538 node.selector.library, name, node.selector); | 1548 node.selector.library, name, node.selector); |
1539 arguments = visitArguments(node.inputs); | 1549 arguments = visitArguments(node.inputs); |
1540 bool inLoop = node.block.enclosingLoopHeader != null; | 1550 bool inLoop = node.block.enclosingLoopHeader != null; |
1541 | 1551 |
1542 // Register this invocation to collect the types used at all call sites. | 1552 // Register this invocation to collect the types used at all call sites. |
1543 Selector selector = getOptimizedSelectorFor(node, node.selector); | 1553 Selector selector = getOptimizedSelectorFor(node, node.selector); |
1544 backend.registerDynamicInvocation(node, selector, types); | 1554 // TODO(ngeoffray): Remove the following restriction. Because |
| 1555 // the second input of this interceptor call is the actual |
| 1556 // receiver (the first is the interceptor), the backend gets |
| 1557 // confused. We should pass a list of types instead of a node to |
| 1558 // [registerDynamicInvocation]. |
| 1559 if (!isInterceptorCall(node)) { |
| 1560 backend.registerDynamicInvocation(node, selector, types); |
| 1561 } |
1545 | 1562 |
1546 // If we don't know what we're calling or if we are calling a getter, | 1563 // If we don't know what we're calling or if we are calling a getter, |
1547 // we need to register that fact that we may be calling a closure | 1564 // we need to register that fact that we may be calling a closure |
1548 // with the same arguments. | 1565 // with the same arguments. |
1549 if (target == null || target.isGetter()) { | 1566 if (target == null || target.isGetter()) { |
1550 // TODO(kasperl): If we have a typed selector for the call, we | 1567 // TODO(kasperl): If we have a typed selector for the call, we |
1551 // may know something about the types of closures that need | 1568 // may know something about the types of closures that need |
1552 // the specific closure call method. | 1569 // the specific closure call method. |
1553 Selector call = new Selector.callClosureFrom(selector); | 1570 Selector call = new Selector.callClosureFrom(selector); |
1554 world.registerDynamicInvocation(call.name, call); | 1571 world.registerDynamicInvocation(call.name, call); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 HInstruction input = node.inputs[0]; | 1976 HInstruction input = node.inputs[0]; |
1960 if (input.isConstantNull()) { | 1977 if (input.isConstantNull()) { |
1961 pushStatement(new js.Return(null), node); | 1978 pushStatement(new js.Return(null), node); |
1962 } else { | 1979 } else { |
1963 use(node.inputs[0]); | 1980 use(node.inputs[0]); |
1964 pushStatement(new js.Return(pop()), node); | 1981 pushStatement(new js.Return(pop()), node); |
1965 } | 1982 } |
1966 } | 1983 } |
1967 | 1984 |
1968 visitThis(HThis node) { | 1985 visitThis(HThis node) { |
1969 push(new js.This()); | 1986 if (backend.isInterceptorClass(work.element.getEnclosingClass())){ |
| 1987 push(new js.VariableUse(variableNames.getName(node)), node); |
| 1988 } else { |
| 1989 push(new js.This()); |
| 1990 } |
1970 } | 1991 } |
1971 | 1992 |
1972 visitThrow(HThrow node) { | 1993 visitThrow(HThrow node) { |
1973 if (node.isRethrow) { | 1994 if (node.isRethrow) { |
1974 use(node.inputs[0]); | 1995 use(node.inputs[0]); |
1975 pushStatement(new js.Throw(pop()), node); | 1996 pushStatement(new js.Throw(pop()), node); |
1976 } else { | 1997 } else { |
1977 generateThrowWithHelper(r'$throw', node.inputs[0]); | 1998 generateThrowWithHelper(r'$throw', node.inputs[0]); |
1978 } | 1999 } |
1979 } | 2000 } |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3080 if (leftType.canBeNull() && rightType.canBeNull()) { | 3101 if (leftType.canBeNull() && rightType.canBeNull()) { |
3081 if (left.isConstantNull() || right.isConstantNull() || | 3102 if (left.isConstantNull() || right.isConstantNull() || |
3082 (leftType.isPrimitive() && leftType == rightType)) { | 3103 (leftType.isPrimitive() && leftType == rightType)) { |
3083 return '=='; | 3104 return '=='; |
3084 } | 3105 } |
3085 return null; | 3106 return null; |
3086 } else { | 3107 } else { |
3087 return '==='; | 3108 return '==='; |
3088 } | 3109 } |
3089 } | 3110 } |
OLD | NEW |