Something like the following first_attr function will retrieve the cursor of the first attribute of the passed cursor, if it exists, or the null cursor if it is not running (untested code ... caveat lector)
CXChildVisitResult attr_visit(CXCursor cursor, CXCursor parent, CXClientData data) { if (clang_isAttribute(cursor)) { *data = cursor; return CXChildVisit_Break; } return CXChildVisit_Continue; } CXCursor first_attr(const CXCursor& c) { CXCursor attr; unsigned visit_result = clang_visitChildren(c, attr_visit, &attr); if (!visit_result)
As for determining which particular attribute cursor a displays, the result of clang_getCursorKind(a) may help, but the only recognized attributes are:
CXCursor_IBActionAttr CXCursor_IBOutletAttr CXCursor_IBOutletCollectionAttr CXCursor_CXXFinalAttr CXCursor_CXXOverrideAttr CXCursor_AnnotateAttr CXCursor_AsmLabelAttr
Everything else will be CXCursor_UnexposedAttr , and the only way I can present its text is to study clang_getCursorExtent(a) (i.e. read the source code, cf. clang_tokenize ). For annotations, the specific annotation used is available through clang_getCursorDisplayName .
Jan Ladislav Dussek
source share