From 7f5c657f52229bcfc194eadda08371013a3c1e77 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 13 Jul 2017 16:39:22 +0200 Subject: [PATCH] Added TranslationUnit::get_cursor(SourceLocation const&), and some minor cleanup of TranslationUnit --- src/TranslationUnit.cc | 26 +++++++++++++++----------- src/TranslationUnit.h | 17 ++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/TranslationUnit.cc b/src/TranslationUnit.cc index 483c4d6..e2992e2 100644 --- a/src/TranslationUnit.cc +++ b/src/TranslationUnit.cc @@ -9,8 +9,8 @@ using namespace std; //TODO: remove clangmm::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path, - const std::vector &command_line_args, - const std::string &buffer, unsigned flags) { + const std::vector &command_line_args, + const std::string &buffer, unsigned flags) { std::vector args; for(auto &a: command_line_args) { args.push_back(a.c_str()); @@ -26,8 +26,8 @@ clangmm::TranslationUnit::TranslationUnit(Index &index, const std::string &file_ } clangmm::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path, - const std::vector &command_line_args, - unsigned flags) { + const std::vector &command_line_args, + unsigned flags) { std::vector args; for(auto &a: command_line_args) { args.push_back(a.c_str()); @@ -41,9 +41,9 @@ clangmm::TranslationUnit::~TranslationUnit() { clang_disposeTranslationUnit(cx_tu); } -void clangmm::TranslationUnit::parse(Index &index, const std::string &file_path, - const std::vector &command_line_args, - const std::map &buffers, unsigned flags) { +void clangmm::TranslationUnit::parse(Index &index, const std::string &file_path, + const std::vector &command_line_args, + const std::map &buffers, unsigned flags) { std::vector files; for (auto &buffer : buffers) { CXUnsavedFile file; @@ -81,7 +81,7 @@ unsigned clangmm::TranslationUnit::DefaultFlags() { } clangmm::CodeCompleteResults clangmm::TranslationUnit::get_code_completions(const std::string &buffer, - unsigned line_number, unsigned column) { + unsigned line_number, unsigned column) { CodeCompleteResults results(cx_tu, buffer, line_number, column); return results; } @@ -105,7 +105,7 @@ std::unique_ptr clangmm::TranslationUnit::get_tokens(unsigned s } std::unique_ptr clangmm::TranslationUnit::get_tokens(unsigned start_line, unsigned start_column, - unsigned end_line, unsigned end_column) { + unsigned end_line, unsigned end_column) { auto path=to_string(clang_getTranslationUnitSpelling(cx_tu)); SourceLocation start_location(cx_tu, path, start_line, start_column); SourceLocation end_location(cx_tu, path, end_line, end_column); @@ -113,12 +113,16 @@ std::unique_ptr clangmm::TranslationUnit::get_tokens(unsigned s return std::unique_ptr(new Tokens(cx_tu, range)); } -clangmm::Cursor clangmm::TranslationUnit::get_cursor(std::string path, unsigned offset) { +clangmm::Cursor clangmm::TranslationUnit::get_cursor(const std::string &path, unsigned offset) { SourceLocation location(cx_tu, path, offset); return Cursor(clang_getCursor(cx_tu, location.cx_location)); } -clangmm::Cursor clangmm::TranslationUnit::get_cursor(std::string path, unsigned line, unsigned column) { +clangmm::Cursor clangmm::TranslationUnit::get_cursor(const std::string &path, unsigned line, unsigned column) { SourceLocation location(cx_tu, path, line, column); return Cursor(clang_getCursor(cx_tu, location.cx_location)); } + +clangmm::Cursor clangmm::TranslationUnit::get_cursor(const SourceLocation &location) { + return Cursor(clang_getCursor(cx_tu, location.cx_location)); +} diff --git a/src/TranslationUnit.h b/src/TranslationUnit.h index fcf9629..d6d486a 100644 --- a/src/TranslationUnit.h +++ b/src/TranslationUnit.h @@ -14,13 +14,11 @@ namespace clangmm { class TranslationUnit { public: - TranslationUnit(Index &index, - const std::string &file_path, + TranslationUnit(Index &index, const std::string &file_path, const std::vector &command_line_args, const std::string &buffer, unsigned flags=DefaultFlags()); - TranslationUnit(Index &index, - const std::string &file_path, + TranslationUnit(Index &index, const std::string &file_path, const std::vector &command_line_args, unsigned flags=DefaultFlags()); ~TranslationUnit(); @@ -35,17 +33,18 @@ namespace clangmm { const std::map &buffers, unsigned flags=DefaultFlags()); - clangmm::CodeCompleteResults get_code_completions(const std::string &buffer, - unsigned line_number, unsigned column); + CodeCompleteResults get_code_completions(const std::string &buffer, + unsigned line_number, unsigned column); - std::vector get_diagnostics(); + std::vector get_diagnostics(); 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); - clangmm::Cursor get_cursor(std::string path, unsigned offset); - clangmm::Cursor get_cursor(std::string path, unsigned line, unsigned column); + Cursor get_cursor(const std::string &path, unsigned offset); + Cursor get_cursor(const std::string &path, unsigned line, unsigned column); + Cursor get_cursor(const SourceLocation &location); CXTranslationUnit cx_tu; };