obj.attr = src (for a native object)
| 910 | |
| 911 | @final |
| 912 | class SetAttr(RegisterOp): |
| 913 | """obj.attr = src (for a native object)""" |
| 914 | |
| 915 | error_kind = ERR_FALSE |
| 916 | |
| 917 | def __init__(self, obj: Value, attr: str, src: Value, line: int) -> None: |
| 918 | super().__init__(line) |
| 919 | self.obj = obj |
| 920 | self.attr = attr |
| 921 | self.src = src |
| 922 | assert isinstance(obj.type, RInstance), "Attribute access not supported: %s" % obj.type |
| 923 | self.class_type = obj.type |
| 924 | self.type = bool_rprimitive |
| 925 | # If True, we can safely assume that the attribute is previously undefined |
| 926 | # and we don't use a setter |
| 927 | self.is_init = False |
| 928 | |
| 929 | cl = self.class_type.class_ir |
| 930 | is_propset = False |
| 931 | for ir in cl.mro: |
| 932 | propset = ir.method_decls.get(PROPSET_PREFIX + attr) |
| 933 | if propset is not None: |
| 934 | is_propset = not propset.implicit |
| 935 | break |
| 936 | # If True, this op represents calling a property setter. |
| 937 | self.is_propset = is_propset |
| 938 | |
| 939 | def mark_as_initializer(self) -> None: |
| 940 | self.is_init = True |
| 941 | self.error_kind = ERR_NEVER |
| 942 | self.type = void_rtype |
| 943 | |
| 944 | def sources(self) -> list[Value]: |
| 945 | return [self.obj, self.src] |
| 946 | |
| 947 | def set_sources(self, new: list[Value]) -> None: |
| 948 | self.obj, self.src = new |
| 949 | |
| 950 | def stolen(self) -> list[Value]: |
| 951 | # The property setter method increfs the passed value so don't treat it as a steal |
| 952 | # to avoid leaking. |
| 953 | if self.is_propset: |
| 954 | return [] |
| 955 | return [self.src] |
| 956 | |
| 957 | def accept(self, visitor: OpVisitor[T]) -> T: |
| 958 | return visitor.visit_set_attr(self) |
| 959 | |
| 960 | |
| 961 | # Default name space for statics, variables |
no outgoing calls
searching dependent graphs…