[cfe-dev] PATCH: Cleanup function redeclaration representations

John Freeman freeman1 at gmail.com
Thu Apr 24 05:57:55 PDT 2008


On Thu, Apr 24, 2008 at 4:31 AM, Argiris Kirtzidis <akyrtzi at gmail.com>
wrote:

> Argiris Kirtzidis wrote:
> >
> >> There's some philosophy behind my approach to function redeclarations:
> >> I want "normal" users of the AST to only see a single FunctionDecl for
> >> each function, and that FunctionDecl should contain all of the
> >> information that the AST contains about that function.
> >
> > I agree. The only difference is in case of
> >
> >  void f(int x); // #1
> >  void f(int x = 2); // #2
> >
> >
> > instead of merging to #2 and swaping contents with #1, thus pointer of
> > #1 now points to #2,
> > I suggest merging to #1.
> > In both cases, every use of 'f' will point to the same FunctionDecl node.
>
> The thing is, it seems to me that 'swaping contents' complicates things
> (from the perspective of a ASTConsumer) without offering some benefit.
> Could you explain why it's useful ?


I believe this was Doug's reason:

<quote>
That way, subsequent lookups of the function get the latest declaration.
This is really important, both for semantic and usability reasons:
semantically, we need all of the information from later declarations
in the FunctionDecl that name lookup finds, e.g.,

 void f(int x); // #1
 void f(int x = 2); // #2
 void g() { f(); } // need to see the default argument from declaration #2

The same thing happens in C, if the first declaration doesn't have a
prototype.
</quote>

However, I'm curious if his approach would be able to handle this:

void f(int x = 2); // #1
void f(int x); // #2
void g() { f(); } // need to see the default argument from declaration #1

Doug also said (emphasis added):

<quote>
So, if name lookup is going to continue to find the first declaration
of a function (as it does in your suggestion and in the patch I
committed), that first declaration either _*needs to accumulate
information from redeclarations*_ or access to its internals needs to
walk through the chain of redeclarations, e.g., to find default
arguments.
</quote>

Perhaps accumulation is the approach most agreeable?

- John

P.S. Howdy everyone! I've been watching the mailing list for awhile now, but
this is my first correspondence.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080424/2b461365/attachment.html>


More information about the cfe-dev mailing list