[cfe-dev] Decls are not synonyms for the symbols they represent
Ted Kremenek
kremenek at apple.com
Wed Sep 17 11:20:02 PDT 2008
On Sep 17, 2008, at 9:50 AM, Argiris Kirtzidis wrote:
> This is what I think too, it's better if the AST is a simple as
> possible, more higher level semantic information could be build on
> top of the AST, instead of getting embedded in.
Agreed. I was thinking of something more of the lines of what Steve
mentioned in his last email. Just a clean way to go from Decls ->
unique identifier.
>
> For example, there could be a framework like the analysis framework,
> that gets "fed" ASTs from multiple translation units and can reason
> about declarations as a whole.
I've been thinking about doing this for a while, and it would be
something needed for inter-procedural static analysis. However, to
me, this is a different concept that would be layered on top of
whatever mechanism is in place to resolve identifiers/declarations
*within* a translation unit.
The problem that I'm concerned with right now is that there are cases
where two DeclRefExprs can refer to different VarDecls that correspond
to the same variable, but a client of the AST has no way of knowing
that that is the case. Consider:
----
extern int x;
void foo() {
x++;
}
extern int x;
void bar() {
x++;
}
void baz() {
extern int x;
x++;
}
-----
If you do an AST dump of this, you will see that the DeclRefExprs for
'x' in foo(), bar(), and baz() respectively refer to separate
VarDecls. Right now a client of the ASTs has no way of knowing that
these VarDecls refer to the same variable. Certainly a higher-level
API that resolves identifiers across translation units could do this,
but it might have to do a lot of work to resolve situations like the
one above. By having a mechanism to resolve identifiers within a
translation unit, this higher-level API would much easier to implement.
More information about the cfe-dev
mailing list