Browse Source

Changed namespace to clangmm due to conflicts with libclang on for instance OpenSuse

merge-requests/37/head
eidheim 9 years ago
parent
commit
4c5fa3f0c1
  1. 12
      src/CodeCompleteResults.cc
  2. 4
      src/CodeCompleteResults.h
  3. 4
      src/CompilationDatabase.cc
  4. 2
      src/CompilationDatabase.h
  5. 4
      src/CompileCommand.cc
  6. 2
      src/CompileCommand.h
  7. 6
      src/CompileCommands.cc
  8. 2
      src/CompileCommands.h
  9. 12
      src/CompletionString.cc
  10. 4
      src/CompletionString.h
  11. 40
      src/Cursor.cc
  12. 4
      src/Cursor.h
  13. 4
      src/Diagnostic.cc
  14. 8
      src/Diagnostic.h
  15. 4
      src/Index.cc
  16. 4
      src/Index.h
  17. 10
      src/SourceLocation.cc
  18. 10
      src/SourceLocation.h
  19. 4
      src/SourceRange.cc
  20. 6
      src/SourceRange.h
  21. 16
      src/Token.cc
  22. 8
      src/Token.h
  23. 6
      src/Tokens.cc
  24. 8
      src/Tokens.h
  25. 26
      src/TranslationUnit.cc
  26. 12
      src/TranslationUnit.h
  27. 2
      src/Utility.cc
  28. 2
      src/Utility.h
  29. 4
      tests/CodeCompleteResults_H_Test.cc
  30. 10
      tests/CompletionString_H_Test.cc
  31. 6
      tests/Cursor_H_Test.cc
  32. 4
      tests/Diagnostics_Test.cc
  33. 4
      tests/SourceLocation_H_Test.cc
  34. 6
      tests/Token_H_Test.cc
  35. 4
      tests/TranslationUnit_Test.cc

12
src/CodeCompleteResults.cc

@ -3,7 +3,7 @@
#include <exception> #include <exception>
#include "Utility.h" #include "Utility.h"
clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu, clangmm::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu,
const std::string &buffer, const std::string &buffer,
unsigned line_num, unsigned column) { unsigned line_num, unsigned column) {
CXUnsavedFile files[1]; CXUnsavedFile files[1];
@ -23,23 +23,23 @@ clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu,
clang_sortCodeCompletionResults(cx_results->Results, cx_results->NumResults); clang_sortCodeCompletionResults(cx_results->Results, cx_results->NumResults);
} }
clang::CodeCompleteResults::~CodeCompleteResults() { clangmm::CodeCompleteResults::~CodeCompleteResults() {
clang_disposeCodeCompleteResults(cx_results); clang_disposeCodeCompleteResults(cx_results);
} }
unsigned clang::CodeCompleteResults::size() const { unsigned clangmm::CodeCompleteResults::size() const {
if(cx_results==NULL) if(cx_results==NULL)
return 0; return 0;
return cx_results->NumResults; return cx_results->NumResults;
} }
clang::CompletionString clang::CodeCompleteResults::get(unsigned i) const { clangmm::CompletionString clangmm::CodeCompleteResults::get(unsigned i) const {
if (i >= size()) { if (i >= size()) {
throw std::invalid_argument("clang::CodeCompleteResults::get(unsigned i): i>=size()"); throw std::invalid_argument("clangmm::CodeCompleteResults::get(unsigned i): i>=size()");
} }
return CompletionString(cx_results->Results[i].CompletionString); return CompletionString(cx_results->Results[i].CompletionString);
} }
std::string clang::CodeCompleteResults::get_usr() const { std::string clangmm::CodeCompleteResults::get_usr() const {
return to_string(clang_codeCompleteGetContainerUSR(cx_results)); return to_string(clang_codeCompleteGetContainerUSR(cx_results));
} }

4
src/CodeCompleteResults.h

