clang: lib/Tooling/Refactoring.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

21#include "llvm/Support/Path.h"

22#include "llvm/Support/raw_os_ostream.h"

23

25namespace tooling {

26

29 std::shared_ptr PCHContainerOps)

30 : ClangTool(Compilations, SourcePaths, std::move(PCHContainerOps)) {}

31

33 return FileToReplaces;

34}

35

37 if (int Result = run(ActionFactory)) {

39 }

40

46 &*DiagOpts, &DiagnosticPrinter, false);

49

51 llvm::errs() << "Skipped some replacements.\n";

52 }

53

54 return saveRewrittenFiles(Rewrite);

55}

56

60 Rewrite.getSourceMgr().getFileManager(), FileToReplaces))

63}

64

65int RefactoringTool::saveRewrittenFiles(Rewriter &Rewrite) {

66 return Rewrite.overwriteChangedFiles() ? 1 : 0;

67}

68

70 const std::map<std::string, Replacements> &FileToReplaces,

74

77 Rewrite.getSourceMgr().getFileManager(), FileToReplaces)) {

78 const std::string &FilePath = FileAndReplaces.first;

79 auto &CurReplaces = FileAndReplaces.second;

80

83 StringRef Code = SM.getBufferData(ID);

84

86 if (!CurStyle) {

87 llvm::errs() << llvm::toString(CurStyle.takeError()) << "\n";

88 return false;

89 }

90

91 auto NewReplacements =

93 if (!NewReplacements) {

94 llvm::errs() << llvm::toString(NewReplacements.takeError()) << "\n";

95 return false;

96 }

98 }

100}

101

102}

103}

Defines the clang::FileManager interface and associated types.

Various functions to configurably format source code.

Defines the SourceManager interface.

Used for handling and querying diagnostic IDs.

Options for controlling the compiler diagnostics engine.

Concrete class used by the front-end to report problems and issues.

A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...

An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...

Implements support for file system lookup, file system caching, and directory search management.

LLVM_DEPRECATED("Functions returning DirectoryEntry are deprecated.", "getOptionalDirectoryRef()") llvm LLVM_DEPRECATED("Functions returning FileEntry are deprecated.", "getOptionalFileRef()") llvm llvm::Expected< FileEntryRef > getFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true, bool IsText=true)

Lookup, cache, and verify the specified directory (real or virtual).

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

Rewriter - This is the main interface to the rewrite buffers.

This class handles loading and caching of source files into memory.

Expected< FormatStyle > getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle, StringRef Code="", llvm::vfs::FileSystem *FS=nullptr, bool AllowUnknownOptions=false, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr)

Construct a FormatStyle based on StyleName.

Expected< tooling::Replacements > formatReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)

Returns the replacements corresponding to applying and formatting Replaces on success; otheriwse,...

The JSON file list parser is used to communicate input to InstallAPI.

@ Rewrite

We are substituting template parameters for (typically) other template parameters in order to rewrite...

@ Result

The result type of a method or function.