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 tree_ir_builder; | 5 library tree_ir_builder; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; | 9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; |
10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 Variable getVariable(cps_ir.Primitive primitive) { | 100 Variable getVariable(cps_ir.Primitive primitive) { |
101 return primitive2variable.putIfAbsent(primitive, | 101 return primitive2variable.putIfAbsent(primitive, |
102 () => new Variable(currentElement, primitive.hint)); | 102 () => new Variable(currentElement, primitive.hint)); |
103 } | 103 } |
104 | 104 |
105 /// Obtains a reference to the tree Variable corresponding to the IR primitive | 105 /// Obtains a reference to the tree Variable corresponding to the IR primitive |
106 /// referred to by [reference]. | 106 /// referred to by [reference]. |
107 /// This increments the reference count for the given variable, so the | 107 /// This increments the reference count for the given variable, so the |
108 /// returned expression must be used in the tree. | 108 /// returned expression must be used in the tree. |
109 Expression getVariableUse(cps_ir.Reference<cps_ir.Primitive> reference) { | 109 Expression getVariableUse(cps_ir.Reference<cps_ir.Primitive> reference) { |
110 if (thisParameter != null && reference.definition == thisParameter) { | 110 cps_ir.Primitive prim = reference.definition.effectiveDefinition; |
| 111 if (thisParameter != null && prim == thisParameter) { |
111 return new This(); | 112 return new This(); |
112 } | 113 } |
113 return new VariableUse(getVariable(reference.definition)); | 114 return new VariableUse(getVariable(prim)); |
| 115 } |
| 116 |
| 117 Expression getVariableUseOrNull( |
| 118 cps_ir.Reference<cps_ir.Primitive> reference) { |
| 119 return reference == null ? null : getVariableUse(reference); |
114 } | 120 } |
115 | 121 |
116 Label getLabel(cps_ir.Continuation cont) { | 122 Label getLabel(cps_ir.Continuation cont) { |
117 return labels.putIfAbsent(cont, () => new Label()); | 123 return labels.putIfAbsent(cont, () => new Label()); |
118 } | 124 } |
119 | 125 |
120 Variable addFunctionParameter(cps_ir.Parameter parameter) { | 126 Variable addFunctionParameter(cps_ir.Parameter parameter) { |
121 return getVariable(parameter); | 127 return getVariable(parameter); |
122 } | 128 } |
123 | 129 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 return new LiteralMap( | 495 return new LiteralMap( |
490 node.dartType, | 496 node.dartType, |
491 new List<LiteralMapEntry>.generate(node.entries.length, (int index) { | 497 new List<LiteralMapEntry>.generate(node.entries.length, (int index) { |
492 return new LiteralMapEntry( | 498 return new LiteralMapEntry( |
493 getVariableUse(node.entries[index].key), | 499 getVariableUse(node.entries[index].key), |
494 getVariableUse(node.entries[index].value)); | 500 getVariableUse(node.entries[index].value)); |
495 }) | 501 }) |
496 ); | 502 ); |
497 } | 503 } |
498 | 504 |
499 FunctionDefinition makeSubFunction(cps_ir.FunctionDefinition function) { | |
500 return createInnerBuilder().buildFunction(function); | |
501 } | |
502 | |
503 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { | 505 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { |
504 return new ReifyRuntimeType( | 506 return new ReifyRuntimeType( |
505 getVariableUse(node.value), node.sourceInformation); | 507 getVariableUse(node.value), node.sourceInformation); |
506 } | 508 } |
507 | 509 |
508 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { | 510 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { |
509 return new ReadTypeVariable( | 511 return new ReadTypeVariable( |
510 node.variable, | 512 node.variable, |
511 getVariableUse(node.target), | 513 getVariableUse(node.target), |
512 node.sourceInformation); | 514 node.sourceInformation); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 return new ForeignStatement( | 638 return new ForeignStatement( |
637 node.codeTemplate, | 639 node.codeTemplate, |
638 node.type, | 640 node.type, |
639 arguments, | 641 arguments, |
640 node.nativeBehavior, | 642 node.nativeBehavior, |
641 node.dependency); | 643 node.dependency); |
642 }; | 644 }; |
643 } | 645 } |
644 } | 646 } |
645 | 647 |
| 648 visitNullCheck(cps_ir.NullCheck node) => (Statement next) { |
| 649 return new NullCheck( |
| 650 condition: getVariableUseOrNull(node.condition), |
| 651 value: getVariableUse(node.value), |
| 652 selector: node.selector, |
| 653 next: next, |
| 654 sourceInformation: node.sourceInformation); |
| 655 }; |
| 656 |
646 Expression visitGetLazyStatic(cps_ir.GetLazyStatic node) { | 657 Expression visitGetLazyStatic(cps_ir.GetLazyStatic node) { |
647 // In the tree IR, GetStatic handles lazy fields because we do not need | 658 // In the tree IR, GetStatic handles lazy fields because we do not need |
648 // as fine-grained control over side effects. | 659 // as fine-grained control over side effects. |
649 return new GetStatic(node.element, node.sourceInformation); | 660 return new GetStatic(node.element, node.sourceInformation); |
650 } | 661 } |
651 | 662 |
652 @override | 663 @override |
653 NodeCallback visitYield(cps_ir.Yield node) { | 664 NodeCallback visitYield(cps_ir.Yield node) { |
654 return (Statement next) { | 665 return (Statement next) { |
655 return new Yield(getVariableUse(node.input), node.hasStar, next); | 666 return new Yield(getVariableUse(node.input), node.hasStar, next); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 --enclosingFunctions; | 708 --enclosingFunctions; |
698 } | 709 } |
699 | 710 |
700 @override | 711 @override |
701 visitInterpolatedNode(js.InterpolatedNode node) { | 712 visitInterpolatedNode(js.InterpolatedNode node) { |
702 if (enclosingFunctions > 0) { | 713 if (enclosingFunctions > 0) { |
703 found = true; | 714 found = true; |
704 } | 715 } |
705 } | 716 } |
706 } | 717 } |
OLD | NEW |