diff --git a/src/Token.cc b/src/Token.cc index 310a130..ce3da9b 100644 --- a/src/Token.cc +++ b/src/Token.cc @@ -59,6 +59,7 @@ std::string clang::Token::get_type() { return spelling; } +//TODO: use clang_Cursor_getBriefCommentText std::string clang::Token::get_brief_comments() { std::string comment_string; auto referenced=clang_getCursorReferenced(cx_cursor); diff --git a/src/Tokens.cc b/src/Tokens.cc index 50d9ebe..b62b982 100644 --- a/src/Tokens.cc +++ b/src/Tokens.cc @@ -33,3 +33,45 @@ std::vector > clang::Tokens::get_similar_token_off } return offsets; } + +std::vector > clang::Tokens::get_cxx_methods() { + std::vector > methods; + long last_offset=-1; + for(auto &token: *this) { + if(token.get_kind()==clang::Token_Identifier) { + auto cursor=token.get_cursor(); + auto kind=cursor.get_kind(); + if(kind==clang::CursorKind::CXXMethod || kind==clang::CursorKind::Constructor || kind==clang::CursorKind::Destructor) { + auto offset=cursor.get_source_location().get_offset(); + if(offset!=last_offset) { + std::string method; + CXString cxstr; + if(kind==clang::CursorKind::CXXMethod) { + auto type=clang_getResultType(clang_getCursorType(cursor.cx_cursor)); + auto cxstr=clang_getTypeSpelling(type); + method+=clang_getCString(cxstr); + clang_disposeString(cxstr); + auto pos=method.find(" "); + if(pos!=std::string::npos) + method.erase(pos, 1); + method+=" "; + } + + clang::Cursor parent(clang_getCursorSemanticParent(cursor.cx_cursor)); + cxstr=clang_getCursorDisplayName(parent.cx_cursor); + method+=clang_getCString(cxstr); + clang_disposeString(cxstr); + + method+="::"; + + cxstr=clang_getCursorDisplayName(cursor.cx_cursor); + method+=clang_getCString(cxstr); + clang_disposeString(cxstr); + methods.emplace_back(method, offset); + } + last_offset=offset; + } + } + } + return methods; +} diff --git a/src/Tokens.h b/src/Tokens.h index ae35873..96366cd 100644 --- a/src/Tokens.h +++ b/src/Tokens.h @@ -14,6 +14,7 @@ namespace clang { public: ~Tokens(); std::vector > get_similar_token_offsets(clang::Token& token); + std::vector > get_cxx_methods(); private: CXToken *cx_tokens; unsigned num_tokens;