[cfe-dev] Decls are not synonyms for the symbols they represent

Ted Kremenek kremenek at apple.com
Wed Sep 17 14:11:23 PDT 2008

On Sep 17, 2008, at 1:06 PM, Nico Weber wrote:

> Hi,
> On 17.09.2008, at 21:52, Ted Kremenek wrote:
>>> For this example, I'd like to know why/when we care if all these
>>> VarDecls refer to the same variable? Since each VarDecl is "extern",
>>> it's the linkers job to bind the actual variable definition (which
>>> isn't in this particular translation unit).
>> Another example would be a client that wanted to rename 'x'.  How
>> would it know all of the declarations for the same variable?  There
>> are lots of cases where clients, looking the AST for a translation
>> unit, want to know which declarations refer to the same thing.
> How would that client work? As far as I understand, each translation  
> unit has its own AST, so this client needs some kind of linker that  
> merges information from several ASTs. For example:
> a.c:
> int a = 4;
> /* use a somewhere below in file*/
> b.c:
> extern int a;
> /* use a somewhere below file */
> c.c:
> extern int a;
> /* use a somewhere below in file*/
> If the tool should rename `a` to `importantCache` (or whatever), it  
> has to know which of a.c, b.c, and c.c belong to the same project  
> and only rename the `a`s in there. More information in a single  
> translation unit doesn't help here, some kind of linker is required.

To rename across files we would need a higher-level API that can  
provide an entire "image" of the entire program/library.  That would  
require some kind of symbol lookup.  As a prerequisite, it seems to me  
that we would need the facilities to be able to do this within a  
single translation unit.

More information about the cfe-dev mailing list