clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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\n""merging/replacing."), cl::init(false), cl::cat(ReplacementCategory))
static cl::opt< bool > | DoFormat ("format", cl::desc("Enable formatting of code changed by applying replacements.\n""Use -style to choose formatting style.\n"), cl::cat(FormattingCategory))
static cl::opt< std::string > | FormatStyleConfig ("style-config", cl::desc("Path to a directory containing a .clang-format file\n""describing a formatting style to use for formatting\n""code when -style=file.\n"), 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 ()
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

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 170 of file ClangApplyReplacementsMain.cpp.

References clang::replace::calculateChangedRanges(), Files, getRewrittenData(), and SM.

Referenced by main().

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 142 of file ClangApplyReplacementsMain.cpp.

References Files, getRewrittenData(), and SM.

Referenced by main().

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

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

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

Referenced by main().

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

Referenced by main().

static cl::opt<std::string> FormatStyleOpt | ( | "style" | ,
|  | cl:: | descformat::StyleOptionHelpDescription,
|  | cl:: | init"LLVM",
|  | cl:: | catFormattingCategory
| ) |  |
| static

Referenced by main().

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

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 107 of file ClangApplyReplacementsMain.cpp.

References Files, and SM.

Referenced by applyFormatting(), and applyReplacements().

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

Definition at line 201 of file ClangApplyReplacementsMain.cpp.

References applyFormatting(), applyReplacements(), clang::replace::collectReplacementsFromDirectory(), DiagOpts, Directory(), DoFormat(), Files, FormatStyleConfig(), FormatStyleOpt(), clang::replace::mergeAndDeduplicate(), printVersion(), RemoveTUReplacementFiles(), SM, and VisibleCategories.

static void printVersion | ( |  | ) |
| static

Definition at line 88 of file ClangApplyReplacementsMain.cpp.

Referenced by main().

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

Referenced by main().

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

## Variable Documentation

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.

Referenced by main().