Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / testsuite / g++.dg / plugin / attribute_plugin.c
blob6327095f7cddc5a6642ab2779cf175febbd51f0a
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"
14 int plugin_is_GPL_compatible;
16 /* Attribute handler callback */
18 static tree
19 handle_user_attribute (tree *node, tree name, tree args,
20 int flags, bool *no_add_attrs)
22 return NULL_TREE;
25 /* Attribute definition */
27 static struct attribute_spec user_attr =
28 { "user", 1, 1, false, false, false, handle_user_attribute };
30 /* Plugin callback called during attribute registration */
32 static void
33 register_attributes (void *event_data, void *data)
35 warning (0, G_("Callback to register attributes"));
36 register_attribute (&user_attr);
39 /* Callback function to invoke before the function body is genericized. */
41 void
42 handle_pre_generic (void *event_data, void *data)
44 tree fndecl = (tree) event_data;
45 tree arg;
46 for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN (arg)) {
47 tree attr;
48 for (attr = DECL_ATTRIBUTES (arg); attr; attr = TREE_CHAIN (attr)) {
49 tree attrname = TREE_PURPOSE (attr);
50 tree attrargs = TREE_VALUE (attr);
51 warning (0, G_("attribute '%s' on param '%s' of function %s"),
52 IDENTIFIER_POINTER (attrname),
53 IDENTIFIER_POINTER (DECL_NAME (arg)),
54 IDENTIFIER_POINTER (DECL_NAME (fndecl))
60 int
61 plugin_init (struct plugin_name_args *plugin_info,
62 struct plugin_gcc_version *version)
64 const char *plugin_name = plugin_info->base_name;
65 register_callback (plugin_name, PLUGIN_PRE_GENERICIZE,
66 handle_pre_generic, NULL);
68 register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
69 return 0;