Browse Source

Removed clang::Tokens::get_cxx_methods and added Cursor::get_display_name

merge-requests/37/head
eidheim 9 years ago
parent
commit
a627c6da5d
  1. 4
      src/Cursor.cc
  2. 1
      src/Cursor.h
  3. 39
      src/Tokens.cc
  4. 1
      src/Tokens.h

4
src/Cursor.cc

@ -34,6 +34,10 @@ std::string clang::Cursor::get_spelling() const {
return to_string(clang_getCursorSpelling(cx_cursor)); return to_string(clang_getCursorSpelling(cx_cursor));
} }
std::string clang::Cursor::get_display_name() const {
return to_string(clang_getCursorDisplayName(cx_cursor));
}
std::string clang::Cursor::get_usr() const { std::string clang::Cursor::get_usr() const {
return to_string(clang_getCursorUSR(cx_cursor)); return to_string(clang_getCursorUSR(cx_cursor));
} }

1
src/Cursor.h

@ -193,6 +193,7 @@ namespace clang {
SourceLocation get_source_location() const; SourceLocation get_source_location() const;
SourceRange get_source_range() const; SourceRange get_source_range() const;
std::string get_spelling() const; std::string get_spelling() const;
std::string get_display_name() const;
std::string get_usr() const; std::string get_usr() const;
Cursor get_referenced() const; Cursor get_referenced() const;
Cursor get_canonical() const; Cursor get_canonical() const;

39
src/Tokens.cc

@ -1,7 +1,5 @@
#include "Tokens.h" #include "Tokens.h"
#include "Utility.h" #include "Utility.h"
#include <iostream> //TODO: remove
using namespace std; //TODO: remove
clang::Tokens::Tokens(CXTranslationUnit &cx_tu, const SourceRange &range): cx_tu(cx_tu) { clang::Tokens::Tokens(CXTranslationUnit &cx_tu, const SourceRange &range): cx_tu(cx_tu) {
clang_tokenize(cx_tu, range.cx_range, &cx_tokens, &num_tokens); clang_tokenize(cx_tu, range.cx_range, &cx_tokens, &num_tokens);
@ -36,40 +34,3 @@ std::vector<std::pair<clang::Offset, clang::Offset> > clang::Tokens::get_similar
} }
return offsets; return offsets;
} }
std::vector<std::pair<std::string, clang::Offset> > clang::Tokens::get_cxx_methods() {
std::vector<std::pair<std::string, Offset> > methods;
Offset last_offset={(unsigned)-1,(unsigned) -1};
for(auto &token: *this) {
if(token.get_kind()==Token::Kind::Identifier) {
auto cursor=token.get_cursor();
auto kind=cursor.get_kind();
if(kind==Cursor::Kind::CXXMethod || kind==Cursor::Kind::Constructor || kind==Cursor::Kind::Destructor) {
auto offset=cursor.get_source_location().get_offset();
if(offset!=last_offset) {
std::string method;
if(kind==Cursor::Kind::CXXMethod) {
auto type=clang_getResultType(clang_getCursorType(cursor.cx_cursor));
method+=to_string(clang_getTypeSpelling(type));
auto pos=method.find(" ");
if(pos!=std::string::npos)
method.erase(pos, 1);
method+=" ";
}
std::string parent_str;
auto parent=cursor.get_semantic_parent();
while(parent && parent.get_kind()!=Cursor::Kind::TranslationUnit) {
parent_str.insert(0, to_string(clang_getCursorDisplayName(parent.cx_cursor))+"::");
parent=parent.get_semantic_parent();
}
method+=parent_str+to_string(clang_getCursorDisplayName(cursor.cx_cursor));
methods.emplace_back(method, offset);
}
last_offset=offset;
}
}
}
return methods;
}

1
src/Tokens.h

@ -16,7 +16,6 @@ namespace clang {
std::vector<std::pair<clang::Offset, clang::Offset> > get_similar_token_offsets(Cursor::Kind kind, std::vector<std::pair<clang::Offset, clang::Offset> > get_similar_token_offsets(Cursor::Kind kind,
const std::string &spelling, const std::string &spelling,
const std::string &usr); const std::string &usr);
std::vector<std::pair<std::string, clang::Offset> > get_cxx_methods();
private: private:
CXToken *cx_tokens; CXToken *cx_tokens;
unsigned num_tokens; unsigned num_tokens;

Loading…
Cancel
Save