From 847a3546f0ee827d5769b2ce7f654d0820a343f8 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 19 Sep 2015 12:18:04 +0200 Subject: [PATCH] Token and Cursor cleanup. --- src/Cursor.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/Cursor.h | 4 ++++ src/Token.cc | 39 --------------------------------------- src/Token.h | 3 --- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Cursor.cc b/src/Cursor.cc index 8ad74b9..882e0fe 100644 --- a/src/Cursor.cc +++ b/src/Cursor.cc @@ -32,3 +32,41 @@ clang::Cursor::operator bool() const { bool clang::Cursor::operator==(const Cursor& rhs) const { 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; +} diff --git a/src/Cursor.h b/src/Cursor.h index 94858eb..2b410d7 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -186,6 +186,10 @@ namespace clang { operator bool() const; bool operator==(const Cursor& rhs) const; + bool has_type(); + std::string get_type(); + std::string get_brief_comments(); + CXCursor cx_cursor; }; } // namespace clang diff --git a/src/Token.cc b/src/Token.cc index e8dbb65..372616c 100644 --- a/src/Token.cc +++ b/src/Token.cc @@ -23,42 +23,3 @@ std::string clang::Token::get_spelling() { const clang::TokenKind clang::Token::get_kind() { 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; -} diff --git a/src/Token.h b/src/Token.h index d8f44db..0dd957b 100644 --- a/src/Token.h +++ b/src/Token.h @@ -25,9 +25,6 @@ namespace clang { SourceLocation get_source_location(); SourceRange get_source_range(); clang::Cursor get_cursor() {return clang::Cursor(cx_cursor);} - bool has_type(); - std::string get_type(); - std::string get_brief_comments(); CXTranslationUnit &cx_tu; CXToken& cx_token;