[cfe-dev] PATCH: Cleanup function redeclaration representations

Argiris Kirtzidis akyrtzi at gmail.com
Thu Apr 24 12:56:12 PDT 2008


Doug Gregor wrote:
> On Thu, Apr 24, 2008 at 11:21 AM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
>   
>>  The point here is, given a decl #1 and a redecl #2, is there an advantage
>> in merging #1 -> #2, instead of #2 -> #1 ?
>>     
>
> Merging #1 into #2 means that both #1 and #2 contain all of the
> information that its corresponding declarations contains. #1 contains
> all of the information about the first declaration of "f", including
> the exact type (with typedefs and such), parameter names, and which
> default arguments were present. #2 contains all of the information
> about the second declaration, its exact parameter types, parameter
> names, etc., which includes the merging of default arguments.
> (Semantically, the merged default arguments become a part of the
> declaration at #2).
>
> So, merging #1 into #2 this gives us very precise information about
> each of the declaration. I don't see how we can keep all of that
> information when merging #2 into #1, unless we do something like the
> "swap" trick that I'm already doing. Just merging #2 into #1 directly
> means that we'll lose the source information that was in #1. Or
> perhaps you are thinking of a different way of doing this merge?
>   

How about having a merge more like #1 <-> #2 :

(1)  -#2 merges default args from #1
(2)  -#2 is checked for error diagnostics about default args
(3)  -#1 gets default args from #2        \ 
(4)  -(#1)->setNextDeclaration(#2)      ----  (maybe 3,4 are performed 
in addRedeclaration method)
(5)  -#2 is returned by the parser but only #1 is visible in scope, thus 
all uses of the function will point to the same FunctionDecl node (#1)

In the end, both #1 and #2 contain all of the information that its 
corresponding declarations contain.
Merged default arguments become a part of both declarations.
Name lookup returns #1, which has all the necessary semantic information 
about default args.

Will this work or am I missing something ?


-Argiris



More information about the cfe-dev mailing list