[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-dev
Subject: Re: [cfe-dev] API for auto type deduction in libclang
From: Jacob Carlborg <doob () me ! com>
Date: 2014-01-26 12:00:24
Message-ID: lc2tcc$koj$1 () ger ! gmane ! org
[Download RAW message or body]
On 2014-01-25 22:03, Kevin Funk wrote:
> That doesn't work for me.
>
> For testing we have a small wrapper binary that basically creates a
> CXTranslationUnit and then traverses through the AST via
> clang_visitChildren().
>
> During the call to 'visit' it does the following (amongst other things):
> - auto location = clang_getCursorLocation(cursor)
> - auto type = clang_getCursorType(cursor)
> - auto typeString = clang_getTypeSpelling(type)
> - now: auto canonicalTypeString =
> clang_getTypeSpelling(clang_getCanonicalType(type))
>
> It outputs all the values of those variabes to stdout, and when I pass "auto i
> = 5;" to it I get:
>
> """
> decl: "auto (canonical type: auto) i " of kind VarDecl (9) in stdin.cpp@1:6
> "int (canonical type: int) " of kind IntegerLiteral (106) in stdin.cpp@1:10
> """
>
> So the 'canonical type' of VarDecl still resolves to 'auto', instead of 'int'.
> Sorry, if we're doing something completely wrong, but I don't seem to get this
> working as you suggest.
Ok, I see, you're using clang_getTypeSpelling. I created my tool before
clang_getTypeSpelling was available. For aggregates, typedefs and a
couple of other types I'm using the following code[1]:
auto cursor = clang_getTypeDeclaration(type);
auto str = clang_getCursorSpelling(cursor);
For basic types like "int", "char" and so on, the above will return an
empty string. For those types I use a big switch statement on the type
kind and just returns a string representation [2].
[1]
https://github.com/jacob-carlborg/dstep/blob/master/dstep/translator/Type.d#L43
[2]
https://github.com/jacob-carlborg/dstep/blob/master/dstep/translator/Type.d#L248
--
/Jacob Carlborg
_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic