Clang Compiler Frontend Get to Grips with the Internals of a C/C++ Compiler Frontend and Create Your Own Tools

Boost your productivity with a variety of compiler tools that integrate seamlessly into your IDE Key Features Expand your understanding of the C++ programming language by learning about how the C++ compiler works and how to utilize its advanced features Explore techniques for static code analysis an...

Descripción completa

Detalles Bibliográficos
Otros Autores: Murashko, Ivan, author (author)
Formato: Libro electrónico
Idioma:Inglés
Publicado: Birmingham, England : Packt Publishing Ltd [2024]
Edición:First edition
Materias:
Ver en Biblioteca Universitat Ramon Llull:https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009810643906719
Tabla de Contenidos:
  • Cover
  • Title Page
  • Copyright and Credits
  • Contributors
  • Table of Contents
  • Preface
  • Part 1: Clang Setup and Architecture
  • Chapter 1: Environment Setup
  • Technical requirements
  • CMake as project configuration tool
  • Ninja as build tool
  • Getting to know LLVM
  • Short LLVM history
  • OS support
  • Linux
  • Darwin (macOS)
  • Windows
  • LLVM/Clang project structure
  • Source code compilation
  • Configuration with CMake
  • Build
  • The LLVM debugger, its build, and usage
  • Test project - syntax check with a Clang tool
  • Summary
  • Further reading
  • Chapter 2: Clang Architecture
  • Technical requirements
  • Getting started with compilers
  • Exploring the compiler workflow
  • Frontend
  • Lexer
  • Parser
  • The codegen
  • Clang driver overview
  • Example program
  • Compilation phases
  • Tool execution
  • Combining it all together
  • Debugging Clang
  • Clang frontend overview
  • Frontend action
  • Preprocessor
  • Parser and sema
  • Summary
  • Further reading
  • Chapter 3: Clang AST
  • Technical requirements
  • AST
  • Statements
  • Declarations
  • Types
  • AST traversal
  • DeclVisitor test tool
  • Visitor implementation
  • Recursive AST visitor
  • AST matchers
  • Explore Clang AST with clang-query
  • Processing AST in the case of errors
  • Summary
  • Further reading
  • Chapter 4: Basic Libraries and Tools
  • Technical requirements
  • LLVM coding style
  • LLVM basic libraries
  • RTTI replacement and cast operators
  • Containers
  • String operations
  • Sequential containers
  • Map-like containers
  • Smart pointers
  • Clang basic libraries
  • SourceManager and SourceLocation
  • Diagnostics support
  • LLVM supporting tools
  • TableGen
  • LLVM test framework
  • Clang plugin project
  • Environment setup
  • CMake build configuration for plugin
  • Recursive visitor class
  • Plugin AST consumer class
  • Plugin AST action class
  • Plugin code.
  • Building and running plugin code
  • LIT tests for clang plugin
  • LIT config files
  • CMake configuration for LIT tests
  • Running LIT tests
  • Summary
  • Further reading
  • Part 2: Clang Tools
  • Chapter 5: Clang-Tidy Linter Framework
  • Technical requirements
  • Overview of Clang-Tidy and usage examples
  • Building and testing Clang-Tidy
  • Clang-Tidy usage
  • Clang-Tidy checks
  • Clang-Tidy's internal design
  • Internal organization
  • Configuration and integration
  • Clang-Tidy configuration
  • Custom Clang-Tidy check
  • Creating a skeleton for the check
  • Clang-Tidy check implementation
  • LIT test
  • Results in the case of compilation errors
  • Compilation errors as edge cases
  • Summary
  • Further reading
  • Chapter 6: Advanced Code Analysis
  • Technical requirements
  • Static analysis
  • CFG
  • Custom CFG check
  • Creating the project skeleton
  • Check implementation
  • Building and testing the cyclomatic complexity check
  • CFG on Clang
  • CFG construction by example
  • CFG construction implementation details
  • Brief description of Clang analysis tools
  • Knowing the limitations of analysis
  • Summary
  • Future reading
  • Chapter 7: Refactoring Tools
  • Technical requirements
  • Custom code modification tool
  • Code modification support at Clang
  • Test class
  • Visitor class implementation
  • Consumer class implementation
  • Build configuration and main function
  • Running the code modification tool
  • Clang-Tidy as a code modification tool
  • FixItHint
  • Creating project skeleton
  • Check implementation
  • Build and run the check
  • Code modification and Clang-Format
  • Clang-Format configuration and usage examples
  • Design considerations
  • Clang-Tidy and Clang-Format
  • Summary
  • Further reading
  • Chapter 8: IDE Support and Clangd
  • Technical requirements
  • Language Server Protocol
  • Environment setup
  • Clangd build.
  • VS Code installation and setup
  • LSP demo
  • Demo description
  • LSP session
  • Initialization
  • Open document
  • Go-to definition
  • Change document
  • Closing a document
  • Integration with Clang tools
  • Clangd support for code formatting using LSP messages
  • Formatting entire documents
  • Formatting specific code ranges
  • Clang-Tidy
  • Clang-Tidy integration with LSP
  • Applying fixes in the IDE
  • Performance optimizations
  • Optimizations for modified documents
  • Source code preamble
  • AST build at Clangd
  • Building preamble optimization
  • Summary
  • Further reading
  • Part 3: Appendix
  • Chapter 9: Appendix 1: Compilation Database
  • Compilation database definition
  • CDB creation
  • Generating a CDB with CMake
  • Ninja to Generate a CDB
  • Clang tools and a CDB
  • Clang-Tidy Configuration for Large Projects
  • Clangd Setup for Large Projects
  • Further reading
  • Chapter 10: Appendix 2: Build Speed Optimization
  • Technical requirements
  • Precompiled headers
  • Clang modules
  • Test project description
  • Modulemap file
  • Explicit modules
  • Implicit modules
  • Some problems related to modules
  • Further reading
  • Index
  • Other Books You Might Enjoy.