clang-tools 20.0.0git
Namespaces | Typedefs | Functions
clang::replace Namespace Reference

Namespaces

namespace  detail
 

Typedefs

typedef std::vector< clang::tooling::TranslationUnitReplacements > TUReplacements
 Collection of TranslationUnitReplacements.
 
typedef std::vector< std::string > TUReplacementFiles
 Collection of TranslationUnitReplacement files.
 
typedef std::vector< clang::tooling::TranslationUnitDiagnostics > TUDiagnostics
 Collection of TranslationUniDiagnostics.
 
using FileToChangesMap = llvm::DenseMap< clang::FileEntryRef, std::vector< tooling::AtomicChange > >
 Map mapping file name to a set of AtomicChange targeting that file.
 

Functions

template<typename TranslationUnits >
std::error_code collectReplacementsFromDirectory (const llvm::StringRef Directory, TranslationUnits &TUs, TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics)=delete
 Recursively descends through a directory structure rooted at Directory and attempts to deserialize *.yaml files as TranslationUnitReplacements.
 
template<>
std::error_code collectReplacementsFromDirectory (const llvm::StringRef Directory, TUReplacements &TUs, TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics)
 
template<>
std::error_code collectReplacementsFromDirectory (const llvm::StringRef Directory, TUDiagnostics &TUs, TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics)
 
bool mergeAndDeduplicate (const TUReplacements &TUs, const TUDiagnostics &TUDs, FileToChangesMap &FileChanges, clang::SourceManager &SM, bool IgnoreInsertConflict=false)
 Deduplicate, check for conflicts, and extract all Replacements stored in TUs.
 
llvm::Expected< std::string > applyChanges (StringRef File, const std::vector< tooling::AtomicChange > &Changes, const tooling::ApplyChangesSpec &Spec, DiagnosticsEngine &Diagnostics)
 Apply AtomicChange on File and rewrite it.
 
bool deleteReplacementFiles (const TUReplacementFiles &Files, clang::DiagnosticsEngine &Diagnostics)
 Delete the replacement files.
 
template<>
std::error_code collectReplacementsFromDirectory (const llvm::StringRef Directory, TUReplacements &TUs, TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics)
 
template<>
std::error_code collectReplacementsFromDirectory (const llvm::StringRef Directory, TUDiagnostics &TUs, TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics)
 
static llvm::DenseMap< FileEntryRef, std::vector< tooling::Replacement > > groupReplacements (const TUReplacements &TUs, const TUDiagnostics &TUDs, const clang::SourceManager &SM)
 Extract replacements from collected TranslationUnitReplacements and TranslationUnitDiagnostics and group them per file.
 

Typedef Documentation

◆ FileToChangesMap

using clang::replace::FileToChangesMap = typedef llvm::DenseMap<clang::FileEntryRef, std::vector<tooling::AtomicChange> >

Map mapping file name to a set of AtomicChange targeting that file.

Definition at line 43 of file ApplyReplacements.h.

◆ TUDiagnostics

typedef std::vector<clang::tooling::TranslationUnitDiagnostics> clang::replace::TUDiagnostics

Collection of TranslationUniDiagnostics.

Definition at line 40 of file ApplyReplacements.h.

◆ TUReplacementFiles

typedef std::vector<std::string> clang::replace::TUReplacementFiles

Collection of TranslationUnitReplacement files.

Definition at line 37 of file ApplyReplacements.h.

◆ TUReplacements

typedef std::vector<clang::tooling::TranslationUnitReplacements> clang::replace::TUReplacements

Collection of TranslationUnitReplacements.

Definition at line 34 of file ApplyReplacements.h.

Function Documentation

◆ applyChanges()

llvm::Expected< std::string > clang::replace::applyChanges ( StringRef  File,
const std::vector< tooling::AtomicChange > &  Changes,
const tooling::ApplyChangesSpec &  Spec,
DiagnosticsEngine &  Diagnostics 
)

Apply AtomicChange on File and rewrite it.

Parameters
[in]FilePath of the file where to apply AtomicChange.
[in]Changesto apply.
[in]SpecFor code cleanup and formatting.
[in]DiagnosticsDiagnosticsEngine used for error output.
Returns
The changed code if all changes are applied successfully; otherwise, an llvm::Error carrying llvm::StringError or an error_code.

Definition at line 246 of file ApplyReplacements.cpp.

References Changes, and Diagnostics.

Referenced by main().

◆ collectReplacementsFromDirectory() [1/5]

