Browse Source

Various new functions to retrieve cursor information more effective.

merge-requests/37/head
eidheim 10 years ago
parent
commit
d4ac255e72
  1. 5
      src/SourceLocation.cc
  2. 1
      src/SourceLocation.h
  3. 14
      src/TranslationUnit.cc
  4. 9
      src/TranslationUnit.h

5
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);

1
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) {}

14
src/TranslationUnit.cc

@ -100,7 +100,21 @@ std::unique_ptr<clang::Tokens> clang::TranslationUnit::get_tokens(unsigned start
return std::unique_ptr<Tokens>(new Tokens(cx_tu, range));
}
std::unique_ptr<clang::Tokens> 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<Tokens>(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));
}

9
src/TranslationUnit.h

@ -34,10 +34,17 @@ namespace clang {
const std::map<std::string, std::string> &buffers,
unsigned flags=DefaultFlags());
clang::CodeCompleteResults get_code_completions(const std::map<std::string, std::string> &buffers, unsigned line_number, unsigned column);
clang::CodeCompleteResults get_code_completions(const std::map<std::string, std::string> &buffers,
unsigned line_number, unsigned column);
std::vector<clang::Diagnostic> get_diagnostics();
std::unique_ptr<Tokens> get_tokens(unsigned start_offset, unsigned end_offset);
std::unique_ptr<Tokens> 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;
};

Loading…
Cancel
Save