-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrewriter.hpp
50 lines (40 loc) · 1.34 KB
/
rewriter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef CFTF_REWRITER_HPP
#define CFTF_REWRITER_HPP
namespace clang {
class Rewriter;
class SourceLocation;
class SourceRange;
class SourceManager;
}
namespace llvm {
class StringRef;
}
namespace cftf {
/**
* Abstract interface akin to clang::Rewriter.
* This allows us to do more sophisticated source manipulation than through Rewriter alone.
*/
class RewriterBase {
public:
virtual ~RewriterBase() = default;
virtual bool ReplaceTextIncludingEndToken(clang::SourceRange, llvm::StringRef) = 0;
virtual bool ReplaceTextExcludingEndToken(clang::SourceRange, llvm::StringRef) = 0;
bool InsertTextAfter(clang::SourceLocation, llvm::StringRef);
bool RemoveTextIncludingEndToken(clang::SourceRange);
bool RemoveTextExcludingEndToken(clang::SourceRange);
virtual clang::SourceManager& getSourceMgr() = 0;
};
/**
* clang::Rewriter based Rewriter that directly operates on the contents of an input source file
*/
class Rewriter final : public RewriterBase {
public:
Rewriter(clang::Rewriter& rewriter) : rewriter(rewriter) {}
private:
bool ReplaceTextIncludingEndToken(clang::SourceRange, llvm::StringRef) override;
bool ReplaceTextExcludingEndToken(clang::SourceRange, llvm::StringRef) override;
clang::SourceManager& getSourceMgr() override;
clang::Rewriter& rewriter;
};
} // namespace cftf
#endif // CFTF_REWRITER_HPP