Browse Source

Smaller fixes and cleanups.

merge-requests/37/head
eidheim 11 years ago
parent
commit
a92970fd69
  1. 22
      src/Cursor.cc
  2. 3
      src/Cursor.h
  3. 7
      src/Tokens.cc

22
src/Cursor.cc

@ -12,12 +12,22 @@ clang::SourceRange clang::Cursor::get_source_range() const {
return SourceRange(clang_getCursorExtent(cx_cursor)); return SourceRange(clang_getCursorExtent(cx_cursor));
} }
bool clang::Cursor::operator==(const Cursor& rhs) const { std::string clang::Cursor::get_usr() const {
auto cxstr=clang_getCursorUSR(cx_cursor); auto cxstr=clang_getCursorUSR(cx_cursor);
std::string lhs_str=clang_getCString(cxstr); std::string USR=clang_getCString(cxstr);
clang_disposeString(cxstr);
cxstr=clang_getCursorUSR(rhs.cx_cursor);
std::string rhs_str=clang_getCString(cxstr);
clang_disposeString(cxstr); clang_disposeString(cxstr);
return lhs_str==rhs_str; return USR;
}
std::string clang::Cursor::get_referenced_usr() const {
auto referenced=clang_getCursorReferenced(cx_cursor);
if(!clang_Cursor_isNull(referenced)) {
return Cursor(referenced).get_usr();
}
else
return "";
}
bool clang::Cursor::operator==(const Cursor& rhs) const {
return get_usr()==rhs.get_usr();
} }

3
src/Cursor.h

@ -3,6 +3,7 @@
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include "SourceLocation.h" #include "SourceLocation.h"
#include "SourceRange.h" #include "SourceRange.h"
#include <string>
namespace clang { namespace clang {
enum class CursorKind { enum class CursorKind {
@ -179,6 +180,8 @@ namespace clang {
const CursorKind get_kind(); const CursorKind get_kind();
SourceLocation get_source_location() const; SourceLocation get_source_location() const;
SourceRange get_source_range() const; SourceRange get_source_range() const;
std::string get_usr() const;
std::string get_referenced_usr() const;
bool operator==(const Cursor& rhs) const; bool operator==(const Cursor& rhs) const;
CXCursor cx_cursor; CXCursor cx_cursor;
}; };

7
src/Tokens.cc

@ -22,13 +22,14 @@ clang::Tokens::~Tokens() {
//Similar tokens defined as tokens with equal referenced cursors. //Similar tokens defined as tokens with equal referenced cursors.
std::vector<std::pair<unsigned, unsigned> > clang::Tokens::get_similar_token_offsets(clang::Token& token) { std::vector<std::pair<unsigned, unsigned> > clang::Tokens::get_similar_token_offsets(clang::Token& token) {
std::vector<std::pair<unsigned, unsigned> > offsets; std::vector<std::pair<unsigned, unsigned> > offsets;
auto referenced=clang_getCursorReferenced(token.get_cursor().cx_cursor); auto referenced_usr=token.get_cursor().get_referenced_usr();
if(referenced_usr!="") {
for(auto &a_token: *this) { for(auto &a_token: *this) {
auto a_referenced=clang_getCursorReferenced(a_token.get_cursor().cx_cursor); if(referenced_usr==a_token.get_cursor().get_referenced_usr() && token.get_token_spelling()==a_token.get_token_spelling()) {
if(Cursor(referenced)==Cursor(a_referenced) && token.get_token_spelling()==a_token.get_token_spelling()) {
auto range_data=a_token.source_range.get_range_data(); auto range_data=a_token.source_range.get_range_data();
offsets.emplace_back(range_data.start_offset, range_data.end_offset); offsets.emplace_back(range_data.start_offset, range_data.end_offset);
} }
} }
}
return offsets; return offsets;
} }

Loading…
Cancel
Save