7.2 Custom code modification tool
We will create a Clang tool that will help us to rename methods for a class that is used for unit testing. We will start with a description for the clang
::
Rewriter
class – the basic class that is used for code modifications.
7.2.1 Code modification support at Clang
clang
::
Rewriter
is a Clang library class that facilitates source code rewriting operations within a translation unit. It provides methods for inserting, removing, and replacing code within theAbstract Syntax Tree (AST) of the source code. Developers can use clang
::
Rewriter
for complex code modifications, such as restructuring or generating new code constructs. It can be applied for both code generation and code refactoring tasks, making it versatile for various code transformation purposes.
The class has several methods for text insertion; for instance, clang
::
Rewriter
::
InsertText
inserts the text at the specified source location, and clang
::
SourceLocation
is used to specify the...