Browse Source

More cleanup.

merge-requests/37/head
eidheim 11 years ago
parent
commit
8137e7a9e6
  1. 12
      src/CodeCompleteResults.cc
  2. 13
      src/CodeCompleteResults.h
  3. 4
      src/Diagnostic.cc
  4. 4
      src/Diagnostic.h
  5. 23
      src/SourceLocation.cc
  6. 14
      src/SourceLocation.h
  7. 4
      src/SourceRange.cc
  8. 3
      src/Token.h
  9. 4
      src/Tokens.h
  10. 2
      src/TranslationUnit.cc
  11. 2
      src/TranslationUnit.h

12
src/CodeCompleteResults.cc

@ -3,11 +3,9 @@
#include <exception> #include <exception>
clang::CodeCompleteResults:: clang::CodeCompleteResults::
CodeCompleteResults(CXTranslationUnit &cx_tu, CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &file_name,
const std::string &file_name,
const std::map<std::string, std::string> &buffers, const std::map<std::string, std::string> &buffers,
int line_num, unsigned line_num, unsigned column) {
int column) {
std::vector<CXUnsavedFile> files; std::vector<CXUnsavedFile> files;
for (auto &buffer : buffers) { for (auto &buffer : buffers) {
CXUnsavedFile file; CXUnsavedFile file;
@ -31,15 +29,15 @@ clang::CodeCompleteResults::~CodeCompleteResults() {
delete cx_results; delete cx_results;
} }
int clang::CodeCompleteResults:: unsigned clang::CodeCompleteResults::
size() { size() {
return cx_results->NumResults; return cx_results->NumResults;
} }
clang::CompletionString clang::CodeCompleteResults:: clang::CompletionString clang::CodeCompleteResults::
get(int i) { get(unsigned i) {
if (i >= size()) { if (i >= size()) {
throw std::invalid_argument("clang::CodeCompleteResults::get(int i): i>=size()"); throw std::invalid_argument("clang::CodeCompleteResults::get(unsigned i): i>=size()");
} }
return CompletionString(cx_results->Results[i].CompletionString); return CompletionString(cx_results->Results[i].CompletionString);
} }

13
src/CodeCompleteResults.h

@ -6,15 +6,14 @@
namespace clang { namespace clang {
class CodeCompleteResults { class CodeCompleteResults {
public: friend class TranslationUnit;
CodeCompleteResults(CXTranslationUnit &cx_tu, CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &file_name,
const std::string &file_name,
const std::map<std::string, std::string> &buffers, const std::map<std::string, std::string> &buffers,
int line_num, unsigned line_num, unsigned column);
int column); public:
~CodeCompleteResults(); ~CodeCompleteResults();
CompletionString get(int index); CompletionString get(unsigned index);
int size(); unsigned size();
CXCodeCompleteResults *cx_results; CXCodeCompleteResults *cx_results;
}; };

4
src/Diagnostic.cc

@ -10,8 +10,8 @@ clang::Diagnostic::Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnos
clang_disposeString(cxstr); clang_disposeString(cxstr);
clang::SourceLocation start_location(clang_getDiagnosticLocation(cx_diagnostic)); clang::SourceLocation start_location(clang_getDiagnosticLocation(cx_diagnostic));
unsigned start_offset; path=start_location.get_path();
start_location.get_data(&path, NULL, NULL, &start_offset); unsigned start_offset=start_location.get_offset();
clang::Tokens tokens(cx_tu, SourceRange(start_location, start_location)); clang::Tokens tokens(cx_tu, SourceRange(start_location, start_location));
if(tokens.size()==1) { if(tokens.size()==1) {
offsets=std::pair<unsigned, unsigned>(start_offset, tokens[0].offsets.second); offsets=std::pair<unsigned, unsigned>(start_offset, tokens[0].offsets.second);

4
src/Diagnostic.h

@ -7,9 +7,9 @@
namespace clang { namespace clang {
class Diagnostic { class Diagnostic {
public: friend class TranslationUnit;
Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnostic); Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnostic);
public:
static const std::string get_severity_spelling(unsigned severity); static const std::string get_severity_spelling(unsigned severity);
unsigned severity; unsigned severity;

23
src/SourceLocation.cc

@ -3,21 +3,22 @@
// // // // // // // // // // // // // // // //
// SourceLocation // // SourceLocation //
// // // // // // // // // // // // // // // //
clang::SourceLocation:: clang::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset) {
SourceLocation(CXTranslationUnit &tu,
const std::string &filename,
int line_number,
int line_offset) {
CXFile file = clang_getFile(tu, filename.c_str());
cx_location = clang_getLocation(tu, file, line_number, line_offset);
}
clang::SourceLocation::
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, int offset) {
CXFile file = clang_getFile(tu, filepath.c_str()); CXFile file = clang_getFile(tu, filepath.c_str());
cx_location = clang_getLocationForOffset(tu, file, offset); cx_location = clang_getLocationForOffset(tu, file, offset);
} }
std::string clang::SourceLocation::get_path() {
std::string path;
get_data(&path, NULL, NULL, NULL);
return path;
}
unsigned clang::SourceLocation::get_offset() {
unsigned offset;
get_data(NULL, NULL, NULL, &offset);
return offset;
}
void clang::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) { void clang::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) {
if(path==nullptr) if(path==nullptr)
clang_getExpansionLocation(cx_location, NULL, line, column, offset); clang_getExpansionLocation(cx_location, NULL, line, column, offset);

14
src/SourceLocation.h

@ -6,19 +6,19 @@
namespace clang { namespace clang {
class SourceLocation { class SourceLocation {
friend class TranslationUnit;
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset);
public: public:
SourceLocation(const CXSourceLocation& cx_location) : cx_location(cx_location) {} SourceLocation(const CXSourceLocation& cx_location) : cx_location(cx_location) {}
SourceLocation(CXTranslationUnit &cx_tu, public:
const std::string &filename, std::string get_path();
int line_number, unsigned get_offset();
int column);
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, int offset); CXSourceLocation cx_location;
private:
void get_data(std::string *path, unsigned *line, unsigned *column, unsigned *offset); void get_data(std::string *path, unsigned *line, unsigned *column, unsigned *offset);
CXSourceLocation cx_location;
}; };
} // namespace clang } // namespace clang

4
src/SourceRange.cc

@ -8,7 +8,7 @@ SourceRange(clang::SourceLocation &start, clang::SourceLocation &end) {
std::pair<unsigned, unsigned> clang::SourceRange::get_offsets() { std::pair<unsigned, unsigned> clang::SourceRange::get_offsets() {
SourceLocation start(clang_getRangeStart(cx_range)), end(clang_getRangeEnd(cx_range)); SourceLocation start(clang_getRangeStart(cx_range)), end(clang_getRangeEnd(cx_range));
std::pair<unsigned, unsigned> offsets; std::pair<unsigned, unsigned> offsets;
start.get_data(NULL, NULL, NULL, &offsets.first); offsets.first=start.get_offset();
end.get_data(NULL, NULL, NULL, &offsets.second); offsets.second=end.get_offset();
return offsets; return offsets;
} }

3
src/Token.h

@ -22,6 +22,7 @@ namespace clang {
const TokenKind get_kind(); const TokenKind get_kind();
std::string get_spelling(); std::string get_spelling();
SourceLocation get_source_location(); SourceLocation get_source_location();
SourceRange get_source_range();
clang::Cursor get_cursor() {return clang::Cursor(cx_cursor);} clang::Cursor get_cursor() {return clang::Cursor(cx_cursor);}
bool has_type(); bool has_type();
std::string get_type(); std::string get_type();
@ -30,8 +31,6 @@ namespace clang {
CXToken& cx_token; CXToken& cx_token;
CXCursor& cx_cursor; CXCursor& cx_cursor;
std::pair<unsigned, unsigned> offsets; std::pair<unsigned, unsigned> offsets;
private:
SourceRange get_source_range();
}; };
} // namespace clang } // namespace clang
#endif // TOKEN_H_ #endif // TOKEN_H_

4
src/Tokens.h

@ -8,8 +8,10 @@
namespace clang { namespace clang {
class Tokens : public std::vector<clang::Token> { class Tokens : public std::vector<clang::Token> {
public: friend class TranslationUnit;
friend class Diagnostic;
Tokens(CXTranslationUnit &cx_tu, const SourceRange &range); Tokens(CXTranslationUnit &cx_tu, const SourceRange &range);
public:
~Tokens(); ~Tokens();
std::vector<std::pair<unsigned, unsigned> > get_similar_token_offsets(clang::Token& token); std::vector<std::pair<unsigned, unsigned> > get_similar_token_offsets(clang::Token& token);
private: private:

2
src/TranslationUnit.cc

@ -90,7 +90,7 @@ unsigned clang::TranslationUnit::DefaultFlags() {
return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; return CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
} }
clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::map<std::string, std::string> &buffers, int line_number, int column) { clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::map<std::string, std::string> &buffers, unsigned line_number, unsigned column) {
auto cxstr=clang_getTranslationUnitSpelling(cx_tu); auto cxstr=clang_getTranslationUnitSpelling(cx_tu);
std::string path=clang_getCString(cxstr); std::string path=clang_getCString(cxstr);
clang_disposeString(cxstr); clang_disposeString(cxstr);

2
src/TranslationUnit.h

@ -35,7 +35,7 @@ namespace clang {
const std::map<std::string, std::string> &buffers, const std::map<std::string, std::string> &buffers,
unsigned flags=DefaultFlags()); unsigned flags=DefaultFlags());
clang::CodeCompleteResults get_code_completions(const std::map<std::string, std::string> &buffers, int line_number, int 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::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_offset, unsigned end_offset);
clang::Cursor get_cursor(std::string path, unsigned offset); clang::Cursor get_cursor(std::string path, unsigned offset);

Loading…
Cancel
Save