Rebase.
[official-gcc.git] / gcc / testsuite / g++.dg / plugin / attribute_plugin.c
blob8de5f44cbf8721521fc20b491a63b5c8af1b7feb
1 /* Demonstrates how to add custom attributes */
3 #include "gcc-plugin.h"
4 #include <stdlib.h>
5 #include "config.h"
6 #include "system.h"
7 #include "coretypes.h"
8 #include "tree.h"
9 #include "tree-pass.h"
10 #include "intl.h"
11 #include "toplev.h"
12 #include "plugin.h"
13 #include "diagnostic.h"
15 int plugin_is_GPL_compatible;
17 /* Attribute handler callback */
19 static tree
20 handle_user_attribute (tree *node, tree name, tree args,
21 int flags, bool *no_add_attrs)
23 return NULL_TREE;
26 /* Attribute definition */
28 static struct attribute_spec user_attr =
29 { "user", 1, 1, false, false, false, handle_user_attribute, false };
31 /* Plugin callback called during attribute registration */
33 static void
34 register_attributes (void *event_data, void *data)
36 warning (0, G_("Callback to register attributes"));
37 register_attribute (&user_attr);
40 /* Callback function to invoke before the function body is genericized. */
42 void
43 handle_pre_generic (void *event_data, void *data)
45 tree fndecl = (tree) event_data;
46 tree arg;
47 for (arg = DECL_ARGUMENTS(fndecl); arg; arg = DECL_CHAIN (arg)) {
48 tree attr;
49 for (attr = DECL_ATTRIBUTES (arg); attr; attr = TREE_CHAIN (attr)) {
50 tree attrname = TREE_PURPOSE (attr);
51 tree attrargs = TREE_VALUE (attr);
52 warning (0, G_("attribute '%s' on param '%s' of function %s"),
53 IDENTIFIER_POINTER (attrname),
54 IDENTIFIER_POINTER (DECL_NAME (arg)),
55 IDENTIFIER_POINTER (DECL_NAME (fndecl))
61 int
62 plugin_init (struct plugin_name_args *plugin_info,
63 struct plugin_gcc_version *version)
65 const char *plugin_name = plugin_info->base_name;
66 register_callback (plugin_name, PLUGIN_PRE_GENERICIZE,
67 handle_pre_generic, NULL);
69 register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
70 return 0;