Browse Source

Added TranslationUnit::get_cursor(SourceLocation const&), and some minor cleanup of TranslationUnit

merge-requests/37/head
eidheim 9 years ago
parent
commit
7f5c657f52
  1. 24
      src/TranslationUnit.cc
  2. 17
      src/TranslationUnit.h

24
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<std::string> &command_line_args,
const std::string &buffer, unsigned flags) {
const std::vector<std::string> &command_line_args,
const std::string &buffer, unsigned flags) {
std::vector<const char*> 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<std::string> &command_line_args,
unsigned flags) {
const std::vector<std::string> &command_line_args,
unsigned flags) {
std::vector<const char*> args;
for(auto &a: command_line_args) {
args.push_back(a.c_str());
@ -42,8 +42,8 @@ clangmm::TranslationUnit::~TranslationUnit() {
}
void clangmm::TranslationUnit::parse(Index &index, const std::string &file_path,
const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers, unsigned flags) {
const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers, unsigned flags) {
std::vector<CXUnsavedFile> 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::Tokens> clangmm::TranslationUnit::get_tokens(unsigned s
}
std::unique_ptr<clangmm::Tokens> 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::Tokens> clangmm::TranslationUnit::get_tokens(unsigned s
return std::unique_ptr<Tokens>(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));
}

17
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<std::string> &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<std::string> &command_line_args,
unsigned flags=DefaultFlags());
~TranslationUnit();
@ -35,17 +33,18 @@ namespace clangmm {
const std::map<std::string, std::string> &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<clangmm::Diagnostic> get_diagnostics();
std::vector<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);
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;
};

Loading…
Cancel
Save