diff options
author | ZhaoQi <zhaoqi01@loongson.cn> | 2025-09-26 10:45:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-26 10:45:29 +0800 |
commit | 4321d4fe8039a745796726dfe145e5e699b928b3 (patch) | |
tree | 589d406b275c99425ea9c7ee22776e9920d7de4f /clang/lib/Frontend/HeaderIncludeGen.cpp | |
parent | d516d07c268f260e245690f89ab0f3e727389cb5 (diff) | |
parent | ef876268b97d664a90dc0d9a044f518557270e3d (diff) | |
download | llvm-users/zhaoqi5/override-isxxxcheap-hooks.zip llvm-users/zhaoqi5/override-isxxxcheap-hooks.tar.gz llvm-users/zhaoqi5/override-isxxxcheap-hooks.tar.bz2 |
Merge branch 'users/zhaoqi5/test-isxxxcheap' into users/zhaoqi5/override-isxxxcheap-hooksusers/zhaoqi5/override-isxxxcheap-hooks
Diffstat (limited to 'clang/lib/Frontend/HeaderIncludeGen.cpp')
-rw-r--r-- | clang/lib/Frontend/HeaderIncludeGen.cpp | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp b/clang/lib/Frontend/HeaderIncludeGen.cpp index 8ab3359..7cd9c8a3 100644 --- a/clang/lib/Frontend/HeaderIncludeGen.cpp +++ b/clang/lib/Frontend/HeaderIncludeGen.cpp @@ -112,11 +112,22 @@ public: /// an array of separate entries, one for each non-system source file used in /// the compilation showing only the direct includes and imports from that file. class HeaderIncludesDirectPerFileCallback : public PPCallbacks { + struct HeaderIncludeInfo { + SourceLocation Location; + FileEntryRef File; + const Module *ImportedModule; + + HeaderIncludeInfo(SourceLocation Location, FileEntryRef File, + const Module *ImportedModule) + : Location(Location), File(File), ImportedModule(ImportedModule) {} + }; + SourceManager &SM; HeaderSearch &HSI; raw_ostream *OutputFile; bool OwnsOutputFile; - using DependencyMap = llvm::DenseMap<FileEntryRef, SmallVector<FileEntryRef>>; + using DependencyMap = + llvm::DenseMap<FileEntryRef, SmallVector<HeaderIncludeInfo>>; DependencyMap Dependencies; public: @@ -295,8 +306,8 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc, } } -void HeaderIncludesCallback::FileSkipped(const FileEntryRef &SkippedFile, const - Token &FilenameTok, +void HeaderIncludesCallback::FileSkipped(const FileEntryRef &SkippedFile, + const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) { if (!DepOpts.ShowSkippedHeaderIncludes) return; @@ -390,18 +401,41 @@ void HeaderIncludesDirectPerFileCallback::EndOfMainFile() { std::string Str; llvm::raw_string_ostream OS(Str); llvm::json::OStream JOS(OS); - JOS.array([&] { - for (auto S = SourceFiles.begin(), SE = SourceFiles.end(); S != SE; ++S) { - JOS.object([&] { - SmallVector<FileEntryRef> &Deps = Dependencies[*S]; - JOS.attribute("source", S->getName().str()); - JOS.attributeArray("includes", [&] { - for (unsigned I = 0, N = Deps.size(); I != N; ++I) - JOS.value(Deps[I].getName().str()); + JOS.object([&] { + JOS.attribute("version", "2.0.0"); + JOS.attributeArray("dependencies", [&] { + for (const auto &S : SourceFiles) { + JOS.object([&] { + SmallVector<HeaderIncludeInfo> &Deps = Dependencies[S]; + JOS.attribute("source", S.getName().str()); + JOS.attributeArray("includes", [&] { + for (unsigned I = 0, N = Deps.size(); I != N; ++I) { + if (!Deps[I].ImportedModule) { + JOS.object([&] { + JOS.attribute("location", Deps[I].Location.printToString(SM)); + JOS.attribute("file", Deps[I].File.getName()); + }); + } + } + }); + JOS.attributeArray("imports", [&] { + for (unsigned I = 0, N = Deps.size(); I != N; ++I) { + if (Deps[I].ImportedModule) { + JOS.object([&] { + JOS.attribute("location", Deps[I].Location.printToString(SM)); + JOS.attribute( + "module", + Deps[I].ImportedModule->getTopLevelModuleName()); + JOS.attribute("file", Deps[I].File.getName()); + }); + } + } + }); }); - }); - } + } + }); }); + OS << "\n"; if (OutputFile->get_kind() == raw_ostream::OStreamKind::OK_FDStream) { @@ -427,7 +461,18 @@ void HeaderIncludesDirectPerFileCallback::InclusionDirective( if (!FromFile) return; - Dependencies[*FromFile].push_back(*File); + FileEntryRef HeaderOrModuleMapFile = *File; + if (ModuleImported && SuggestedModule) { + OptionalFileEntryRef ModuleMapFile = + HSI.getModuleMap().getModuleMapFileForUniquing(SuggestedModule); + if (ModuleMapFile) { + HeaderOrModuleMapFile = *ModuleMapFile; + } + } + + HeaderIncludeInfo DependenciesEntry( + Loc, HeaderOrModuleMapFile, (ModuleImported ? SuggestedModule : nullptr)); + Dependencies[*FromFile].push_back(DependenciesEntry); } void HeaderIncludesDirectPerFileCallback::moduleImport(SourceLocation ImportLoc, @@ -448,5 +493,6 @@ void HeaderIncludesDirectPerFileCallback::moduleImport(SourceLocation ImportLoc, if (!ModuleMapFile) return; - Dependencies[*FromFile].push_back(*ModuleMapFile); + HeaderIncludeInfo DependenciesEntry(Loc, *ModuleMapFile, Imported); + Dependencies[*FromFile].push_back(DependenciesEntry); } |