From b165cfa59d03fec0776b6b0b28f4065a587086a0 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Thu, 23 Feb 2017 00:21:46 -0800 Subject: [PATCH] Remove parts of libclangmm --- libclangmm/CompilationDatabase.cc | 17 ----------- libclangmm/CompilationDatabase.h | 20 ------------- libclangmm/CompileCommand.cc | 28 ------------------ libclangmm/CompileCommand.h | 16 ----------- libclangmm/CompileCommands.cc | 22 --------------- libclangmm/CompileCommands.h | 19 ------------- libclangmm/Cursor.cc | 2 ++ libclangmm/Cursor.h | 3 +- libclangmm/SourceLocation.cc | 47 ------------------------------- libclangmm/SourceLocation.h | 41 --------------------------- libclangmm/SourceRange.h | 1 - libclangmm/TranslationUnit.cc | 1 - libclangmm/clangmm.h | 4 --- 13 files changed, 3 insertions(+), 218 deletions(-) delete mode 100644 libclangmm/CompilationDatabase.cc delete mode 100644 libclangmm/CompilationDatabase.h delete mode 100644 libclangmm/CompileCommand.cc delete mode 100644 libclangmm/CompileCommand.h delete mode 100644 libclangmm/CompileCommands.cc delete mode 100644 libclangmm/CompileCommands.h delete mode 100644 libclangmm/SourceLocation.cc delete mode 100644 libclangmm/SourceLocation.h diff --git a/libclangmm/CompilationDatabase.cc b/libclangmm/CompilationDatabase.cc deleted file mode 100644 index b353cac0..00000000 --- a/libclangmm/CompilationDatabase.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include "CompilationDatabase.h" - -#include - -clang::CompilationDatabase::CompilationDatabase(const std::string& project_path) { - CXCompilationDatabase_Error error; - cx_db = clang_CompilationDatabase_fromDirectory(project_path.c_str(), &error); - if (error == CXCompilationDatabase_CanNotLoadDatabase) { - std::cerr << "[FATAL]: Unable to load compile_commands.json located at \"" - << project_path << "\""; - exit(1); - } -} - -clang::CompilationDatabase::~CompilationDatabase() { - clang_CompilationDatabase_dispose(cx_db); -} diff --git a/libclangmm/CompilationDatabase.h b/libclangmm/CompilationDatabase.h deleted file mode 100644 index e6c69915..00000000 --- a/libclangmm/CompilationDatabase.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include - -namespace clang { - -struct CompilationCommand { - std::string path; - std::string args; -}; - -class CompilationDatabase { -public: - explicit CompilationDatabase(const std::string &project_path); - ~CompilationDatabase(); - - CXCompilationDatabase cx_db; -}; -} diff --git a/libclangmm/CompileCommand.cc b/libclangmm/CompileCommand.cc deleted file mode 100644 index ff23e34b..00000000 --- a/libclangmm/CompileCommand.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "CompileCommand.h" -#include "CompileCommands.h" -#include "Utility.h" - -namespace clang { - -CompileCommand::CompileCommand(const CXCompileCommand& command) - : cx_command(command) {}; - -std::string CompileCommand::get_command() const { - std::string result; - unsigned int num_args = clang_CompileCommand_getNumArgs(cx_command); - for (unsigned int i = 0; i < num_args; i++) - result += ToString(clang_CompileCommand_getArg(cx_command, i)); - - return result; -} - -std::vector CompileCommand::get_command_as_args() const { - unsigned num_args = clang_CompileCommand_getNumArgs(cx_command); - std::vector result(num_args); - for (unsigned i = 0; i < num_args; i++) - result[i] = ToString(clang_CompileCommand_getArg(cx_command, i)); - - return result; -} - -} // namespace clang \ No newline at end of file diff --git a/libclangmm/CompileCommand.h b/libclangmm/CompileCommand.h deleted file mode 100644 index f769d218..00000000 --- a/libclangmm/CompileCommand.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace clang { -class CompileCommand { -public: - CompileCommand(const CXCompileCommand& cx_command); - std::string get_command() const; - std::vector get_command_as_args() const; - - CXCompileCommand cx_command; -}; -} diff --git a/libclangmm/CompileCommands.cc b/libclangmm/CompileCommands.cc deleted file mode 100644 index 5290c18a..00000000 --- a/libclangmm/CompileCommands.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include "CompileCommands.h" - -clang::CompileCommands::CompileCommands(const CompilationDatabase& db) { - cx_commands = - clang_CompilationDatabase_getAllCompileCommands(db.cx_db); - //if (clang_CompileCommands_getSize(cx_commands) == 0) - // cx_commands = clang_CompilationDatabase_getAllCompileCommands(db.cx_db); -} - -clang::CompileCommands::~CompileCommands() { - clang_CompileCommands_dispose(cx_commands); -} - -std::vector clang::CompileCommands::get_commands() { - unsigned N = clang_CompileCommands_getSize(cx_commands); - std::vector res; - for (unsigned i = 0; i < N; i++) { - CXCompileCommand command = clang_CompileCommands_getCommand(cx_commands, i); - res.push_back(command); - } - return res; -} diff --git a/libclangmm/CompileCommands.h b/libclangmm/CompileCommands.h deleted file mode 100644 index 49ac5440..00000000 --- a/libclangmm/CompileCommands.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "CompilationDatabase.h" -#include "CompileCommand.h" - -namespace clang { -class CompileCommands { -public: - CompileCommands(const CompilationDatabase& db); - std::vector get_commands(); - ~CompileCommands(); - - CXCompileCommands cx_commands; -}; -} diff --git a/libclangmm/Cursor.cc b/libclangmm/Cursor.cc index b33296d1..788b7e8f 100644 --- a/libclangmm/Cursor.cc +++ b/libclangmm/Cursor.cc @@ -46,9 +46,11 @@ std::string Type::get_spelling() const { return ToString(clang_getTypeSpelling(cx_type)); } +/* SourceLocation Cursor::get_source_location() const { return SourceLocation(clang_getCursorLocation(cx_cursor)); } +*/ Type Type::get_return_type() const { return Type(clang_getResultType(cx_type)); diff --git a/libclangmm/Cursor.h b/libclangmm/Cursor.h index 6b7b40d2..69b8b476 100644 --- a/libclangmm/Cursor.h +++ b/libclangmm/Cursor.h @@ -6,7 +6,6 @@ #include #include -#include "SourceLocation.h" #include "SourceRange.h" @@ -51,7 +50,7 @@ public: CXCursorKind get_kind() const; Type get_type() const; - SourceLocation get_source_location() const; + //SourceLocation get_source_location() const; //SourceRange get_source_range() const; std::string get_spelling() const; std::string get_display_name() const; diff --git a/libclangmm/SourceLocation.cc b/libclangmm/SourceLocation.cc deleted file mode 100644 index 1ccfd8c5..00000000 --- a/libclangmm/SourceLocation.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include - -#include "SourceLocation.h" -#include "Utility.h" - -namespace clang { - -SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset) { - CXFile file = clang_getFile(tu, filepath.c_str()); - assert(false); - //cx_location = clang_getLocationForOffset(tu, file, offset); -} - -SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column) { - CXFile file = clang_getFile(tu, filepath.c_str()); - assert(false); - //cx_location = clang_getLocation(tu, file, line, column); -} - -SourceLocation::SourceLocation() {} - -SourceLocation::SourceLocation(const CXSourceLocation& cx_location) { - //clang_getExpansionLocation - - CXFile file; - clang_getSpellingLocation(cx_location, &file, &line, &column, &offset); - if (file != nullptr) - path = clang::ToString(clang_getFileName(file)); -} - -SourceLocation::SourceLocation(const CXIdxLoc& cx_location) - : SourceLocation(clang_indexLoc_getCXSourceLocation(cx_location)) { -} - -bool operator==(const SourceLocation& a, const SourceLocation& b) { - return a.path == b.path && a.line == b.line && a.column == b.column; -} - -bool operator!=(const SourceLocation& a, const SourceLocation& b) { - return !(a == b); -} - -std::string SourceLocation::ToString() const { - return path + ":" + std::to_string(line) + ":" + std::to_string(column); -} - -} \ No newline at end of file diff --git a/libclangmm/SourceLocation.h b/libclangmm/SourceLocation.h deleted file mode 100644 index 07d2986f..00000000 --- a/libclangmm/SourceLocation.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef SOURCELOCATION_H_ -#define SOURCELOCATION_H_ - -#include -#include - -namespace clang { - -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); } - unsigned line; - unsigned index; //byte index in line (not char number) -}; - -class SourceLocation { - friend class TranslationUnit; - SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset); - SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column); -public: - SourceLocation(); - SourceLocation(const CXSourceLocation& cx_location); - SourceLocation(const CXIdxLoc& cx_location); - - std::string path; - unsigned line = 0; - unsigned column = 0; - unsigned offset = 0; - - std::string ToString() const; -}; - -bool operator==(const SourceLocation& a, const SourceLocation& b); -bool operator!=(const SourceLocation& a, const SourceLocation& b); - -} // namespace clang - -#endif // SOURCELOCATION_H_ diff --git a/libclangmm/SourceRange.h b/libclangmm/SourceRange.h index feee63f0..f128c43b 100644 --- a/libclangmm/SourceRange.h +++ b/libclangmm/SourceRange.h @@ -1,7 +1,6 @@ #ifndef SOURCERANGE_H_ #define SOURCERANGE_H_ #include -#include "SourceLocation.h" #include #include diff --git a/libclangmm/TranslationUnit.cc b/libclangmm/TranslationUnit.cc index 462243f1..207e1d2e 100644 --- a/libclangmm/TranslationUnit.cc +++ b/libclangmm/TranslationUnit.cc @@ -1,5 +1,4 @@ #include "TranslationUnit.h" -#include "SourceLocation.h" #include "Tokens.h" #include "Utility.h" #include diff --git a/libclangmm/clangmm.h b/libclangmm/clangmm.h index b1abb81c..05cd4cb8 100644 --- a/libclangmm/clangmm.h +++ b/libclangmm/clangmm.h @@ -1,13 +1,9 @@ #ifndef CLANGMM_H_ #define CLANGMM_H_ #include "TranslationUnit.h" -#include "SourceLocation.h" #include "SourceRange.h" #include "Token.h" #include "Tokens.h" -#include "CompilationDatabase.h" -#include "CompileCommands.h" -#include "CompileCommand.h" #include "CodeCompleteResults.h" #include "CompletionString.h" #include "Index.h"