class FixedCompilationDatabase

Declaration

class FixedCompilationDatabase : public CompilationDatabase { /* full declaration omitted */ };

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 {}.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:154

Inherits from: CompilationDatabase

Member Variables

private std::vector<CompileCommand> CompileCommands
This is built up to contain a single entry vector to be returned from getCompileCommands after adding the positional argument.

Method Overview

  • public FixedCompilationDatabase(const llvm::Twine & Directory, ArrayRef<std::string> CommandLine)
  • public std::vector<CompileCommand> getCompileCommands(llvm::StringRef FilePath) const
  • public static std::unique_ptr<FixedCompilationDatabase> loadFromBuffer(llvm::StringRef Directory, llvm::StringRef Data, std::string & ErrorMsg)
  • public static std::unique_ptr<FixedCompilationDatabase> loadFromCommandLine(int & Argc, const char *const * Argv, std::string & ErrorMsg, const llvm::Twine & Directory = ".")
  • public static std::unique_ptr<FixedCompilationDatabase> loadFromFile(llvm::StringRef Path, std::string & ErrorMsg)

Inherited from CompilationDatabase:

Methods

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

Description

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

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:199

Parameters

const llvm::Twine& Directory
ArrayRef<std::string> CommandLine

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

Description

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.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:208

Parameters

llvm::StringRef FilePath

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

Description

Reads flags from the given buffer, one-per-line. Directory is the command CWD, typically the parent of compile_flags.txt.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:195

Parameters

llvm::StringRef Directory
llvm::StringRef Data
std::string& ErrorMsg

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

Description

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); ... }

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:184

Parameters

int& Argc
The number of command line arguments - will be changed to the number of arguments before "--", if "--" was found in the argument list.
const char* const* Argv
Points to the command line arguments.
std::string& ErrorMsg
Contains error text if the function returns null pointer.
const llvm::Twine& Directory = "."
The base directory used in the FixedCompilationDatabase.

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

Description

Reads flags from the given file, one-per-line. Returns nullptr and sets ErrorMessage if we can't read the file.

Declared at: clang/include/clang/Tooling/CompilationDatabase.h:190

Parameters

llvm::StringRef Path
std::string& ErrorMsg