[cfe-users] libclang: Spelling on typedefs lacks namespaces
Michael via cfe-users
cfe-users at lists.llvm.org
Tue Sep 27 07:37:23 PDT 2016
> I think you want to get the underlying type from the typedef and then
use getTypeSpelling on that result.
Hmm, I don't think so, I actually would like to keep the typedefs in my
generated code (for readability, and because it might actually resolve
to something different when the generated code is used or to something
clang specific which then fails with other compilers). Also the
underlying type could again contain typedefs with missing namespace, so
I would have to go all the way down to the canonical type (which is what
I'm actually doing currently as a workaround)...
Michael
On 09/27/2016 03:53 PM, Adam McLaughlin wrote:
> Hi Michael,
>
> I haven't used libclang much (my use case requires LibTooling) but I
> think you want to get the underlying type from the typedef and then use
> getTypeSpelling on that result. Basically you want to check if
> CXType.kind is CXType_Typedef and if so, get the underlying type (which
> in this case should be "Bar") and then call clang_getTypeSpelling on
> that result.
>
> I don't know anything about CXCursors or CXTypes so I'll leave it to you
> to figure out how to get the underlying type, but hopefully this helps.
>
> -Adam
>
>
>
> On Tue, Sep 27, 2016 at 8:55 AM, Michael via cfe-users
> <cfe-users at lists.llvm.org <mailto:cfe-users at lists.llvm.org>> wrote:
>
> Nobody? Wrong list? Any insight in this would be greatly appreciated.
>
> Thanks
>
> Michael
>
>
> On 08/30/2016 07:00 PM, Michael via cfe-users wrote:
>
> Hi
>
> Hope I picked the right place for this kind of problem, if not
> please let me know.
>
> I'm using libclang to parse header files and generate code from
> them. I found that clang_getTypeSpelling() usually includes the
> namespace(s) a type was declared in. However with the exception
> being typedefs (and same for "using A = B"). Not sure if this is
> a bug or intended behavior, but it seems at least inconsistent.
> I also couldn't really find a good workaround for this. I'd have
> to manually figure out all typedefs (not just pure typedefs,
> they could also be template parameters or whatever) and then
> their originating namespaces. This sounds a bit cumbersome and
> not really straight forward.
>
> Minimal example:
>
> namespace foo {
> class Bar {
> };
> typedef Bar BarDef;
> }
>
> clang_getTypeSpelling on "Bar" (kind "Record") gives: "foo::Bar"
> clang_getTypeSpelling on "BarDef" (kind "Typedef") gives:
> "BarDef" (<== missing "foo::")
>
> Any idea how to solve this problem? Am I missing something?
>
> Thanks
>
> Michael
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org <mailto:cfe-users at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
> <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users>
>
>
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org <mailto:cfe-users at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
> <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users>
>
>
More information about the cfe-users
mailing list