]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/plugin/pragma_plugin.c
function.h: Flatten file.
[thirdparty/gcc.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 "hashtab.h"
12 #include "hash-set.h"
13 #include "vec.h"
14 #include "machmode.h"
15 #include "hard-reg-set.h"
16 #include "input.h"
17 #include "function.h"
18 #include "c-family/c-pragma.h"
19 #include "cpplib.h"
20 #include "tree-pass.h"
21 #include "intl.h"
22 #include "toplev.h"
23 #include "diagnostic.h"
24
25 int plugin_is_GPL_compatible;
26
27
28 /* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to
29 handler of #pragma GCC message...*/
30
31 static void
32 handle_pragma_sayhello (cpp_reader *dummy)
33 {
34 tree message = 0;
35 if (pragma_lex (&message) != CPP_STRING)
36 {
37 warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN sayhello%> is not a string");
38 return;
39 }
40 if (TREE_STRING_LENGTH (message) > 1)
41 if (cfun)
42 warning (OPT_Wpragmas,
43 "%<pragma GCCPLUGIN sayhello%> from function %qE: %s",
44 cfun->decl, TREE_STRING_POINTER (message));
45 else
46 warning (OPT_Wpragmas,
47 "%<pragma GCCPLUGIN sayhello%> outside of function: %s",
48 TREE_STRING_POINTER (message));
49 }
50
51 /* Plugin callback called during pragma registration */
52
53 static void
54 register_my_pragma (void *event_data, void *data)
55 {
56 warning (0, G_("Callback to register pragmas"));
57 c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello);
58 }
59
60 int
61 plugin_init (struct plugin_name_args *plugin_info,
62 struct plugin_gcc_version *version)
63 {
64 const char *plugin_name = plugin_info->base_name;
65
66 register_callback (plugin_name, PLUGIN_PRAGMAS, register_my_pragma, NULL);
67 return 0;
68 }