clang-tools 23.0.0git
clang::clangd::CompileCommandsProjectModules Class Reference

Reads project module information directly from compile commands. More...

Inheritance diagram for clang::clangd::CompileCommandsProjectModules:
[legend]

Public Member Functions

 CompileCommandsProjectModules (std::shared_ptr< const clang::tooling::CompilationDatabase > CDB, const ThreadsafeFS &TFS)
std::vector< std::string > getRequiredModules (PathRef File) override
std::string getModuleNameForSource (PathRef File) override
ModuleNameState getModuleNameState (llvm::StringRef ModuleName) override
std::string getSourceForModuleName (llvm::StringRef ModuleName, PathRef RequiredSourceFile) override
void setCommandMangler (CommandMangler Mangler) override
Public Member Functions inherited from clang::clangd::ProjectModules
virtual ~ProjectModules ()=default

Additional Inherited Members

Public Types inherited from clang::clangd::ProjectModules
enum class  ModuleNameState { Unknown , Unique , Multiple }
using CommandMangler

Detailed Description

Reads project module information directly from compile commands.

The key observation is that compile commands may already encode the mapping between a TU, the module names it imports, and the BMI paths it uses:

  • producers may spell the BMI path with --precompile -o <bmi> or -fmodule-output=<bmi>
  • consumers may spell the mapping from module name to BMI path with -fmodule-file=<module>=<bmi>

When that information is present, we can answer getSourceForModuleName(ModuleName, RequiredSourceFile) by first looking up the BMI path the consumer TU uses for ModuleName, and then mapping that BMI path back to the module unit source that produced it. This avoids the older scanning-only approach of guessing the module unit from the module name alone.

One subtle point is that producer commands alone do not reliably tell us the module name associated with a BMI path. In practice this backend learns that association from consumer -fmodule-file= entries, and then uses the BMI path to recover the producer source file. That is why indexing is built from both producer and consumer commands.

Note that compilation database can be stale, so results from this backend should be treated as preferred hints rather than unquestionable truth. The compound layer below validates or falls back when needed.

Definition at line 374 of file ProjectModules.cpp.

Constructor & Destructor Documentation

◆ CompileCommandsProjectModules()

clang::clangd::CompileCommandsProjectModules::CompileCommandsProjectModules ( std::shared_ptr< const clang::tooling::CompilationDatabase > CDB,
const ThreadsafeFS & TFS )
inline

Definition at line 376 of file ProjectModules.cpp.

Member Function Documentation

◆ getModuleNameForSource()

std::string clang::clangd::CompileCommandsProjectModules::getModuleNameForSource ( PathRef File)
inlineoverridevirtual

◆ getModuleNameState()

ModuleNameState clang::clangd::CompileCommandsProjectModules::getModuleNameState ( llvm::StringRef ModuleName)
inlineoverridevirtual

◆ getRequiredModules()

std::vector< std::string > clang::clangd::CompileCommandsProjectModules::getRequiredModules ( PathRef File)
inlineoverridevirtual

Implements clang::clangd::ProjectModules.

Definition at line 381 of file ProjectModules.cpp.

References clang::clangd::File.

◆ getSourceForModuleName()

std::string clang::clangd::CompileCommandsProjectModules::getSourceForModuleName ( llvm::StringRef ModuleName,
PathRef RequiredSourceFile )
inlineoverridevirtual

Implements clang::clangd::ProjectModules.

Definition at line 411 of file ProjectModules.cpp.

References clang::clangd::maybeCaseFoldPath().

◆ setCommandMangler()

void clang::clangd::CompileCommandsProjectModules::setCommandMangler ( CommandMangler Mangler)
inlineoverridevirtual

Reimplemented from clang::clangd::ProjectModules.

Definition at line 429 of file ProjectModules.cpp.


The documentation for this class was generated from the following file: