OSDN Git Service

4a9ea47195d30c34bcaac168d820c686dbfa4c0d
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / plugin / pragma_plugin.c
1 /* Demonstrates how to add custom pragmas */
2
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
18 int plugin_is_GPL_compatible;
19
20
21 /* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to
22    handler of #pragma GCC message...*/
23
24 static void
25 handle_pragma_sayhello (cpp_reader *dummy)
26 {
27   tree message = 0;
28   if (pragma_lex (&message) != CPP_STRING)
29     {
30       warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN sayhello%>  is not a string");
31       return;
32     }
33   if (TREE_STRING_LENGTH (message) > 1)
34     if (cfun)
35       warning (OPT_Wpragmas, 
36               "%<pragma GCCPLUGIN sayhello%> from function %qE: %s",
37               cfun->decl, TREE_STRING_POINTER (message));
38       else
39         warning (OPT_Wpragmas, 
40             "%<pragma GCCPLUGIN sayhello%> outside of function: %s",
41             TREE_STRING_POINTER (message));
42 }
43
44 /* Plugin callback called during pragma registration */
45
46 static void 
47 register_my_pragma (void *event_data, void *data) 
48 {
49   warning (0, G_("Callback to register pragmas"));
50   c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello);
51 }
52
53 int
54 plugin_init (struct plugin_name_args *plugin_info,
55              struct plugin_gcc_version *version)
56 {
57   const char *plugin_name = plugin_info->base_name;
58
59   register_callback (plugin_name, PLUGIN_PRAGMAS, register_my_pragma, NULL);
60   return 0;
61 }