From 4c5fa3f0c171ccd7e8a7a19d650116ddf4614f78 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 6 May 2017 11:39:00 +0200 Subject: [PATCH] Changed namespace to clangmm due to conflicts with libclang on for instance OpenSuse --- src/CodeCompleteResults.cc | 12 ++++----- src/CodeCompleteResults.h | 4 +-- src/CompilationDatabase.cc | 4 +-- src/CompilationDatabase.h | 2 +- src/CompileCommand.cc | 4 +-- src/CompileCommand.h | 2 +- src/CompileCommands.cc | 6 ++--- src/CompileCommands.h | 2 +- src/CompletionString.cc | 12 ++++----- src/CompletionString.h | 4 +-- src/Cursor.cc | 40 ++++++++++++++--------------- src/Cursor.h | 4 +-- src/Diagnostic.cc | 4 +-- src/Diagnostic.h | 8 +++--- src/Index.cc | 4 +-- src/Index.h | 4 +-- src/SourceLocation.cc | 10 ++++---- src/SourceLocation.h | 10 ++++---- src/SourceRange.cc | 4 +-- src/SourceRange.h | 6 ++--- src/Token.cc | 16 ++++++------ src/Token.h | 8 +++--- src/Tokens.cc | 6 ++--- src/Tokens.h | 8 +++--- src/TranslationUnit.cc | 26 +++++++++---------- src/TranslationUnit.h | 12 ++++----- src/Utility.cc | 2 +- src/Utility.h | 2 +- tests/CodeCompleteResults_H_Test.cc | 4 +-- tests/CompletionString_H_Test.cc | 10 ++++---- tests/Cursor_H_Test.cc | 6 ++--- tests/Diagnostics_Test.cc | 4 +-- tests/SourceLocation_H_Test.cc | 4 +-- tests/Token_H_Test.cc | 6 ++--- tests/TranslationUnit_Test.cc | 4 +-- 35 files changed, 132 insertions(+), 132 deletions(-) diff --git a/src/CodeCompleteResults.cc b/src/CodeCompleteResults.cc index a555243..a5b51f1 100644 --- a/src/CodeCompleteResults.cc +++ b/src/CodeCompleteResults.cc @@ -3,7 +3,7 @@ #include #include "Utility.h" -clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu, +clangmm::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &buffer, unsigned line_num, unsigned column) { CXUnsavedFile files[1]; @@ -23,23 +23,23 @@ clang::CodeCompleteResults::CodeCompleteResults(CXTranslationUnit &cx_tu, clang_sortCodeCompletionResults(cx_results->Results, cx_results->NumResults); } -clang::CodeCompleteResults::~CodeCompleteResults() { +clangmm::CodeCompleteResults::~CodeCompleteResults() { clang_disposeCodeCompleteResults(cx_results); } -unsigned clang::CodeCompleteResults::size() const { +unsigned clangmm::CodeCompleteResults::size() const { if(cx_results==NULL) return 0; return cx_results->NumResults; } -clang::CompletionString clang::CodeCompleteResults::get(unsigned i) const { +clangmm::CompletionString clangmm::CodeCompleteResults::get(unsigned i) const { 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); } -std::string clang::CodeCompleteResults::get_usr() const { +std::string clangmm::CodeCompleteResults::get_usr() const { return to_string(clang_codeCompleteGetContainerUSR(cx_results)); } diff --git a/src/CodeCompleteResults.h b/src/CodeCompleteResults.h index 64d855b..c749a66 100644 --- a/src/CodeCompleteResults.h +++ b/src/CodeCompleteResults.h @@ -5,7 +5,7 @@ #include #include "CompletionString.h" -namespace clang { +namespace clangmm { class CodeCompleteResults { friend class TranslationUnit; @@ -19,5 +19,5 @@ namespace clang { CXCodeCompleteResults *cx_results; }; -} // namespace clang +} // namespace clangmm #endif // CODECOMPLETERESULTS_H_ diff --git a/src/CompilationDatabase.cc b/src/CompilationDatabase.cc index 46b2c83..2940407 100644 --- a/src/CompilationDatabase.cc +++ b/src/CompilationDatabase.cc @@ -1,7 +1,7 @@ #include "CompilationDatabase.h" #include -clang::CompilationDatabase::CompilationDatabase(const std::string &project_path) { +clangmm::CompilationDatabase::CompilationDatabase(const std::string &project_path) { CXCompilationDatabase_Error error; cx_db = clang_CompilationDatabase_fromDirectory(project_path.c_str(), &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); } diff --git a/src/CompilationDatabase.h b/src/CompilationDatabase.h index 2e4e81a..c724ae5 100644 --- a/src/CompilationDatabase.h +++ b/src/CompilationDatabase.h @@ -4,7 +4,7 @@ #include #include -namespace clang { +namespace clangmm { class CompilationDatabase { public: explicit CompilationDatabase(const std::string &project_path); diff --git a/src/CompileCommand.cc b/src/CompileCommand.cc index a291da5..b9f3f45 100644 --- a/src/CompileCommand.cc +++ b/src/CompileCommand.cc @@ -2,7 +2,7 @@ #include "CompileCommands.h" #include "Utility.h" -std::string clang::CompileCommand::get_command() { +std::string clangmm::CompileCommand::get_command() { std::string res; unsigned N = clang_CompileCommand_getNumArgs(cx_command); for (unsigned i = 0; i < N; i++) { @@ -11,7 +11,7 @@ std::string clang::CompileCommand::get_command() { return res; } -std::vector clang::CompileCommand::get_command_as_args() { +std::vector clangmm::CompileCommand::get_command_as_args() { unsigned N = clang_CompileCommand_getNumArgs(cx_command); std::vector res(N); for (unsigned i = 0; i < N; i++) { diff --git a/src/CompileCommand.h b/src/CompileCommand.h index 582d2b4..c5a26e6 100644 --- a/src/CompileCommand.h +++ b/src/CompileCommand.h @@ -4,7 +4,7 @@ #include #include -namespace clang { +namespace clangmm { class CompileCommand { public: CompileCommand(const CXCompileCommand& cx_command) : cx_command(cx_command) {}; diff --git a/src/CompileCommands.cc b/src/CompileCommands.cc index 44fddcb..198b183 100644 --- a/src/CompileCommands.cc +++ b/src/CompileCommands.cc @@ -1,17 +1,17 @@ #include "CompileCommands.h" -clang::CompileCommands::CompileCommands(const std::string &filename, CompilationDatabase &db) { +clangmm::CompileCommands::CompileCommands(const std::string &filename, CompilationDatabase &db) { cx_commands = clang_CompilationDatabase_getCompileCommands(db.cx_db, filename.c_str()); if(clang_CompileCommands_getSize(cx_commands)==0) cx_commands = clang_CompilationDatabase_getAllCompileCommands(db.cx_db); } -clang::CompileCommands::~CompileCommands() { +clangmm::CompileCommands::~CompileCommands() { clang_CompileCommands_dispose(cx_commands); } -std::vector clang::CompileCommands::get_commands() { +std::vector clangmm::CompileCommands::get_commands() { unsigned N = clang_CompileCommands_getSize(cx_commands); std::vector res; for (unsigned i = 0; i < N; i++) { diff --git a/src/CompileCommands.h b/src/CompileCommands.h index f822d18..79ea418 100644 --- a/src/CompileCommands.h +++ b/src/CompileCommands.h @@ -6,7 +6,7 @@ #include #include -namespace clang { +namespace clangmm { class CompileCommands { public: CompileCommands(const std::string &filename, CompilationDatabase &db); diff --git a/src/CompletionString.cc b/src/CompletionString.cc index e9b465e..a154885 100644 --- a/src/CompletionString.cc +++ b/src/CompletionString.cc @@ -1,18 +1,18 @@ #include "CompletionString.h" #include "Utility.h" -clang::CompletionString:: +clangmm::CompletionString:: 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; } -unsigned clang::CompletionString::get_num_chunks() { +unsigned clangmm::CompletionString::get_num_chunks() { return clang_getNumCompletionChunks(cx_completion_sting); } -std::vector clang::CompletionString::get_chunks() { +std::vector clangmm::CompletionString::get_chunks() { std::vector res; for (unsigned i = 0; i < get_num_chunks(); i++) { res.emplace_back(to_string(clang_getCompletionChunkText(cx_completion_sting, i)), static_cast (clang_getCompletionChunkKind(cx_completion_sting, i))); @@ -20,9 +20,9 @@ std::vector clang::CompletionString::get_chunks() { return res; } -std::string clang::CompletionString::get_brief_comments() { +std::string clangmm::CompletionString::get_brief_comments() { 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) { } diff --git a/src/CompletionString.h b/src/CompletionString.h index 8c3b16c..c03221b 100644 --- a/src/CompletionString.h +++ b/src/CompletionString.h @@ -4,7 +4,7 @@ #include #include -namespace clang { +namespace clangmm { enum CompletionChunkKind { CompletionChunk_Optional, CompletionChunk_TypedText, CompletionChunk_Text, CompletionChunk_Placeholder, @@ -36,5 +36,5 @@ namespace clang { CXCompletionString cx_completion_sting; }; -} // namespace clang +} // namespace clangmm #endif // COMPLETIONSTRING_H_ diff --git a/src/Cursor.cc b/src/Cursor.cc index 5c0caef..1e98ed7 100644 --- a/src/Cursor.cc +++ b/src/Cursor.cc @@ -2,63 +2,63 @@ #include "Utility.h" #include -std::string clang::Cursor::Type::get_spelling() const { +std::string clangmm::Cursor::Type::get_spelling() const { 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)); } -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); } -clang::Cursor::Kind clang::Cursor::get_kind() const { +clangmm::Cursor::Kind clangmm::Cursor::get_kind() const { return static_cast(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)); } -clang::SourceLocation clang::Cursor::get_source_location() const { +clangmm::SourceLocation clangmm::Cursor::get_source_location() const { 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)); } -std::string clang::Cursor::get_spelling() const { +std::string clangmm::Cursor::get_spelling() const { 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)); } -std::string clang::Cursor::get_usr() const { +std::string clangmm::Cursor::get_usr() const { 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)); } -clang::Cursor clang::Cursor::get_canonical() const { +clangmm::Cursor clangmm::Cursor::get_canonical() const { 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)); } -clang::Cursor clang::Cursor::get_semantic_parent() const { +clangmm::Cursor clangmm::Cursor::get_semantic_parent() const { return Cursor(clang_getCursorSemanticParent(cx_cursor)); } -std::vector clang::Cursor::get_arguments() const { +std::vector clangmm::Cursor::get_arguments() const { std::vector cursors; auto size=clang_Cursor_getNumArguments(cx_cursor); for(int c=0;c clang::Cursor::get_arguments() const { return cursors; } -clang::Cursor::operator bool() const { +clangmm::Cursor::operator bool() const { 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); } -bool clang::Cursor::is_valid_kind() const { +bool clangmm::Cursor::is_valid_kind() const { auto referenced=clang_getCursorReferenced(cx_cursor); if(clang_Cursor_isNull(referenced)) return false; @@ -82,7 +82,7 @@ bool clang::Cursor::is_valid_kind() const { return kind>Kind::UnexposedDecl && (kindKind::LastInvalid); } -std::string clang::Cursor::get_type_description() const { +std::string clangmm::Cursor::get_type_description() const { std::string spelling; auto referenced=clang_getCursorReferenced(cx_cursor); if(!clang_Cursor_isNull(referenced)) { @@ -118,7 +118,7 @@ std::string clang::Cursor::get_type_description() const { return spelling; } -std::string clang::Cursor::get_brief_comments() const { +std::string clangmm::Cursor::get_brief_comments() const { std::string comment_string; auto referenced=get_referenced(); if(referenced) { diff --git a/src/Cursor.h b/src/Cursor.h index b04ee6d..25ad76a 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -6,7 +6,7 @@ #include #include -namespace clang { +namespace clangmm { class Cursor { public: enum class Kind { @@ -209,5 +209,5 @@ namespace clang { CXCursor cx_cursor; }; -} // namespace clang +} // namespace clangmm #endif // CURSOR_H_ diff --git a/src/Diagnostic.cc b/src/Diagnostic.cc index f7d4264..c41cb43 100644 --- a/src/Diagnostic.cc +++ b/src/Diagnostic.cc @@ -3,7 +3,7 @@ #include "Tokens.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_spelling=get_severity_spelling(severity); 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) { case CXDiagnostic_Ignored: return "Ignored"; diff --git a/src/Diagnostic.h b/src/Diagnostic.h index de12443..d9e1491 100644 --- a/src/Diagnostic.h +++ b/src/Diagnostic.h @@ -5,17 +5,17 @@ #include #include "SourceRange.h" -namespace clang { +namespace clangmm { class Diagnostic { friend class TranslationUnit; Diagnostic(CXTranslationUnit& cx_tu, CXDiagnostic& cx_diagnostic); public: class FixIt { public: - FixIt(const std::string &source, const std::pair &offsets): + FixIt(const std::string &source, const std::pair &offsets): source(source), offsets(offsets) {} std::string source; - std::pair offsets; + std::pair offsets; }; static const std::string get_severity_spelling(unsigned severity); @@ -24,7 +24,7 @@ namespace clang { std::string severity_spelling; std::string spelling; std::string path; - std::pair offsets; + std::pair offsets; std::vector fix_its; }; } diff --git a/src/Index.cc b/src/Index.cc index 2340347..ab30d69 100644 --- a/src/Index.cc +++ b/src/Index.cc @@ -1,9 +1,9 @@ #include "Index.h" -clang::Index::Index(int excludeDeclarationsFromPCH, int displayDiagnostics) { +clangmm::Index::Index(int excludeDeclarationsFromPCH, int displayDiagnostics) { cx_index = clang_createIndex(excludeDeclarationsFromPCH, displayDiagnostics); } -clang::Index::~Index() { +clangmm::Index::~Index() { clang_disposeIndex(cx_index); } \ No newline at end of file diff --git a/src/Index.h b/src/Index.h index cd41977..387d956 100644 --- a/src/Index.h +++ b/src/Index.h @@ -2,12 +2,12 @@ #define INDEX_H_ #include -namespace clang { +namespace clangmm { class Index { public: Index(int excludeDeclarationsFromPCH, int displayDiagnostics); ~Index(); CXIndex cx_index; }; -} // namespace clang +} // namespace clangmm #endif // INDEX_H_ diff --git a/src/SourceLocation.cc b/src/SourceLocation.cc index d38059c..69cae14 100644 --- a/src/SourceLocation.cc +++ b/src/SourceLocation.cc @@ -4,28 +4,28 @@ // // // // // // // // // 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()); 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()); cx_location = clang_getLocation(tu, file, line, column); } -std::string clang::SourceLocation::get_path() { +std::string clangmm::SourceLocation::get_path() { std::string path; get_data(&path, NULL, NULL, NULL); return path; } -clang::Offset clang::SourceLocation::get_offset() { +clangmm::Offset clangmm::SourceLocation::get_offset() { unsigned line, index; get_data(NULL, &line, &index, NULL); 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) clang_getExpansionLocation(cx_location, NULL, line, column, offset); else { diff --git a/src/SourceLocation.h b/src/SourceLocation.h index 74e3dff..4c3ae7c 100644 --- a/src/SourceLocation.h +++ b/src/SourceLocation.h @@ -3,13 +3,13 @@ #include #include -namespace clang { +namespace clangmm { class Offset { public: Offset() {} 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 clang::Offset &o) {return !(*this==o);} + bool operator==(const clangmm::Offset &o) {return (line==o.line && index==o.index);} + bool operator!=(const clangmm::Offset &o) {return !(*this==o);} unsigned line; unsigned index; //byte index in line (not char number) }; @@ -23,7 +23,7 @@ namespace clang { public: std::string get_path(); - clang::Offset get_offset(); + clangmm::Offset get_offset(); CXSourceLocation cx_location; @@ -31,5 +31,5 @@ namespace clang { void get_data(std::string *path, unsigned *line, unsigned *column, unsigned *offset); }; -} // namespace clang +} // namespace clangmm #endif // SOURCELOCATION_H_ diff --git a/src/SourceRange.cc b/src/SourceRange.cc index c0e8407..490f757 100644 --- a/src/SourceRange.cc +++ b/src/SourceRange.cc @@ -1,10 +1,10 @@ #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); } -std::pair clang::SourceRange::get_offsets() { +std::pair clangmm::SourceRange::get_offsets() { SourceLocation start(clang_getRangeStart(cx_range)), end(clang_getRangeEnd(cx_range)); return {start.get_offset(), end.get_offset()}; } \ No newline at end of file diff --git a/src/SourceRange.h b/src/SourceRange.h index e8edd56..9953c5d 100644 --- a/src/SourceRange.h +++ b/src/SourceRange.h @@ -5,13 +5,13 @@ #include #include -namespace clang { +namespace clangmm { class SourceRange { public: SourceRange(const CXSourceRange& cx_range) : cx_range(cx_range) {} SourceRange(SourceLocation &start, SourceLocation &end); - std::pair get_offsets(); + std::pair get_offsets(); CXSourceRange cx_range; }; -} // namespace clang +} // namespace clangmm #endif // SOURCERANGE_H_ diff --git a/src/Token.cc b/src/Token.cc index 94e39ee..fae4012 100644 --- a/src/Token.cc +++ b/src/Token.cc @@ -7,34 +7,34 @@ // returns gets an source location for this token objekt // 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)); } // 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)); } // 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)); } -clang::Token::Kind clang::Token::get_kind() const { +clangmm::Token::Kind clangmm::Token::get_kind() const { return static_cast(clang_getTokenKind(cx_token)); } -bool clang::Token::is_identifier() const { +bool clangmm::Token::is_identifier() const { auto token_kind=get_kind(); 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; - 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(); if(spelling=="operator" || (spelling=="bool" && get_cursor().get_spelling()=="operator bool")) 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(); if(referenced) { auto referenced_kind=referenced.get_kind(); diff --git a/src/Token.h b/src/Token.h index bc24fe1..ce5105c 100644 --- a/src/Token.h +++ b/src/Token.h @@ -6,7 +6,7 @@ #include "Cursor.h" #include -namespace clang { +namespace clangmm { class Token { friend class Tokens; public: @@ -25,14 +25,14 @@ namespace clang { std::string get_spelling() const; SourceLocation get_source_location() 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; CXTranslationUnit &cx_tu; CXToken& cx_token; CXCursor& cx_cursor; - std::pair offsets; + std::pair offsets; }; -} // namespace clang +} // namespace clangmm #endif // TOKEN_H_ diff --git a/src/Tokens.cc b/src/Tokens.cc index d954773..19ec8d5 100644 --- a/src/Tokens.cc +++ b/src/Tokens.cc @@ -1,7 +1,7 @@ #include "Tokens.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); cx_cursors.resize(num_tokens); 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()); } //This works across TranslationUnits! However, to get rename refactoring to work, //one have to open all the files that might include a similar token //Similar tokens defined as tokens with equal referenced cursors. -std::vector > clang::Tokens::get_similar_token_offsets(Cursor::Kind kind, +std::vector > clangmm::Tokens::get_similar_token_offsets(Cursor::Kind kind, const std::string &spelling, const std::string &usr) { std::vector > offsets; diff --git a/src/Tokens.h b/src/Tokens.h index 6fb52ce..f9bf80b 100644 --- a/src/Tokens.h +++ b/src/Tokens.h @@ -6,14 +6,14 @@ #include #include -namespace clang { - class Tokens : public std::vector { +namespace clangmm { + class Tokens : public std::vector { friend class TranslationUnit; friend class Diagnostic; Tokens(CXTranslationUnit &cx_tu, const SourceRange &range); public: ~Tokens(); - std::vector > get_similar_token_offsets(Cursor::Kind kind, + std::vector > get_similar_token_offsets(Cursor::Kind kind, const std::string &spelling, const std::string &usr); private: @@ -22,5 +22,5 @@ namespace clang { std::vector cx_cursors; CXTranslationUnit& cx_tu; }; -} // namespace clang +} // namespace clangmm #endif // TOKENS_H_ diff --git a/src/TranslationUnit.cc b/src/TranslationUnit.cc index c5f2bc9..483c4d6 100644 --- a/src/TranslationUnit.cc +++ b/src/TranslationUnit.cc @@ -8,7 +8,7 @@ #include //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 &command_line_args, const std::string &buffer, unsigned flags) { std::vector args; @@ -25,7 +25,7 @@ clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_pa 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 &command_line_args, unsigned flags) { std::vector args; @@ -37,11 +37,11 @@ clang::TranslationUnit::TranslationUnit(Index &index, const std::string &file_pa args.size(), NULL, 0, flags); } -clang::TranslationUnit::~TranslationUnit() { +clangmm::TranslationUnit::~TranslationUnit() { 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 &command_line_args, const std::map &buffers, unsigned flags) { std::vector files; @@ -60,7 +60,7 @@ void clang::TranslationUnit::parse(Index &index, const std::string &file_path, 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]; 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); } -unsigned clang::TranslationUnit::DefaultFlags() { +unsigned clangmm::TranslationUnit::DefaultFlags() { auto flags=CXTranslationUnit_CacheCompletionResults | CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_Incomplete | CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; #if CINDEX_VERSION_MAJOR>0 || (CINDEX_VERSION_MAJOR==0 && CINDEX_VERSION_MINOR>=35) flags|=CXTranslationUnit_KeepGoing; @@ -80,13 +80,13 @@ unsigned clang::TranslationUnit::DefaultFlags() { 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) { CodeCompleteResults results(cx_tu, buffer, line_number, column); return results; } -std::vector clang::TranslationUnit::get_diagnostics() { +std::vector clangmm::TranslationUnit::get_diagnostics() { std::vector diagnostics; for(unsigned c=0;c clang::TranslationUnit::get_diagnostics() { return diagnostics; } -std::unique_ptr clang::TranslationUnit::get_tokens(unsigned start_offset, unsigned end_offset) { - auto path=clang::to_string(clang_getTranslationUnitSpelling(cx_tu)); +std::unique_ptr clangmm::TranslationUnit::get_tokens(unsigned start_offset, unsigned end_offset) { + auto path=clangmm::to_string(clang_getTranslationUnitSpelling(cx_tu)); SourceLocation start_location(cx_tu, path, start_offset); SourceLocation end_location(cx_tu, path, end_offset); SourceRange range(start_location, end_location); return std::unique_ptr(new Tokens(cx_tu, range)); } -std::unique_ptr clang::TranslationUnit::get_tokens(unsigned start_line, unsigned start_column, +std::unique_ptr clangmm::TranslationUnit::get_tokens(unsigned start_line, unsigned start_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); @@ -113,12 +113,12 @@ std::unique_ptr clang::TranslationUnit::get_tokens(unsigned start return std::unique_ptr(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); 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); return Cursor(clang_getCursor(cx_tu, location.cx_location)); } diff --git a/src/TranslationUnit.h b/src/TranslationUnit.h index e3d5123..fcf9629 100644 --- a/src/TranslationUnit.h +++ b/src/TranslationUnit.h @@ -11,7 +11,7 @@ #include "CodeCompleteResults.h" #include "Cursor.h" -namespace clang { +namespace clangmm { class TranslationUnit { public: TranslationUnit(Index &index, @@ -35,20 +35,20 @@ namespace clang { const std::map &buffers, 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); - std::vector get_diagnostics(); + 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); + clangmm::Cursor get_cursor(std::string path, unsigned offset); + clangmm::Cursor get_cursor(std::string path, unsigned line, unsigned column); CXTranslationUnit cx_tu; }; -} // namespace clang +} // namespace clangmm #endif // TRANSLATIONUNIT_H_ diff --git a/src/Utility.cc b/src/Utility.cc index 7f1c266..cede9a2 100644 --- a/src/Utility.cc +++ b/src/Utility.cc @@ -1,6 +1,6 @@ #include "Utility.h" -std::string clang::to_string(CXString cx_string) { +std::string clangmm::to_string(CXString cx_string) { std::string string; if(cx_string.data!=NULL) { string=clang_getCString(cx_string); diff --git a/src/Utility.h b/src/Utility.h index 6f7e319..45cf2ea 100644 --- a/src/Utility.h +++ b/src/Utility.h @@ -3,7 +3,7 @@ #include #include -namespace clang { +namespace clangmm { std::string to_string(CXString cx_string); } diff --git a/tests/CodeCompleteResults_H_Test.cc b/tests/CodeCompleteResults_H_Test.cc index 12b6e74..bc1bb14 100644 --- a/tests/CodeCompleteResults_H_Test.cc +++ b/tests/CodeCompleteResults_H_Test.cc @@ -8,8 +8,8 @@ BOOST_AUTO_TEST_CASE(code_complete_results) { std::string path("./case/main.cpp"); - clang::Index index(0, 0); - clang::TranslationUnit tu(index, path, {}); + clangmm::Index index(0, 0); + clangmm::TranslationUnit tu(index, path, {}); std::string buffer="#include \n" "int main(int argc, char *argv[]) {\n" diff --git a/tests/CompletionString_H_Test.cc b/tests/CompletionString_H_Test.cc index ba1c37b..55f7a95 100644 --- a/tests/CompletionString_H_Test.cc +++ b/tests/CompletionString_H_Test.cc @@ -3,10 +3,10 @@ #include 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.kind == clang::CompletionChunk_LeftBrace); + BOOST_CHECK(str.kind == clangmm::CompletionChunk_LeftBrace); } BOOST_AUTO_TEST_CASE(completion_string) { @@ -15,8 +15,8 @@ BOOST_AUTO_TEST_CASE(completion_string) { std::string path("./case/main.cpp"); - clang::Index index(0, 0); - clang::TranslationUnit tu(index, path, {}); + clangmm::Index index(0, 0); + clangmm::TranslationUnit tu(index, path, {}); std::string buffer="#include \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); // ] - clang::CompletionString str = results.get(0); + clangmm::CompletionString str = results.get(0); BOOST_CHECK(str.get_num_chunks() == 5); BOOST_CHECK(str.get_chunks().size() == 5); diff --git a/tests/Cursor_H_Test.cc b/tests/Cursor_H_Test.cc index f179fcb..6c54299 100644 --- a/tests/Cursor_H_Test.cc +++ b/tests/Cursor_H_Test.cc @@ -7,12 +7,12 @@ BOOST_AUTO_TEST_CASE(cursor) { std::string path("./case/main.cpp"); - clang::Index index(0, 0); - clang::TranslationUnit tu(index, path, {}); + clangmm::Index index(0, 0); + clangmm::TranslationUnit tu(index, path, {}); // ] 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); } diff --git a/tests/Diagnostics_Test.cc b/tests/Diagnostics_Test.cc index 253e4c2..8d79d02 100644 --- a/tests/Diagnostics_Test.cc +++ b/tests/Diagnostics_Test.cc @@ -8,9 +8,9 @@ using namespace std; BOOST_AUTO_TEST_CASE(diagnostics_test) { 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(); BOOST_CHECK(diagnostics.size()==1); diff --git a/tests/SourceLocation_H_Test.cc b/tests/SourceLocation_H_Test.cc index 82f088c..e71131b 100644 --- a/tests/SourceLocation_H_Test.cc +++ b/tests/SourceLocation_H_Test.cc @@ -5,9 +5,9 @@ BOOST_AUTO_TEST_CASE(source_location) { 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 offsets=(*tokens)[28].offsets; diff --git a/tests/Token_H_Test.cc b/tests/Token_H_Test.cc index adbade5..1bbd45b 100644 --- a/tests/Token_H_Test.cc +++ b/tests/Token_H_Test.cc @@ -5,14 +5,14 @@ BOOST_AUTO_TEST_CASE(token) { 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); 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(); BOOST_CHECK(str == "return"); diff --git a/tests/TranslationUnit_Test.cc b/tests/TranslationUnit_Test.cc index 868ab94..1dd3a28 100644 --- a/tests/TranslationUnit_Test.cc +++ b/tests/TranslationUnit_Test.cc @@ -6,9 +6,9 @@ BOOST_AUTO_TEST_CASE(translation_unit) { 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::cout << \"Hello World!\" << std::endl;\n"