diff --git a/src/Diagnostic.cc b/src/Diagnostic.cc index 2d2fda6..bc9bc8b 100644 --- a/src/Diagnostic.cc +++ b/src/Diagnostic.cc @@ -12,8 +12,7 @@ clang::Diagnostic::Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnos clang::Tokens tokens(cx_tu, range); if(tokens.size()==1) { auto& token=tokens[0]; - clang::SourceRange range=token.get_source_range(); - auto locations=range.get_source_locations(); + auto locations=token.source_range.get_source_locations(); this->range=SourceRange::get_range_data(location, locations.second); } } diff --git a/src/Token.h b/src/Token.h index c77d2f4..d88817f 100644 --- a/src/Token.h +++ b/src/Token.h @@ -17,11 +17,11 @@ namespace clang { class Token { public: - explicit Token(CXTranslationUnit &cx_tu, CXToken &cx_token, CXCursor &cx_cursor): cx_tu(cx_tu), cx_token(cx_token), cx_cursor(cx_cursor) {}; + Token(CXTranslationUnit &cx_tu, CXToken &cx_token, CXCursor &cx_cursor): + cx_tu(cx_tu), cx_token(cx_token), cx_cursor(cx_cursor), source_range(get_source_range()) {}; const TokenKind kind(); std::string get_token_spelling(); SourceLocation get_source_location(); - SourceRange get_source_range(); clang::Cursor get_cursor() {return clang::Cursor(cx_cursor);} bool has_type(); std::string get_type(); @@ -29,6 +29,9 @@ namespace clang { CXTranslationUnit &cx_tu; CXToken& cx_token; CXCursor& cx_cursor; + SourceRange source_range; + private: + SourceRange get_source_range(); }; } // namespace clang #endif // TOKEN_H_ diff --git a/tests/SourceLocation_H_Test.cc b/tests/SourceLocation_H_Test.cc index 3b11c52..ab6d1c0 100644 --- a/tests/SourceLocation_H_Test.cc +++ b/tests/SourceLocation_H_Test.cc @@ -10,7 +10,7 @@ BOOST_AUTO_TEST_CASE(source_location) { clang::TranslationUnit tu(index, path); auto tokens=tu.get_tokens(0, 113); - clang::SourceRange token_range = (*tokens)[28].get_source_range(); + clang::SourceRange token_range = (*tokens)[28].source_range; unsigned token_start_line, token_start_column, token_start_offset, token_end_line, token_end_column, token_end_offset;