[cfe-dev] PATCH: Cleanup function redeclaration representations

Chris Lattner clattner at apple.com
Sun May 4 16:34:02 PDT 2008


On May 4, 2008, at 11:42 AM, Doug Gregor wrote:

>> I think this is a fairly reasonable sweet spot, what do you guys  
>> think?
>
> With Argiris' tweak, I almost like it. I'm concerned about the
> programmability of this system, where the FunctionDecl node that is
> found by name lookup is not the 'aggregate' node. As with the
> canonical type system, clients will have to be very careful to always
> map into the 'aggregate' node before querying any properties. With the
> canonical type system, we need to do the mapping because we need to
> preserve typedefs in the AST. With declarations, however, the
> complexity isn't coming directly from the language... it's coming from
> the representation. It will take a lot of discipline to use
> FunctionDecls properly if name lookup doesn't find the 'aggregate'
> FunctionDecl.

That is a great point, would it be reasonable to just always make the  
aggregate version by the one returned by scope lookups?

> It occurs to me that using FunctionDecl for each of the redeclarations
> isn't even as efficient as we could be. For example, the
> redeclarations don't need to have scope or name information, because
> we know they're the same as the aggregate FunctionDecl, nor do they
> need information about the body of the function. On the other hand,
> they do need some additional flags, such as "am I the definition?" One
> could imagine that each function only has a single FunctionDecl, which
> represents the aggregate declaration. That FunctionDecl contains a
> SmallVector<FunctionRedecl*, 2>, where each FunctionRedecl contains
> minimal information about a redeclaration... the exact types used in
> the parameter-type-list, the attributes, whether it was the
> definition, etc. All of semantic analysis sees just that one
> FunctionDecl, and those clients interested in dealing with
> redeclarations can walk that redeclaration list; One could also
> consider adding a callback that is invoked on each redeclaration.

That is an interesting idea.  I think that it could be done as a  
refinement on the first step of getting the current plan in place, do  
you agree?

-Chris



More information about the cfe-dev mailing list