| 13 | """Contains information about functions as they are generated.""" |
| 14 | |
| 15 | def __init__( |
| 16 | self, |
| 17 | fitem: FuncItem = INVALID_FUNC_DEF, |
| 18 | name: str = "", |
| 19 | class_name: str | None = None, |
| 20 | namespace: str = "", |
| 21 | is_nested: bool = False, |
| 22 | contains_nested: bool = False, |
| 23 | is_decorated: bool = False, |
| 24 | in_non_ext: bool = False, |
| 25 | add_nested_funcs_to_env: bool = False, |
| 26 | is_comprehension_scope: bool = False, |
| 27 | ) -> None: |
| 28 | self.fitem = fitem |
| 29 | self.name = name |
| 30 | self.class_name = class_name |
| 31 | self.ns = namespace |
| 32 | # Callable classes implement the '__call__' method, and are used to represent functions |
| 33 | # that are nested inside of other functions. |
| 34 | self._callable_class: ImplicitClass | None = None |
| 35 | # Environment classes are ClassIR instances that contain attributes representing the |
| 36 | # variables in the environment of the function they correspond to. Environment classes are |
| 37 | # generated for functions that contain nested functions. |
| 38 | self._env_class: ClassIR | None = None |
| 39 | # Generator classes implement the '__next__' method, and are used to represent generators |
| 40 | # returned by generator functions. |
| 41 | self._generator_class: GeneratorClass | None = None |
| 42 | # Environment class registers are the local registers associated with instances of an |
| 43 | # environment class, used for getting and setting attributes. curr_env_reg is the register |
| 44 | # associated with the current environment. |
| 45 | self._curr_env_reg: Value | None = None |
| 46 | # These are flags denoting whether a given function is nested, contains a nested function, |
| 47 | # is decorated, or is within a non-extension class. |
| 48 | self.is_nested = is_nested |
| 49 | self.contains_nested = contains_nested |
| 50 | self.is_decorated = is_decorated |
| 51 | self.in_non_ext = in_non_ext |
| 52 | self.add_nested_funcs_to_env = add_nested_funcs_to_env |
| 53 | # Comprehension scopes are lightweight scope boundaries created when |
| 54 | # a comprehension body contains a lambda. The comprehension is still |
| 55 | # inlined (same basic blocks), but we push a new FuncInfo so the |
| 56 | # closure machinery can capture loop variables through env classes. |
| 57 | self.is_comprehension_scope = is_comprehension_scope |
| 58 | |
| 59 | # TODO: add field for ret_type: RType = none_rprimitive |
| 60 | |
| 61 | def namespaced_name(self) -> str: |
| 62 | return "_".join(x for x in [self.name, self.class_name, self.ns] if x) |