From 411890a110ebf91ed4eada8b1059d64ffa1cbb3c Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 13 Aug 2017 09:06:48 +0200 Subject: [PATCH] Corrected Cursor::get_usr_extended --- src/Cursor.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Cursor.cc b/src/Cursor.cc index 9feb6e6..62a222d 100644 --- a/src/Cursor.cc +++ b/src/Cursor.cc @@ -50,7 +50,7 @@ std::string clangmm::Cursor::get_usr_extended() const { for(size_t i=0;i0 && spelling[0]=='~') - return spelling.substr(1, i); + return spelling.substr(1, i-1); return spelling.substr(0, i); } } @@ -62,16 +62,18 @@ std::string clangmm::Cursor::get_usr_extended() const { auto cursor=*this; auto kind=cursor.get_kind(); // If constructor, destructor or function template, and the token spelling is equal, set cursor to parent - if(kind==clangmm::Cursor::Kind::Constructor || kind==clangmm::Cursor::Kind::Destructor || - kind==clangmm::Cursor::Kind::FunctionTemplate) { + if(kind==Cursor::Kind::Constructor || kind==Cursor::Kind::Destructor || + kind==Cursor::Kind::FunctionTemplate) { auto parent=cursor.get_semantic_parent(); - if(token_spelling(cursor.get_spelling())==token_spelling(parent.get_spelling())) - cursor=parent; + auto parent_kind=parent.get_kind(); + if((parent_kind==Cursor::Kind::ClassDecl || parent_kind==Cursor::Kind::StructDecl || parent_kind==Cursor::Kind::ClassTemplate) && + token_spelling(cursor.get_spelling())==token_spelling(parent.get_spelling())) + cursor=parent; } std::string usr=token_spelling(cursor.get_spelling()); - cursor=cursor.get_semantic_parent(); - while((kind=cursor.get_kind())!=Kind::TranslationUnit && cursor.is_valid_kind()) { + auto parent=cursor.get_semantic_parent(); + while((kind=parent.get_kind())!=Kind::TranslationUnit && parent.is_valid_kind()) { if(kind==Kind::CXXMethod || kind==Kind::FunctionDecl || kind==Kind::FunctionTemplate || kind==Kind::Constructor || kind==Kind::Destructor) { auto canonical=cursor.get_canonical(); @@ -79,8 +81,8 @@ std::string clangmm::Cursor::get_usr_extended() const { auto offset=location.get_offset(); return std::to_string(offset.line)+':'+std::to_string(offset.index)+':'+location.get_path(); } - usr+=':'+token_spelling(cursor.get_spelling()); - cursor=cursor.get_semantic_parent(); + usr+=':'+token_spelling(parent.get_spelling()); + parent=parent.get_semantic_parent(); } return usr; }