You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>Hash Nodes (The GNU C Preprocessor Internals)</title>
  7. <meta name="description" content="Hash Nodes (The GNU C Preprocessor Internals)">
  8. <meta name="keywords" content="Hash Nodes (The GNU C Preprocessor Internals)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  14. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="index.html#Top" rel="up" title="Top">
  16. <link href="Macro-Expansion.html#Macro-Expansion" rel="next" title="Macro Expansion">
  17. <link href="Lexer.html#Lexer" rel="prev" title="Lexer">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="Hash-Nodes"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="Macro-Expansion.html#Macro-Expansion" accesskey="n" rel="next">Macro Expansion</a>, Previous: <a href="Lexer.html#Lexer" accesskey="p" rel="prev">Lexer</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="Hash-Nodes-1"></a>
  54. <h2 class="unnumbered">Hash Nodes</h2>
  55. <a name="index-hash-table"></a>
  56. <a name="index-identifiers"></a>
  57. <a name="index-macros"></a>
  58. <a name="index-assertions"></a>
  59. <a name="index-named-operators"></a>
  60. <p>When cpplib encounters an &ldquo;identifier&rdquo;, it generates a hash code for
  61. it and stores it in the hash table. By &ldquo;identifier&rdquo; we mean tokens
  62. with type <code>CPP_NAME</code>; this includes identifiers in the usual C
  63. sense, as well as keywords, directive names, macro names and so on. For
  64. example, all of <code>pragma</code>, <code>int</code>, <code>foo</code> and
  65. <code>__GNUC__</code> are identifiers and hashed when lexed.
  66. </p>
  67. <p>Each node in the hash table contain various information about the
  68. identifier it represents. For example, its length and type. At any one
  69. time, each identifier falls into exactly one of three categories:
  70. </p>
  71. <ul>
  72. <li> Macros
  73. <p>These have been declared to be macros, either on the command line or
  74. with <code>#define</code>. A few, such as <code>__TIME__</code> are built-ins
  75. entered in the hash table during initialization. The hash node for a
  76. normal macro points to a structure with more information about the
  77. macro, such as whether it is function-like, how many arguments it takes,
  78. and its expansion. Built-in macros are flagged as special, and instead
  79. contain an enum indicating which of the various built-in macros it is.
  80. </p>
  81. </li><li> Assertions
  82. <p>Assertions are in a separate namespace to macros. To enforce this, cpp
  83. actually prepends a <code>#</code> character before hashing and entering it in
  84. the hash table. An assertion&rsquo;s node points to a chain of answers to
  85. that assertion.
  86. </p>
  87. </li><li> Void
  88. <p>Everything else falls into this category&mdash;an identifier that is not
  89. currently a macro, or a macro that has since been undefined with
  90. <code>#undef</code>.
  91. </p>
  92. <p>When preprocessing C++, this category also includes the named operators,
  93. such as <code>xor</code>. In expressions these behave like the operators they
  94. represent, but in contexts where the spelling of a token matters they
  95. are spelt differently. This spelling distinction is relevant when they
  96. are operands of the stringizing and pasting macro operators <code>#</code> and
  97. <code>##</code>. Named operator hash nodes are flagged, both to catch the
  98. spelling distinction and to prevent them from being defined as macros.
  99. </p></li></ul>
  100. <p>The same identifiers share the same hash node. Since each identifier
  101. token, after lexing, contains a pointer to its hash node, this is used
  102. to provide rapid lookup of various information. For example, when
  103. parsing a <code>#define</code> statement, CPP flags each argument&rsquo;s identifier
  104. hash node with the index of that argument. This makes duplicated
  105. argument checking an O(1) operation for each argument. Similarly, for
  106. each identifier in the macro&rsquo;s expansion, lookup to see if it is an
  107. argument, and which argument it is, is also an O(1) operation. Further,
  108. each directive name, such as <code>endif</code>, has an associated directive
  109. enum stored in its hash node, so that directive lookup is also O(1).
  110. </p>
  111. <hr>
  112. <div class="header">
  113. <p>
  114. Next: <a href="Macro-Expansion.html#Macro-Expansion" accesskey="n" rel="next">Macro Expansion</a>, Previous: <a href="Lexer.html#Lexer" accesskey="p" rel="prev">Lexer</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  115. </div>
  116. </body>
  117. </html>