clang-tools  3.9.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 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 &TURFiles, clang::DiagnosticsEngine &Diagnostics)
 Recursively descends through a directory structure rooted at Directory and attempts to deserialize *.yaml files as TranslationUnitReplacements. More...
 
bool mergeAndDeduplicate (const TUReplacements &TUs, FileToReplacementsMap &GroupedReplacements, clang::SourceManager &SM)
 Deduplicate, check for conflicts, and apply all Replacements stored in TUs. More...
 
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 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 50 of file ApplyReplacements.h.

Collection of source ranges.

Definition at line 38 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::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 190 of file ApplyReplacements.cpp.

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

References Range.

Referenced by applyFormatting().

std::error_code clang::replace::collectReplacementsFromDirectory ( const llvm::StringRef  Directory,
TUReplacements &  TUs,
TUReplacementFiles &  TURFiles,
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.
[out]TURFilesCollection 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 40 of file ApplyReplacements.cpp.

References eatDiagnostics().

Referenced by main().

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

References 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 243 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 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 166 of file ApplyReplacements.cpp.

References deduplicateAndDetectConflicts().

Referenced by main().

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