19 #ifndef LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H 20 #define LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H 24 #include "llvm/ADT/Optional.h" 25 #include "llvm/ADT/StringRef.h" 26 #include "llvm/Support/Compiler.h" 27 #include "llvm/Support/Error.h" 28 #include "llvm/Support/raw_ostream.h" 32 #include <system_error> 48 Range(
unsigned Offset,
unsigned Length) : Offset(Offset), Length(Length) {}
60 return Offset + Length > RHS.Offset && Offset < RHS.Offset + RHS.Length;
65 return RHS.Offset >= Offset &&
66 (RHS.Offset + RHS.Length) <= (Offset + Length);
96 StringRef ReplacementText);
101 unsigned Length, StringRef ReplacementText);
105 StringRef ReplacementText,
109 template <
typename Node>
111 StringRef ReplacementText,
117 bool isApplicable()
const;
122 unsigned getOffset()
const {
return ReplacementRange.getOffset(); }
123 unsigned getLength()
const {
return ReplacementRange.getLength(); }
128 bool apply(
Rewriter &Rewrite)
const;
135 unsigned Length, StringRef ReplacementText);
138 StringRef ReplacementText,
141 std::string FilePath;
142 Range ReplacementRange;
143 std::string ReplacementText;
161 : Err(Err), ExistingReplacement(
std::move(Existing)) {}
166 : Err(Err), NewReplacement(
std::move(New)),
167 ExistingReplacement(
std::move(Existing)) {}
169 std::string message()
const override;
171 void log(raw_ostream &OS)
const override { OS << message(); }
178 return NewReplacement;
182 return ExistingReplacement;
187 std::error_code convertToErrorCode()
const override {
188 return llvm::inconvertibleErrorCode();
212 using ReplacementsImpl = std::set<Replacement>;
266 std::vector<Range> getAffectedRanges()
const;
271 unsigned getShiftedCodePosition(
unsigned Position)
const;
288 return Replaces == RHS.Replaces;
293 : Replaces(Begin, End) {}
309 mergeIfOrderIndependent(
const Replacement &R)
const;
311 ReplacementsImpl Replaces;
350 const std::vector<Range> &Ranges);
357 const std::map<std::string, Replacements> &FileToReplaces);
359 template <
typename Node>
361 const Node &NodeToReplace, StringRef ReplacementText,
365 setFromSourceRange(Sources, Range, ReplacementText, LangOpts);
372 #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.