]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/plugin/pragma_plugin.c
1 /* Demonstrates how to add custom pragmas */
3 #include "gcc-plugin.h"
15 #include "hard-reg-set.h"
18 #include "c-family/c-pragma.h"
20 #include "tree-pass.h"
23 #include "diagnostic.h"
25 int plugin_is_GPL_compatible
;
28 /* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to
29 handler of #pragma GCC message...*/
32 handle_pragma_sayhello (cpp_reader
*dummy
)
35 if (pragma_lex (&message
) != CPP_STRING
)
37 warning (OPT_Wpragmas
, "%<#pragma GCCPLUGIN sayhello%> is not a string");
40 if (TREE_STRING_LENGTH (message
) > 1)
42 warning (OPT_Wpragmas
,
43 "%<pragma GCCPLUGIN sayhello%> from function %qE: %s",
44 cfun
->decl
, TREE_STRING_POINTER (message
));
46 warning (OPT_Wpragmas
,
47 "%<pragma GCCPLUGIN sayhello%> outside of function: %s",
48 TREE_STRING_POINTER (message
));
51 /* Plugin callback called during pragma registration */
54 register_my_pragma (void *event_data
, void *data
)
56 warning (0, G_("Callback to register pragmas"));
57 c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello
);
61 plugin_init (struct plugin_name_args
*plugin_info
,
62 struct plugin_gcc_version
*version
)
64 const char *plugin_name
= plugin_info
->base_name
;
66 register_callback (plugin_name
, PLUGIN_PRAGMAS
, register_my_pragma
, NULL
);