From 6df6b218872dc95c7afee99befc1bbecabdac357 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 7 Aug 2017 18:39:43 +0200 Subject: [PATCH] Renamed TranslationUnit::ReparseTranslationUnit to TranslationUnit::reparse, and added additional TranslationUnit::get_tokens overloads --- src/TranslationUnit.cc | 14 +++++++++++++- src/TranslationUnit.h | 4 +++- tests/CodeCompleteResults_H_Test.cc | 2 +- tests/CompletionString_H_Test.cc | 2 +- tests/TranslationUnit_Test.cc | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/TranslationUnit.cc b/src/TranslationUnit.cc index e2992e2..32a1573 100644 --- a/src/TranslationUnit.cc +++ b/src/TranslationUnit.cc @@ -60,7 +60,7 @@ void clangmm::TranslationUnit::parse(Index &index, const std::string &file_path, args.size(), files.data(), files.size(), flags); } -int clangmm::TranslationUnit::ReparseTranslationUnit(const std::string &buffer, unsigned flags) { +int clangmm::TranslationUnit::reparse(const std::string &buffer, unsigned flags) { CXUnsavedFile files[1]; auto file_path=to_string(clang_getTranslationUnitSpelling(cx_tu)); @@ -96,6 +96,18 @@ std::vector clangmm::TranslationUnit::get_diagnostics() { return diagnostics; } +std::unique_ptr clangmm::TranslationUnit::get_tokens() { + SourceRange range(clang_getCursorExtent(clang_getTranslationUnitCursor(cx_tu))); + return std::unique_ptr(new Tokens(cx_tu, range)); +} + +std::unique_ptr clangmm::TranslationUnit::get_tokens(const std::string &path, unsigned start_offset, unsigned end_offset) { + SourceLocation start_location(cx_tu, path, start_offset); + SourceLocation end_location(cx_tu, path, end_offset); + SourceRange range(start_location, end_location); + return std::unique_ptr(new Tokens(cx_tu, range)); +} + std::unique_ptr clangmm::TranslationUnit::get_tokens(unsigned start_offset, unsigned end_offset) { auto path=clangmm::to_string(clang_getTranslationUnitSpelling(cx_tu)); SourceLocation start_location(cx_tu, path, start_offset); diff --git a/src/TranslationUnit.h b/src/TranslationUnit.h index d6d486a..a7f6c60 100644 --- a/src/TranslationUnit.h +++ b/src/TranslationUnit.h @@ -23,7 +23,7 @@ namespace clangmm { unsigned flags=DefaultFlags()); ~TranslationUnit(); - int ReparseTranslationUnit(const std::string &buffer, unsigned flags=DefaultFlags()); + int reparse(const std::string &buffer, unsigned flags=DefaultFlags()); static unsigned DefaultFlags(); @@ -38,6 +38,8 @@ namespace clangmm { std::vector get_diagnostics(); + std::unique_ptr get_tokens(); + std::unique_ptr get_tokens(const std::string &path, unsigned start_offset, unsigned end_offset); std::unique_ptr get_tokens(unsigned start_offset, unsigned end_offset); std::unique_ptr get_tokens(unsigned start_line, unsigned start_column, unsigned end_line, unsigned end_column); diff --git a/tests/CodeCompleteResults_H_Test.cc b/tests/CodeCompleteResults_H_Test.cc index aea2e8b..d3672a2 100644 --- a/tests/CodeCompleteResults_H_Test.cc +++ b/tests/CodeCompleteResults_H_Test.cc @@ -20,7 +20,7 @@ BOOST_AUTO_TEST_CASE(code_complete_results) { // ] - tu.ReparseTranslationUnit(buffer); + tu.reparse(buffer); auto results=tu.get_code_completions(buffer, 4, 5); bool substr_found=false; diff --git a/tests/CompletionString_H_Test.cc b/tests/CompletionString_H_Test.cc index cb18f50..558066a 100644 --- a/tests/CompletionString_H_Test.cc +++ b/tests/CompletionString_H_Test.cc @@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(completion_string) { "return 0\n" "}"; - tu.ReparseTranslationUnit(buffer); + tu.reparse(buffer); auto results=tu.get_code_completions(buffer, 4, 5); // ] diff --git a/tests/TranslationUnit_Test.cc b/tests/TranslationUnit_Test.cc index 1dd3a28..75be196 100644 --- a/tests/TranslationUnit_Test.cc +++ b/tests/TranslationUnit_Test.cc @@ -15,5 +15,5 @@ BOOST_AUTO_TEST_CASE(translation_unit) { "return 0\n" "}\n"; - BOOST_CHECK(tu.ReparseTranslationUnit(buffer) == 0); + BOOST_CHECK(tu.reparse(buffer) == 0); }