Browse Source

Improved Tokens::get_cxx_methods and various minor cleanups

merge-requests/37/head
eidheim 10 years ago
parent
commit
251ff8ef0c
  1. 6
      src/Cursor.cc
  2. 1
      src/Cursor.h
  3. 13
      src/Tokens.cc

6
src/Cursor.cc

@ -26,12 +26,16 @@ clang::Cursor clang::Cursor::get_referenced() const {
return Cursor(clang_getCursorReferenced(cx_cursor)); 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 { clang::Cursor::operator bool() const {
return !clang_Cursor_isNull(cx_cursor); return !clang_Cursor_isNull(cx_cursor);
} }
bool clang::Cursor::operator==(const Cursor& rhs) const { 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() { bool clang::Cursor::has_type() {

1
src/Cursor.h

@ -183,6 +183,7 @@ namespace clang {
std::string get_spelling() const; std::string get_spelling() const;
std::string get_usr() const; std::string get_usr() const;
Cursor get_referenced() const; Cursor get_referenced() const;
Cursor get_semantic_parent() const;
operator bool() const; operator bool() const;
bool operator==(const Cursor& rhs) const; bool operator==(const Cursor& rhs) const;

13
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::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);
cx_cursors.clear();
cx_cursors.resize(num_tokens); cx_cursors.resize(num_tokens);
clang_annotateTokens(cx_tu, cx_tokens, num_tokens, cx_cursors.data()); clang_annotateTokens(cx_tu, cx_tokens, num_tokens, cx_cursors.data());
for (unsigned i = 0; i < num_tokens; i++) { for (unsigned i = 0; i < num_tokens; i++) {
@ -58,12 +57,14 @@ std::vector<std::pair<std::string, clang::Offset> > clang::Tokens::get_cxx_metho
method+=" "; method+=" ";
} }
clang::Cursor parent(clang_getCursorSemanticParent(cursor.cx_cursor)); std::string parent_str;
method+=clang::to_string(clang_getCursorDisplayName(parent.cx_cursor)); auto parent=cursor.get_semantic_parent();
while(parent && parent.get_kind()!=clang::CursorKind::TranslationUnit) {
method+="::"; 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); methods.emplace_back(method, offset);
} }
last_offset=offset; last_offset=offset;

Loading…
Cancel
Save