diff --git a/src/Cursor.cc b/src/Cursor.cc index 1e98ed7..0194f94 100644 --- a/src/Cursor.cc +++ b/src/Cursor.cc @@ -42,6 +42,34 @@ std::string clangmm::Cursor::get_usr() const { return to_string(clang_getCursorUSR(cx_cursor)); } +std::string clangmm::Cursor::get_usr_extended() const { + if(!is_valid_kind()) + return std::string(); + + const auto token_spelling=[](const std::string &spelling) -> std::string { + for(size_t i=0;i > clangmm::Tokens::get_similar_token_offsets(Cursor::Kind kind, - const std::string &spelling, - const std::string &usr) { +//This works across TranslationUnits. Similar tokens defined as tokens with equal canonical cursors. +std::vector > clangmm::Tokens::get_similar_token_offsets(const std::string &spelling, const std::string &usr) { std::vector > offsets; for(auto &token: *this) { if(token.is_identifier()) { auto referenced=token.get_cursor().get_referenced(); - if(referenced && kind==referenced.get_kind() && spelling==token.get_spelling() && usr==referenced.get_usr()) + if(referenced && spelling==token.get_spelling() && usr==referenced.get_usr_extended()) offsets.emplace_back(token.offsets); } } diff --git a/src/Tokens.h b/src/Tokens.h index f9bf80b..63317e1 100644 --- a/src/Tokens.h +++ b/src/Tokens.h @@ -13,9 +13,7 @@ namespace clangmm { Tokens(CXTranslationUnit &cx_tu, const SourceRange &range); public: ~Tokens(); - std::vector > get_similar_token_offsets(Cursor::Kind kind, - const std::string &spelling, - const std::string &usr); + std::vector > get_similar_token_offsets(const std::string &spelling, const std::string &usr); private: CXToken *cx_tokens; unsigned num_tokens;