Constant-expressions.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Constant expressions</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Constant expressions">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Constant expressions">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Expression-trees.html#Expression-trees" rel="up" title="Expression trees">
  30. <link href="Storage-References.html#Storage-References" rel="next" title="Storage References">
  31. <link href="Expression-trees.html#Expression-trees" rel="prev" title="Expression trees">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Constant-expressions"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Storage-References.html#Storage-References" accesskey="n" rel="next">Storage References</a>, Up: <a href="Expression-trees.html#Expression-trees" accesskey="u" rel="up">Expression trees</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Constant-expressions-1"></a>
  69. <h4 class="subsection">10.6.1 Constant expressions</h4>
  70. <a name="index-INTEGER_005fCST"></a>
  71. <a name="index-tree_005fint_005fcst_005flt"></a>
  72. <a name="index-tree_005fint_005fcst_005fequal"></a>
  73. <a name="index-tree_005ffits_005fuhwi_005fp"></a>
  74. <a name="index-tree_005ffits_005fshwi_005fp"></a>
  75. <a name="index-tree_005fto_005fuhwi"></a>
  76. <a name="index-tree_005fto_005fshwi"></a>
  77. <a name="index-TREE_005fINT_005fCST_005fNUNITS"></a>
  78. <a name="index-TREE_005fINT_005fCST_005fELT"></a>
  79. <a name="index-TREE_005fINT_005fCST_005fLOW"></a>
  80. <a name="index-REAL_005fCST"></a>
  81. <a name="index-FIXED_005fCST"></a>
  82. <a name="index-COMPLEX_005fCST"></a>
  83. <a name="index-VECTOR_005fCST"></a>
  84. <a name="index-STRING_005fCST"></a>
  85. <a name="index-TREE_005fSTRING_005fLENGTH"></a>
  86. <a name="index-TREE_005fSTRING_005fPOINTER"></a>
  87. <p>The table below begins with constants, moves on to unary expressions,
  88. then proceeds to binary expressions, and concludes with various other
  89. kinds of expressions:
  90. </p>
  91. <dl compact="compact">
  92. <dt><code>INTEGER_CST</code></dt>
  93. <dd><p>These nodes represent integer constants. Note that the type of these
  94. constants is obtained with <code>TREE_TYPE</code>; they are not always of type
  95. <code>int</code>. In particular, <code>char</code> constants are represented with
  96. <code>INTEGER_CST</code> nodes. The value of the integer constant <code>e</code> is
  97. represented in an array of HOST_WIDE_INT. There are enough elements
  98. in the array to represent the value without taking extra elements for
  99. redundant 0s or -1. The number of elements used to represent <code>e</code>
  100. is available via <code>TREE_INT_CST_NUNITS</code>. Element <code>i</code> can be
  101. extracted by using <code>TREE_INT_CST_ELT (e, i)</code>.
  102. <code>TREE_INT_CST_LOW</code> is a shorthand for <code>TREE_INT_CST_ELT (e, 0)</code>.
  103. </p>
  104. <p>The functions <code>tree_fits_shwi_p</code> and <code>tree_fits_uhwi_p</code>
  105. can be used to tell if the value is small enough to fit in a
  106. signed HOST_WIDE_INT or an unsigned HOST_WIDE_INT respectively.
  107. The value can then be extracted using <code>tree_to_shwi</code> and
  108. <code>tree_to_uhwi</code>.
  109. </p>
  110. </dd>
  111. <dt><code>REAL_CST</code></dt>
  112. <dd>
  113. <p>FIXME: Talk about how to obtain representations of this constant, do
  114. comparisons, and so forth.
  115. </p>
  116. </dd>
  117. <dt><code>FIXED_CST</code></dt>
  118. <dd>
  119. <p>These nodes represent fixed-point constants. The type of these constants
  120. is obtained with <code>TREE_TYPE</code>. <code>TREE_FIXED_CST_PTR</code> points to
  121. a <code>struct fixed_value</code>; <code>TREE_FIXED_CST</code> returns the structure
  122. itself. <code>struct fixed_value</code> contains <code>data</code> with the size of two
  123. <code>HOST_BITS_PER_WIDE_INT</code> and <code>mode</code> as the associated fixed-point
  124. machine mode for <code>data</code>.
  125. </p>
  126. </dd>
  127. <dt><code>COMPLEX_CST</code></dt>
  128. <dd><p>These nodes are used to represent complex number constants, that is a
  129. <code>__complex__</code> whose parts are constant nodes. The
  130. <code>TREE_REALPART</code> and <code>TREE_IMAGPART</code> return the real and the
  131. imaginary parts respectively.
  132. </p>
  133. </dd>
  134. <dt><code>VECTOR_CST</code></dt>
  135. <dd><p>These nodes are used to represent vector constants, whose parts are
  136. constant nodes. Each individual constant node is either an integer or a
  137. double constant node. The first operand is a <code>TREE_LIST</code> of the
  138. constant nodes and is accessed through <code>TREE_VECTOR_CST_ELTS</code>.
  139. </p>
  140. </dd>
  141. <dt><code>STRING_CST</code></dt>
  142. <dd><p>These nodes represent string-constants. The <code>TREE_STRING_LENGTH</code>
  143. returns the length of the string, as an <code>int</code>. The
  144. <code>TREE_STRING_POINTER</code> is a <code>char*</code> containing the string
  145. itself. The string may not be <code>NUL</code>-terminated, and it may contain
  146. embedded <code>NUL</code> characters. Therefore, the
  147. <code>TREE_STRING_LENGTH</code> includes the trailing <code>NUL</code> if it is
  148. present.
  149. </p>
  150. <p>For wide string constants, the <code>TREE_STRING_LENGTH</code> is the number
  151. of bytes in the string, and the <code>TREE_STRING_POINTER</code>
  152. points to an array of the bytes of the string, as represented on the
  153. target system (that is, as integers in the target endianness). Wide and
  154. non-wide string constants are distinguished only by the <code>TREE_TYPE</code>
  155. of the <code>STRING_CST</code>.
  156. </p>
  157. <p>FIXME: The formats of string constants are not well-defined when the
  158. target system bytes are not the same width as host system bytes.
  159. </p>
  160. </dd>
  161. </dl>
  162. <hr>
  163. <div class="header">
  164. <p>
  165. Next: <a href="Storage-References.html#Storage-References" accesskey="n" rel="next">Storage References</a>, Up: <a href="Expression-trees.html#Expression-trees" accesskey="u" rel="up">Expression trees</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  166. </div>
  167. </body>
  168. </html>