[cfe-dev] nodes not appearing in AST?

David Blaikie dblaikie at gmail.com
Fri Jan 6 12:18:35 PST 2012


I'm not sure if it's what the op was asking, but shouldn't the ast have
some node in the (uninstantiated template) that represents the
dependent call to too? Yet it seems printing the ast didn't show 'foo'
anywhere in the template by the looks of it. Is it perhaps just
something that's not printed by the ast pretty printing?
From: Eli Friedman
Sent: 1/6/2012 10:04 AM
To: Robert Anderson
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] nodes not appearing in AST?
On Fri, Jan 6, 2012 at 11:37 AM, Robert Anderson
<rwa at alumni.princeton.edu> wrote:
>
> It seems the AST generated by libclang is missing nodes in some cases.
> Example:
>
> The AST for the program:
>
> struct A {
>    void foo() {};
> };
>
> template <class T>
> struct B {
>    void bar();
>    A m_a;
> };
>
> template <class T>
> void B<T>::bar()
> {
>    m_a.foo();
> }
>
> contains a CALL_EXPR node for the symbol foo, just as I expect:
>
> % ./c-index-test -test-print-typekind test6.cxx > out
> % grep foo out
> CXXMethod=foo:3:9 (Definition) typekind=FunctionProto [result=Void]
> [isPOD=0]
> CallExpr=foo:3:9 typekind=Dependent [isPOD=1]
> MemberRefExpr=foo:3:9 SingleRefName=[15:8 - 15:11] RefName=[15:8 - 15:11]
> typekind=Unexposed [isPOD=1]
>
> However, the program:
>
> template <class T>
> struct A {
>    void foo() {};
> };
>
> template <class T>
> struct B {
>    void bar();
>    A<T> m_a;
> };
>
> template <class T>
> void B<T>::bar()
> {
>    m_a.foo();
> }
>
> where A is now a class template, does NOT contain such a node.  The only
> node referencing foo is the declaration:
>
> % ./c-index-test -test-print-typekind test5.cxx > out
> % grep foo out
> CXXMethod=foo:4:9 (Definition) typekind=FunctionProto [result=Void]
> [isPOD=0]
>
> Can someone explain this?  Is this a bug?  How can I discover the "uses" of
> foo in this program if none of the nodes in the AST have that spelling?

In C++, you can't perform name lookup into a dependent type; we can't
actually prove what method "m_a.foo()" calls until "B<T>::bar()" is
instantiated.

-Eli

_______________________________________________
cfe-dev mailing list
cfe-dev at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list