]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/cppinternals/internal-representation-of-macros.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / cppinternals / internal-representation-of-macros.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. index:: macro representation (internal)
7
8 Internal representation of macros
9 *********************************
10
11 The preprocessor stores macro expansions in tokenized form. This
12 saves repeated lexing passes during expansion, at the cost of a small
13 increase in memory consumption on average. The tokens are stored
14 contiguously in memory, so a pointer to the first one and a token
15 count is all you need to get the replacement list of a macro.
16
17 If the macro is a function-like macro the preprocessor also stores its
18 parameters, in the form of an ordered list of pointers to the hash
19 table entry of each parameter's identifier. Further, in the macro's
20 stored expansion each occurrence of a parameter is replaced with a
21 special token of type ``CPP_MACRO_ARG``. Each such token holds the
22 index of the parameter it represents in the parameter list, which
23 allows rapid replacement of parameters with their arguments during
24 expansion. Despite this optimization it is still necessary to store
25 the original parameters to the macro, both for dumping with e.g.,
26 :option:`-dD`, and to warn about non-trivial macro redefinitions when
27 the parameter names have changed.