clang-tools  14.0.0git
Public Types | Public Member Functions | Static Public Member Functions | List of all members
clang::clangd::PreamblePatch Class Reference

Stores information required to parse a TU using a (possibly stale) Baseline preamble. More...

#include <Preamble.h>

Public Types

enum  PatchType { PatchType::MacroDirectives, PatchType::All }
 

Public Member Functions

void apply (CompilerInvocation &CI) const
 Adjusts CI (which compiles the modified inputs) to be used with the baseline preamble. More...
 
std::vector< InclusionpreambleIncludes () const
 Returns #include directives from the Modified preamble that were resolved using the Baseline preamble. More...
 
PreambleBounds modifiedBounds () const
 Returns preamble bounds for the Modified. More...
 
llvm::StringRef text () const
 Returns textual patch contents. More...
 
bool preserveDiagnostics () const
 Whether diagnostics generated using this patch are trustable. More...
 

Static Public Member Functions

static PreamblePatch unmodified (const PreambleData &Preamble)
 Preamble is used verbatim. More...
 
static PreamblePatch createFullPatch (llvm::StringRef FileName, const ParseInputs &Modified, const PreambleData &Baseline)
 Builds a patch that contains new PP directives introduced to the preamble section of Modified compared to Baseline. More...
 
static PreamblePatch createMacroPatch (llvm::StringRef FileName, const ParseInputs &Modified, const PreambleData &Baseline)
 

Detailed Description

Stores information required to parse a TU using a (possibly stale) Baseline preamble.

Later on this information can be injected into the main file by updating compiler invocation with apply. This injected section approximately reflects additions to the preamble in Modified contents, e.g. new include directives.

Definition at line 100 of file Preamble.h.

Member Enumeration Documentation

◆ PatchType

Enumerator
MacroDirectives 
All 

Definition at line 102 of file Preamble.h.

Member Function Documentation

◆ apply()

void clang::clangd::PreamblePatch::apply ( CompilerInvocation &  CI) const

Adjusts CI (which compiles the modified inputs) to be used with the baseline preamble.

This is done by inserting an artifical include to the CI that contains new directives calculated in create.

Definition at line 553 of file Preamble.cpp.

References CI.

◆ createFullPatch()

PreamblePatch clang::clangd::PreamblePatch::createFullPatch ( llvm::StringRef  FileName,
const ParseInputs Modified,
const PreambleData Baseline 
)
static

Builds a patch that contains new PP directives introduced to the preamble section of Modified compared to Baseline.

FIXME: This only handles include directives, we should at least handle define/undef.

Definition at line 541 of file Preamble.cpp.

References All, and FileName.

◆ createMacroPatch()

PreamblePatch clang::clangd::PreamblePatch::createMacroPatch ( llvm::StringRef  FileName,
const ParseInputs Modified,
const PreambleData Baseline 
)
static

Definition at line 547 of file Preamble.cpp.

References FileName, and MacroDirectives.

◆ modifiedBounds()

PreambleBounds clang::clangd::PreamblePatch::modifiedBounds ( ) const
inline

Returns preamble bounds for the Modified.

Definition at line 130 of file Preamble.h.

◆ preambleIncludes()

std::vector< Inclusion > clang::clangd::PreamblePatch::preambleIncludes ( ) const

Returns #include directives from the Modified preamble that were resolved using the Baseline preamble.

This covers the new locations of inclusions that were moved around, but not inclusions of new files. Those will be recorded when parsing the main file: the includes in the injected section will be resolved back to their spelled positions in the main file using the presumed-location mechanism.

Definition at line 569 of file Preamble.cpp.

◆ preserveDiagnostics()

bool clang::clangd::PreamblePatch::preserveDiagnostics ( ) const
inline

Whether diagnostics generated using this patch are trustable.

Definition at line 136 of file Preamble.h.

◆ text()

llvm::StringRef clang::clangd::PreamblePatch::text ( ) const
inline

Returns textual patch contents.

Definition at line 133 of file Preamble.h.

◆ unmodified()

PreamblePatch clang::clangd::PreamblePatch::unmodified ( const PreambleData Preamble)
static

Preamble is used verbatim.

Definition at line 573 of file Preamble.cpp.

References clang::tidy::bugprone::PP, and Preamble.


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