clang-tools 6.0.0

Functions | Variables
ClangApplyReplacementsMain.cpp File Reference

This file provides the main function for the clang-apply-replacements tool. More...

`#include "clang-apply-replacements/Tooling/ApplyReplacements.h"`
`#include "clang/Basic/Diagnostic.h"`
`#include "clang/Basic/DiagnosticOptions.h"`
`#include "clang/Basic/SourceManager.h"`
`#include "clang/Basic/Version.h"`
`#include "clang/Format/Format.h"`
`#include "clang/Rewrite/Core/Rewriter.h"`
`#include "llvm/ADT/STLExtras.h"`
`#include "llvm/ADT/StringSet.h"`
`#include "llvm/Support/CommandLine.h"`
Include dependency graph for ClangApplyReplacementsMain.cpp:

Go to the source code of this file.

## Functions
static cl::opt< std::string > | Directory (cl::Positional, cl::Required, cl::desc("<Search Root Directory>"))
static cl::OptionCategory | ReplacementCategory ("Replacement Options")
static cl::OptionCategory | FormattingCategory ("Formatting Options")
static cl::opt< bool > | RemoveTUReplacementFiles ("remove-change-desc-files", cl::desc("Remove the change description files regardless of successful\ "merging/replacing."), cl::init(false), cl::cat(ReplacementCategory))
static cl::opt< bool > | DoFormat ("format", cl::desc("Enable formatting of code changed by applying replacements.\ "Use -style to choose formatting style.\"), cl::cat(FormattingCategory))
static cl::opt< std::string > | FormatStyleConfig ("style-config", cl::desc("Path to a directory containing a .clang-format file\ "describing a formatting style to use for formatting\" "code when -style=file.\"), cl::init(""), cl::cat(FormattingCategory))
static cl::opt< std::string > | FormatStyleOpt ("style", cl::desc(format::StyleOptionHelpDescription), cl::init("LLVM"), cl::cat(FormattingCategory))
static void | printVersion (raw_ostream &OS)
static bool | getRewrittenData (const std::vector< tooling::Replacement > &Replacements, Rewriter &Rewrites, std::string &Result)
| Convenience function to get rewritten content for `Filename` from `Rewrites`. More...
static bool | applyReplacements (const std::vector< tooling::Replacement > &Replacements, std::string &Result, DiagnosticsEngine &Diagnostics)
| Apply `Replacements` and return the new file contents. More...
static bool | applyFormatting (const std::vector< tooling::Replacement > &Replacements, const StringRef FileData, std::string &FormattedFileData, const format::FormatStyle &FormatStyle, DiagnosticsEngine &Diagnostics)
| Apply code formatting to all places where replacements were made. More...
int | main (int argc, char **argv)

## Variables
const cl::OptionCategory * | VisibleCategories []

## Detailed Description

This file provides the main function for the clang-apply-replacements tool.

Definition in file ClangApplyReplacementsMain.cpp.

## Function Documentation

## ◆ applyFormatting()

static bool applyFormatting | ( | const std::vector< tooling::Replacement > & | Replacements,
|  | const StringRef | FileData,
|  | std::string & | FormattedFileData,
|  | const format::FormatStyle & | FormatStyle,
|  | DiagnosticsEngine & | Diagnostics
| ) |  |
| static

Apply code formatting to all places where replacements were made.

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

Parameters

  [in] | Replacements | Replacements that were made to the file. Provided to indicate where changes were made.
  [in] | FileData | The contents of the file after `Replacements` have been applied.
  [out] | FormattedFileData | The contents of the file after reformatting.
  [in] | FormatStyle | Style to apply.
  [in] | Diagnostics | For diagnostic output.

Returns
  - true if reformatting replacements were all successfully applied.
  - false if at least one reformatting replacement failed to apply.

Definition at line 168 of file ClangApplyReplacementsMain.cpp.

References clang::replace::calculateChangedRanges().

## ◆ applyReplacements()

static bool applyReplacements | ( | const std::vector< tooling::Replacement > & | Replacements,
|  | std::string & | Result,
|  | DiagnosticsEngine & | Diagnostics
| ) |  |
| static

Apply `Replacements` and return the new file contents.

Precondition
  Replacements[i].getFilePath() == Replacements[i+1].getFilePath().

Postcondition
  Replacements.empty() -> Result.empty()

Parameters

  [in] | Replacements | Replacements to apply.
  [out] | Result | Contents of the file after applying replacements if replacements were provided.
  [in] | Diagnostics | For diagnostic output.

Returns
  - true if all replacements applied successfully.
  - false if at least one replacement failed to apply.

Definition at line 140 of file ClangApplyReplacementsMain.cpp.

## ◆ Directory()

static cl::opt<std::string> Directory | ( | cl::Positional | ,
|  | cl::Required | ,
|  | cl::desc("<Search Root Directory>") |
| ) |  |
| static

Referenced by Modularize::CoverageChecker::collectFileSystemHeaders(), Modularize::CoverageChecker::collectUmbrellaHeaders(), Modularize::ModularizeUtilities::collectUmbrellaHeaders(), and Modularize::ModularizeUtilities::getDirectoryFromPath().

## ◆ DoFormat()

static cl::opt<bool> DoFormat | ( | "format" | ,
|  | cl::desc("Enable formatting of code changed by applying replacements.\"Use -style to choose formatting style.\") | ,
|  | cl::cat(FormattingCategory) |
| ) |  |
| static

## ◆ FormatStyleConfig()

static cl::opt<std::string> FormatStyleConfig | ( | "style-config" | ,
|  | cl::desc("Path to a directory containing a .clang-format file\"describing a formatting style to use for formatting\" "code when -style=file.\") | ,
|  | cl::init("") | ,
|  | cl::cat(FormattingCategory) |
| ) |  |
| static

## ◆ FormatStyleOpt()

static cl::opt<std::string> FormatStyleOpt | ( | "style" | ,
|  | cl::desc(format::StyleOptionHelpDescription) | ,
|  | cl::init("LLVM") | ,
|  | cl::cat(FormattingCategory) |
| ) |  |
| static

## ◆ FormattingCategory()

static cl::OptionCategory FormattingCategory | ( | "Formatting Options" |  | ) |
| static

## ◆ getRewrittenData()

static bool getRewrittenData | ( | const std::vector< tooling::Replacement > & | Replacements,
|  | Rewriter & | Rewrites,
|  | std::string & | Result
| ) |  |
| static

Convenience function to get rewritten content for `Filename` from `Rewrites`.

Precondition
  Replacements[i].getFilePath() == Replacements[i+1].getFilePath().

Postcondition
  Replacements.empty() -> Result.empty()

Parameters

  [in] | Replacements | Replacements to apply
  [in] | Rewrites | Rewriter to use to apply replacements.
  [out] | Result | Contents of the file after applying replacements if replacements were provided.

Returns
  - true if all replacements were applied successfully.
  - false if at least one replacement failed to apply.

Definition at line 104 of file ClangApplyReplacementsMain.cpp.

References clang::replace::applyAllReplacements().

## ◆ main()

int main | ( | int | argc,
|  | char ** | argv
| ) |  |

Definition at line 199 of file ClangApplyReplacementsMain.cpp.

References printVersion().

## ◆ printVersion()

static void printVersion | ( | raw_ostream & | OS | ) |
| static

Definition at line 85 of file ClangApplyReplacementsMain.cpp.

Referenced by main().

## ◆ RemoveTUReplacementFiles()

static cl::opt<bool> RemoveTUReplacementFiles | ( | "remove-change-desc-files" | ,
|  | cl::desc("Remove the change description files regardless of successful\"merging/replacing.") | ,
|  | cl::init(false) | ,
|  | cl::cat(ReplacementCategory) |
| ) |  |
| static

## ◆ ReplacementCategory()

static cl::OptionCategory ReplacementCategory | ( | "Replacement Options" |  | ) |
| static

## Variable Documentation

## ◆ VisibleCategories

const cl::OptionCategory* VisibleCategories[]

Initial value:
= {&ReplacementCategory,
&FormattingCategory}
FormattingCategory
static cl::OptionCategory FormattingCategory("Formatting Options")
ReplacementCategory
static cl::OptionCategory ReplacementCategory("Replacement Options")

Definition at line 37 of file ClangApplyReplacementsMain.cpp.