This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PLUGIN] Fix PLUGIN_FINISH_TYPE


Hi

2011/9/12 Dodji Seketeli <dodji@seketeli.org>:
> Romain Geissler <romain.geissler@gmail.com> a Ãcrit:
>> When i recontributed the PLUGIN_FINISH_DECL patch from the original
>> Brian Hackett, i didn't exactly checked  what may or may not trigger
>> this new event. I know for example that declaring a function triggers
>> this event, but defining it does not.
>>
>> I don't really know when those event should be triggered, we should
>> clarify the meaning of those.
>>
>> According to me:
>> PLUGIN_FINISH_DECL should be triggered anytime the parser parse a
>> declaration (which includes declaration + definition of function,
>> typedef definition, namespaces, ..., all DECL_P trees built by the
>> parser).
>
> The general idea sounds sensible, IMHO.  However, we must keep in mind
> that there are cases like, e.g, 'struct C;' where G++ creates a typedef
> 'typedef struct C C;' so that you can name that type 'C' instead of
> having to type "struct C' all the time.  For these cases, I don't think
> the PLUGIN_FINISH_DECL event should be emitted.

I agree.

>
>> For, PLUGIN_FINISH_TYPE i don't really know it means a new type
>> declaration (or declaration + definition) or if it means usage of a
>> type (in a function prototype, the type of a local variable.
>
> I'd say it's a definition of a new type, IMHO.

Ok, so it only involves struct, unions, enum and class declaration / definitions.

>
>> I would rather vote for new type definition (including typedefs)
>
> My understanding is that a typedef declaration doesn't define a new
> type.  Rather, it declares an alias for an existing type.  As such, I
> would think that notifying typedef declarations via PLUGIN_FINISH_DECL
> would be the way to go.

Ok

>
>> but for special cases of struct, you can declare and use them at the
>> same time:
>
> Just to be sure I understand, do you need to be notified about *uses* of
> types and decls as well?  If so, maybe a new kind of event should
> probably be defined, because PLUGIN_FINISH_DECL and PLUGIN_FINISH_TYPE
> seem to have more to do with declaring/defining decls and types than
> using them.
>

Personally i don't need to catch all struct uses, but i need to catch struct declarations.
I want to apply some __attributes__ to a given struct type, for example let's say i need to mark *struct my_struct* as deprecated thanks to a plugin. I know how to apply some attributes to a type or a decl. See the plugin (test_plugin.c) and the test files attached.


With test_pass.c, my_struct is declared first, then defined after, applying the deprecated attribute works.
With test_fail.c, my_struct is declared and defined at the same time, applying the deprecated attribute doesn't work with the current trunk (and also with my patch).
I got:
test_fail.c:4:1: warning: type attributes ignored after type is already defined [-Wattributes]


So i may need a PLUGIN_FINISH_TYPE_DECLARATION triggered when the type is declared but before it is finally defined.

Does two different events PLUGIN_FINISH_TYPE_DECLARATION and PLUGIN_FINISH_TYPE_DEFINITION make sens to you ?

> --
>                Dodji
>

Romain Geissler

Attachment: test_fail.c
Description: Text document

Attachment: test_pass.c
Description: Text document

Attachment: test_plugin.c
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]