Browse Source

Improved Cursor::get_type_description

master
eidheim 6 years ago
parent
commit
45abfa439c
  1. 33
      src/cursor.cc

33
src/cursor.cc

@ -217,39 +217,18 @@ bool clangmm::Cursor::is_valid_kind() const {
} }
std::string clangmm::Cursor::get_type_description() const { std::string clangmm::Cursor::get_type_description() const {
std::string spelling; auto type = clang_getCursorType(cx_cursor);
if(type.kind != CXTypeKind::CXType_Invalid)
return to_string(clang_getTypeSpelling(type));
auto referenced = clang_getCursorReferenced(cx_cursor); auto referenced = clang_getCursorReferenced(cx_cursor);
if(!clang_Cursor_isNull(referenced)) { if(!clang_Cursor_isNull(referenced)) {
auto type = clang_getCursorType(referenced); auto type = clang_getCursorType(referenced);
spelling = to_string(clang_getTypeSpelling(type)); if(type.kind != CXTypeKind::CXType_Invalid)
return to_string(clang_getTypeSpelling(type));
#if CINDEX_VERSION_MAJOR == 0 && CINDEX_VERSION_MINOR < 32
const std::string auto_str = "auto";
if(spelling.size() >= 4 && std::equal(auto_str.begin(), auto_str.end(), spelling.begin())) {
auto canonical_type = clang_getCanonicalType(clang_getCursorType(cx_cursor));
auto canonical_spelling = to_string(clang_getTypeSpelling(canonical_type));
if(spelling.size() > 5 && spelling[4] == ' ' && spelling[5] == '&' && spelling != canonical_spelling)
return canonical_spelling + " &";
else
return canonical_spelling;
}
const std::string const_auto_str = "const auto";
if(spelling.size() >= 10 && std::equal(const_auto_str.begin(), const_auto_str.end(), spelling.begin())) {
auto canonical_type = clang_getCanonicalType(clang_getCursorType(cx_cursor));
auto canonical_spelling = to_string(clang_getTypeSpelling(canonical_type));
if(spelling.size() > 11 && spelling[10] == ' ' && spelling[11] == '&' && spelling != canonical_spelling)
return canonical_spelling + " &";
else
return canonical_spelling;
}
#endif
} }
if(spelling.empty())
return get_spelling(); return get_spelling();
return spelling;
} }
std::string clangmm::Cursor::get_brief_comments() const { std::string clangmm::Cursor::get_brief_comments() const {

Loading…
Cancel
Save