clang-tools  5.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

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.

Collection of source ranges.

Definition at line 39 of file ApplyReplacements.h.

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

Collection of TranslationUniDiagnostics.

Definition at line 48 of file ApplyReplacements.h.

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

Collection of TranslationUnitReplacement files.

Definition at line 45 of file ApplyReplacements.h.

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

Collection of TranslationUnitReplacements.

Definition at line 42 of file ApplyReplacements.h.

Function Documentation

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().

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

Apply all replacements in GroupedReplacements.

Parameters
[in]GroupedReplacementsDeduplicated and conflict free Replacements to apply.
[out]RewritesThe 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 333 of file ApplyReplacements.cpp.

References applyAllReplacements().

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]ReplacementsReplacements from a single file.
Returns
Collection of source ranges that enclose all given Replacements. One range is created for each replacement.

Definition at line 350 of file ApplyReplacements.cpp.

References Range.

Referenced by applyFormatting().

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]DirectoryDirectory to begin search for serialized TranslationUnitReplacements.
[out]TUsCollection of all found and deserialized TranslationUnitReplacements or TranslationUnitDiagnostics.
[out]TUFilesCollection of all TranslationUnitReplacement files found in Directory.
[in]DiagnosticsDiagnosticsEngine 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().

Referenced by main().

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().

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.

Referenced by 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]ReplacementsContainer of all replacements grouped by file to be deduplicated and checked for conflicts.
[in]SMSourceManager required for conflict reporting.
Returns
  • true if conflicts were detected
  • false if no conflicts were detected

Definition at line 252 of file ApplyReplacements.cpp.

References deduplicate(), Range, and reportConflict().

Referenced by mergeAndDeduplicate().

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 385 of file ApplyReplacements.cpp.

References Filename.

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]TUsCollection of TranslationUnitReplacements or TranslationUnitDiagnostics to merge, deduplicate, and test for conflicts.
[out]GroupedReplacementsContainer grouping all Replacements by the file they target.
[in]SMSourceManager 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.

References deduplicateAndDetectConflicts().

Referenced by main().

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

Definition at line 305 of file ApplyReplacements.cpp.

References deduplicateAndDetectConflicts(), and Fix().

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]FileFileEntry for the file the conflicting Replacements are for.
[in]ConflictingReplacementsList of conflicting Replacements.
[in]SMSourceManager used for reporting.

Definition at line 134 of file ApplyReplacements.cpp.

Referenced by deduplicateAndDetectConflicts().

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]RewritesRewriter containing written files to write to disk.

Definition at line 366 of file ApplyReplacements.cpp.