Browse Source

clang::Cursor and clang::Token cleanup.

merge-requests/365/head
eidheim 10 years ago
parent
commit
8224a1f76e
  1. 19
      src/source.cc

19
src/source.cc

@ -1446,15 +1446,16 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
type_tooltips.clear(); type_tooltips.clear();
for(auto &token: *tokens) { for(auto &token: *tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) { auto cursor=token.get_cursor();
if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) {
if(static_cast<unsigned>(token.get_cursor().get_kind())==103) //These cursors are buggy if(static_cast<unsigned>(token.get_cursor().get_kind())==103) //These cursors are buggy
continue; continue;
auto start=get_buffer()->get_iter_at_line_index(token.offsets.first.line-1, token.offsets.first.index-1); auto start=get_buffer()->get_iter_at_line_index(token.offsets.first.line-1, token.offsets.first.index-1);
auto end=get_buffer()->get_iter_at_line_index(token.offsets.second.line-1, token.offsets.second.index-1); auto end=get_buffer()->get_iter_at_line_index(token.offsets.second.line-1, token.offsets.second.index-1);
auto create_tooltip_buffer=[this, &token]() { auto create_tooltip_buffer=[this, &token]() {
auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table()); auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table());
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "Type: "+token.get_type(), "def:note"); tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "Type: "+token.get_cursor().get_type(), "def:note");
auto brief_comment=token.get_brief_comments(); auto brief_comment=token.get_cursor().get_brief_comments();
if(brief_comment!="") if(brief_comment!="")
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\n"+brief_comment, "def:note"); tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\n"+brief_comment, "def:note");
return tooltip_buffer; return tooltip_buffer;
@ -1949,11 +1950,12 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
auto line=(unsigned)iter.get_line(); auto line=(unsigned)iter.get_line();
auto index=(unsigned)iter.get_line_index(); auto index=(unsigned)iter.get_line_index();
for(auto &token: *clang_tokens) { for(auto &token: *clang_tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) { auto cursor=token.get_cursor();
if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) {
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) {
if(static_cast<unsigned>(token.get_cursor().get_kind())==103) //These cursors are buggy if(static_cast<unsigned>(token.get_cursor().get_kind())==103) //These cursors are buggy
continue; continue;
auto referenced=token.get_cursor().get_referenced(); auto referenced=cursor.get_referenced();
if(referenced) if(referenced)
return {referenced.get_usr(), static_cast<int>(referenced.get_kind())}; return {referenced.get_usr(), static_cast<int>(referenced.get_kind())};
} }
@ -1969,7 +1971,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
auto line=(unsigned)iter.get_line(); auto line=(unsigned)iter.get_line();
auto index=(unsigned)iter.get_line_index(); auto index=(unsigned)iter.get_line_index();
for(auto &token: *clang_tokens) { for(auto &token: *clang_tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) { if(token.get_kind()==clang::Token_Identifier && token.get_cursor().has_type()) {
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) {
return token.get_spelling(); return token.get_spelling();
} }
@ -2037,9 +2039,10 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
auto line=(unsigned)iter.get_line(); auto line=(unsigned)iter.get_line();
auto index=(unsigned)iter.get_line_index(); auto index=(unsigned)iter.get_line_index();
for(auto &token: *clang_tokens) { for(auto &token: *clang_tokens) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) { auto cursor=token.get_cursor();
if(token.get_kind()==clang::Token_Identifier && cursor.has_type()) {
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 referenced=token.get_cursor().get_referenced(); auto referenced=cursor.get_referenced();
if(referenced) { if(referenced) {
location.first=referenced.get_source_location().get_path(); location.first=referenced.get_source_location().get_path();
location.second=referenced.get_source_location().get_offset(); location.second=referenced.get_source_location().get_offset();

Loading…
Cancel
Save