mirror of https://gitlab.com/cppit/libclangmm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
|
8 years ago
|
#include "token.h"
|
||
|
|
#include "utility.h"
|
||
|
11 years ago
|
|
||
|
|
// // // // //
|
||
|
|
// Token //
|
||
|
|
// // // // //
|
||
|
|
|
||
|
|
// returns gets an source location for this token objekt
|
||
|
|
// based on the translationunit given
|
||
|
9 years ago
|
clangmm::SourceLocation clangmm::Token::get_source_location() const {
|
||
|
11 years ago
|
return SourceLocation(clang_getTokenLocation(cx_tu, cx_token));
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
// returns a sourcerange that covers this token
|
||
|
9 years ago
|
clangmm::SourceRange clangmm::Token::get_source_range() const {
|
||
|
11 years ago
|
return SourceRange(clang_getTokenExtent(cx_tu, cx_token));
|
||
|
11 years ago
|
}
|
||
|
|
// returns a string description of this tokens kind
|
||
|
9 years ago
|
std::string clangmm::Token::get_spelling() const {
|
||
|
10 years ago
|
return to_string(clang_getTokenSpelling(cx_tu, cx_token));
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
9 years ago
|
clangmm::Token::Kind clangmm::Token::get_kind() const {
|
||
|
10 years ago
|
return static_cast<Kind>(clang_getTokenKind(cx_token));
|
||
|
11 years ago
|
}
|
||
|
9 years ago
|
|
||
|
9 years ago
|
bool clangmm::Token::is_identifier() const {
|
||
|
9 years ago
|
auto token_kind=get_kind();
|
||
|
|
auto cursor=get_cursor();
|
||
|
9 years ago
|
if(token_kind==clangmm::Token::Kind::Identifier && cursor.is_valid_kind())
|
||
|
9 years ago
|
return true;
|
||
|
9 years ago
|
else if(token_kind==clangmm::Token::Kind::Keyword && cursor.is_valid_kind()) {
|
||
|
9 years ago
|
auto spelling=get_spelling();
|
||
|
|
if(spelling=="operator" || (spelling=="bool" && get_cursor().get_spelling()=="operator bool"))
|
||
|
|
return true;
|
||
|
|
}
|
||
|
9 years ago
|
else if(token_kind==clangmm::Token::Kind::Punctuation && cursor.is_valid_kind()) {
|
||
|
8 years ago
|
auto referenced=cursor.get_referenced();
|
||
|
9 years ago
|
if(referenced) {
|
||
|
|
auto referenced_kind=referenced.get_kind();
|
||
|
|
if(referenced_kind==Cursor::Kind::FunctionDecl || referenced_kind==Cursor::Kind::CXXMethod || referenced_kind==Cursor::Kind::Constructor)
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|