clang-tools 6.0.0

Typedefs | Functions
clang::replace Namespace Reference

## Typedefs
typedef std::vector< clang::tooling::Range > | RangeVector
| Collection of source ranges. More...
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< clang::tooling::Replacement > > | FileToReplacementsMap
| Map mapping file name to Replacements 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, FileToReplacementsMap &GroupedReplacements, clang::SourceManager &SM)
| Deduplicate, check for conflicts, and apply all Replacements stored in `TUs`. More...
bool | mergeAndDeduplicate (const TUDiagnostics &TUs, FileToReplacementsMap &GroupedReplacements, clang::SourceManager &SM)
bool | applyAllReplacements (const std::vector< tooling::Replacement > &Replaces, Rewriter &Rewrite)
bool | applyReplacements (const FileToReplacementsMap &GroupedReplacements, clang::Rewriter &Rewrites)
| Apply all replacements in `GroupedReplacements`. More...
RangeVector | calculateChangedRanges (const std::vector< clang::tooling::Replacement > &Replacements)
| Given a collection of Replacements for a single file, produces a list of source ranges that enclose those Replacements. More...
bool | writeFiles (const clang::Rewriter &Rewrites)
| Write the contents of `FileContents` to disk. More...
bool | deleteReplacementFiles (const TUReplacementFiles &Files, clang::DiagnosticsEngine &Diagnostics)
| Delete the replacement files. More...
static void | reportConflict (const FileEntry *File, const llvm::ArrayRef< clang::tooling::Replacement > ConflictingReplacements, SourceManager &SM)
| Dumps information for a sequence of conflicting Replacements. More...
static void | deduplicate (std::vector< tooling::Replacement > &Replaces, std::vector< tooling::Range > &Conflicts)
static bool | deduplicateAndDetectConflicts (FileToReplacementsMap &Replacements, SourceManager &SM)
| Deduplicates and tests for conflicts among the replacements for each file in `Replacements`. More...

## Typedef Documentation

## ◆ FileToReplacementsMap

typedef llvm::DenseMap<const clang::FileEntry *, std::vector<clang::tooling::Replacement> > clang::replace::FileToReplacementsMap

Map mapping file name to Replacements targeting that file.

Definition at line 53 of file ApplyReplacements.h.

## ◆ RangeVector

typedef std::vector<clang::tooling::Range> clang::replace::RangeVector

Collection of source ranges.

Definition at line 39 of file ApplyReplacements.h.

## ◆ TUDiagnostics

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

Collection of TranslationUniDiagnostics.

Definition at line 48 of file ApplyReplacements.h.

## ◆ TUReplacementFiles

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

Collection of TranslationUnitReplacement files.

Definition at line 45 of file ApplyReplacements.h.

## ◆ TUReplacements

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

Collection of TranslationUnitReplacements.

Definition at line 42 of file ApplyReplacements.h.

## Function Documentation

## ◆ applyAllReplacements()

bool clang::replace::applyAllReplacements | ( | const std::vector< tooling::Replacement > & | Replaces,
|  | Rewriter & | Rewrite
| ) |  |

Definition at line 170 of file ApplyReplacements.cpp.

Referenced by applyReplacements(), and getRewrittenData().

## ◆ applyReplacements()

bool clang::replace::applyReplacements | ( | const FileToReplacementsMap & | GroupedReplacements,
|  | clang::Rewriter & | Rewrites
| ) |  |

Apply all replacements in `GroupedReplacements`.

Parameters

  [in] | GroupedReplacements | Deduplicated and conflict free Replacements to apply.
  [out] | Rewrites | The results of applying replacements will be applied to this Rewriter.

Returns
  - true If all changes were applied successfully.
  - false If a replacement failed to apply.

Definition at line 331 of file ApplyReplacements.cpp.

References applyAllReplacements().

## ◆ calculateChangedRanges()

