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 /** |
| 8 * A special element for the extra parameter taken by intercepted |
| 9 * methods. We need to override [Element.computeType] because our |
| 10 * optimizers may look at its declared type. |
| 11 */ |
| 12 class InterceptedElement extends Element { |
| 13 final HType ssaType; |
| 14 InterceptedElement(this.ssaType, Element enclosing) |
| 15 : super(const SourceString('receiver'), |
| 16 ElementKind.PARAMETER, |
| 17 enclosing); |
| 18 |
| 19 DartType computeType(Compiler compiler) => ssaType.computeType(compiler); |
| 20 } |
| 21 |
7 class Interceptors { | 22 class Interceptors { |
8 Compiler compiler; | 23 Compiler compiler; |
9 Interceptors(Compiler this.compiler); | 24 Interceptors(Compiler this.compiler); |
10 | 25 |
11 SourceString mapOperatorToMethodName(Operator op) { | 26 SourceString mapOperatorToMethodName(Operator op) { |
12 String name = op.source.stringValue; | 27 String name = op.source.stringValue; |
13 if (identical(name, '+')) return const SourceString('add'); | 28 if (identical(name, '+')) return const SourceString('add'); |
14 if (identical(name, '-')) return const SourceString('sub'); | 29 if (identical(name, '-')) return const SourceString('sub'); |
15 if (identical(name, '*')) return const SourceString('mul'); | 30 if (identical(name, '*')) return const SourceString('mul'); |
16 if (identical(name, '/')) return const SourceString('div'); | 31 if (identical(name, '/')) return const SourceString('div'); |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // not have any thisElement if the closure was created inside a static | 432 // not have any thisElement if the closure was created inside a static |
418 // context. | 433 // context. |
419 ClassElement cls = element.getEnclosingClass(); | 434 ClassElement cls = element.getEnclosingClass(); |
420 DartType type = cls.computeType(builder.compiler); | 435 DartType type = cls.computeType(builder.compiler); |
421 builder.thisInstruction = new HThis(closureData.thisElement, | 436 builder.thisInstruction = new HThis(closureData.thisElement, |
422 new HBoundedType.nonNull(type)); | 437 new HBoundedType.nonNull(type)); |
423 builder.graph.entry.addAtEntry(builder.thisInstruction); | 438 builder.graph.entry.addAtEntry(builder.thisInstruction); |
424 directLocals[closureData.thisElement] = builder.thisInstruction; | 439 directLocals[closureData.thisElement] = builder.thisInstruction; |
425 } | 440 } |
426 | 441 |
| 442 // If this method is an intercepted method, add the extra |
| 443 // parameter to it, that is the actual receiver. |
427 ClassElement cls = element.getEnclosingClass(); | 444 ClassElement cls = element.getEnclosingClass(); |
428 if (builder.backend.isInterceptorClass(cls)) { | 445 if (builder.backend.isInterceptorClass(cls)) { |
429 Element parameter = new Element( | |
430 const SourceString('receiver'), ElementKind.VARIABLE, element); | |
431 HParameterValue value = new HParameterValue(parameter); | |
432 builder.graph.entry.addAfter( | |
433 directLocals[closureData.thisElement], value); | |
434 directLocals[closureData.thisElement] = value; | |
435 HType type = HType.UNKNOWN; | 446 HType type = HType.UNKNOWN; |
436 if (cls == builder.backend.jsArrayClass) { | 447 if (cls == builder.backend.jsArrayClass) { |
437 type = HType.READABLE_ARRAY; | 448 type = HType.READABLE_ARRAY; |
438 } else if (cls == builder.backend.jsStringClass) { | 449 } else if (cls == builder.backend.jsStringClass) { |
439 type = HType.STRING; | 450 type = HType.STRING; |
440 } else if (cls == builder.backend.jsNumberClass) { | 451 } else if (cls == builder.backend.jsNumberClass) { |
441 type = HType.NUMBER; | 452 type = HType.NUMBER; |
442 } else if (cls == builder.backend.jsIntClass) { | 453 } else if (cls == builder.backend.jsIntClass) { |
443 type = HType.INTEGER; | 454 type = HType.INTEGER; |
444 } else if (cls == builder.backend.jsDoubleClass) { | 455 } else if (cls == builder.backend.jsDoubleClass) { |
445 type = HType.DOUBLE; | 456 type = HType.DOUBLE; |
446 } else if (cls == builder.backend.jsNullClass) { | 457 } else if (cls == builder.backend.jsNullClass) { |
447 type = HType.NULL; | 458 type = HType.NULL; |
448 } else if (cls == builder.backend.jsBoolClass) { | 459 } else if (cls == builder.backend.jsBoolClass) { |
449 type = HType.BOOLEAN; | 460 type = HType.BOOLEAN; |
450 } | 461 } |
| 462 Element parameter = new InterceptedElement(type, element); |
| 463 HParameterValue value = new HParameterValue(parameter); |
| 464 builder.graph.entry.addAfter( |
| 465 directLocals[closureData.thisElement], value); |
| 466 directLocals[closureData.thisElement] = value; |
451 value.guaranteedType = type; | 467 value.guaranteedType = type; |
452 } | 468 } |
453 } | 469 } |
454 | 470 |
455 bool hasValueForDirectLocal(Element element) { | 471 bool hasValueForDirectLocal(Element element) { |
456 assert(element != null); | 472 assert(element != null); |
457 assert(isAccessedDirectly(element)); | 473 assert(isAccessedDirectly(element)); |
458 return directLocals[element] != null; | 474 return directLocals[element] != null; |
459 } | 475 } |
460 | 476 |
(...skipping 4481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4942 new HSubGraphBlockInformation(elseBranch.graph)); | 4958 new HSubGraphBlockInformation(elseBranch.graph)); |
4943 | 4959 |
4944 HBasicBlock conditionStartBlock = conditionBranch.block; | 4960 HBasicBlock conditionStartBlock = conditionBranch.block; |
4945 conditionStartBlock.setBlockFlow(info, joinBlock); | 4961 conditionStartBlock.setBlockFlow(info, joinBlock); |
4946 SubGraph conditionGraph = conditionBranch.graph; | 4962 SubGraph conditionGraph = conditionBranch.graph; |
4947 HIf branch = conditionGraph.end.last; | 4963 HIf branch = conditionGraph.end.last; |
4948 assert(branch is HIf); | 4964 assert(branch is HIf); |
4949 branch.blockInformation = conditionStartBlock.blockFlow; | 4965 branch.blockInformation = conditionStartBlock.blockFlow; |
4950 } | 4966 } |
4951 } | 4967 } |
OLD | NEW |