18 #ifndef LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H 19 #define LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H 23 #include "llvm/ADT/Optional.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/Support/Compiler.h" 26 #include "llvm/Support/Error.h" 27 #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);
95 StringRef ReplacementText);
100 unsigned Length, StringRef ReplacementText);
104 StringRef ReplacementText,
108 template <
typename Node>
110 StringRef ReplacementText,
116 bool isApplicable()
const;
121 unsigned getOffset()
const {
return ReplacementRange.getOffset(); }
122 unsigned getLength()
const {
return ReplacementRange.getLength(); }
127 bool apply(
Rewriter &Rewrite)
const;
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();
211 using ReplacementsImpl = std::set<Replacement>;
265 std::vector<Range> getAffectedRanges()
const;
270 unsigned getShiftedCodePosition(
unsigned Position)
const;
287 return Replaces == RHS.Replaces;
292 : Replaces(Begin, End) {}
308 mergeIfOrderIndependent(
const Replacement &R)
const;
310 ReplacementsImpl Replaces;
349 const std::vector<Range> &Ranges);
356 const std::map<std::string, Replacements> &FileToReplaces);
358 template <
typename Node>
360 const Node &NodeToReplace, StringRef ReplacementText,
364 setFromSourceRange(Sources, Range, ReplacementText, LangOpts);
371 #endif // LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H
Implements support for file system lookup, file system caching, and directory search management...
static CharSourceRange getTokenRange(SourceRange R)
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Defines the clang::LangOptions interface.
Represents a character-granular source range.
Encodes a location in the source.
ast_type_traits::DynTypedNode Node
Dataflow Directional Tag Classes.
Rewriter - This is the main interface to the rewrite buffers.
Defines the clang::SourceLocation class and associated facilities.
This class handles loading and caching of source files into memory.