[cfe-dev] Function return type and namespace qualifiers in libclang

Victor Gaydov victor at enise.org
Sat Feb 9 07:58:25 PST 2013


Victor Gaydov (Sunday 03 February 2013 00:49:16):
> Hello!
> 
> 1) When traversing AST (with clang_visitChildren) parsed from this code:
> > namespace foo {
> >   struct bar {};
> >   struct baz {
> >     bar qux();
> >   };
> > }
> > 
> > foo::bar foo::baz::qux() {}
> 
> ..following nodes are visited for qux() definition (last line):
>
> > +--------------+---------+--------+-----------------+
> > | kind         | parent  | text   | spelling        |
> > +--------------+---------+--------+-----------------+
> > | NamespaceRef | qux()   | foo    | foo             |
> > | TypeRef      | qux()   | bar    | struct foo::bar |
> > | NamespaceRef | qux()   | foo    | foo             |
> > | TypeRef      | qux()   | baz    | struct foo::baz |
> > +--------------+---------+--------+-----------------+
> 
> First two nodes are function return type and second two nodes are function
> namespace qualifiers.
> 
> Is it possible to determine, if visited node (cursor) belongs to return
> type or to qualifier?
> 
> [...]

Update: I also was unable to get namespace qualifiers of FunctionDecl with 
clang_getCursorReferenceNameRange() and didn't find anything helpful in 
clang/tools/c-index-test.c.

So is it impossible to get qualified name of function and its return type 
(when both are qualified) with current API?

If this is so, I would like to write a patch. One possible approach is to 
transform AST for this code:

> foo::bar foo::baz::qux() {}

from:

>       qux <-- FunctionDecl
>       / \
>      /   \
>     /|   |\
>    / |   | \
>   /  |   |  \
>  /   |   |   \
> foo bar foo baz

to:

>         qux <-- FunctionDecl
>         / \
>        /   \
>       / \   \
>      /  foo baz
>     /
>    o <-- FunctionReturnType (new cursor type)
>   / \
>  /   \
> foo  bar

But I guess this can break backward compatibility? I'm new to libclang, so I 
need some advice about preferred way to implement such patch.

Thanks, sorry for self-replying.
 
-- Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130209/ed646373/attachment.html>


More information about the cfe-dev mailing list