Generate glue methods for properties that mediate between different subclass types. Similarly to methods, properties of derived types can be covariantly subtyped. Thus, properties also require glue. However, this only requires the return type to change. Further, instead of a method call
(
builder: IRBuilder,
sig: FuncSignature,
target: FuncIR,
cls: ClassIR,
base: ClassIR,
line: int,
do_pygetattr: bool,
)
| 806 | |
| 807 | |
| 808 | def gen_glue_property( |
| 809 | builder: IRBuilder, |
| 810 | sig: FuncSignature, |
| 811 | target: FuncIR, |
| 812 | cls: ClassIR, |
| 813 | base: ClassIR, |
| 814 | line: int, |
| 815 | do_pygetattr: bool, |
| 816 | ) -> FuncIR: |
| 817 | """Generate glue methods for properties that mediate between different subclass types. |
| 818 | |
| 819 | Similarly to methods, properties of derived types can be covariantly subtyped. Thus, |
| 820 | properties also require glue. However, this only requires the return type to change. |
| 821 | Further, instead of a method call, an attribute get is performed. |
| 822 | |
| 823 | If do_pygetattr is True, then get the attribute using the Python C |
| 824 | API instead of a native call. |
| 825 | """ |
| 826 | builder.enter() |
| 827 | |
| 828 | rt_arg = RuntimeArg(SELF_NAME, RInstance(cls)) |
| 829 | self_target = builder.add_self_to_env(cls) |
| 830 | arg = builder.read(self_target, line) |
| 831 | builder.ret_types[-1] = sig.ret_type |
| 832 | if do_pygetattr: |
| 833 | retval = builder.py_get_attr(arg, target.name, line) |
| 834 | else: |
| 835 | retval = builder.add(GetAttr(arg, target.name, line)) |
| 836 | retbox = builder.coerce(retval, sig.ret_type, line) |
| 837 | builder.add(Return(retbox)) |
| 838 | |
| 839 | args, _, blocks, return_type, _ = builder.leave() |
| 840 | return FuncIR( |
| 841 | FuncDecl( |
| 842 | target.name + "__" + base.name + "_glue", |
| 843 | cls.name, |
| 844 | builder.module_name, |
| 845 | FuncSignature([rt_arg], return_type), |
| 846 | ), |
| 847 | args, |
| 848 | blocks, |
| 849 | ) |
| 850 | |
| 851 | |
| 852 | def gen_glue_property_setter( |
no test coverage detected
searching dependent graphs…