[cfe-dev] API for auto type deduction in libclang
krf at gmx.de
Fri Jan 24 16:33:25 PST 2014
I'm also part of the group trying to integrate Clang into KDevelop. We're
using the C interface to Clang.
I'm currently struggling to figure out how to get the automatically deduced
type of a C++11 auto type. What we basically do atm is the following:
Assume we have some code such as 'auto i = 42;'
- We have a CXCursor pointing to the declaration
- Now clang_getCursorType(cursor) at this point
just returns CXType_Unexposed. This indicates some internal type.
- clang_getTypeSpelling(cursor) then just gives us 'auto'.
Which is somewhat correct, but not what we really want.
- We'd like to know the deduced type
So the question is:
Is there some way to get the deduced type for 'i' (obviously 'int' here)?
Through debugging, I found out that C++11 auto types are internally handled as
clang::AutoType. So, right now I'm missing API in the C interface, such as
'CXType clang_getAutoDeducedType(CXType)' that internally calls something like
clang::AutoType::getDeducedType() (from AST/Type.h).
I actually tried to patch Clang (excerpt attached) to get a proof-of-concept,
but apparently AutoType::getDeducedType() always returns a null QualType for
me. Hence the resulting type we get is garbage. Is AutoType::getDeducedType()
even the correct method to use here? Is this approach completely wrong?
Any hints are welcome
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 661 bytes
Desc: not available
More information about the cfe-dev