[libcpp] patch: add used callback
Basile STARYNKEVITCH
basile@starynkevitch.net
Mon Nov 16 17:17:00 GMT 2009
Arnaud Charlet wrote:
>
> BTW, here is an updated patch, using the proper source location for the
> macro reference (use pfile->invocation_location instead of
> pfile->directive_line which gives the line of the last cpp directive,
> not very useful in this context).
I would still like a plugin hook here.
> Maybe I could make it clearer that this callback does not get called
> for define/undef in the cpplib.h comment?
Yes please
>
> What about this patch?
>
> --
> Index: macro.c
> ===================================================================
> --- macro.c (revision 153897)
> +++ macro.c (working copy)
> @@ -885,6 +885,9 @@ enter_macro_context (cpp_reader *pfile,
> pfile->cb.used_define (pfile, pfile->directive_line, node);
> }
>
> + if (pfile->cb.used)
> + pfile->cb.used (pfile, pfile->invocation_location, node);
> +
> macro->used = 1;
Perhaps something like
invoke_plugin_callbacks (PLUGIN_EXPAND_MACRO, node);
would be useful at this place (e.g. for a plugin doing metrics on macro expansions)?
[I am not sure to get it right; I don't understand a lot libcpp]
>
> if (macro->paramc == 0)
> Index: include/cpplib.h
> ===================================================================
> --- include/cpplib.h (revision 153897)
> +++ include/cpplib.h (working copy)
> @@ -508,6 +508,10 @@ struct cpp_callbacks
> /* Called before #define and #undef or other macro definition
> changes are processed. */
> void (*before_define) (cpp_reader *);
> + /* Called whenever a macro is expanded or tested.
> + Note: this callback is not called when a #define/#undef directive is
> + processed, consider used_define or used_undef instead. */
> + void (*used) (cpp_reader *, unsigned int, cpp_hashnode *);
> };
If a plugin event gets added for macro expansions, please add a comment refering to it here.
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***
More information about the Gcc-patches
mailing list