Reader small image

You're reading from  Clang Compiler Frontend

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781837630981
Edition1st Edition
Right arrow
Author (1)
Ivan Murashko
Ivan Murashko
author image
Ivan Murashko

Ivan V. Murashko is a C++ software engineer: He got his PhD from Peter the Great St.Petersburg Polytechnic University and has over 20 years of C++ programming experience; since 2020 he has worked with LLVM compilers. His area of interest includes clang compiler frontend and clang tools (clang-tidy, clangd).
Read more about Ivan Murashko

Right arrow

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Clang Compiler Frontend
Published in: Mar 2024Publisher: PacktISBN-13: 9781837630981

Author (1)

author image
Ivan Murashko

Ivan V. Murashko is a C++ software engineer: He got his PhD from Peter the Great St.Petersburg Polytechnic University and has over 20 years of C++ programming experience; since 2020 he has worked with LLVM compilers. His area of interest includes clang compiler frontend and clang tools (clang-tidy, clangd).
Read more about Ivan Murashko