[cfe-dev] PATCH: Cleanup function redeclaration representations

Argiris Kirtzidis akyrtzi at gmail.com
Wed Apr 23 08:24:30 PDT 2008


Hi Doug,

When a function is redeclared, the parser reports the same decl pointer 
to the ASTConsumer, basically the ASTConsumer gets a new object but with 
the same
pointer as the previous decl. I think that this complicates things a bit 
from the aspect of a ASTConsumer.

For example, there's a consumer in clang (SerializationTest used with 
'-test-pickling'), that stores the decls reported from 
HandleTopLevelDecl into a vector
so that it can later 'feed' them in the same order to another consumer. 
This breaks when a redeclaration is reported because it then stores the 
same pointer
for each redeclaration.

How about instead of linking with previous decl, linking with next decl 
is used instead. For example:

   int f(int x) { return x; } // #1
   int f(int x); // #2
   int f(int x) { return x; } // #3


-For #1 , parser reports it
-For #2, it is merged with #1, #2 is not introduced in scope, #1 points 
to #2 (as next decl), and parser reports the decl pointer of #2
-For #3, it is merged with #1, #3 is not introduced in scope, #2 points 
to #3 (as next decl), and parser reports the decl pointer of #3

I think this is simpler and there's no need to have in AST the 
addDeclaration method that swaps the contents of decl objects.
The drawback is that there needs to be an additional connection, like #2 
and #3 both pointing to #1 as the decl that represents the function.

What do you think ?


-Argiris



More information about the cfe-dev mailing list