[cfe-dev] Function return type and namespace qualifiers in libclang
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Feb 21 14:06:15 PST 2013
On Feb 9, 2013, at 7:58 AM, Victor Gaydov <victor at enise.org> wrote:
> 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.
I suggest enhancing "clang_Cursor_getSpellingNameRange()" to work similar as "clang_getCursorReferenceNameRange()" and have it accept the same options (e.g. CXNameRange_WantQualifier).
Then you can pass it the cursor for the function and compare the CXSourceRanges that it gives you with the ones for the NamespaceRef/TypeRef cursors.
>
> Thanks, sorry for self-replying.
>
> -- Victor
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130221/bf722e0b/attachment.html>
More information about the cfe-dev
mailing list