@@ -112,11 +112,22 @@ class HeaderIncludesJSONCallback : public PPCallbacks {
112
112
// / an array of separate entries, one for each non-system source file used in
113
113
// / the compilation showing only the direct includes and imports from that file.
114
114
class HeaderIncludesDirectPerFileCallback : public PPCallbacks {
115
+ struct HeaderIncludeInfo {
116
+ SourceLocation Location;
117
+ FileEntryRef File;
118
+ const Module *ImportedModule;
119
+
120
+ HeaderIncludeInfo (SourceLocation Location, FileEntryRef File,
121
+ const Module *ImportedModule)
122
+ : Location(Location), File(File), ImportedModule(ImportedModule) {}
123
+ };
124
+
115
125
SourceManager &SM;
116
126
HeaderSearch &HSI;
117
127
raw_ostream *OutputFile;
118
128
bool OwnsOutputFile;
119
- using DependencyMap = llvm::DenseMap<FileEntryRef, SmallVector<FileEntryRef>>;
129
+ using DependencyMap =
130
+ llvm::DenseMap<FileEntryRef, SmallVector<HeaderIncludeInfo>>;
120
131
DependencyMap Dependencies;
121
132
122
133
public:
@@ -295,8 +306,8 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
295
306
}
296
307
}
297
308
298
- void HeaderIncludesCallback::FileSkipped (const FileEntryRef &SkippedFile, const
299
- Token &FilenameTok,
309
+ void HeaderIncludesCallback::FileSkipped (const FileEntryRef &SkippedFile,
310
+ const Token &FilenameTok,
300
311
SrcMgr::CharacteristicKind FileType) {
301
312
if (!DepOpts.ShowSkippedHeaderIncludes )
302
313
return ;
@@ -390,18 +401,41 @@ void HeaderIncludesDirectPerFileCallback::EndOfMainFile() {
390
401
std::string Str;
391
402
llvm::raw_string_ostream OS (Str);
392
403
llvm::json::OStream JOS (OS);
393
- JOS.array ([&] {
394
- for (auto S = SourceFiles.begin (), SE = SourceFiles.end (); S != SE; ++S) {
395
- JOS.object ([&] {
396
- SmallVector<FileEntryRef> &Deps = Dependencies[*S];
397
- JOS.attribute (" source" , S->getName ().str ());
398
- JOS.attributeArray (" includes" , [&] {
399
- for (unsigned I = 0 , N = Deps.size (); I != N; ++I)
400
- JOS.value (Deps[I].getName ().str ());
404
+ JOS.object ([&] {
405
+ JOS.attribute (" version" , " 2.0.0" );
406
+ JOS.attributeArray (" dependencies" , [&] {
407
+ for (const auto &S : SourceFiles) {
408
+ JOS.object ([&] {
409
+ SmallVector<HeaderIncludeInfo> &Deps = Dependencies[S];
410
+ JOS.attribute (" source" , S.getName ().str ());
411
+ JOS.attributeArray (" includes" , [&] {
412
+ for (unsigned I = 0 , N = Deps.size (); I != N; ++I) {
413
+ if (!Deps[I].ImportedModule ) {
414
+ JOS.object ([&] {
415
+ JOS.attribute (" location" , Deps[I].Location .printToString (SM));
416
+ JOS.attribute (" file" , Deps[I].File .getName ());
417
+ });
418
+ }
419
+ }
420
+ });
421
+ JOS.attributeArray (" imports" , [&] {
422
+ for (unsigned I = 0 , N = Deps.size (); I != N; ++I) {
423
+ if (Deps[I].ImportedModule ) {
424
+ JOS.object ([&] {
425
+ JOS.attribute (" location" , Deps[I].Location .printToString (SM));
426
+ JOS.attribute (
427
+ " module" ,
428
+ Deps[I].ImportedModule ->getTopLevelModuleName ());
429
+ JOS.attribute (" file" , Deps[I].File .getName ());
430
+ });
431
+ }
432
+ }
433
+ });
401
434
});
402
- });
403
- }
435
+ }
436
+ });
404
437
});
438
+
405
439
OS << " \n " ;
406
440
407
441
if (OutputFile->get_kind () == raw_ostream::OStreamKind::OK_FDStream) {
@@ -427,7 +461,18 @@ void HeaderIncludesDirectPerFileCallback::InclusionDirective(
427
461
if (!FromFile)
428
462
return ;
429
463
430
- Dependencies[*FromFile].push_back (*File);
464
+ FileEntryRef HeaderOrModuleMapFile = *File;
465
+ if (ModuleImported && SuggestedModule) {
466
+ OptionalFileEntryRef ModuleMapFile =
467
+ HSI.getModuleMap ().getModuleMapFileForUniquing (SuggestedModule);
468
+ if (ModuleMapFile) {
469
+ HeaderOrModuleMapFile = *ModuleMapFile;
470
+ }
471
+ }
472
+
473
+ HeaderIncludeInfo DependenciesEntry (
474
+ Loc, HeaderOrModuleMapFile, (ModuleImported ? SuggestedModule : nullptr ));
475
+ Dependencies[*FromFile].push_back (DependenciesEntry);
431
476
}
432
477
433
478
void HeaderIncludesDirectPerFileCallback::moduleImport (SourceLocation ImportLoc,
@@ -448,5 +493,6 @@ void HeaderIncludesDirectPerFileCallback::moduleImport(SourceLocation ImportLoc,
448
493
if (!ModuleMapFile)
449
494
return ;
450
495
451
- Dependencies[*FromFile].push_back (*ModuleMapFile);
496
+ HeaderIncludeInfo DependenciesEntry (Loc, *ModuleMapFile, Imported);
497
+ Dependencies[*FromFile].push_back (DependenciesEntry);
452
498
}
0 commit comments