How do you detect the difference between enum and enum enum using libclang?

I wrote the C ++ AST parser using the excellent C libclang interface ( http://clang.llvm.org/doxygen/group__CINDEX.html ). Unfortunately, apparently, there are no differences between the C ++ 11 areas and the old lists: both are of type CXCursor_EnumDecl and type CXType_Enum Ie are identical.

I tried to visit the children to find out if their parent type is different - unfortunately not. I tried asking for the base type, I am returning an integer for both. I reviewed all the elements declared after Enum to see if there could be a link or typedef for old-fashioned Enums, again the difference is not obvious.

I'm starting to think that something is missing me. Should I use the code completion API to find out what type of Enum it is or something else?

+8
c ++ 11 abstract-syntax-tree libclang
source share
1 answer

So, here is one solution, although it is not great, but it can help others. CXCursor is a structure that looks like this:

typedef struct { enum CXCursorKind kind; int xdata; const void *data[3]; } CXCursor; 

Currently, void * [3] data is mapped to {const clang :: Decl * Parent, const clang :: Stmt * S, CXTranslationUnit TU}. Knowing this, we can write code that extracts C ++ internal clang objects from C libclang state:

 #include "clang/AST/Decl.h" bool isScoped=false; { using namespace clang; const Decl *D = static_cast<const Decl *>(cursor.data[0]); if(const EnumDecl *TD = dyn_cast_or_null<EnumDecl>(D)) { isScoped=TD->isScoped(); } } 

Many bad things can happen to this solution if your clang headers deviate from your libclang. I don't really care about this solution, but it works.

+3
source share

All Articles