Plugins-attr.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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: Plugins attr</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Plugins attr">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Plugins attr">
  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="Plugins.html#Plugins" rel="up" title="Plugins">
  30. <link href="Plugins-recording.html#Plugins-recording" rel="next" title="Plugins recording">
  31. <link href="Plugins-description.html#Plugins-description" rel="prev" title="Plugins description">
  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="Plugins-attr"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Plugins-recording.html#Plugins-recording" accesskey="n" rel="next">Plugins recording</a>, Previous: <a href="Plugins-description.html#Plugins-description" accesskey="p" rel="prev">Plugins description</a>, Up: <a href="Plugins.html#Plugins" accesskey="u" rel="up">Plugins</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="Registering-custom-attributes-or-pragmas"></a>
  69. <h3 class="section">23.6 Registering custom attributes or pragmas</h3>
  70. <p>For analysis (or other) purposes it is useful to be able to add custom
  71. attributes or pragmas.
  72. </p>
  73. <p>The <code>PLUGIN_ATTRIBUTES</code> callback is called during attribute
  74. registration. Use the <code>register_attribute</code> function to register
  75. custom attributes.
  76. </p>
  77. <div class="smallexample">
  78. <pre class="smallexample">/* Attribute handler callback */
  79. static tree
  80. handle_user_attribute (tree *node, tree name, tree args,
  81. int flags, bool *no_add_attrs)
  82. {
  83. return NULL_TREE;
  84. }
  85. /* Attribute definition */
  86. static struct attribute_spec user_attr =
  87. { &quot;user&quot;, 1, 1, false, false, false, handle_user_attribute, false };
  88. /* Plugin callback called during attribute registration.
  89. Registered with register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL)
  90. */
  91. static void
  92. register_attributes (void *event_data, void *data)
  93. {
  94. warning (0, G_(&quot;Callback to register attributes&quot;));
  95. register_attribute (&amp;user_attr);
  96. }
  97. </pre></div>
  98. <p>The <i>PLUGIN_PRAGMAS</i> callback is called once during pragmas
  99. registration. Use the <code>c_register_pragma</code>,
  100. <code>c_register_pragma_with_data</code>,
  101. <code>c_register_pragma_with_expansion</code>,
  102. <code>c_register_pragma_with_expansion_and_data</code> functions to register
  103. custom pragmas and their handlers (which often want to call
  104. <code>pragma_lex</code>) from <samp>c-family/c-pragma.h</samp>.
  105. </p>
  106. <div class="smallexample">
  107. <pre class="smallexample">/* Plugin callback called during pragmas registration. Registered with
  108. register_callback (plugin_name, PLUGIN_PRAGMAS,
  109. register_my_pragma, NULL);
  110. */
  111. static void
  112. register_my_pragma (void *event_data, void *data)
  113. {
  114. warning (0, G_(&quot;Callback to register pragmas&quot;));
  115. c_register_pragma (&quot;GCCPLUGIN&quot;, &quot;sayhello&quot;, handle_pragma_sayhello);
  116. }
  117. </pre></div>
  118. <p>It is suggested to pass <code>&quot;GCCPLUGIN&quot;</code> (or a short name identifying
  119. your plugin) as the &ldquo;space&rdquo; argument of your pragma.
  120. </p>
  121. <p>Pragmas registered with <code>c_register_pragma_with_expansion</code> or
  122. <code>c_register_pragma_with_expansion_and_data</code> support
  123. preprocessor expansions. For example:
  124. </p>
  125. <div class="smallexample">
  126. <pre class="smallexample">#define NUMBER 10
  127. #pragma GCCPLUGIN foothreshold (NUMBER)
  128. </pre></div>
  129. </body>
  130. </html>