macro_expansion_process.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>The Macro Expansion Process</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <link href="theme/style.css" rel="stylesheet" type="text/css">
  7. </head>
  8. <body>
  9. <table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
  10. <tr>
  11. <td width="21"> <h1></h1></td>
  12. <td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
  13. Macro Expansion Process</font></b></font></td>
  14. <td width="96"><a href="http://www.boost.org"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
  15. </tr>
  16. </table>
  17. <br>
  18. <table border="0">
  19. <tr>
  20. <td width="10"></td>
  21. <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
  22. <td width="30"><a href="predefined_macros.html"><img src="theme/l_arr.gif" border="0"></a></td>
  23. <td width="30"><a href="compiletime_config.html"><img src="theme/r_arr.gif" border="0"></a></td>
  24. </tr>
  25. </table>
  26. <p>The macro expansion process described here was initially developed by <a href="mailto:pmenso57@attbi.com">Paul
  27. Mensonides</a> and is implemented in <tt>Wave</tt>. It is much more understandable
  28. as the description of the desired macro expansion algorithm provided in the
  29. C++ Standard <a href="references.html#iso_cpp">[1]</a>.</p>
  30. <p>Macro replacement proceeds left-to-right. </p>
  31. <p>If, during scanning (or rescanning) an identifier is found, it is looked up
  32. in the symbol table. If the identifier is not found in the symbol table, it
  33. is not a macro and scanning continues.</p>
  34. <p>If the identifier is found, the value of a flag associated with the identifier
  35. is used to determine if the identifier is available for expansion. If it is
  36. not, the specific token (i.e. the specific instance of the identifier) is marked
  37. as disabled and is not expanded. If the identifier is available for expansion,
  38. the value of a different flag associated with the identifier in the symbol table
  39. is used to determine if the identifier is an object-like or function-like macro.
  40. If it is an object-like macro, it is expanded. If it is a function-like macro,
  41. it is only expanded if the next token is an left parenthesis.<br>
  42. An identifier is available for expansion if it is not marked as disabled and
  43. if the the value of the flag associated with the identifier is not set, which
  44. is used to determine if the identifier is available for expansion.</p>
  45. <p>(If a macro is an object-like macro, skip past the next two paragraphs.)</p>
  46. <p>If a macro to be expanded is a function-like macro, it must have the exact
  47. number of actual arguments as the number of formal parameters required by the
  48. definition of the macro. Each argument is recursively scanned and expanded.
  49. Each parameter name found in the replacement list is replaced by the expanded
  50. actual argument after leading and trailing whitespace and all placeholder tokens
  51. are removed unless the parameter name immediately follows the stringizing operator
  52. (<tt>'#'</tt>) or is adjacent to the token-pasting operator (<tt>'##'</tt>).</p>
  53. <p>If the parameter name immediately follows the stringizing operator (<tt>'#'</tt>),
  54. a stringized version of the unexpanded actual argument is inserted. If the parameter
  55. name is adjacent to the token-pasting operator (<tt>'##'</tt>), the unexpanded
  56. actual argument is inserted after all placeholder tokens are removed.</p>
  57. <p>All concatenation takes place in the replacement list. (If a single concatenation
  58. yields multiple tokens, the behavior is undefined. Moreover, <tt>Wave</tt> in
  59. normal C++98 and C99 modes issues an error, if more then one token is produced
  60. as the result of the concatenation. In C++0x mode <tt>Wave</tt> treats token-pasting
  61. of unrelated tokens as well defined and inserts the reparsed string representation
  62. of the concatenated tokens into the replacement list.).</p>
  63. <p>The flag in the symbol table entry associated with the name of the macro being
  64. expanded is set to indicate the that the macro is not available for expansion.</p>
  65. <p>The replacement list is rescanned for further macro expansion. All leading
  66. and trailing whitespace tokens in the replacement list are removed (the placeholder
  67. tokens are left intact). </p>
  68. <p>After rescanning completes, the flag in the symbol table entry associated with
  69. the name of macro being expanded is cleared to indicate that the macro is again
  70. available for expansion, and the sequence of tokens that constitutes the rescanned
  71. replacement list is returned to the point of invocation of the macro.</p>
  72. <p>If this sequence of tokens is empty, it is replaced by a placeholder token.
  73. If a placeholder is found during scanning (or rescanning) it is ignored. (Also,
  74. if the only thing separating a parameter from the stringizing operator or token-pasting
  75. operator is placeholder, it is also ignored in that context.)</p>
  76. <p>This sequence of tokens is inserted at the original point that the macro was
  77. invoked, and scanning continues starting with the last token of the newly inserted
  78. sequence of tokens. I.e. scanning looks back a single token (possibly a placeholder
  79. token) and continues.<br>
  80. </p>
  81. <table border="0">
  82. <tr>
  83. <td width="10"></td>
  84. <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
  85. <td width="30"><a href="predefined_macros.html"><img src="theme/l_arr.gif" border="0"></a></td>
  86. <td width="30"><a href="compiletime_config.html"><img src="theme/r_arr.gif" border="0"></a></td>
  87. </tr>
  88. </table>
  89. <hr size="1">
  90. <p class="copyright">Copyright &copy; 2003-2011 Hartmut Kaiser<br>
  91. <br>
  92. <font size="2">Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) </font> </p>
  93. <span class="updated"></span>
  94. <p class="copyright"><span class="updated">Last updated:
  95. <!-- #BeginDate format:fcAm1m -->Sunday, May 15, 2005 12:23<!-- #EndDate -->
  96. </span>
  97. </p>
  98. <p>&nbsp; </p>
  99. </body>
  100. </html>
  101. <!-- #BeginDate format:fcAm1m -->Saturday, February 25, 2006 15:46<!-- #EndDate -->