Builder class used to construct mypyc IR from a mypy AST. The IRBuilder class maintains IR transformation state and provides access to various helpers used to implement the transform. mypyc.irbuild.visitor.IRBuilderVisitor is used to dispatch based on mypy AST node type to code tha
| 173 | |
| 174 | |
| 175 | class IRBuilder: |
| 176 | """Builder class used to construct mypyc IR from a mypy AST. |
| 177 | |
| 178 | The IRBuilder class maintains IR transformation state and provides access |
| 179 | to various helpers used to implement the transform. |
| 180 | |
| 181 | mypyc.irbuild.visitor.IRBuilderVisitor is used to dispatch based on mypy |
| 182 | AST node type to code that actually does the bulk of the work. For |
| 183 | example, expressions are transformed in mypyc.irbuild.expression and |
| 184 | functions are transformed in mypyc.irbuild.function. |
| 185 | |
| 186 | Use the "accept()" method to translate individual mypy AST nodes to IR. |
| 187 | Other methods are used to generate IR for various lower-level operations. |
| 188 | |
| 189 | This class wraps the lower-level LowLevelIRBuilder class, an instance |
| 190 | of which is available through the "builder" attribute. The low-level |
| 191 | builder class doesn't have any knowledge of the mypy AST. Wrappers for |
| 192 | some LowLevelIRBuilder method are provided for convenience, but others |
| 193 | can also be accessed via the "builder" attribute. |
| 194 | |
| 195 | See also: |
| 196 | * The mypyc IR is defined in the mypyc.ir package. |
| 197 | * The top-level IR transform control logic is in mypyc.irbuild.main. |
| 198 | """ |
| 199 | |
| 200 | def __init__( |
| 201 | self, |
| 202 | current_module: str, |
| 203 | types: dict[Expression, Type], |
| 204 | graph: Graph, |
| 205 | errors: Errors, |
| 206 | mapper: Mapper, |
| 207 | pbv: PreBuildVisitor, |
| 208 | visitor: IRVisitor, |
| 209 | options: CompilerOptions, |
| 210 | singledispatch_impls: dict[FuncDef, list[RegisterImplInfo]], |
| 211 | ) -> None: |
| 212 | self.builder = LowLevelIRBuilder(errors, options) |
| 213 | self.builders = [self.builder] |
| 214 | self.symtables: list[dict[SymbolNode, SymbolTarget]] = [{}] |
| 215 | self.runtime_args: list[list[RuntimeArg]] = [[]] |
| 216 | self.function_name_stack: list[str] = [] |
| 217 | self.class_ir_stack: list[ClassIR] = [] |
| 218 | # Keep track of whether the next statement in a block is reachable |
| 219 | # or not, separately for each block nesting level |
| 220 | self.block_reachable_stack: list[bool] = [True] |
| 221 | |
| 222 | self.current_module = current_module |
| 223 | self.mapper = mapper |
| 224 | self.types = types |
| 225 | self.graph = graph |
| 226 | self.ret_types: list[RType] = [] |
| 227 | self.functions: list[FuncIR] = [] |
| 228 | self.function_names: set[tuple[str | None, str]] = set() |
| 229 | self.classes: list[ClassIR] = [] |
| 230 | self.final_names: list[tuple[str, RType]] = [] |
| 231 | self.type_var_names: list[str] = [] |
| 232 | self.callable_class_names: set[str] = set() |
no outgoing calls
searching dependent graphs…