template<typename TranslationUnits >
std::error_code clang::replace::collectReplacementsFromDirectory ( const llvm::StringRef  Directory,
TranslationUnits &  TUs,
TUReplacementFiles TUFiles,
clang::DiagnosticsEngine &  Diagnostics 
)
delete

Recursively descends through a directory structure rooted at Directory and attempts to deserialize *.yaml files as TranslationUnitReplacements.

All docs that successfully deserialize are added to TUs.

Directories starting with '.' are ignored during traversal.

Parameters
[in]DirectoryDirectory to begin search for serialized TranslationUnitReplacements or TranslationUnitDiagnostics.
[out]TUsCollection of all found and deserialized TranslationUnitReplacements or TranslationUnitDiagnostics.
[out]TUFilesCollection of all TranslationUnitReplacement or TranslationUnitDiagnostics files found in Directory.
[in]DiagnosticsDiagnosticsEngine used for error output.
Returns
An error_code indicating success or failure in navigating the directory structure.

Referenced by main().

◆ collectReplacementsFromDirectory() [2/5]

template<>
std::error_code clang::replace::collectReplacementsFromDirectory ( const llvm::StringRef  Directory,
TUDiagnostics TUs,
TUReplacementFiles TUFiles,
clang::DiagnosticsEngine &  Diagnostics 
)

◆ collectReplacementsFromDirectory() [3/5]

template<>
std::error_code clang::replace::collectReplacementsFromDirectory ( const llvm::StringRef  Directory,
TUDiagnostics TUs,
TUReplacementFiles TUFiles,
clang::DiagnosticsEngine &  Diagnostics 
)

◆ collectReplacementsFromDirectory() [4/5]

template<>
std::error_code clang::replace::collectReplacementsFromDirectory ( const llvm::StringRef  Directory,
TUReplacements TUs,
TUReplacementFiles TUFiles,
clang::DiagnosticsEngine &  Diagnostics 
)

◆ collectReplacementsFromDirectory() [5/5]

template<>
std::error_code clang::replace::collectReplacementsFromDirectory ( const llvm::StringRef  Directory,
TUReplacements TUs,
TUReplacementFiles TUFiles,
clang::DiagnosticsEngine &  Diagnostics 
)

◆ deleteReplacementFiles()

bool clang::replace::deleteReplacementFiles ( const TUReplacementFiles Files,
clang::DiagnosticsEngine &  Diagnostics 
)

Delete the replacement files.

Parameters
[in]FilesReplacement files to delete.
[in]DiagnosticsDiagnosticsEngine used for error output.
Returns
  • true If all files have been deleted successfully.
  • false If at least one or more failures occur when deleting files.

Definition at line 260 of file ApplyReplacements.cpp.

References Error, and Filename.

◆ groupReplacements()

static llvm::DenseMap< FileEntryRef, std::vector< tooling::Replacement > > clang::replace::groupReplacements ( const TUReplacements TUs,
const TUDiagnostics TUDs,
const clang::SourceManager &  SM 
)
static

Extract replacements from collected TranslationUnitReplacements and TranslationUnitDiagnostics and group them per file.

Identical replacements from diagnostics are deduplicated.

Parameters
[in]TUsCollection of all found and deserialized TranslationUnitReplacements.
[in]TUDsCollection of all found and deserialized TranslationUnitDiagnostics.
[in]SMUsed to deduplicate paths.
Returns
A map mapping FileEntry to a set of Replacement targeting that file.

Definition at line 123 of file ApplyReplacements.cpp.

References BuildDir, Fix(), Path, and Replaces.

Referenced by mergeAndDeduplicate().

◆ mergeAndDeduplicate()

bool clang::replace::mergeAndDeduplicate ( const TUReplacements TUs,
const TUDiagnostics TUDs,
FileToChangesMap FileChanges,
clang::SourceManager &  SM,
bool  IgnoreInsertConflict = false 
)

Deduplicate, check for conflicts, and extract all Replacements stored in TUs.

Conflicting replacements are skipped.

Postcondition
For all (key,value) in FileChanges, value[i].getOffset() <= value[i+1].getOffset().
Parameters
[in]TUsCollection of TranslationUnitReplacements or TranslationUnitDiagnostics to merge, deduplicate, and test for conflicts.
[out]FileChangesContainer grouping all changes by the file they target. Only non conflicting replacements are kept into FileChanges.
[in]SMSourceManager required for conflict reporting.
Returns
  • true If all changes were converted successfully.
  • false If there were conflicts.

Definition at line 187 of file ApplyReplacements.cpp.

References groupReplacements(), and IgnoreInsertConflict().

Referenced by main().