clang: include/clang/Tooling/Core/Replacement.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H
19#define LLVM_CLANG_TOOLING_CORE_REPLACEMENT_H
20
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"
27#include
28#include
29#include
30#include
31#include <system_error>
32#include
33#include
34
36
37class FileManager;
38class Rewriter;
39class SourceManager;
40
41namespace tooling {
42
43
45public:
47 Range(unsigned Offset, unsigned Length) : Offset(Offset), Length(Length) {}
48
49
50
51 unsigned getOffset() const { return Offset; }
52 unsigned getLength() const { return Length; }
53
54
55
56
57
59 return Offset + Length > RHS.Offset && Offset < RHS.Offset + RHS.Length;
60 }
61
62
64 return RHS.Offset >= Offset &&
65 (RHS.Offset + RHS.Length) <= (Offset + Length);
66 }
67
68
71 }
72
73
74private:
75 unsigned Offset = 0;
76 unsigned Length = 0;
77};
78
79
80
81
82
84public:
85
87
88
89
90
91
92
93
94 Replacement(StringRef FilePath, unsigned Offset, unsigned Length,
95 StringRef ReplacementText);
96
97
98
100 unsigned Length, StringRef ReplacementText);
101
102
104 StringRef ReplacementText,
106
107
108 template
110 StringRef ReplacementText,
112
113
114
115
117
118
119
124
125
126
128
129
130 std::string toString() const;
131
132private:
134 unsigned Length, StringRef ReplacementText);
135 void setFromSourceRange(const SourceManager &Sources,
137 StringRef ReplacementText,
139
140 std::string FilePath;
141 Range ReplacementRange;
142 std::string ReplacementText;
143};
144
150};
151
152
153
155public:
157
158
160 : Err(Err), ExistingReplacement(std::move(Existing)) {}
161
162
163
165 : Err(Err), NewReplacement(std::move(New)),
166 ExistingReplacement(std::move(Existing)) {}
167
168 std::string message() const override;
169
170 void log(raw_ostream &OS) const override { OS << message(); }
171
173
175
177 return NewReplacement;
178 }
179
181 return ExistingReplacement;
182 }
183
184private:
185
186 std::error_code convertToErrorCode() const override {
187 return llvm::inconvertibleErrorCode();
188 }
189
191
192
193
194 std::optional NewReplacement;
195
196
197 std::optional ExistingReplacement;
198};
199
200
201bool operator<(const Replacement &LHS, const Replacement &RHS);
202
203
204bool operator==(const Replacement &LHS, const Replacement &RHS);
206 return !(LHS == RHS);
207}
208
209
210
211
213private:
214 using ReplacementsImpl = std::set;
215
216public:
219
221
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
262
263
264
266
267
269
270
271
272
274
275 unsigned size() const { return Replaces.size(); }
276
277 void clear() { Replaces.clear(); }
278
279 bool empty() const { return Replaces.empty(); }
280
282
284
286
288
290 return Replaces == RHS.Replaces;
291 }
292
293private:
295 : Replaces(Begin, End) {}
296
297
298
299 Replacement getReplacementInChangedCode(const Replacement &R) const;
300
301
302
303
304
305 Replacements getCanonicalReplacements() const;
306
307
308
309
311 mergeIfOrderIndependent(const Replacement &R) const;
312
313 ReplacementsImpl Replaces;
314};
315
316
317
318
319
320
321
323
324
325
326
327
328
329
330
332 const Replacements &Replaces);
333
334
336
338
340};
341
342
343
344
345
346
347
348
349
350std::vector
352 const std::vector &Ranges);
353
354
355
356
359 const std::map<std::string, Replacements> &FileToReplaces);
360
361template
363 const Node &NodeToReplace, StringRef ReplacementText,
367 setFromSourceRange(Sources, Range, ReplacementText, LangOpts);
368}
369
370}
371
372}
373
374#endif
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...