How do I get an enum element's numerical value using libclang?
libclang exposes this information through clang_getEnumConstantDeclValue
and clang_getEnumConstantDeclUnsignedValue
. A map like you describe can be built by visiting the children of a CXCursor_EnumDecl
:
static enum CXChildVisitResult VisitCursor(CXCursor cursor, CXCursor parent, CXClientData client_data) {
if (cursor.kind == CXCursor_EnumConstantDecl) {
CXString spelling = clang_getCursorSpelling(cursor);
myMap[clang_getCString(spelling)] = clang_getEnumConstantDeclValue(cursor);
clang_disposeString(spelling);
}
return CXChildVisit_Continue;
}