def build_ir(modules: List[MypyFile], graph: Graph, types: Dict[Expression, Type], mapper: Mapper, options: CompilerOptions, errors: Errors) -> ModuleIRs: """Build IR for a set of modules that have been type-checked by mypy.""" build_type_map(mapper, modules, graph, types, options, errors) singledispatch_info = find_singledispatch_register_impls(modules, errors) result: ModuleIRs = OrderedDict() # Generate IR for all modules. class_irs = [] for module in modules: # First pass to determine free symbols. pbv = PreBuildVisitor(errors, module, singledispatch_info.decorators_to_remove) module.accept(pbv) # Construct and configure builder objects (cyclic runtime dependency). visitor = IRBuilderVisitor() builder = IRBuilder( module.fullname, types, graph, errors, mapper, pbv, visitor, options, singledispatch_info.singledispatch_impls, ) visitor.builder = builder # Second pass does the bulk of the work. transform_mypy_file(builder, module) module_ir = ModuleIR(module.fullname, list(builder.imports), builder.functions, builder.classes, builder.final_names) result[module.fullname] = module_ir class_irs.extend(builder.classes) analyze_always_defined_attrs(class_irs) # Compute vtables. for cir in class_irs: if cir.is_ext_class: compute_vtable(cir) return result
def build_ir(modules: List[MypyFile], graph: Graph, types: Dict[Expression, Type], mapper: 'Mapper', options: CompilerOptions, errors: Errors) -> ModuleIRs: build_type_map(mapper, modules, graph, types, options, errors) result = OrderedDict() # type: ModuleIRs # Generate IR for all modules. class_irs = [] for module in modules: # First pass to determine free symbols. pbv = PreBuildVisitor() module.accept(pbv) # Construct and configure builder objects (cyclic runtime dependency). visitor = IRBuilderVisitor() builder = IRBuilder( module.fullname, types, graph, errors, mapper, pbv, visitor, options ) visitor.builder = builder # Second pass does the bulk of the work. builder.visit_mypy_file(module) module_ir = ModuleIR( module.fullname, list(builder.imports), builder.functions, builder.classes, builder.final_names ) result[module.fullname] = module_ir class_irs.extend(builder.classes) # Compute vtables. for cir in class_irs: if cir.is_ext_class: compute_vtable(cir) return result