class JSONCompilationDatabase

Declaration

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

Description

Interface for compilation databases. A compilation database allows the user to retrieve compile command lines for the files in a project. Many implementations are enumerable, allowing all command lines to be retrieved. These can be used to run clang tools over a subset of the files in a project.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:61

Inherits from: CompilationDatabase

Member Variables

private llvm::StringMap<std::vector<CompileCommandRef>> IndexByFile
private std::vector<CompileCommandRef> AllCommands
All the compile commands in the order that they were provided in the JSON stream.
private clang::tooling::FileMatchTrie MatchTrie
private std::unique_ptr<llvm::MemoryBuffer> Database
private clang::tooling::JSONCommandLineSyntax Syntax
private llvm::SourceMgr SM
private llvm::yaml::Stream YAMLStream

Method Overview

  • private JSONCompilationDatabase(std::unique_ptr<llvm::MemoryBuffer> Database, clang::tooling::JSONCommandLineSyntax Syntax)
  • public std::vector<CompileCommand> getAllCompileCommands() const
  • public std::vector<std::string> getAllFiles() const
  • private void getCommands(ArrayRef<clang::tooling::JSONCompilationDatabase::CompileCommandRef> CommandsRef, std::vector<CompileCommand> & Commands) const
  • public std::vector<CompileCommand> getCompileCommands(llvm::StringRef FilePath) const
  • public static std::unique_ptr<JSONCompilationDatabase> loadFromBuffer(llvm::StringRef DatabaseString, std::string & ErrorMessage, clang::tooling::JSONCommandLineSyntax Syntax)
  • public static std::unique_ptr<JSONCompilationDatabase> loadFromFile(llvm::StringRef FilePath, std::string & ErrorMessage, clang::tooling::JSONCommandLineSyntax Syntax)
  • private bool parse(std::string & ErrorMessage)

Inherited from CompilationDatabase:

Methods

JSONCompilationDatabase(
    std::unique_ptr<llvm::MemoryBuffer> Database,
    clang::tooling::JSONCommandLineSyntax Syntax)

Description

Constructs a JSON compilation database on a memory buffer.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:97

Parameters

std::unique_ptr<llvm::MemoryBuffer> Database
clang::tooling::JSONCommandLineSyntax Syntax

std::vector<CompileCommand>
getAllCompileCommands() const

Description

Returns all compile commands for all the files in the compilation database.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:93

std::vector<std::string> getAllFiles() const

Description

Returns the list of all files available in the compilation database. These are the 'file' entries of the JSON objects.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:89

void getCommands(
    ArrayRef<
        clang::tooling::JSONCompilationDatabase::
            CompileCommandRef> CommandsRef,
    std::vector<CompileCommand>& Commands) const

Description

Converts the given array of CompileCommandRefs to CompileCommands.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:121

Parameters

ArrayRef<clang::tooling::JSONCompilationDatabase:: CompileCommandRef> CommandsRef
std::vector<CompileCommand>& Commands

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

Description

Returns all compile commands in which the specified file was compiled. FIXME: Currently FilePath must be an absolute path inside the source directory which does not have symlinks resolved.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:84

Parameters

llvm::StringRef FilePath

static std::unique_ptr<JSONCompilationDatabase>
loadFromBuffer(
    llvm::StringRef DatabaseString,
    std::string& ErrorMessage,
    clang::tooling::JSONCommandLineSyntax Syntax)

Description

Loads a JSON compilation database from a data buffer. Returns NULL and sets ErrorMessage if the database could not be loaded.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:75

Parameters

llvm::StringRef DatabaseString
std::string& ErrorMessage
clang::tooling::JSONCommandLineSyntax Syntax

static std::unique_ptr<JSONCompilationDatabase>
loadFromFile(
    llvm::StringRef FilePath,
    std::string& ErrorMessage,
    clang::tooling::JSONCommandLineSyntax Syntax)

Description

Loads a JSON compilation database from the specified file. Returns NULL and sets ErrorMessage if the database could not be loaded from the given file.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:68

Parameters

llvm::StringRef FilePath
std::string& ErrorMessage
clang::tooling::JSONCommandLineSyntax Syntax

bool parse(std::string& ErrorMessage)

Description

Parses the database file and creates the index. Returns whether parsing succeeded. Sets ErrorMessage if parsing failed.

Declared at: clang/include/clang/Tooling/JSONCompilationDatabase.h:106

Parameters

std::string& ErrorMessage