@@ -922,37 +922,44 @@ static swiftscan_dependency_graph_t generateFullDependencyGraph(
922922 }
923923 moduleInfo->link_libraries = linkLibrarySet;
924924
925- // Create source import infos set for this module
926- auto imports = moduleDependencyInfo.getModuleImports ();
927- swiftscan_import_info_set_t *importInfoSet =
928- new swiftscan_import_info_set_t ;
929- importInfoSet->count = imports.size ();
930- importInfoSet->imports = new swiftscan_import_info_t [importInfoSet->count ];
931- for (size_t i = 0 ; i < imports.size (); ++i) {
932- const auto &ii = imports[i];
933- swiftscan_import_info_s *iInfo = new swiftscan_import_info_s;
934- iInfo->import_identifier = create_clone (ii.importIdentifier .c_str ());
935- iInfo->access_level =
936- static_cast <swiftscan_access_level_t >(ii.accessLevel );
937-
938- const auto &sourceLocations = ii.importLocations ;
939- swiftscan_source_location_set_t *sourceLocSet =
940- new swiftscan_source_location_set_t ;
941- sourceLocSet->count = sourceLocations.size ();
942- sourceLocSet->source_locations =
943- new swiftscan_source_location_t [sourceLocSet->count ];
944- for (size_t j = 0 ; j < sourceLocations.size (); ++j) {
945- const auto &sl = sourceLocations[j];
946- swiftscan_source_location_s *slInfo = new swiftscan_source_location_s;
947- slInfo->buffer_identifier = create_clone (sl.bufferIdentifier .c_str ());
948- slInfo->line_number = sl.lineNumber ;
949- slInfo->column_number = sl.columnNumber ;
950- sourceLocSet->source_locations [j] = slInfo;
925+ auto createImportSetInfo = [&](ArrayRef<ScannerImportStatementInfo> imports)
926+ -> swiftscan_import_info_set_t * {
927+ swiftscan_import_info_set_t *importInfoSet =
928+ new swiftscan_import_info_set_t ;
929+ importInfoSet->count = imports.size ();
930+ importInfoSet->imports =
931+ new swiftscan_import_info_t [importInfoSet->count ];
932+ for (size_t i = 0 ; i < imports.size (); ++i) {
933+ const auto &ii = imports[i];
934+ swiftscan_import_info_s *iInfo = new swiftscan_import_info_s;
935+ iInfo->import_identifier = create_clone (ii.importIdentifier .c_str ());
936+ iInfo->access_level =
937+ static_cast <swiftscan_access_level_t >(ii.accessLevel );
938+
939+ const auto &sourceLocations = ii.importLocations ;
940+ swiftscan_source_location_set_t *sourceLocSet =
941+ new swiftscan_source_location_set_t ;
942+ sourceLocSet->count = sourceLocations.size ();
943+ sourceLocSet->source_locations =
944+ new swiftscan_source_location_t [sourceLocSet->count ];
945+ for (size_t j = 0 ; j < sourceLocations.size (); ++j) {
946+ const auto &sl = sourceLocations[j];
947+ swiftscan_source_location_s *slInfo = new swiftscan_source_location_s;
948+ slInfo->buffer_identifier = create_clone (sl.bufferIdentifier .c_str ());
949+ slInfo->line_number = sl.lineNumber ;
950+ slInfo->column_number = sl.columnNumber ;
951+ sourceLocSet->source_locations [j] = slInfo;
952+ }
953+ iInfo->source_locations = sourceLocSet;
954+ importInfoSet->imports [i] = iInfo;
951955 }
952- iInfo->source_locations = sourceLocSet;
953- importInfoSet->imports [i] = iInfo;
954- }
955- moduleInfo->imports = importInfoSet;
956+ return importInfoSet;
957+ };
958+ // Create source import infos set for this module
959+ moduleInfo->imports =
960+ createImportSetInfo (moduleDependencyInfo.getModuleImports ());
961+ moduleInfo->optional_imports =
962+ createImportSetInfo (moduleDependencyInfo.getOptionalModuleImports ());
956963 }
957964
958965 swiftscan_dependency_graph_t result = new swiftscan_dependency_graph_s;
0 commit comments