RangeVector clang::replace::calculateChangedRanges | ( | const std::vector< clang::tooling::Replacement > & | Replacements | ) |

Given a collection of Replacements for a single file, produces a list of source ranges that enclose those Replacements.

Precondition
  Replacements[i].getOffset() <= Replacements[i+1].getOffset().

Parameters

  [in] | Replacements | Replacements from a single file.

Returns
  Collection of source ranges that enclose all given Replacements. One range is created for each replacement.

Definition at line 348 of file ApplyReplacements.cpp.

References Range.

Referenced by applyFormatting().

## ◆ 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 eatDiagnostics().

## ◆ collectReplacementsFromDirectory() [2/2]

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

Definition at line 84 of file ApplyReplacements.cpp.

References eatDiagnostics().

## ◆ deduplicate()

static void clang::replace::deduplicate | ( | std::vector< tooling::Replacement > & | Replaces,
|  | std::vector< tooling::Range > & | Conflicts
| ) |  |
| static

Definition at line 185 of file ApplyReplacements.cpp.

References Range.

## ◆ deduplicateAndDetectConflicts()

static bool clang::replace::deduplicateAndDetectConflicts | ( | FileToReplacementsMap & | Replacements,
|  | SourceManager & | SM
| ) |  |
| static

Deduplicates and tests for conflicts among the replacements for each file in `Replacements`.

Any conflicts found are reported.

Postcondition
  Replacements[i].getOffset() <= Replacements[i+1].getOffset().

Parameters

  [in,out] | Replacements | Container of all replacements grouped by file to be deduplicated and checked for conflicts.
  [in] | SM | SourceManager required for conflict reporting.

Returns
  - true if conflicts were detected
  - false if no conflicts were detected

Definition at line 252 of file ApplyReplacements.cpp.

## ◆ 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 383 of file ApplyReplacements.cpp.

## ◆ mergeAndDeduplicate() [1/2]

bool clang::replace::mergeAndDeduplicate | ( | const TUReplacements & | TUs,
|  | FileToReplacementsMap & | GroupedReplacements,
|  | clang::SourceManager & | SM
| ) |  |

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

If conflicts occur, no Replacements are applied.

Postcondition
  For all (key,value) in GroupedReplacements, value[i].getOffset() <= value[i+1].getOffset().

Parameters

  [in] | TUs | Collection of TranslationUnitReplacements or TranslationUnitDiagnostics to merge, deduplicate, and test for conflicts.
  [out] | GroupedReplacements | Container grouping all Replacements by the file they target.
  [in] | SM | SourceManager required for conflict reporting.

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

Definition at line 281 of file ApplyReplacements.cpp.

## ◆ mergeAndDeduplicate() [2/2]

bool clang::replace::mergeAndDeduplicate | ( | const TUDiagnostics & | TUs,
|  | FileToReplacementsMap & | GroupedReplacements,
|  | clang::SourceManager & | SM
| ) |  |

Definition at line 304 of file ApplyReplacements.cpp.

## ◆ reportConflict()

static void clang::replace::reportConflict | ( | const FileEntry * | File,
|  | const llvm::ArrayRef< clang::tooling::Replacement > | ConflictingReplacements,
|  | SourceManager & | SM
| ) |  |
| static

Dumps information for a sequence of conflicting Replacements.

Parameters

  [in] | File | FileEntry for the file the conflicting Replacements are for.
  [in] | ConflictingReplacements | List of conflicting Replacements.
  [in] | SM | SourceManager used for reporting.

Definition at line 134 of file ApplyReplacements.cpp.

## ◆ writeFiles()

bool clang::replace::writeFiles | ( | const clang::Rewriter & | Rewrites | ) |

Write the contents of `FileContents` to disk.

Keys of the map are filenames and values are the new contents for those files.

Parameters

  [in] | Rewrites | Rewriter containing written files to write to disk.

Definition at line 364 of file ApplyReplacements.cpp.