How can I get the value of a primitive literal using libclang?
For example, if I have a CX cursor type cursor CXCursor_IntegerLiteral, how can I extract a literal value.
UPDATE:
I had a lot of problems using libclang. I highly recommend completely abandoning it and using the C ++ interface instead. The C ++ interface is very useful and very well documented: http://clang.llvm.org/doxygen/annotated.html
The only goal that I see now in libclang is to create an ASTUnit object for you, as with the following code (this is not entirely simple):
ASTUnit * astUnit; { index = clang_createIndex(0, 0); tu = clang_parseTranslationUnit( index, 0, clangArgs, nClangArgs, 0, 0, CXTranslationUnit_None ); astUnit = static_cast<ASTUnit *>(tu->TUData); }
Now you can say that libclang is stable, but the C ++ interface is not. This hardly matters, since the time spent figuring out AST using libclang and creating kludges with it spends so much of your time anyway. I would also spend several hours fixing the code that does not compile after updating the version (if necessary).
source share