[cfe-dev] API for auto type deduction in libclang

Jacob Carlborg doob at me.com
Wed Jan 29 01:12:01 PST 2014


On 2014-01-28 12:40, Kevin Funk wrote:

> Unfortunately, your source code doesn't help me, nor can I get it to work
> using any combination of getTypeDeclaration, getCursorSpelling, and the ones I
> referred to earlier...

If you have a cursor pointing to the "x" in "auto x = 10;". Then calling 
clang_getCursorType on the cursor:

Cursor cursor;
// ..., cursor not points to "x"
auto type = clang_getCursorType(cursor);
assert(type.kind == CXType_Int);

Doesn't that work? Then use a switch like this:

string typeToString (CXType type)
{
     switch (type.kind)
     {
         case CXType_Int: return "int";
         case CXType_Double : return "double";
         //...
     }
}

It's not pretty but it should work as a workaround.

-- 
/Jacob Carlborg




More information about the cfe-dev mailing list