18#ifndef LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H
19#define LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H
23#include "llvm/ADT/StringRef.h"
24#include "llvm/Support/Compiler.h"
25#include "llvm/Support/Error.h"
26#include "llvm/Support/raw_ostream.h"
31#include <system_error>
47 Range(
unsigned Offset,
unsigned Length) : Offset(Offset), Length(Length) {}
59 return Offset + Length > RHS.Offset && Offset < RHS.Offset + RHS.Length;
64 return RHS.Offset >= Offset &&
65 (RHS.Offset + RHS.Length) <= (Offset + Length);
94 Replacement(StringRef FilePath,
unsigned Offset,
unsigned Length,
95 StringRef ReplacementText);
100 unsigned Length, StringRef ReplacementText);
104 StringRef ReplacementText,
108 template <
typename Node>
110 StringRef ReplacementText,
134 unsigned Length, StringRef ReplacementText);
137 StringRef ReplacementText,
140 std::string FilePath;
141 Range ReplacementRange;
142 std::string ReplacementText;
160 : Err(Err), ExistingReplacement(
std::move(Existing)) {}
165 : Err(Err), NewReplacement(
std::move(New)),
166 ExistingReplacement(
std::move(Existing)) {}
168 std::string
message()
const override;
170 void log(raw_ostream &OS)
const override { OS <<
message(); }
177 return NewReplacement;
181 return ExistingReplacement;
186 std::error_code convertToErrorCode()
const override {
187 return llvm::inconvertibleErrorCode();
194 std::optional<Replacement> NewReplacement;
197 std::optional<Replacement> ExistingReplacement;
201bool operator<(
const Replacement &LHS,
const Replacement &RHS);
204bool operator==(
const Replacement &LHS,
const Replacement &RHS);
206 return !(LHS == RHS);
214 using ReplacementsImpl = std::set<Replacement>;
275 unsigned size()
const {
return Replaces.size(); }
279 bool empty()
const {
return Replaces.empty(); }
290 return Replaces == RHS.Replaces;
295 : Replaces(
Begin, End) {}
299 Replacement getReplacementInChangedCode(
const Replacement &R)
const;
311 mergeIfOrderIndependent(
const Replacement &R)
const;
313 ReplacementsImpl Replaces;
332 const Replacements &Replaces);
352 const std::vector<Range> &Ranges);
359 const std::map<std::string, Replacements> &FileToReplaces);
361template <
typename Node>
363 const Node &NodeToReplace, StringRef ReplacementText,
367 setFromSourceRange(Sources,
Range, ReplacementText, LangOpts);
Defines the clang::LangOptions interface.
Defines the clang::SourceLocation class and associated facilities.
Represents a character-granular source range.
static CharSourceRange getTokenRange(SourceRange R)
Implements support for file system lookup, file system caching, and directory search management.
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.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
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...