[cfe-dev] Getting the pointer to an out-of-class VarDecl

Ismail Pazarbasi ismail.pazarbasi at gmail.com
Wed Oct 1 02:23:56 PDT 2014


On Tue, Sep 30, 2014 at 12:49 PM, Manuel Klimek <klimek at google.com> wrote:
>
>
> On Tue Sep 30 2014 at 12:44:02 PM Mihai Draghicioiu
> <mihai.draghicioiu at gmail.com> wrote:
>>
>> Ah, I've figured out why this happens, it's because I call TraverseDecl
>> from ASTConsumer::HandleTopLevelDecl(), so the full AST isn't traversed at
>> this point. So now I need to figure out how to traverse the AST only after
>> fully parsing it....
>>
>> class MyASTConsumer : public ASTConsumer {
>>   public:
>> virtual bool HandleTopLevelDecl(DeclGroupRef d) {
>> typedef DeclGroupRef::iterator iter;
>> MyRecursiveASTVisitor rv;
>> for (iter b = d.begin(), e = d.end(); b != e; ++b) {
>> rv.TraverseDecl(*b);
>> }
>> return true;
>> }
>> };
>
>
> http://clang.llvm.org/docs/RAVFrontendAction.html
> -> use HandleTranslationUnit
>
> Cheers,
> /Manuel

Yes, wait until translation unit is parsed without any errors. Then,
you can check whether the decl you are visiting is the definition (see
VarDecl::isThisDeclarationADefinition()).



More information about the cfe-dev mailing list