clang 22.0.0git
clang::tooling::FixedCompilationDatabase Class Reference

A compilation database that returns a single compile command line. More...

#include "clang/Tooling/CompilationDatabase.h"

Inheritance diagram for clang::tooling::FixedCompilationDatabase:
[legend]

Public Member Functions

 FixedCompilationDatabase (const Twine &Directory, ArrayRef< std::string > CommandLine)
 Constructs a compilation data base from a specified directory and command line.
std::vector< CompileCommandgetCompileCommands (StringRef FilePath) const override
 Returns the given compile command.
Public Member Functions inherited from clang::tooling::CompilationDatabase
virtual ~CompilationDatabase ()
virtual std::vector< std::string > getAllFiles () const
 Returns the list of all files available in the compilation database.
virtual std::vector< CompileCommandgetAllCompileCommands () const
 Returns all compile commands for all the files in the compilation database.

Static Public Member Functions

static std::unique_ptr< FixedCompilationDatabaseloadFromCommandLine (int &Argc, const char *const *Argv, std::string &ErrorMsg, const Twine &Directory=".")
 Creates a FixedCompilationDatabase from the arguments after "--".
static std::unique_ptr< FixedCompilationDatabaseloadFromFile (StringRef Path, std::string &ErrorMsg)
 Reads flags from the given file, one-per-line.
static std::unique_ptr< FixedCompilationDatabaseloadFromBuffer (StringRef Directory, StringRef Data, std::string &ErrorMsg)
 Reads flags from the given buffer, one-per-line.
Static Public Member Functions inherited from clang::tooling::CompilationDatabase
static std::unique_ptr< CompilationDatabaseloadFromDirectory (StringRef BuildDirectory, std::string &ErrorMessage)
 Loads a compilation database from a build directory.
static std::unique_ptr< CompilationDatabaseautoDetectFromSource (StringRef SourceFile, std::string &ErrorMessage)
 Tries to detect a compilation database location and load it.
static std::unique_ptr< CompilationDatabaseautoDetectFromDirectory (StringRef SourceDir, std::string &ErrorMessage)
 Tries to detect a compilation database location and load it.

Detailed Description

A compilation database that returns a single compile command line.

Useful when we want a tool to behave more like a compiler invocation. This compilation database is not enumerable: getAllFiles() returns {}.

Definition at line 154 of file CompilationDatabase.h.

Constructor & Destructor Documentation

◆ FixedCompilationDatabase()

FixedCompilationDatabase::FixedCompilationDatabase ( const Twine & Directory,
ArrayRef< std::string > CommandLine )

Constructs a compilation data base from a specified directory and command line.

Definition at line 366 of file CompilationDatabase.cpp.

Member Function Documentation

◆ getCompileCommands()

std::vector< CompileCommand > FixedCompilationDatabase::getCompileCommands ( StringRef FilePath) const
overridevirtual

Returns the given compile command.

Will always return a vector with one entry that contains the directory and command line specified at construction with "clang-tool" as argv[0] and 'FilePath' as positional argument.

Implements clang::tooling::CompilationDatabase.

Definition at line 377 of file CompilationDatabase.cpp.

References clang::Result.

◆ loadFromBuffer()

std::unique_ptr< FixedCompilationDatabase > FixedCompilationDatabase::loadFromBuffer ( StringRef Directory,
StringRef Data,
std::string & ErrorMsg )
static

Reads flags from the given buffer, one-per-line.

Directory is the command CWD, typically the parent of compile_flags.txt.

Definition at line 351 of file CompilationDatabase.cpp.

References clang::Data, and clang::Line.

Referenced by loadFromFile().

◆ loadFromCommandLine()

std::unique_ptr< FixedCompilationDatabase > FixedCompilationDatabase::loadFromCommandLine ( int & Argc,
const char *const * Argv,
std::string & ErrorMsg,
const Twine & Directory = "." )
static

Creates a FixedCompilationDatabase from the arguments after "--".

Parses the given command line for "--". If "--" is found, the rest of the arguments will make up the command line in the returned FixedCompilationDatabase. The arguments after "--" must not include positional parameters or the argv[0] of the tool. Those will be added by the FixedCompilationDatabase when a CompileCommand is requested. The argv[0] of the returned command line will be "clang-tool".

Returns NULL in case "--" is not found.

The argument list is meant to be compatible with normal llvm command line parsing in main methods. int main(int argc, char **argv) { std::unique_ptr<FixedCompilationDatabase> Compilations( FixedCompilationDatabase::loadFromCommandLine(argc, argv)); cl::ParseCommandLineOptions(argc, argv); ... }

Parameters
ArgcThe number of command line arguments - will be changed to the number of arguments before "--", if "--" was found in the argument list.
ArgvPoints to the command line arguments.
ErrorMsgContains error text if the function returns null pointer.
DirectoryThe base directory used in the FixedCompilationDatabase.

Definition at line 318 of file CompilationDatabase.cpp.

References stripPositionalArgs().

◆ loadFromFile()

std::unique_ptr< FixedCompilationDatabase > FixedCompilationDatabase::loadFromFile ( StringRef Path,
std::string & ErrorMsg )
static

Reads flags from the given file, one-per-line.

Returns nullptr and sets ErrorMessage if we can't read the file.

Definition at line 338 of file CompilationDatabase.cpp.

References clang::File, loadFromBuffer(), and clang::Result.


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