Browse Source

Token and Cursor cleanup.

merge-requests/37/head
eidheim 10 years ago
parent
commit
847a3546f0
  1. 38
      src/Cursor.cc
  2. 4
      src/Cursor.h
  3. 39
      src/Token.cc
  4. 3
      src/Token.h

38
src/Cursor.cc

@ -32,3 +32,41 @@ clang::Cursor::operator bool() const {
bool clang::Cursor::operator==(const Cursor& rhs) const { bool clang::Cursor::operator==(const Cursor& rhs) const {
return get_usr()==rhs.get_usr(); return get_usr()==rhs.get_usr();
} }
//TODO: Is there a way to optimise this?
bool clang::Cursor::has_type() {
auto referenced=clang_getCursorReferenced(cx_cursor);
if(clang_Cursor_isNull(referenced))
return false;
auto type=clang_getCursorType(referenced);
auto spelling=clang::to_string(clang_getTypeSpelling(type));
return spelling!="";
}
std::string clang::Cursor::get_type() {
std::string spelling;
auto referenced=clang_getCursorReferenced(cx_cursor);
if(!clang_Cursor_isNull(referenced)) {
auto type=clang_getCursorType(referenced);
spelling=clang::to_string(clang_getTypeSpelling(type));
std::string auto_end="";
//TODO fix const auto
if((spelling.size()>=4 && spelling.substr(0, 4)=="auto")) {
auto_end=spelling.substr(4);
auto type=clang_getCanonicalType(clang_getCursorType(cx_cursor));
spelling=clang::to_string(clang_getTypeSpelling(type));
if(spelling.find(" ")==std::string::npos)
spelling+=auto_end;
}
}
return spelling;
}
std::string clang::Cursor::get_brief_comments() {
std::string comment_string;
auto referenced=get_referenced();
if(referenced) {
comment_string=clang::to_string(clang_Cursor_getBriefCommentText(referenced.cx_cursor));
}
return comment_string;
}

4
src/Cursor.h

@ -186,6 +186,10 @@ namespace clang {
operator bool() const; operator bool() const;
bool operator==(const Cursor& rhs) const; bool operator==(const Cursor& rhs) const;
bool has_type();
std::string get_type();
std::string get_brief_comments();
CXCursor cx_cursor; CXCursor cx_cursor;
}; };
} // namespace clang } // namespace clang

39
src/Token.cc

@ -23,42 +23,3 @@ std::string clang::Token::get_spelling() {
const clang::TokenKind clang::Token::get_kind() { const clang::TokenKind clang::Token::get_kind() {
return (TokenKind) clang_getTokenKind(cx_token); return (TokenKind) clang_getTokenKind(cx_token);
} }
//TODO: Is there a way to optimise this?
bool clang::Token::has_type() {
auto referenced=clang_getCursorReferenced(cx_cursor);
if(clang_Cursor_isNull(referenced))
return false;
auto type=clang_getCursorType(referenced);
auto spelling=clang::to_string(clang_getTypeSpelling(type));
return spelling!="";
}
//TODO: Move to clang::Cursor
std::string clang::Token::get_type() {
std::string spelling;
auto referenced=clang_getCursorReferenced(cx_cursor);
if(!clang_Cursor_isNull(referenced)) {
auto type=clang_getCursorType(referenced);
spelling=clang::to_string(clang_getTypeSpelling(type));
std::string auto_end="";
//TODO fix const auto
if((spelling.size()>=4 && spelling.substr(0, 4)=="auto")) {
auto_end=spelling.substr(4);
auto type=clang_getCanonicalType(clang_getCursorType(cx_cursor));
spelling=clang::to_string(clang_getTypeSpelling(type));
if(spelling.find(" ")==std::string::npos)
spelling+=auto_end;
}
}
return spelling;
}
std::string clang::Token::get_brief_comments() {
std::string comment_string;
auto referenced=get_cursor().get_referenced();
if(referenced) {
comment_string=clang::to_string(clang_Cursor_getBriefCommentText(referenced.cx_cursor));
}
return comment_string;
}

3
src/Token.h

@ -25,9 +25,6 @@ namespace clang {
SourceLocation get_source_location(); SourceLocation get_source_location();
SourceRange get_source_range(); SourceRange get_source_range();
clang::Cursor get_cursor() {return clang::Cursor(cx_cursor);} clang::Cursor get_cursor() {return clang::Cursor(cx_cursor);}
bool has_type();
std::string get_type();
std::string get_brief_comments();
CXTranslationUnit &cx_tu; CXTranslationUnit &cx_tu;
CXToken& cx_token; CXToken& cx_token;

Loading…
Cancel
Save