diff --git a/src/SourceLocation.cc b/src/SourceLocation.cc index 7638807..96904d6 100644 --- a/src/SourceLocation.cc +++ b/src/SourceLocation.cc @@ -9,6 +9,11 @@ clang::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string & cx_location = clang_getLocationForOffset(tu, file, offset); } +clang::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column) { + CXFile file = clang_getFile(tu, filepath.c_str()); + cx_location = clang_getLocation(tu, file, line, column); +} + std::string clang::SourceLocation::get_path() { std::string path; get_data(&path, NULL, NULL, NULL); diff --git a/src/SourceLocation.h b/src/SourceLocation.h index 501c9e6..74e3dff 100644 --- a/src/SourceLocation.h +++ b/src/SourceLocation.h @@ -17,6 +17,7 @@ namespace clang { class SourceLocation { friend class TranslationUnit; SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset); + SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column); public: SourceLocation(const CXSourceLocation& cx_location) : cx_location(cx_location) {} diff --git a/src/TranslationUnit.cc b/src/TranslationUnit.cc index 098329d..64e3af3 100644 --- a/src/TranslationUnit.cc +++ b/src/TranslationUnit.cc @@ -100,7 +100,21 @@ std::unique_ptr clang::TranslationUnit::get_tokens(unsigned start return std::unique_ptr(new Tokens(cx_tu, range)); } +std::unique_ptr clang::TranslationUnit::get_tokens(unsigned start_line, unsigned start_column, + unsigned end_line, unsigned end_column) { + auto path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu)); + clang::SourceLocation start_location(cx_tu, path, start_line, start_column); + clang::SourceLocation end_location(cx_tu, path, end_line, end_column); + clang::SourceRange range(start_location, end_location); + return std::unique_ptr(new Tokens(cx_tu, range)); +} + clang::Cursor clang::TranslationUnit::get_cursor(std::string path, unsigned offset) { clang::SourceLocation location(cx_tu, path, offset); return Cursor(clang_getCursor(cx_tu, location.cx_location)); } + +clang::Cursor clang::TranslationUnit::get_cursor(std::string path, unsigned line, unsigned column) { + clang::SourceLocation location(cx_tu, path, line, column); + return Cursor(clang_getCursor(cx_tu, location.cx_location)); +} diff --git a/src/TranslationUnit.h b/src/TranslationUnit.h index 7cdd4dd..bd8dc58 100644 --- a/src/TranslationUnit.h +++ b/src/TranslationUnit.h @@ -34,10 +34,17 @@ namespace clang { const std::map &buffers, unsigned flags=DefaultFlags()); - clang::CodeCompleteResults get_code_completions(const std::map &buffers, unsigned line_number, unsigned column); + clang::CodeCompleteResults get_code_completions(const std::map &buffers, + unsigned line_number, unsigned column); + 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); + clang::Cursor get_cursor(std::string path, unsigned offset); + clang::Cursor get_cursor(std::string path, unsigned line, unsigned column); CXTranslationUnit cx_tu; };