clang 20.0.0git
Namespaces | Functions | Variables
CompilationDatabase.cpp File Reference
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/LLVM.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Job.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Tooling/CompilationDatabasePluginRegistry.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/Arg.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iterator>
#include <memory>
#include <sstream>
#include <string>
#include <system_error>
#include <utility>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  clang
 The JSON file list parser is used to communicate input to InstallAPI.
 
namespace  clang::tooling
 

Functions

static std::unique_ptr< CompilationDatabasefindCompilationDatabaseFromDirectory (StringRef Directory, std::string &ErrorMessage)
 
static bool stripPositionalArgs (std::vector< const char * > Args, std::vector< std::string > &Result, std::string &ErrorMsg)
 Strips any positional args and possible argv[0] from a command-line provided by the user to construct a FixedCompilationDatabase.
 
static CompilationDatabasePluginRegistry::Add< FixedCompilationDatabasePlugin > X ("fixed-compilation-database", "Reads plain-text flags file")
 

Variables

volatile int clang::tooling::JSONAnchorSource = 0
 
static int LLVM_ATTRIBUTE_UNUSED clang::tooling::JSONAnchorDest = JSONAnchorSource
 

Function Documentation

◆ findCompilationDatabaseFromDirectory()

static std::unique_ptr< CompilationDatabase > findCompilationDatabaseFromDirectory ( StringRef  Directory,
std::string &  ErrorMessage 
)
static

◆ stripPositionalArgs()

static bool stripPositionalArgs ( std::vector< const char * >  Args,
std::vector< std::string > &  Result,
std::string &  ErrorMsg 
)
static

Strips any positional args and possible argv[0] from a command-line provided by the user to construct a FixedCompilationDatabase.

FixedCompilationDatabase requires a command line to be in this format as it constructs the command line for each file by appending the name of the file to be compiled. FixedCompilationDatabase also adds its own argv[0] to the start of the command line although its value is not important as it's just ignored by the Driver invoked by the ClangTool using the FixedCompilationDatabase.

FIXME: This functionality should probably be made available by clang::driver::Driver although what the interface should look like is not clear.

Parameters
[in]ArgsArgs as provided by the user.
Returns
Resulting stripped command line.
  • true if successful.
  • false if Args cannot be used for compilation jobs (e.g. contains an option like -E or -version).

Definition at line 243 of file CompilationDatabase.cpp.

References clang::driver::Action::AssembleJobClass, clang::driver::Action::BackendJobClass, Cmd, clang::driver::Action::CompileJobClass, clang::driver::JobList::getJobs(), clang::driver::Action::PrecompileJobClass, and clang::Result.

Referenced by clang::tooling::FixedCompilationDatabase::loadFromCommandLine().

◆ X()

static CompilationDatabasePluginRegistry::Add< FixedCompilationDatabasePlugin > X ( "fixed-compilation-database"  ,
"Reads plain-text flags file"   
)
static