Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Clang Compiler Frontend

You're reading from  Clang Compiler Frontend

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781837630981
Pages 326 pages
Edition 1st Edition
Languages
Author (1):
Ivan Murashko Ivan Murashko
Profile icon Ivan Murashko

Table of Contents (17) Chapters

Preface 1. Part I: Clang Setup and Architecture
2. Chapter 1: Environment Setup 3. Chapter 2: Clang Architecture 4. Chapter 3: Clang AST 5. Chapter 4: Basic Libraries and Tools 6. Part II: Clang Tools
7. Chapter 5: Clang-Tidy Linter Framework 8. Chapter 6: Advanced Code Analysis 9. Chapter 7: Refactoring Tools 10. Chapter 8: IDE Support and Clangd 11. Part III: Appendix
12. Bibliography
13. Index 14. Other Books You Might Enjoy Appendix 1: Compilation Database 1. Appendix 2: Build Speed Optimization

3.3 AST traversal

The compiler requires traversal of the AST to generate IR code. Thus, having a well-structured data structure for tree traversal is paramount for AST design. To put it another way, the design of the AST should prioritize facilitating easy tree traversal. A standard approach in many systems is to have a common base class for all AST nodes. This class typically provides a method to retrieve the node’s children, allowing for tree traversal using popular algorithms such as Breadth-First Search (BFS) [19]. Clang, however, takes a different approach: its AST nodes don’t share a common ancestor. This poses the question: how is tree traversal organized in Clang?

Clang employs three unique techniques:

  • The Curiously Recurring Template Pattern (CRTP) for visitor class definition

  • Ad hoc methods tailored specifically for different nodes

  • Macros, which can be perceived as the connecting layer between the ad hoc methods and CRTP

We will explore these techniques through...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}