[cfe-dev] TreeTransform and Clang

Sebastian Redl sebastian.redl at getdesigned.at
Fri Aug 20 10:36:04 PDT 2010


On Aug 20, 2010, at 4:08 AM, Vassil Vassilev wrote:

> Hello Doug,
>  Sorry for the delayed answer but I tried to dig a little bit in the
> problem. After all I am going to try what you suggested:
>> The right way to do this would be to augment Sema's name-lookup facilities, so that your application gets a chance to provide symbols when no other symbols of the same name work. One way to do this is to create your own ExternalASTSource, and override FindExternalVisibleDeclsByName to add those symbols. If I remember correctly, LLDB does this.
> If I have understood correctly I need to create a new class in the
> interpreter which is actually new ExternalASTSource. Then the Sema is
> going to check for the symbol first in the most inner scope then outer
> and finally it will check the ExternalASTSource class if it can
> recognize the symbol. If it does then it is going to put what I want in
> the AST right?

No, ExternalASTSource doesn't work that way.
For C, the EASTS is queried the moment the identifier is first encountered in a source file. It only works for global identifiers.
For C++, the moment you do name lookup in a given context, the context checks if it has names in the external source (a flag that currently can only be set by that external source, if the context itself originates there) and loads them all. For a function that is in the source, the EASTS will never be queried. For the global context, the source will be queried at the very first name lookup done.
We will change the C++ case soon, but probably not in a way that really helps you, given that you want the contents of the external source modified in the middle of a function.

Sebastian





More information about the cfe-dev mailing list