clang-tools 10.0.0

Typedefs | Functions
clang::replace Namespace Reference

## Typedefs
typedef std::vector< clang::tooling::TranslationUnitReplacements > | TUReplacements
| Collection of TranslationUnitReplacements. More...
typedef std::vector< std::string > | TUReplacementFiles
| Collection of TranslationUnitReplacement files. More...
typedef std::vector< clang::tooling::TranslationUnitDiagnostics > | TUDiagnostics
| Collection of TranslationUniDiagnostics. More...
typedef llvm::DenseMap< const clang::FileEntry *, std::vector< tooling::AtomicChange > > | FileToChangesMap
| Map mapping file name to a set of AtomicChange targeting that file. More...

## Functions
std::error_code | collectReplacementsFromDirectory (const llvm::StringRef Directory, TUReplacements &TUs, TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics)
| Recursively descends through a directory structure rooted at `Directory` and attempts to deserialize *.yaml files as TranslationUnitReplacements. More...
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)
| Deduplicate, check for conflicts, and extract all Replacements stored in `TUs`. More...
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. More...
bool | deleteReplacementFiles (const TUReplacementFiles &Files, clang::DiagnosticsEngine &Diagnostics)
| Delete the replacement files. More...
static llvm::DenseMap< const FileEntry *, 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. More...

## Typedef Documentation

## ◆ FileToChangesMap

typedef llvm::DenseMap<const clang::FileEntry *, std::vector<tooling::AtomicChange> > clang::replace::FileToChangesMap

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

Definition at line 46 of file ApplyReplacements.h.

## ◆ TUDiagnostics

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

Collection of TranslationUniDiagnostics.

Definition at line 41 of file ApplyReplacements.h.

## ◆ TUReplacementFiles

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

Collection of TranslationUnitReplacement files.

Definition at line 38 of file ApplyReplacements.h.

## ◆ TUReplacements

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

Collection of TranslationUnitReplacements.

Definition at line 35 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] | File | Path of the file where to apply AtomicChange.
  [in] | Changes | to apply.
  [in] | Spec | For code cleanup and formatting.
  [in] | Diagnostics | DiagnosticsEngine 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 231 of file ApplyReplacements.cpp.

References Files.

## ◆ collectReplacementsFromDirectory() [1/2]

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

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] | Directory | Directory to begin search for serialized TranslationUnitReplacements.
  [out] | TUs | Collection of all found and deserialized TranslationUnitReplacements or TranslationUnitDiagnostics.
  [out] | TUFiles | Collection of all TranslationUnitReplacement files found in `Directory`.
  [in] | Diagnostics | DiagnosticsEngine used for error output.

Returns
  An error_code indicating success or failure in navigating the directory structure.

Definition at line 39 of file ApplyReplacements.cpp.

References E.

## ◆ collectReplacementsFromDirectory() [2/2]

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

Definition at line 83 of file ApplyReplacements.cpp.

References E.

## ◆ deleteReplacementFiles()

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

Delete the replacement files.

Parameters

  [in] | Files | Replacement files to delete.
  [in] | Diagnostics | DiagnosticsEngine 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 245 of file ApplyReplacements.cpp.

References Filename.

## ◆ groupReplacements()

static llvm::DenseMap<const FileEntry *, 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] | TUs | Collection of all found and deserialized TranslationUnitReplacements.
  [in] | TUDs | Collection of all found and deserialized TranslationUnitDiagnostics.
  [in] | SM | Used to deduplicate paths.

Returns
  A map mapping FileEntry to a set of Replacement targeting that file.

Definition at line 140 of file ApplyReplacements.cpp.

## ◆ mergeAndDeduplicate()

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

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] | TUs | Collection of TranslationUnitReplacements or TranslationUnitDiagnostics to merge, deduplicate, and test for conflicts.
  [out] | FileChanges | Container grouping all changes by the file they target. Only non conflicting replacements are kept into FileChanges.
  [in] | SM | SourceManager required for conflict reporting.

Returns
  - true If all changes were converted successfully.
  - false If there were conflicts.

Definition at line 189 of file ApplyReplacements.cpp.