Summary
The preprocessor and lexer mark the beginning of a frontend. The former replaces preprocessor directives with other textual contents, while the latter cuts source code into more meaningful tokens. In this chapter, we've learned how these two components cooperate with each other to provide a single view of token streams to work on in later stages. In addition, we've also learned about various important APIs—such as the Preprocessor
class, the Token
class, and how macros are represented in Clang—that can be used for the development of this part, especially for creating handler plugins to support custom #pragma
directives, as well as creating custom preprocessor callbacks for deeper integration with preprocessing events.
Following the order of Clang's compilation stages, the next chapter will show you how to work with an abstract syntax tree (AST) and how to develop an AST plugin to insert custom logic into it.