@@ -77,6 +77,11 @@ void writeJSONValue(llvm::raw_ostream &out, bool value, unsigned indentLevel) {
7777 out.write_escaped (value ? " true" : " false" );
7878}
7979
80+ // / Write a boolean value as JSON.
81+ void writeJSONValue (llvm::raw_ostream &out, uint32_t value, unsigned indentLevel) {
82+ out.write_escaped (std::to_string (value));
83+ }
84+
8085// / Write a JSON array.
8186template <typename T>
8287void writeJSONValue (llvm::raw_ostream &out, ArrayRef<T> values,
@@ -226,6 +231,90 @@ void writeLinkLibraries(llvm::raw_ostream &out,
226231 out << " \n " ;
227232}
228233
234+ void writeImportInfos (llvm::raw_ostream &out,
235+ const swiftscan_import_info_set_t *imports,
236+ unsigned indentLevel, bool trailingComma) {
237+ out.indent (indentLevel * 2 );
238+ out << " \" imports\" : " ;
239+ out << " [\n " ;
240+
241+ for (size_t i = 0 ; i < imports->count ; ++i) {
242+ const auto &iInfo = *imports->imports [i];
243+ out.indent ((indentLevel + 1 ) * 2 );
244+ out << " {\n " ;
245+ auto entryIndentLevel = ((indentLevel + 2 ) * 2 );
246+ out.indent (entryIndentLevel);
247+ out << " \" identifier\" : " ;
248+ writeJSONValue (out, iInfo.import_identifier , indentLevel);
249+ out << " ,\n " ;
250+ out.indent (entryIndentLevel);
251+ out << " \" accessLevel\" : " ;
252+ switch (iInfo.access_level ) {
253+ case SWIFTSCAN_ACCESS_LEVEL_PRIVATE:
254+ writeJSONValue (out, StringRef (" private" ), entryIndentLevel);
255+ break ;
256+ case SWIFTSCAN_ACCESS_LEVEL_FILEPRIVATE:
257+ writeJSONValue (out, StringRef (" fileprivate" ), entryIndentLevel);
258+ break ;
259+ case SWIFTSCAN_ACCESS_LEVEL_INTERNAL:
260+ writeJSONValue (out, StringRef (" internal" ), entryIndentLevel);
261+ break ;
262+ case SWIFTSCAN_ACCESS_LEVEL_PACKAGE:
263+ writeJSONValue (out, StringRef (" package" ), entryIndentLevel);
264+ break ;
265+ case SWIFTSCAN_ACCESS_LEVEL_PUBLIC:
266+ writeJSONValue (out, StringRef (" public" ), entryIndentLevel);
267+ break ;
268+ }
269+
270+ if (iInfo.source_locations ->count ) {
271+ out << " ,\n " ;
272+ out.indent (entryIndentLevel);
273+ out << " \" importLocations\" : " ;
274+ out << " [\n " ;
275+ auto slIndentLevel = ((entryIndentLevel + 4 ));
276+ for (size_t i = 0 ; i < iInfo.source_locations ->count ; ++i) {
277+ out.indent (entryIndentLevel + 2 );
278+ out << " {\n " ;
279+ const auto &sl = *iInfo.source_locations ->source_locations [i];
280+ out.indent (slIndentLevel);
281+ out << " \" bufferIdentifier\" : " ;
282+ writeJSONValue (out, sl.buffer_identifier , indentLevel);
283+ out << " ,\n " ;
284+ out.indent (slIndentLevel);
285+ out << " \" linuNumber\" : " ;
286+ writeJSONValue (out, sl.line_number , indentLevel);
287+ out << " ,\n " ;
288+ out.indent (slIndentLevel);
289+ out << " \" columnNumber\" : " ;
290+ writeJSONValue (out, sl.column_number , indentLevel);
291+ out << " \n " ;
292+ out.indent (entryIndentLevel + 2 );
293+ out << " }" ;
294+ if (i != iInfo.source_locations ->count - 1 )
295+ out << " ," ;
296+ out << " \n " ;
297+ }
298+ out.indent (entryIndentLevel);
299+ out << " ]\n " ;
300+ } else {
301+ out << " \n " ;
302+ }
303+ out.indent ((indentLevel + 1 ) * 2 );
304+ out << " }" ;
305+ if (i != imports->count - 1 )
306+ out << " ," ;
307+ out << " \n " ;
308+ }
309+
310+ out.indent (indentLevel * 2 );
311+ out << " ]" ;
312+
313+ if (trailingComma)
314+ out << " ," ;
315+ out << " \n " ;
316+ }
317+
229318static void
230319writeMacroDependencies (llvm::raw_ostream &out,
231320 const swiftscan_macro_dependency_set_t *macro_deps,
@@ -243,15 +332,15 @@ writeMacroDependencies(llvm::raw_ostream &out,
243332 auto entryIndentLevel = ((indentLevel + 2 ) * 2 );
244333 out.indent (entryIndentLevel);
245334 out << " \" moduleName\" : " ;
246- writeJSONValue (out, macroInfo.moduleName , indentLevel);
335+ writeJSONValue (out, macroInfo.module_name , indentLevel);
247336 out << " ,\n " ;
248337 out.indent (entryIndentLevel);
249338 out << " \" libraryPath\" : " ;
250- writeJSONValue (out, macroInfo.libraryPath , entryIndentLevel);
339+ writeJSONValue (out, macroInfo.library_path , entryIndentLevel);
251340 out << " ,\n " ;
252341 out.indent (entryIndentLevel);
253342 out << " \" executablePath\" : " ;
254- writeJSONValue (out, macroInfo.executablePath , entryIndentLevel);
343+ writeJSONValue (out, macroInfo.executable_path , entryIndentLevel);
255344 out << " \n " ;
256345 out.indent ((indentLevel + 1 ) * 2 );
257346 out << " }" ;
@@ -368,6 +457,8 @@ void writeJSON(llvm::raw_ostream &out,
368457 /* trailingComma=*/ true );
369458 writeLinkLibraries (out, moduleInfo.link_libraries ,
370459 3 , /* trailingComma=*/ true );
460+ writeImportInfos (out, moduleInfo.imports ,
461+ 3 , /* trailingComma=*/ true );
371462 }
372463 // Swift and Clang-specific details.
373464 out.indent (3 * 2 );
0 commit comments