Browse Source

Implement method and goto method now also includes regular functions

merge-requests/365/head
eidheim 9 years ago
parent
commit
b47ddae801
  1. 2
      libclangmm
  2. 38
      src/source_clang.cc

2
libclangmm

@ -1 +1 @@
Subproject commit ca2021d93599de931ba5219efd36b0ecb930e3b5 Subproject commit a627c6da5d807862741d7affeca09678cdee5f54

38
src/source_clang.cc

@ -1064,12 +1064,13 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
if(token.get_kind()==clang::Token::Kind::Identifier && cursor.has_type_description()) { if(token.get_kind()==clang::Token::Kind::Identifier && cursor.has_type_description()) {
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
auto kind=cursor.get_kind(); auto kind=cursor.get_kind();
if(kind==clang::Cursor::Kind::CXXMethod || kind==clang::Cursor::Kind::Constructor || kind==clang::Cursor::Kind::Destructor) { if(kind==clang::Cursor::Kind::FunctionDecl || kind==clang::Cursor::Kind::CXXMethod ||
kind==clang::Cursor::Kind::Constructor || kind==clang::Cursor::Kind::Destructor) {
auto referenced=cursor.get_referenced(); auto referenced=cursor.get_referenced();
if(referenced && referenced==cursor) { if(referenced && referenced==cursor) {
std::string result; std::string result;
std::string specifier; std::string specifier;
if(kind==clang::Cursor::Kind::CXXMethod) { if(kind==clang::Cursor::Kind::FunctionDecl || kind==clang::Cursor::Kind::CXXMethod) {
result=cursor.get_type().get_result().get_spelling(); result=cursor.get_type().get_result().get_spelling();
if(!result.empty() && result.back()!='*' && result.back()!='&') if(!result.empty() && result.back()!='*' && result.back()!='&')
@ -1120,9 +1121,32 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
Info::get().print("Buffer is parsing"); Info::get().print("Buffer is parsing");
return methods; return methods;
} }
auto cxx_methods=clang_tokens->get_cxx_methods(); for(auto &token: *clang_tokens) {
for(auto &method: cxx_methods) { auto cursor=token.get_cursor();
std::string row=std::to_string(method.second.line)+": "+Glib::Markup::escape_text(method.first); if(token.get_kind()==clang::Token::Kind::Identifier && cursor.has_type_description()) {
auto kind=cursor.get_kind();
if(kind==clang::Cursor::Kind::FunctionDecl || kind==clang::Cursor::Kind::CXXMethod ||
kind==clang::Cursor::Kind::Constructor || kind==clang::Cursor::Kind::Destructor) {
auto offset=cursor.get_source_location().get_offset();
std::string method;
if(kind==clang::Cursor::Kind::FunctionDecl || kind==clang::Cursor::Kind::CXXMethod) {
method+=cursor.get_type().get_result().get_spelling();
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()!=clang::Cursor::Kind::TranslationUnit) {
parent_str.insert(0, parent.get_display_name()+"::");
parent=parent.get_semantic_parent();
}
method+=parent_str+cursor.get_display_name();
std::string row=std::to_string(offset.line)+": "+Glib::Markup::escape_text(method);
//Add bold method token //Add bold method token
size_t token_end_pos=row.find('('); size_t token_end_pos=row.find('(');
if(token_end_pos==0 || token_end_pos==std::string::npos) if(token_end_pos==0 || token_end_pos==std::string::npos)
@ -1151,7 +1175,9 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
(row[pos]>='0' && row[pos]<='9') || row[pos]=='_' || row[pos]=='~') && pos>0); (row[pos]>='0' && row[pos]<='9') || row[pos]=='_' || row[pos]=='~') && pos>0);
row.insert(token_end_pos, "</b>"); row.insert(token_end_pos, "</b>");
row.insert(pos+1, "<b>"); row.insert(pos+1, "<b>");
methods.emplace_back(Offset(method.second.line-1, method.second.index-1), row); methods.emplace_back(Offset(offset.line-1, offset.index-1), row);
}
}
} }
return methods; return methods;
}; };

Loading…
Cancel
Save