3636#include " clang/Lex/Preprocessor.h"
3737#include " clang/Lex/Token.h"
3838#include " clang/Tooling/Inclusions/HeaderAnalysis.h"
39+ #include " clang/Tooling/Inclusions/StandardLibrary.h"
3940#include " llvm/ADT/ArrayRef.h"
4041#include " llvm/ADT/DenseMap.h"
4142#include " llvm/ADT/SmallVector.h"
@@ -836,14 +837,25 @@ void SymbolCollector::setIncludeLocation(const Symbol &S, SourceLocation DefLoc,
836837 // Use the expansion location to get the #include header since this is
837838 // where the symbol is exposed.
838839 IncludeFiles[S.ID ] = SM.getDecomposedExpansionLoc (DefLoc).first ;
840+ }
839841
840- auto [It, Inserted] = SymbolProviders.try_emplace (S.ID );
841- if (Inserted) {
842- auto Headers =
843- include_cleaner::headersForSymbol (Sym, SM, Opts.PragmaIncludes );
844- if (!Headers.empty ())
845- It->second = Headers.front ();
846- }
842+ llvm::StringRef getStdHeader (const Symbol *S, const LangOptions &LangOpts) {
843+ tooling::stdlib::Lang Lang = tooling::stdlib::Lang::CXX;
844+ if (LangOpts.C11 )
845+ Lang = tooling::stdlib::Lang::C;
846+ else if (!LangOpts.CPlusPlus )
847+ return " " ;
848+
849+ if (S->Scope == " std::" && S->Name == " move" ) {
850+ if (!S->Signature .contains (' ,' ))
851+ return " <utility>" ;
852+ return " <algorithm>" ;
853+ }
854+
855+ if (auto StdSym = tooling::stdlib::Symbol::named (S->Scope , S->Name , Lang))
856+ if (auto Header = StdSym->header ())
857+ return Header->name ();
858+ return " " ;
847859}
848860
849861void SymbolCollector::finish () {
@@ -869,16 +881,13 @@ void SymbolCollector::finish() {
869881 }
870882 }
871883 llvm::DenseMap<FileID, bool > FileToContainsImportsOrObjC;
872- llvm::DenseMap<include_cleaner::Header, std::string> HeaderSpelling;
873884 // Fill in IncludeHeaders.
874885 // We delay this until end of TU so header guards are all resolved.
875- for (const auto &[SID, OptionalProvider ] : SymbolProviders ) {
886+ for (const auto &[SID, FID ] : IncludeFiles ) {
876887 const Symbol *S = Symbols.find (SID);
877888 if (!S)
878889 continue ;
879- assert (IncludeFiles.find (SID) != IncludeFiles.end ());
880890
881- const auto FID = IncludeFiles.at (SID);
882891 // Determine if the FID is #include'd or #import'ed.
883892 Symbol::IncludeDirective Directives = Symbol::Invalid;
884893 auto CollectDirectives = shouldCollectIncludePath (S->SymInfo .Kind );
@@ -898,54 +907,20 @@ void SymbolCollector::finish() {
898907 if (Directives == Symbol::Invalid)
899908 continue ;
900909
901- // Use the include location-based logic for Objective-C symbols.
902- if (Directives & Symbol::Import) {
903- if (auto IncludeHeader = HeaderFileURIs->getIncludeHeader (FID);
904- !IncludeHeader.empty ()) {
905- auto NewSym = *S;
906- NewSym.IncludeHeaders .push_back ({IncludeHeader, 1 , Directives});
907- Symbols.insert (NewSym);
908- }
909- // FIXME: use providers from include-cleaner library once it's polished
910- // for Objective-C.
911- continue ;
912- }
913-
914- assert (Directives == Symbol::Include);
915- // For #include's, use the providers computed by the include-cleaner
916- // library.
917- if (!OptionalProvider)
918- continue ;
919- const auto &H = *OptionalProvider;
920- const auto [SpellingIt, Inserted] = HeaderSpelling.try_emplace (H);
921- if (Inserted) {
922- auto &SM = ASTCtx->getSourceManager ();
923- if (H.kind () == include_cleaner::Header::Kind::Physical) {
924- if (auto Canonical =
925- HeaderFileURIs->mapCanonical (H.physical ()->getName ());
926- !Canonical.empty ())
927- SpellingIt->second = Canonical;
928- else if (tooling::isSelfContainedHeader (H.physical (), SM,
929- PP->getHeaderSearchInfo ()))
930- SpellingIt->second =
931- HeaderFileURIs->toURI (H.physical ()->getLastRef ());
932- } else {
933- SpellingIt->second = include_cleaner::spellHeader (
934- {H, PP->getHeaderSearchInfo (),
935- SM.getFileEntryForID (SM.getMainFileID ())});
936- }
937- }
910+ // FIXME: Use the include-cleaner library instead.
911+ llvm::StringRef IncludeHeader = getStdHeader (S, ASTCtx->getLangOpts ());
912+ if (IncludeHeader.empty ())
913+ IncludeHeader = HeaderFileURIs->getIncludeHeader (FID);
938914
939- if (!SpellingIt-> second .empty ()) {
915+ if (!IncludeHeader .empty ()) {
940916 auto NewSym = *S;
941- NewSym.IncludeHeaders .push_back ({SpellingIt-> second , 1 , Directives});
917+ NewSym.IncludeHeaders .push_back ({IncludeHeader , 1 , Directives});
942918 Symbols.insert (NewSym);
943919 }
944920 }
945921
946922 ReferencedSymbols.clear ();
947923 IncludeFiles.clear ();
948- SymbolProviders.clear ();
949924 FilesWithObjCConstructs.clear ();
950925}
951926
0 commit comments