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

Victor Gaydov victor at enise.org
Sat Feb 2 12:49:16 PST 2013


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?

If not, what is a preferred way to implement such mechanism in libclang?

2) When traversing AST parsed from this code:

>   foo::bar var1;
> ::foo::bar var2;

where foo is top-level namespace, is it possible to determine, was foo 
referenced as 'foo' or as '::foo'?

For both var1 and var2 NamespaceRef spelling and substring pointed by cursor 
extent are just 'foo'.

Thanks.

PS.

I'm working on experimental back-end for emacs's semantic that will implement 
C++ parser using libclang. It will be plugin for irony-mode written by 
Guillaume Papin.

https://github.com/Sarcasm/irony-mode
https://github.com/Sarcasm/irony-mode/issues/5

-- Victor

In these matters the only certainty is that there is nothing certain.
		-- Pliny the Elder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130203/f886700f/attachment.html>


More information about the cfe-dev mailing list