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

Milian Wolff mail at milianw.de
Wed Jan 29 02:29:05 PST 2014


On Wednesday 29 January 2014 10:12:01 Jacob Carlborg wrote:
> 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:

No, it does not work. Have you tried the example that Kevin linked to?

wget -O clang-standalone-parser.c "http://quickgit.kde.org/?p=kdev-clang.git&a=blob&h=dbad9e8942cc5e20fd005677fc32a5a0b54977ae&f=tests%2Fclang-standalone-parser.c&o=plain"
clang clang-standalone-parser.c -I/usr/include/clang-c -l clang -o clang-
standalone-parser

echo "auto i = 1;" > test.cpp
./clang-standalone-parser --std=c++11 test.cpp

Gives me:

test.cpp:1:6 (5, 0-10) kind: VarDecl type: auto display name: i usr: c:@i 
definition 
  test.cpp:1:10 (9, 9-10) kind: IntegerLiteral type: int 

If I add something like this to the standalone example:

printString("type.kind", clang_getTypeKindSpelling(type.kind));

I see: "type.kind: Unexposed" - your assertion fails.

Thanks
-- 
Milian Wolff
mail at milianw.de
http://milianw.de



More information about the cfe-dev mailing list