Browse Source

Added Tokens::get_cxx_methods().

merge-requests/37/head
eidheim 11 years ago
parent
commit
ff1d7fe09b
  1. 1
      src/Token.cc
  2. 42
      src/Tokens.cc
  3. 1
      src/Tokens.h

1
src/Token.cc

@ -59,6 +59,7 @@ std::string clang::Token::get_type() {
return spelling; return spelling;
} }
//TODO: use clang_Cursor_getBriefCommentText
std::string clang::Token::get_brief_comments() { std::string clang::Token::get_brief_comments() {
std::string comment_string; std::string comment_string;
auto referenced=clang_getCursorReferenced(cx_cursor); auto referenced=clang_getCursorReferenced(cx_cursor);

42
src/Tokens.cc

@ -33,3 +33,45 @@ std::vector<std::pair<unsigned, unsigned> > clang::Tokens::get_similar_token_off
} }
return offsets; return offsets;
} }
std::vector<std::pair<std::string, unsigned> > clang::Tokens::get_cxx_methods() {
std::vector<std::pair<std::string, unsigned> > methods;
long last_offset=-1;
for(auto &token: *this) {
if(token.get_kind()==clang::Token_Identifier) {
auto cursor=token.get_cursor();
auto kind=cursor.get_kind();
if(kind==clang::CursorKind::CXXMethod || kind==clang::CursorKind::Constructor || kind==clang::CursorKind::Destructor) {
auto offset=cursor.get_source_location().get_offset();
if(offset!=last_offset) {
std::string method;
CXString cxstr;
if(kind==clang::CursorKind::CXXMethod) {
auto type=clang_getResultType(clang_getCursorType(cursor.cx_cursor));
auto cxstr=clang_getTypeSpelling(type);
method+=clang_getCString(cxstr);
clang_disposeString(cxstr);
auto pos=method.find(" ");
if(pos!=std::string::npos)
method.erase(pos, 1);
method+=" ";
}
clang::Cursor parent(clang_getCursorSemanticParent(cursor.cx_cursor));
cxstr=clang_getCursorDisplayName(parent.cx_cursor);
method+=clang_getCString(cxstr);
clang_disposeString(cxstr);
method+="::";
cxstr=clang_getCursorDisplayName(cursor.cx_cursor);
method+=clang_getCString(cxstr);
clang_disposeString(cxstr);
methods.emplace_back(method, offset);
}
last_offset=offset;
}
}
}
return methods;
}

1
src/Tokens.h

@ -14,6 +14,7 @@ namespace clang {
public: public:
~Tokens(); ~Tokens();
std::vector<std::pair<unsigned, unsigned> > get_similar_token_offsets(clang::Token& token); std::vector<std::pair<unsigned, unsigned> > get_similar_token_offsets(clang::Token& token);
std::vector<std::pair<std::string, unsigned> > get_cxx_methods();
private: private:
CXToken *cx_tokens; CXToken *cx_tokens;
unsigned num_tokens; unsigned num_tokens;

Loading…
Cancel
Save