From 251ff8ef0cb25f55649d67da3f14f85f481b530f Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 18 May 2016 12:55:38 +0200 Subject: [PATCH] Improved Tokens::get_cxx_methods and various minor cleanups --- src/Cursor.cc | 6 +++++- src/Cursor.h | 1 + src/Tokens.cc | 13 +++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Cursor.cc b/src/Cursor.cc index 07db31c..f413c45 100644 --- a/src/Cursor.cc +++ b/src/Cursor.cc @@ -26,12 +26,16 @@ clang::Cursor clang::Cursor::get_referenced() const { return Cursor(clang_getCursorReferenced(cx_cursor)); } +clang::Cursor clang::Cursor::get_semantic_parent() const { + return clang::Cursor(clang_getCursorSemanticParent(cx_cursor)); +} + clang::Cursor::operator bool() const { return !clang_Cursor_isNull(cx_cursor); } bool clang::Cursor::operator==(const Cursor& rhs) const { - return get_usr()==rhs.get_usr(); + return clang_equalCursors(cx_cursor, rhs.cx_cursor); } bool clang::Cursor::has_type() { diff --git a/src/Cursor.h b/src/Cursor.h index b395183..4df1ff4 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -183,6 +183,7 @@ namespace clang { std::string get_spelling() const; std::string get_usr() const; Cursor get_referenced() const; + Cursor get_semantic_parent() const; operator bool() const; bool operator==(const Cursor& rhs) const; diff --git a/src/Tokens.cc b/src/Tokens.cc index 2b8e603..d4f2892 100644 --- a/src/Tokens.cc +++ b/src/Tokens.cc @@ -5,7 +5,6 @@ using namespace std; //TODO: remove clang::Tokens::Tokens(CXTranslationUnit &cx_tu, const SourceRange &range): cx_tu(cx_tu) { clang_tokenize(cx_tu, range.cx_range, &cx_tokens, &num_tokens); - cx_cursors.clear(); cx_cursors.resize(num_tokens); clang_annotateTokens(cx_tu, cx_tokens, num_tokens, cx_cursors.data()); for (unsigned i = 0; i < num_tokens; i++) { @@ -58,12 +57,14 @@ std::vector > clang::Tokens::get_cxx_metho method+=" "; } - clang::Cursor parent(clang_getCursorSemanticParent(cursor.cx_cursor)); - method+=clang::to_string(clang_getCursorDisplayName(parent.cx_cursor)); - - method+="::"; + std::string parent_str; + auto parent=cursor.get_semantic_parent(); + while(parent && parent.get_kind()!=clang::CursorKind::TranslationUnit) { + parent_str.insert(0, clang::to_string(clang_getCursorDisplayName(parent.cx_cursor))+"::"); + parent=parent.get_semantic_parent(); + } - method+=clang::to_string(clang_getCursorDisplayName(cursor.cx_cursor)); + method+=parent_str+clang::to_string(clang_getCursorDisplayName(cursor.cx_cursor)); methods.emplace_back(method, offset); } last_offset=offset;