Finding anonymous enums with libclang
Unfortunately clang_Cursor_isAnonymous
works only with structs and unions as you can see from clang source code in tools/libclang/CXType.cpp
unsigned clang_Cursor_isAnonymous(CXCursor C){ if (!clang_isDeclaration(C.kind)) return 0; const Decl *D = cxcursor::getCursorDecl(C); if (const RecordDecl *FD = dyn_cast_or_null<RecordDecl>(D)) return FD->isAnonymousStructOrUnion(); return 0;}
So fallback to the conf.lib.clang_Cursor_isAnonymous
in clang.cindex.Cursor.is_anonymous does nothing new as cursor type has been already checked against FIELD_DECL (which is true only for structs and unions)
def is_anonymous(self): """ Check if the record is anonymous. """ if self.kind == CursorKind.FIELD_DECL: return self.type.get_declaration().is_anonymous() return conf.lib.clang_Cursor_isAnonymous(self)
You can try to extract identifier of current element (n in your sample) and check if it exists or is null