[cfe-dev] Getting the FieldDecl of a template class from a MemberExpr

Adrien Chauve adrien.chauve at gmail.com
Fri May 27 10:02:03 PDT 2011


Hi,

Using a RecursiveASTVisitor, I've been trying to rename field names against
some conventions.

Let's say I would like to rename Foo::bar into Foo::m_bar in the following
code:

template<typename T>
struct Foo
{
    int bar;
};

int main()
{
    Foo<double> foo;
    foo.bar = 2;

    return 1;
}


In my custom visitor, I implement the following method:

bool VisitMemberExpr(MemberExpr* member)
{
    ValueDecl* v = member->getMemberDecl(); // FieldDecl or CXXMethodDecl
    ...
}

But the FieldDecl I get when visiting the statement corresponding to
"foo.bar=2;" is Foo<double>::bar, but not Foo::bar.

So my question is: is it possible to get the FieldDecl of Foo<T>::bar from
the FieldDecl of Foo<double>::bar ? at least when the struct is not
specialized?
What happens when the struct is specialized?


Thanks,
Adrien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110527/3aa79a37/attachment.html>


More information about the cfe-dev mailing list