More #include suggestions (PR c++/84269)
[official-gcc.git] / gcc / testsuite / g++.dg / plugin / pragma_plugin.c
blob6f4739868d3fff4fb63641366c92861b0d6e9a8b
1 /* Demonstrates how to add custom pragmas */
3 #include "gcc-plugin.h"
4 #include <stdlib.h>
5 #include "config.h"
6 #include "system.h"
7 #include "coretypes.h"
8 #include "tm.h"
9 #include "rtl.h"
10 #include "tree.h"
11 #include "function.h"
12 #include "c-family/c-pragma.h"
13 #include "cpplib.h"
14 #include "tree-pass.h"
15 #include "intl.h"
16 #include "toplev.h"
17 #include "diagnostic.h"
19 int plugin_is_GPL_compatible;
22 /* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to
23 handler of #pragma GCC message...*/
25 static void
26 handle_pragma_sayhello (cpp_reader *dummy)
28 tree message = 0;
29 if (pragma_lex (&message) != CPP_STRING)
31 warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN sayhello%> is not a string");
32 return;
34 if (TREE_STRING_LENGTH (message) > 1)
36 if (cfun)
37 warning (OPT_Wpragmas,
38 "%<pragma GCCPLUGIN sayhello%> from function %qE: %s",
39 cfun->decl, TREE_STRING_POINTER (message));
40 else
41 warning (OPT_Wpragmas,
42 "%<pragma GCCPLUGIN sayhello%> outside of function: %s",
43 TREE_STRING_POINTER (message));
47 /* Plugin callback called during pragma registration */
49 static void
50 register_my_pragma (void *event_data, void *data)
52 warning (0, G_("Callback to register pragmas"));
53 c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello);
56 int
57 plugin_init (struct plugin_name_args *plugin_info,
58 struct plugin_gcc_version *version)
60 const char *plugin_name = plugin_info->base_name;
62 register_callback (plugin_name, PLUGIN_PRAGMAS, register_my_pragma, NULL);
63 return 0;