From d1c8e08a0c45483b90b09e6cdf12cf8d77876fd6 Mon Sep 17 00:00:00 2001 From: Taras Glek Date: Thu, 14 May 2009 01:38:33 +0000 Subject: 2009-05-13 Taras Glek gcc/ * attribs.c moved out attribute registration into register_attribute * doc/plugins.texi Documented register_attribute and PLUGIN_ATTRIBUTES * gcc-plugin.h Added forward decl for register_attribute * plugin.c Added PLUGIN_ATTRIBUTES boilerplate * plugin.h Added PLUGIN_ATTRIBUTES gcc/testsuite/ * g++.dg/plugin/attribute_plugin-test-1.C Testcase input for custom attributes and decl smashing * g++.dg/plugin/attribute_plugin.c Testcase plugin to test user attributes * g++.dg/plugin/dumb_plugin.c Fixed typo * g++.dg/plugin/plugin.exp Added attribute_plugin test From-SVN: r147516 --- gcc/doc/plugins.texi | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'gcc/doc/plugins.texi') diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi index 7c3fbed..1710395 100644 --- a/gcc/doc/plugins.texi +++ b/gcc/doc/plugins.texi @@ -71,6 +71,7 @@ enum plugin_event PLUGIN_FINISH_UNIT, /* Useful for summary processing. */ PLUGIN_CXX_CP_PRE_GENERICIZE, /* Allows to see low level AST in C++ FE. */ PLUGIN_FINISH, /* Called before GCC exits. */ + PLUGIN_ATTRIBUTES, /* Called during attribute registration */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ @}; @@ -135,3 +136,35 @@ plugin_init (const char *plugin_name, int argc, struct plugin_argument *argv) ... @} @end smallexample +@section Registering custom attributes + +For analysis purposes it is useful to be able to add custom attributes. + +The @code{PLUGIN_ATTRIBUTES} callback is called during attribute +registration. Use the @code{register_attribute} function to register +custom attributes. + +@smallexample +/* Attribute handler callback */ +static tree +handle_user_attribute (tree *node, tree name, tree args, + int flags, bool *no_add_attrs) +@{ + return NULL_TREE; +@} + +/* Attribute definition */ +static struct attribute_spec user_attr = + @{ "user", 1, 1, false, false, false, handle_user_attribute @}; + +/* Plugin callback called during attribute registration. +Registered with register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL) +*/ +static void +register_attributes (void *event_data, void *data) +@{ + warning (0, G_("Callback to register attributes")); + register_attribute (&user_attr); +@} + +@end smallexample -- cgit v1.1