@ -5,7 +5,7 @@
#include <string> #include <string>
#include "CompletionString.h" #include "CompletionString.h"
namespace clang { namespace clangmm {
class CodeCompleteResults { class CodeCompleteResults {
friend class TranslationUnit; friend class TranslationUnit;
@ -19,5 +19,5 @@ namespace clang {
CXCodeCompleteResults *cx_results; CXCodeCompleteResults *cx_results;
}; };
} // namespace clang } // namespace clangmm
#endif // CODECOMPLETERESULTS_H_ #endif // CODECOMPLETERESULTS_H_

4
src/CompilationDatabase.cc

@ -1,7 +1,7 @@
#include "CompilationDatabase.h" #include "CompilationDatabase.h"
#include <exception> #include <exception>
clang::CompilationDatabase::CompilationDatabase(const std::string &project_path) { clangmm::CompilationDatabase::CompilationDatabase(const std::string &project_path) {
CXCompilationDatabase_Error error; CXCompilationDatabase_Error error;
cx_db = clang_CompilationDatabase_fromDirectory(project_path.c_str(), &error); cx_db = clang_CompilationDatabase_fromDirectory(project_path.c_str(), &error);
if(error) { if(error) {
@ -9,6 +9,6 @@ clang::CompilationDatabase::CompilationDatabase(const std::string &project_path)
} }
} }
clang::CompilationDatabase::~CompilationDatabase() { clangmm::CompilationDatabase::~CompilationDatabase() {
clang_CompilationDatabase_dispose(cx_db); clang_CompilationDatabase_dispose(cx_db);
} }

2
src/CompilationDatabase.h

@ -4,7 +4,7 @@
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include <string> #include <string>
namespace clang { namespace clangmm {
class CompilationDatabase { class CompilationDatabase {
public: public:
explicit CompilationDatabase(const std::string &project_path); explicit CompilationDatabase(const std::string &project_path);

4
src/CompileCommand.cc

@ -2,7 +2,7 @@
#include "CompileCommands.h" #include "CompileCommands.h"
#include "Utility.h" #include "Utility.h"
std::string clang::CompileCommand::get_command() { std::string clangmm::CompileCommand::get_command() {
std::string res; std::string res;
unsigned N = clang_CompileCommand_getNumArgs(cx_command); unsigned N = clang_CompileCommand_getNumArgs(cx_command);
for (unsigned i = 0; i < N; i++) { for (unsigned i = 0; i < N; i++) {
@ -11,7 +11,7 @@ std::string clang::CompileCommand::get_command() {
return res; return res;
} }
std::vector<std::string> clang::CompileCommand::get_command_as_args() { std::vector<std::string> clangmm::CompileCommand::get_command_as_args() {
unsigned N = clang_CompileCommand_getNumArgs(cx_command); unsigned N = clang_CompileCommand_getNumArgs(cx_command);
std::vector<std::string> res(N); std::vector<std::string> res(N);
for (unsigned i = 0; i < N; i++) { for (unsigned i = 0; i < N; i++) {

2
src/CompileCommand.h

@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
namespace clang { namespace clangmm {
class CompileCommand { class CompileCommand {
public: public:
CompileCommand(const CXCompileCommand& cx_command) : cx_command(cx_command) {}; CompileCommand(const CXCompileCommand& cx_command) : cx_command(cx_command) {};

6
src/CompileCommands.cc

@ -1,17 +1,17 @@
#include "CompileCommands.h" #include "CompileCommands.h"
clang::CompileCommands::CompileCommands(const std::string &filename, CompilationDatabase &db) { clangmm::CompileCommands::CompileCommands(const std::string &filename, CompilationDatabase &db) {
cx_commands = cx_commands =
clang_CompilationDatabase_getCompileCommands(db.cx_db, filename.c_str()); clang_CompilationDatabase_getCompileCommands(db.cx_db, filename.c_str());
if(clang_CompileCommands_getSize(cx_commands)==0) if(clang_CompileCommands_getSize(cx_commands)==0)
cx_commands = clang_CompilationDatabase_getAllCompileCommands(db.cx_db); cx_commands = clang_CompilationDatabase_getAllCompileCommands(db.cx_db);
} }
clang::CompileCommands::~CompileCommands() { clangmm::CompileCommands::~CompileCommands() {
clang_CompileCommands_dispose(cx_commands); clang_CompileCommands_dispose(cx_commands);
} }
std::vector<clang::CompileCommand> clang::CompileCommands::get_commands() { std::vector<clangmm::CompileCommand> clangmm::CompileCommands::get_commands() {
unsigned N = clang_CompileCommands_getSize(cx_commands); unsigned N = clang_CompileCommands_getSize(cx_commands);
std::vector<CompileCommand> res; std::vector<CompileCommand> res;
for (unsigned i = 0; i < N; i++) { for (unsigned i = 0; i < N; i++) {

2
src/CompileCommands.h

@ -6,7 +6,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace clang { namespace clangmm {
class CompileCommands { class CompileCommands {
public: public:
CompileCommands(const std::string &filename, CompilationDatabase &db); CompileCommands(const std::string &filename, CompilationDatabase &db);

12
src/CompletionString.cc

@ -1,18 +1,18 @@
#include "CompletionString.h" #include "CompletionString.h"
#include "Utility.h" #include "Utility.h"
clang::CompletionString:: clangmm::CompletionString::
CompletionString(const CXCompletionString &cx_completion_sting) : cx_completion_sting(cx_completion_sting) {} CompletionString(const CXCompletionString &cx_completion_sting) : cx_completion_sting(cx_completion_sting) {}
bool clang::CompletionString::available() { bool clangmm::CompletionString::available() {
return clang_getCompletionAvailability(cx_completion_sting) == CXAvailability_Available; return clang_getCompletionAvailability(cx_completion_sting) == CXAvailability_Available;
} }
unsigned clang::CompletionString::get_num_chunks() { unsigned clangmm::CompletionString::get_num_chunks() {
return clang_getNumCompletionChunks(cx_completion_sting); return clang_getNumCompletionChunks(cx_completion_sting);
} }
std::vector<clang::CompletionChunk> clang::CompletionString::get_chunks() { std::vector<clangmm::CompletionChunk> clangmm::CompletionString::get_chunks() {
std::vector<CompletionChunk> res; std::vector<CompletionChunk> res;
for (unsigned i = 0; i < get_num_chunks(); i++) { for (unsigned i = 0; i < get_num_chunks(); i++) {
res.emplace_back(to_string(clang_getCompletionChunkText(cx_completion_sting, i)), static_cast<CompletionChunkKind> (clang_getCompletionChunkKind(cx_completion_sting, i))); res.emplace_back(to_string(clang_getCompletionChunkText(cx_completion_sting, i)), static_cast<CompletionChunkKind> (clang_getCompletionChunkKind(cx_completion_sting, i)));
@ -20,9 +20,9 @@ std::vector<clang::CompletionChunk> clang::CompletionString::get_chunks() {
return res; return res;
} }
std::string clang::CompletionString::get_brief_comments() { std::string clangmm::CompletionString::get_brief_comments() {
return to_string(clang_getCompletionBriefComment(cx_completion_sting)); return to_string(clang_getCompletionBriefComment(cx_completion_sting));
} }
clang::CompletionChunk::CompletionChunk(std::string chunk, CompletionChunkKind kind) : clangmm::CompletionChunk::CompletionChunk(std::string chunk, CompletionChunkKind kind) :
chunk(chunk), kind(kind) { } chunk(chunk), kind(kind) { }

4
src/CompletionString.h

@ -4,7 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace clang { namespace clangmm {
enum CompletionChunkKind { enum CompletionChunkKind {
CompletionChunk_Optional, CompletionChunk_TypedText, CompletionChunk_Optional, CompletionChunk_TypedText,
CompletionChunk_Text, CompletionChunk_Placeholder, CompletionChunk_Text, CompletionChunk_Placeholder,
@ -36,5 +36,5 @@ namespace clang {
CXCompletionString cx_completion_sting; CXCompletionString cx_completion_sting;
}; };
} // namespace clang } // namespace clangmm
#endif // COMPLETIONSTRING_H_ #endif // COMPLETIONSTRING_H_

40
src/Cursor.cc

@ -2,63 +2,63 @@
#include "Utility.h" #include "Utility.h"
#include <algorithm> #include <algorithm>
std::string clang::Cursor::Type::get_spelling() const { std::string clangmm::Cursor::Type::get_spelling() const {
return to_string(clang_getTypeSpelling(cx_type)); return to_string(clang_getTypeSpelling(cx_type));
} }
clang::Cursor::Type clang::Cursor::Type::get_result() const { clangmm::Cursor::Type clangmm::Cursor::Type::get_result() const {
return Type(clang_getResultType(cx_type)); return Type(clang_getResultType(cx_type));
} }
bool clang::Cursor::Type::operator==(const Cursor::Type& rhs) const { bool clangmm::Cursor::Type::operator==(const Cursor::Type& rhs) const {
return clang_equalTypes(cx_type, rhs.cx_type); return clang_equalTypes(cx_type, rhs.cx_type);
} }
clang::Cursor::Kind clang::Cursor::get_kind() const { clangmm::Cursor::Kind clangmm::Cursor::get_kind() const {
return static_cast<Kind>(clang_getCursorKind(cx_cursor)); return static_cast<Kind>(clang_getCursorKind(cx_cursor));
} }
clang::Cursor::Type clang::Cursor::get_type() const { clangmm::Cursor::Type clangmm::Cursor::get_type() const {
return Type(clang_getCursorType(cx_cursor)); return Type(clang_getCursorType(cx_cursor));
} }
clang::SourceLocation clang::Cursor::get_source_location() const { clangmm::SourceLocation clangmm::Cursor::get_source_location() const {
return SourceLocation(clang_getCursorLocation(cx_cursor)); return SourceLocation(clang_getCursorLocation(cx_cursor));
} }
clang::SourceRange clang::Cursor::get_source_range() const { clangmm::SourceRange clangmm::Cursor::get_source_range() const {
return SourceRange(clang_getCursorExtent(cx_cursor)); return SourceRange(clang_getCursorExtent(cx_cursor));
} }
std::string clang::Cursor::get_spelling() const { std::string clangmm::Cursor::get_spelling() const {
return to_string(clang_getCursorSpelling(cx_cursor)); return to_string(clang_getCursorSpelling(cx_cursor));
} }
std::string clang::Cursor::get_display_name() const { std::string clangmm::Cursor::get_display_name() const {
return to_string(clang_getCursorDisplayName(cx_cursor)); return to_string(clang_getCursorDisplayName(cx_cursor));
} }
std::string clang::Cursor::get_usr() const { std::string clangmm::Cursor::get_usr() const {
return to_string(clang_getCursorUSR(cx_cursor)); return to_string(clang_getCursorUSR(cx_cursor));
} }
clang::Cursor clang::Cursor::get_referenced() const { clangmm::Cursor clangmm::Cursor::get_referenced() const {
return Cursor(clang_getCursorReferenced(cx_cursor)); return Cursor(clang_getCursorReferenced(cx_cursor));
} }
clang::Cursor clang::Cursor::get_canonical() const { clangmm::Cursor clangmm::Cursor::get_canonical() const {
return Cursor(clang_getCanonicalCursor(cx_cursor)); return Cursor(clang_getCanonicalCursor(cx_cursor));
} }
clang::Cursor clang::Cursor::get_definition() const { clangmm::Cursor clangmm::Cursor::get_definition() const {
return Cursor(clang_getCursorDefinition(cx_cursor)); return Cursor(clang_getCursorDefinition(cx_cursor));
} }
clang::Cursor clang::Cursor::get_semantic_parent() const { clangmm::Cursor clangmm::Cursor::get_semantic_parent() const {
return Cursor(clang_getCursorSemanticParent(cx_cursor)); return Cursor(clang_getCursorSemanticParent(cx_cursor));
} }
std::vector<clang::Cursor> clang::Cursor::get_arguments() const { std::vector<clangmm::Cursor> clangmm::Cursor::get_arguments() const {
std::vector<Cursor> cursors; std::vector<Cursor> cursors;
auto size=clang_Cursor_getNumArguments(cx_cursor); auto size=clang_Cursor_getNumArguments(cx_cursor);
for(int c=0;c<size;++c) for(int c=0;c<size;++c)
@ -66,15 +66,15 @@ std::vector<clang::Cursor> clang::Cursor::get_arguments() const {
return cursors; return cursors;
} }
clang::Cursor::operator bool() const { clangmm::Cursor::operator bool() const {
return !clang_Cursor_isNull(cx_cursor); return !clang_Cursor_isNull(cx_cursor);
} }
bool clang::Cursor::operator==(const Cursor& rhs) const { bool clangmm::Cursor::operator==(const Cursor& rhs) const {
return clang_equalCursors(cx_cursor, rhs.cx_cursor); return clang_equalCursors(cx_cursor, rhs.cx_cursor);
} }
bool clang::Cursor::is_valid_kind() const { bool clangmm::Cursor::is_valid_kind() const {
auto referenced=clang_getCursorReferenced(cx_cursor); auto referenced=clang_getCursorReferenced(cx_cursor);
if(clang_Cursor_isNull(referenced)) if(clang_Cursor_isNull(referenced))
return false; return false;
@ -82,7 +82,7 @@ bool clang::Cursor::is_valid_kind() const {
return kind>Kind::UnexposedDecl && (kind<Kind::FirstInvalid || kind>Kind::LastInvalid); return kind>Kind::UnexposedDecl && (kind<Kind::FirstInvalid || kind>Kind::LastInvalid);
} }
std::string clang::Cursor::get_type_description() const { std::string clangmm::Cursor::get_type_description() const {
std::string spelling; std::string spelling;
auto referenced=clang_getCursorReferenced(cx_cursor); auto referenced=clang_getCursorReferenced(cx_cursor);
if(!clang_Cursor_isNull(referenced)) { if(!clang_Cursor_isNull(referenced)) {
@ -118,7 +118,7 @@ std::string clang::Cursor::get_type_description() const {
return spelling; return spelling;
} }
std::string clang::Cursor::get_brief_comments() const { std::string clangmm::Cursor::get_brief_comments() const {
std::string comment_string; std::string comment_string;
auto referenced=get_referenced(); auto referenced=get_referenced();
if(referenced) { if(referenced) {

4
src/Cursor.h

@ -6,7 +6,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace clang { namespace clangmm {
class Cursor { class Cursor {
public: public:
enum class Kind { enum class Kind {
@ -209,5 +209,5 @@ namespace clang {
CXCursor cx_cursor; CXCursor cx_cursor;
}; };
} // namespace clang } // namespace clangmm
#endif // CURSOR_H_ #endif // CURSOR_H_

4
src/Diagnostic.cc

@ -3,7 +3,7 @@
#include "Tokens.h" #include "Tokens.h"
#include "Utility.h" #include "Utility.h"
clang::Diagnostic::Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnostic) { clangmm::Diagnostic::Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnostic) {
severity=clang_getDiagnosticSeverity(cx_diagnostic); severity=clang_getDiagnosticSeverity(cx_diagnostic);
severity_spelling=get_severity_spelling(severity); severity_spelling=get_severity_spelling(severity);
spelling=to_string(clang_getDiagnosticSpelling(cx_diagnostic)); spelling=to_string(clang_getDiagnosticSpelling(cx_diagnostic));
@ -23,7 +23,7 @@ clang::Diagnostic::Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnos
} }
} }
const std::string clang::Diagnostic::get_severity_spelling(unsigned severity) { const std::string clangmm::Diagnostic::get_severity_spelling(unsigned severity) {
switch(severity) { switch(severity) {
case CXDiagnostic_Ignored: case CXDiagnostic_Ignored:
return "Ignored"; return "Ignored";

8
src/Diagnostic.h

@ -5,17 +5,17 @@
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include "SourceRange.h" #include "SourceRange.h"
namespace clang { namespace clangmm {
class Diagnostic { class Diagnostic {
friend class TranslationUnit; friend class TranslationUnit;
Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnostic); Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnostic);
public: public:
class FixIt { class FixIt {
public: public:
FixIt(const std::string &source, const std::pair<clang::Offset, clang::Offset> &offsets): FixIt(const std::string &source, const std::pair<clangmm::Offset, clangmm::Offset> &offsets):
source(source), offsets(offsets) {} source(source), offsets(offsets) {}
std::string source; std::string source;
std::pair<clang::Offset, clang::Offset> offsets; std::pair<clangmm::Offset, clangmm::Offset> offsets;
}; };
static const std::string get_severity_spelling(unsigned severity); static const std::string get_severity_spelling(unsigned severity);
@ -24,7 +24,7 @@ namespace clang {
std::string severity_spelling; std::string severity_spelling;
std::string spelling; std::string spelling;
std::string path; std::string path;
std::pair<clang::Offset, clang::Offset> offsets; std::pair<clangmm::Offset, clangmm::Offset> offsets;
std::vector<FixIt> fix_its; std::vector<FixIt> fix_its;
}; };
} }

4
src/Index.cc

@ -1,9 +1,9 @@
#include "Index.h" #include "Index.h"
clang::Index::Index(int excludeDeclarationsFromPCH, int displayDiagnostics) { clangmm::Index::Index(int excludeDeclarationsFromPCH, int displayDiagnostics) {
cx_index = clang_createIndex(excludeDeclarationsFromPCH, displayDiagnostics); cx_index = clang_createIndex(excludeDeclarationsFromPCH, displayDiagnostics);
} }
clang::Index::~Index() { clangmm::Index::~Index() {
clang_disposeIndex(cx_index); clang_disposeIndex(cx_index);
} }

4
src/Index.h

@ -2,12 +2,12 @@
#define INDEX_H_ #define INDEX_H_
#include <clang-c/Index.h> #include <clang-c/Index.h>
namespace clang { namespace clangmm {
class Index { class Index {
public: public:
Index(int excludeDeclarationsFromPCH, int displayDiagnostics); Index(int excludeDeclarationsFromPCH, int displayDiagnostics);
~Index(); ~Index();
CXIndex cx_index; CXIndex cx_index;
}; };
} // namespace clang } // namespace clangmm
#endif // INDEX_H_ #endif // INDEX_H_

10
src/SourceLocation.cc

@ -4,28 +4,28 @@
// // // // // // // // // // // // // // // //
// SourceLocation // // SourceLocation //
// // // // // // // // // // // // // // // //
clang::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset) { clangmm::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned 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);
} }
clang::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column) { clangmm::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column) {
CXFile file = clang_getFile(tu, filepath.c_str()); CXFile file = clang_getFile(tu, filepath.c_str());
cx_location = clang_getLocation(tu, file, line, column); cx_location = clang_getLocation(tu, file, line, column);
} }
std::string clang::SourceLocation::get_path() { std::string clangmm::SourceLocation::get_path() {
std::string path; std::string path;
get_data(&path, NULL, NULL, NULL); get_data(&path, NULL, NULL, NULL);
return path; return path;
} }
clang::Offset clang::SourceLocation::get_offset() { clangmm::Offset clangmm::SourceLocation::get_offset() {
unsigned line, index; unsigned line, index;
get_data(NULL, &line, &index, NULL); get_data(NULL, &line, &index, NULL);
return {line, index}; return {line, index};
} }
void clang::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) { void clangmm::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);
else { else {

10
src/SourceLocation.h

@ -3,13 +3,13 @@
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include <string> #include <string>
namespace clang { namespace clangmm {
class Offset { class Offset {
public: public:
Offset() {} Offset() {}
Offset(unsigned line, unsigned index): line(line), index(index) {} Offset(unsigned line, unsigned index): line(line), index(index) {}
bool operator==(const clang::Offset &o) {return (line==o.line && index==o.index);} bool operator==(const clangmm::Offset &o) {return (line==o.line && index==o.index);}
bool operator!=(const clang::Offset &o) {return !(*this==o);} bool operator!=(const clangmm::Offset &o) {return !(*this==o);}
unsigned line; unsigned line;
unsigned index; //byte index in line (not char number) unsigned index; //byte index in line (not char number)
}; };
@ -23,7 +23,7 @@ namespace clang {
public: public:
std::string get_path(); std::string get_path();
clang::Offset get_offset(); clangmm::Offset get_offset();
CXSourceLocation cx_location; CXSourceLocation cx_location;
@ -31,5 +31,5 @@ namespace clang {
void get_data(std::string *path, unsigned *line, unsigned *column, unsigned *offset); void get_data(std::string *path, unsigned *line, unsigned *column, unsigned *offset);
}; };
} // namespace clang } // namespace clangmm
#endif // SOURCELOCATION_H_ #endif // SOURCELOCATION_H_

4
src/SourceRange.cc

@ -1,10 +1,10 @@
#include "SourceRange.h" #include "SourceRange.h"
clang::SourceRange::SourceRange(clang::SourceLocation &start, clang::SourceLocation &end) { clangmm::SourceRange::SourceRange(clangmm::SourceLocation &start, clangmm::SourceLocation &end) {
cx_range = clang_getRange(start.cx_location, end.cx_location); cx_range = clang_getRange(start.cx_location, end.cx_location);
} }
std::pair<clang::Offset, clang::Offset> clang::SourceRange::get_offsets() { std::pair<clangmm::Offset, clangmm::Offset> clangmm::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));
return {start.get_offset(), end.get_offset()}; return {start.get_offset(), end.get_offset()};
} }

6
src/SourceRange.h

@ -5,13 +5,13 @@
#include <string> #include <string>
#include <utility> #include <utility>
namespace clang { namespace clangmm {
class SourceRange { class SourceRange {
public: public:
SourceRange(const CXSourceRange& cx_range) : cx_range(cx_range) {} SourceRange(const CXSourceRange& cx_range) : cx_range(cx_range) {}
SourceRange(SourceLocation &start, SourceLocation &end); SourceRange(SourceLocation &start, SourceLocation &end);
std::pair<clang::Offset, clang::Offset> get_offsets(); std::pair<clangmm::Offset, clangmm::Offset> get_offsets();
CXSourceRange cx_range; CXSourceRange cx_range;
}; };
} // namespace clang } // namespace clangmm
#endif // SOURCERANGE_H_ #endif // SOURCERANGE_H_

16
src/Token.cc

@ -7,34 +7,34 @@
// returns gets an source location for this token objekt // returns gets an source location for this token objekt
// based on the translationunit given // based on the translationunit given
clang::SourceLocation clang::Token::get_source_location() const { clangmm::SourceLocation clangmm::Token::get_source_location() const {
return SourceLocation(clang_getTokenLocation(cx_tu, cx_token)); return SourceLocation(clang_getTokenLocation(cx_tu, cx_token));
} }
// returns a sourcerange that covers this token // returns a sourcerange that covers this token
clang::SourceRange clang::Token::get_source_range() const { clangmm::SourceRange clangmm::Token::get_source_range() const {
return SourceRange(clang_getTokenExtent(cx_tu, cx_token)); return SourceRange(clang_getTokenExtent(cx_tu, cx_token));
} }
// returns a string description of this tokens kind // returns a string description of this tokens kind
std::string clang::Token::get_spelling() const { std::string clangmm::Token::get_spelling() const {
return to_string(clang_getTokenSpelling(cx_tu, cx_token)); return to_string(clang_getTokenSpelling(cx_tu, cx_token));
} }
clang::Token::Kind clang::Token::get_kind() const { clangmm::Token::Kind clangmm::Token::get_kind() const {
return static_cast<Kind>(clang_getTokenKind(cx_token)); return static_cast<Kind>(clang_getTokenKind(cx_token));
} }
bool clang::Token::is_identifier() const { bool clangmm::Token::is_identifier() const {
auto token_kind=get_kind(); auto token_kind=get_kind();
auto cursor=get_cursor(); auto cursor=get_cursor();
if(token_kind==clang::Token::Kind::Identifier && cursor.is_valid_kind()) if(token_kind==clangmm::Token::Kind::Identifier && cursor.is_valid_kind())
return true; return true;
else if(token_kind==clang::Token::Kind::Keyword && cursor.is_valid_kind()) { else if(token_kind==clangmm::Token::Kind::Keyword && cursor.is_valid_kind()) {
auto spelling=get_spelling(); auto spelling=get_spelling();
if(spelling=="operator" || (spelling=="bool" && get_cursor().get_spelling()=="operator bool")) if(spelling=="operator" || (spelling=="bool" && get_cursor().get_spelling()=="operator bool"))
return true; return true;
} }
else if(token_kind==clang::Token::Kind::Punctuation && cursor.is_valid_kind()) { else if(token_kind==clangmm::Token::Kind::Punctuation && cursor.is_valid_kind()) {
auto referenced=get_cursor().get_referenced(); auto referenced=get_cursor().get_referenced();
if(referenced) { if(referenced) {
auto referenced_kind=referenced.get_kind(); auto referenced_kind=referenced.get_kind();

8
src/Token.h

@ -6,7 +6,7 @@
#include "Cursor.h" #include "Cursor.h"
#include <string> #include <string>
namespace clang { namespace clangmm {
class Token { class Token {
friend class Tokens; friend class Tokens;
public: public:
@ -25,14 +25,14 @@ namespace clang {
std::string get_spelling() const; std::string get_spelling() const;
SourceLocation get_source_location() const; SourceLocation get_source_location() const;
SourceRange get_source_range() const; SourceRange get_source_range() const;
clang::Cursor get_cursor() const {return clang::Cursor(cx_cursor);} clangmm::Cursor get_cursor() const {return clangmm::Cursor(cx_cursor);}
bool is_identifier() const; bool is_identifier() const;
CXTranslationUnit &cx_tu; CXTranslationUnit &cx_tu;
CXToken& cx_token; CXToken& cx_token;
CXCursor& cx_cursor; CXCursor& cx_cursor;
std::pair<clang::Offset, clang::Offset> offsets; std::pair<clangmm::Offset, clangmm::Offset> offsets;
}; };
} // namespace clang } // namespace clangmm
#endif // TOKEN_H_ #endif // TOKEN_H_

6
src/Tokens.cc

@ -1,7 +1,7 @@
#include "Tokens.h" #include "Tokens.h"
#include "Utility.h" #include "Utility.h"
clang::Tokens::Tokens(CXTranslationUnit &cx_tu, const SourceRange &range): cx_tu(cx_tu) { clangmm::Tokens::Tokens(CXTranslationUnit &cx_tu, const SourceRange &range): cx_tu(cx_tu) {
clang_tokenize(cx_tu, range.cx_range, &cx_tokens, &num_tokens); clang_tokenize(cx_tu, range.cx_range, &cx_tokens, &num_tokens);
cx_cursors.resize(num_tokens); cx_cursors.resize(num_tokens);
clang_annotateTokens(cx_tu, cx_tokens, num_tokens, cx_cursors.data()); clang_annotateTokens(cx_tu, cx_tokens, num_tokens, cx_cursors.data());
@ -14,14 +14,14 @@ clang::Tokens::Tokens(CXTranslationUnit &cx_tu, const SourceRange &range): cx_tu
} }
} }
clang::Tokens::~Tokens() { clangmm::Tokens::~Tokens() {
clang_disposeTokens(cx_tu, cx_tokens, size()); clang_disposeTokens(cx_tu, cx_tokens, size());
} }
//This works across TranslationUnits! However, to get rename refactoring to work, //This works across TranslationUnits! However, to get rename refactoring to work,
//one have to open all the files that might include a similar token //one have to open all the files that might include a similar token
//Similar tokens defined as tokens with equal referenced cursors. //Similar tokens defined as tokens with equal referenced cursors.
std::vector<std::pair<clang::Offset, clang::Offset> > clang::Tokens::get_similar_token_offsets(Cursor::Kind kind, std::vector<std::pair<clangmm::Offset, clangmm::Offset> > clangmm::Tokens::get_similar_token_offsets(Cursor::Kind kind,
const std::string &spelling, const std::string &spelling,
const std::string &usr) { const std::string &usr) {
std::vector<std::pair<Offset, Offset> > offsets; std::vector<std::pair<Offset, Offset> > offsets;

8
src/Tokens.h

@ -6,14 +6,14 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
namespace clang { namespace clangmm {
class Tokens : public std::vector<clang::Token> { class Tokens : public std::vector<clangmm::Token> {
friend class TranslationUnit; friend class TranslationUnit;
friend class Diagnostic; friend class Diagnostic;
Tokens(CXTranslationUnit &cx_tu, const SourceRange &range); Tokens(CXTranslationUnit &cx_tu, const SourceRange &range);
public: public:
~Tokens(); ~Tokens();
std::vector<std::pair<clang::Offset, clang::Offset> > get_similar_token_offsets(Cursor::Kind kind, std::vector<std::pair<clangmm::Offset, clangmm::Offset> > get_similar_token_offsets(Cursor::Kind kind,
const std::string &spelling, const std::string &spelling,
const std::string &usr); const std::string &usr);
private: private:
@ -22,5 +22,5 @@ namespace clang {
std::vector<CXCursor> cx_cursors; std::vector<CXCursor> cx_cursors;
CXTranslationUnit& cx_tu; CXTranslationUnit& cx_tu;
}; };
} // namespace clang } // namespace clangmm
#endif // TOKENS_H_ #endif // TOKENS_H_

26
src/TranslationUnit.cc

@ -8,7 +8,7 @@
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path, clangmm::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path,
const std::vector<std::string> &command_line_args, const std::vector<std::string> &command_line_args,
const std::string &buffer, unsigned flags) { const std::string &buffer, unsigned flags) {
std::vector<const char*> args; std::vector<const char*> args;
@ -25,7 +25,7 @@ clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_pa
args.size(), files, 1, flags); args.size(), files, 1, flags);
} }
clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path, clangmm::TranslationUnit::TranslationUnit(Index &index, const std::string &file_path,
const std::vector<std::string> &command_line_args, const std::vector<std::string> &command_line_args,
unsigned flags) { unsigned flags) {
std::vector<const char*> args; std::vector<const char*> args;
@ -37,11 +37,11 @@ clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_pa
args.size(), NULL, 0, flags); args.size(), NULL, 0, flags);
} }
clang::TranslationUnit::~TranslationUnit() { clangmm::TranslationUnit::~TranslationUnit() {
clang_disposeTranslationUnit(cx_tu); clang_disposeTranslationUnit(cx_tu);
} }
void clang::TranslationUnit::parse(Index &index, const std::string &file_path, void clangmm::TranslationUnit::parse(Index &index, const std::string &file_path,
const std::vector<std::string> &command_line_args, const std::vector<std::string> &command_line_args,
const std::map<std::string, std::string> &buffers, unsigned flags) { const std::map<std::string, std::string> &buffers, unsigned flags) {
std::vector<CXUnsavedFile> files; std::vector<CXUnsavedFile> files;
@ -60,7 +60,7 @@ void clang::TranslationUnit::parse(Index &index, const std::string &file_path,
args.size(), files.data(), files.size(), flags); args.size(), files.data(), files.size(), flags);
} }
int clang::TranslationUnit::ReparseTranslationUnit(const std::string &buffer, unsigned flags) { int clangmm::TranslationUnit::ReparseTranslationUnit(const std::string &buffer, unsigned flags) {
CXUnsavedFile files[1]; CXUnsavedFile files[1];
auto file_path=to_string(clang_getTranslationUnitSpelling(cx_tu)); auto file_path=to_string(clang_getTranslationUnitSpelling(cx_tu));
@ -72,7 +72,7 @@ int clang::TranslationUnit::ReparseTranslationUnit(const std::string &buffer, un
return clang_reparseTranslationUnit(cx_tu, 1, files, flags); return clang_reparseTranslationUnit(cx_tu, 1, files, flags);
} }
unsigned clang::TranslationUnit::DefaultFlags() { unsigned clangmm::TranslationUnit::DefaultFlags() {
auto flags=CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; auto flags=CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
#if CINDEX_VERSION_MAJOR>0 || (CINDEX_VERSION_MAJOR==0 && CINDEX_VERSION_MINOR>=35) #if CINDEX_VERSION_MAJOR>0 || (CINDEX_VERSION_MAJOR==0 && CINDEX_VERSION_MINOR>=35)
flags|=CXTranslationUnit_KeepGoing; flags|=CXTranslationUnit_KeepGoing;
@ -80,13 +80,13 @@ unsigned clang::TranslationUnit::DefaultFlags() {
return flags; return flags;
} }
clang::CodeCompleteResults clang::TranslationUnit::get_code_completions(const std::string &buffer, 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); CodeCompleteResults results(cx_tu, buffer, line_number, column);
return results; return results;
} }
std::vector<clang::Diagnostic> clang::TranslationUnit::get_diagnostics() { std::vector<clangmm::Diagnostic> clangmm::TranslationUnit::get_diagnostics() {
std::vector<Diagnostic> diagnostics; std::vector<Diagnostic> diagnostics;
for(unsigned c=0;c<clang_getNumDiagnostics(cx_tu);c++) { for(unsigned c=0;c<clang_getNumDiagnostics(cx_tu);c++) {
CXDiagnostic clang_diagnostic=clang_getDiagnostic(cx_tu, c); CXDiagnostic clang_diagnostic=clang_getDiagnostic(cx_tu, c);
@ -96,15 +96,15 @@ std::vector<clang::Diagnostic> clang::TranslationUnit::get_diagnostics() {
return diagnostics; return diagnostics;
} }
std::unique_ptr<clang::Tokens> clang::TranslationUnit::get_tokens(unsigned start_offset, unsigned end_offset) { std::unique_ptr<clangmm::Tokens> clangmm::TranslationUnit::get_tokens(unsigned start_offset, unsigned end_offset) {
auto path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu)); auto path=clangmm::to_string(clang_getTranslationUnitSpelling(cx_tu));
SourceLocation start_location(cx_tu, path, start_offset); SourceLocation start_location(cx_tu, path, start_offset);
SourceLocation end_location(cx_tu, path, end_offset); SourceLocation end_location(cx_tu, path, end_offset);
SourceRange range(start_location, end_location); SourceRange range(start_location, end_location);
return std::unique_ptr<Tokens>(new Tokens(cx_tu, range)); 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, 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)); auto path=to_string(clang_getTranslationUnitSpelling(cx_tu));
SourceLocation start_location(cx_tu, path, start_line, start_column); SourceLocation start_location(cx_tu, path, start_line, start_column);
@ -113,12 +113,12 @@ std::unique_ptr<clang::Tokens> clang::TranslationUnit::get_tokens(unsigned start
return std::unique_ptr<Tokens>(new Tokens(cx_tu, range)); return std::unique_ptr<Tokens>(new Tokens(cx_tu, range));
} }
clang::Cursor clang::TranslationUnit::get_cursor(std::string path, unsigned offset) { clangmm::Cursor clangmm::TranslationUnit::get_cursor(std::string path, unsigned offset) {
SourceLocation location(cx_tu, path, offset); SourceLocation location(cx_tu, path, offset);
return Cursor(clang_getCursor(cx_tu, location.cx_location)); return Cursor(clang_getCursor(cx_tu, location.cx_location));
} }
clang::Cursor clang::TranslationUnit::get_cursor(std::string path, unsigned line, unsigned column) { clangmm::Cursor clangmm::TranslationUnit::get_cursor(std::string path, unsigned line, unsigned column) {
SourceLocation location(cx_tu, path, line, column); SourceLocation location(cx_tu, path, line, column);
return Cursor(clang_getCursor(cx_tu, location.cx_location)); return Cursor(clang_getCursor(cx_tu, location.cx_location));
} }

12
src/TranslationUnit.h

@ -11,7 +11,7 @@
#include "CodeCompleteResults.h" #include "CodeCompleteResults.h"
#include "Cursor.h" #include "Cursor.h"
namespace clang { namespace clangmm {
class TranslationUnit { class TranslationUnit {
public: public:
TranslationUnit(Index &index, TranslationUnit(Index &index,
@ -35,20 +35,20 @@ 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::string &buffer, clangmm::CodeCompleteResults get_code_completions(const std::string &buffer,
unsigned line_number, unsigned column); unsigned line_number, unsigned column);
std::vector<clang::Diagnostic> get_diagnostics(); std::vector<clangmm::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);
std::unique_ptr<Tokens> get_tokens(unsigned start_line, unsigned start_column, std::unique_ptr<Tokens> get_tokens(unsigned start_line, unsigned start_column,
unsigned end_line, unsigned end_column); unsigned end_line, unsigned end_column);
clang::Cursor get_cursor(std::string path, unsigned offset); clangmm::Cursor get_cursor(std::string path, unsigned offset);
clang::Cursor get_cursor(std::string path, unsigned line, unsigned column); clangmm::Cursor get_cursor(std::string path, unsigned line, unsigned column);
CXTranslationUnit cx_tu; CXTranslationUnit cx_tu;
}; };
} // namespace clang } // namespace clangmm
#endif // TRANSLATIONUNIT_H_ #endif // TRANSLATIONUNIT_H_

2
src/Utility.cc

@ -1,6 +1,6 @@
#include "Utility.h" #include "Utility.h"
std::string clang::to_string(CXString cx_string) { std::string clangmm::to_string(CXString cx_string) {
std::string string; std::string string;
if(cx_string.data!=NULL) { if(cx_string.data!=NULL) {
string=clang_getCString(cx_string); string=clang_getCString(cx_string);

2
src/Utility.h

@ -3,7 +3,7 @@
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include <string> #include <string>
namespace clang { namespace clangmm {
std::string to_string(CXString cx_string); std::string to_string(CXString cx_string);
} }

4
tests/CodeCompleteResults_H_Test.cc

@ -8,8 +8,8 @@ BOOST_AUTO_TEST_CASE(code_complete_results) {
std::string path("./case/main.cpp"); std::string path("./case/main.cpp");
clang::Index index(0, 0); clangmm::Index index(0, 0);
clang::TranslationUnit tu(index, path, {}); clangmm::TranslationUnit tu(index, path, {});
std::string buffer="#include <string>\n" std::string buffer="#include <string>\n"
"int main(int argc, char *argv[]) {\n" "int main(int argc, char *argv[]) {\n"

10
tests/CompletionString_H_Test.cc

@ -3,10 +3,10 @@
#include <string> #include <string>
BOOST_AUTO_TEST_CASE(completion_chunk) { BOOST_AUTO_TEST_CASE(completion_chunk) {
clang::CompletionChunk str("(", clang::CompletionChunk_LeftBrace); clangmm::CompletionChunk str("(", clangmm::CompletionChunk_LeftBrace);
BOOST_CHECK(str.chunk == "("); BOOST_CHECK(str.chunk == "(");
BOOST_CHECK(str.kind == clang::CompletionChunk_LeftBrace); BOOST_CHECK(str.kind == clangmm::CompletionChunk_LeftBrace);
} }
BOOST_AUTO_TEST_CASE(completion_string) { BOOST_AUTO_TEST_CASE(completion_string) {
@ -15,8 +15,8 @@ BOOST_AUTO_TEST_CASE(completion_string) {
std::string path("./case/main.cpp"); std::string path("./case/main.cpp");
clang::Index index(0, 0); clangmm::Index index(0, 0);
clang::TranslationUnit tu(index, path, {}); clangmm::TranslationUnit tu(index, path, {});
std::string buffer="#include <string>\n" std::string buffer="#include <string>\n"
"int main(int argc, char *argv[]) {\n" "int main(int argc, char *argv[]) {\n"
@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE(completion_string) {
auto results=tu.get_code_completions(buffer, 4, 5); auto results=tu.get_code_completions(buffer, 4, 5);
// ] // ]
clang::CompletionString str = results.get(0); clangmm::CompletionString str = results.get(0);
BOOST_CHECK(str.get_num_chunks() == 5); BOOST_CHECK(str.get_num_chunks() == 5);
BOOST_CHECK(str.get_chunks().size() == 5); BOOST_CHECK(str.get_chunks().size() == 5);

6
tests/Cursor_H_Test.cc

@ -7,12 +7,12 @@ BOOST_AUTO_TEST_CASE(cursor) {
std::string path("./case/main.cpp"); std::string path("./case/main.cpp");
clang::Index index(0, 0); clangmm::Index index(0, 0);
clang::TranslationUnit tu(index, path, {}); clangmm::TranslationUnit tu(index, path, {});
// ] // ]
auto cursor=tu.get_cursor(path, 103); auto cursor=tu.get_cursor(path, 103);
BOOST_CHECK(cursor.get_kind() == clang::Cursor::Kind::ReturnStmt); BOOST_CHECK(cursor.get_kind() == clangmm::Cursor::Kind::ReturnStmt);
} }

4
tests/Diagnostics_Test.cc

@ -8,9 +8,9 @@ using namespace std;
BOOST_AUTO_TEST_CASE(diagnostics_test) { BOOST_AUTO_TEST_CASE(diagnostics_test) {
std::string path("./case/main_error.cpp"); std::string path("./case/main_error.cpp");
clang::Index index(0, 0); clangmm::Index index(0, 0);
clang::TranslationUnit tu(index, path, {}); clangmm::TranslationUnit tu(index, path, {});
auto diagnostics=tu.get_diagnostics(); auto diagnostics=tu.get_diagnostics();
BOOST_CHECK(diagnostics.size()==1); BOOST_CHECK(diagnostics.size()==1);

4
tests/SourceLocation_H_Test.cc

@ -5,9 +5,9 @@
BOOST_AUTO_TEST_CASE(source_location) { BOOST_AUTO_TEST_CASE(source_location) {
std::string path("./case/main.cpp"); std::string path("./case/main.cpp");
clang::Index index(0, 0); clangmm::Index index(0, 0);
clang::TranslationUnit tu(index, path, {}); clangmm::TranslationUnit tu(index, path, {});
auto tokens=tu.get_tokens(0, 113); auto tokens=tu.get_tokens(0, 113);
auto offsets=(*tokens)[28].offsets; auto offsets=(*tokens)[28].offsets;

6
tests/Token_H_Test.cc

@ -5,14 +5,14 @@
BOOST_AUTO_TEST_CASE(token) { BOOST_AUTO_TEST_CASE(token) {
std::string path("./case/main.cpp"); std::string path("./case/main.cpp");
clang::Index index(0, 0); clangmm::Index index(0, 0);
clang::TranslationUnit tu(index, path, {}); clangmm::TranslationUnit tu(index, path, {});
auto tokens=tu.get_tokens(0, 113); auto tokens=tu.get_tokens(0, 113);
BOOST_CHECK(tokens->size() == 32); BOOST_CHECK(tokens->size() == 32);
BOOST_CHECK((*tokens)[1].get_kind() == clang::Token::Kind::Identifier); BOOST_CHECK((*tokens)[1].get_kind() == clangmm::Token::Kind::Identifier);
std::string str = (*tokens)[28].get_spelling(); std::string str = (*tokens)[28].get_spelling();
BOOST_CHECK(str == "return"); BOOST_CHECK(str == "return");

4
tests/TranslationUnit_Test.cc

@ -6,9 +6,9 @@
BOOST_AUTO_TEST_CASE(translation_unit) { BOOST_AUTO_TEST_CASE(translation_unit) {
std::string path("./case/main.cpp"); std::string path("./case/main.cpp");
clang::Index index(0, 0); clangmm::Index index(0, 0);
clang::TranslationUnit tu(index, path, {}); clangmm::TranslationUnit tu(index, path, {});
std::string buffer = "int main(int argc, char *argv[]) {\n" std::string buffer = "int main(int argc, char *argv[]) {\n"
"std::cout << \"Hello World!\" << std::endl;\n" "std::cout << \"Hello World!\" << std::endl;\n"

Loading…
Cancel
Save