mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Move all libclangmm/* files into src/* directory
This commit is contained in:
parent
348b4a2e4e
commit
601af73ca9
@ -9,40 +9,8 @@
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
|
||||
/*
|
||||
#include <execinfo.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
*/
|
||||
|
||||
namespace {
|
||||
|
||||
#if false
|
||||
constexpr int kBacktraceBufferSize = 300;
|
||||
|
||||
void EmitBacktrace() {
|
||||
void* buffer[kBacktraceBufferSize];
|
||||
int nptrs = backtrace(buffer, kBacktraceBufferSize);
|
||||
|
||||
fprintf(stderr, "backtrace() returned %d addresses\n", nptrs);
|
||||
|
||||
/* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
|
||||
would produce similar output to the following: */
|
||||
|
||||
char** strings = backtrace_symbols(buffer, nptrs);
|
||||
if (!strings) {
|
||||
perror("Failed to emit backtrace");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (int j = 0; j < nptrs; j++)
|
||||
fprintf(stderr, "%s\n", strings[j]);
|
||||
|
||||
free(strings);
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned Flags() {
|
||||
// TODO: use clang_defaultEditingTranslationUnitOptions()?
|
||||
return CXTranslationUnit_Incomplete | CXTranslationUnit_KeepGoing |
|
||||
@ -283,8 +251,8 @@ void BuildDetailString(CXCompletionString completion_string,
|
||||
|
||||
void TryEnsureDocumentParsed(ClangCompleteManager* manager,
|
||||
std::shared_ptr<CompletionSession> session,
|
||||
std::unique_ptr<clang::TranslationUnit>* tu,
|
||||
clang::Index* index) {
|
||||
std::unique_ptr<ClangTranslationUnit>* tu,
|
||||
ClangIndex* index) {
|
||||
// Nothing to do. We already have a translation unit.
|
||||
if (*tu)
|
||||
return;
|
||||
@ -304,14 +272,14 @@ void TryEnsureDocumentParsed(ClangCompleteManager* manager,
|
||||
|
||||
LOG_S(INFO) << "Creating completion session with arguments "
|
||||
<< StringJoin(args);
|
||||
*tu = clang::TranslationUnit::Create(index, session->file.filename, args,
|
||||
*tu = ClangTranslationUnit::Create(index, session->file.filename, args,
|
||||
unsaved, Flags());
|
||||
|
||||
// Build diagnostics.
|
||||
if (manager->config_->diagnosticsOnParse && *tu) {
|
||||
// If we're emitting diagnostics, do an immediate reparse, otherwise we will
|
||||
// emit stale/bad diagnostics.
|
||||
*tu = clang::TranslationUnit::Reparse(std::move(*tu), unsaved);
|
||||
*tu = ClangTranslationUnit::Reparse(std::move(*tu), unsaved);
|
||||
if (!*tu) {
|
||||
LOG_S(ERROR) << "Reparsing translation unit for diagnostics failed for "
|
||||
<< session->file.filename;
|
||||
@ -352,7 +320,7 @@ void CompletionParseMain(ClangCompleteManager* completion_manager) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::unique_ptr<clang::TranslationUnit> parsing;
|
||||
std::unique_ptr<ClangTranslationUnit> parsing;
|
||||
TryEnsureDocumentParsed(completion_manager, session, &parsing,
|
||||
&session->index);
|
||||
|
||||
@ -468,7 +436,7 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
|
||||
|
||||
timer.Reset();
|
||||
session->tu =
|
||||
clang::TranslationUnit::Reparse(std::move(session->tu), unsaved);
|
||||
ClangTranslationUnit::Reparse(std::move(session->tu), unsaved);
|
||||
timer.ResetAndPrint("[complete] clang_reparseTranslationUnit");
|
||||
if (!session->tu) {
|
||||
LOG_S(ERROR) << "Reparsing translation unit for diagnostics failed for "
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "atomic_object.h"
|
||||
#include "clang_index.h"
|
||||
#include "clang_translation_unit.h"
|
||||
#include "language_server_api.h"
|
||||
#include "libclangmm/Index.h"
|
||||
#include "libclangmm/TranslationUnit.h"
|
||||
#include "project.h"
|
||||
#include "threaded_queue.h"
|
||||
#include "working_files.h"
|
||||
@ -17,7 +17,7 @@ struct CompletionSession
|
||||
: public std::enable_shared_from_this<CompletionSession> {
|
||||
Project::Entry file;
|
||||
WorkingFiles* working_files;
|
||||
clang::Index index;
|
||||
ClangIndex index;
|
||||
|
||||
// When |tu| was last parsed.
|
||||
optional<std::chrono::time_point<std::chrono::high_resolution_clock>>
|
||||
@ -27,7 +27,7 @@ struct CompletionSession
|
||||
std::mutex tu_lock;
|
||||
|
||||
// The active translation unit.
|
||||
std::unique_ptr<clang::TranslationUnit> tu;
|
||||
std::unique_ptr<ClangTranslationUnit> tu;
|
||||
|
||||
CompletionSession(const Project::Entry& file, WorkingFiles* working_files);
|
||||
~CompletionSession();
|
||||
@ -52,7 +52,7 @@ struct ClangCompleteManager {
|
||||
using OnDiagnostic =
|
||||
std::function<void(std::string path,
|
||||
NonElidedVector<lsDiagnostic> diagnostics)>;
|
||||
using OnIndex = std::function<void(clang::TranslationUnit* tu,
|
||||
using OnIndex = std::function<void(ClangTranslationUnit* tu,
|
||||
const std::vector<CXUnsavedFile>& unsaved,
|
||||
const std::string& path,
|
||||
const std::vector<std::string>& args)>;
|
||||
|
13
src/clang_index.cc
Normal file
13
src/clang_index.cc
Normal file
@ -0,0 +1,13 @@
|
||||
#include "clang_index.h"
|
||||
|
||||
ClangIndex::ClangIndex() : ClangIndex(1, 0) {}
|
||||
|
||||
ClangIndex::ClangIndex(int exclude_declarations_from_pch,
|
||||
int display_diagnostics) {
|
||||
cx_index =
|
||||
clang_createIndex(exclude_declarations_from_pch, display_diagnostics);
|
||||
}
|
||||
|
||||
ClangIndex::~ClangIndex() {
|
||||
clang_disposeIndex(cx_index);
|
||||
}
|
12
src/clang_index.h
Normal file
12
src/clang_index.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
// Simple RAII wrapper about CXIndex.
|
||||
class ClangIndex {
|
||||
public:
|
||||
ClangIndex();
|
||||
ClangIndex(int exclude_declarations_from_pch, int display_diagnostics);
|
||||
~ClangIndex();
|
||||
CXIndex cx_index;
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
#include "TranslationUnit.h"
|
||||
#include "clang_translation_unit.h"
|
||||
|
||||
#include "../platform.h"
|
||||
#include "../utils.h"
|
||||
#include "platform.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
@ -10,11 +10,9 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace clang {
|
||||
|
||||
// static
|
||||
std::unique_ptr<TranslationUnit> TranslationUnit::Create(
|
||||
Index* index,
|
||||
std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Create(
|
||||
ClangIndex* index,
|
||||
const std::string& filepath,
|
||||
const std::vector<std::string>& arguments,
|
||||
std::vector<CXUnsavedFile> unsaved_files,
|
||||
@ -34,7 +32,7 @@ std::unique_ptr<TranslationUnit> TranslationUnit::Create(
|
||||
|
||||
switch (error_code) {
|
||||
case CXError_Success:
|
||||
return MakeUnique<TranslationUnit>(cx_tu);
|
||||
return MakeUnique<ClangTranslationUnit>(cx_tu);
|
||||
case CXError_Failure:
|
||||
LOG_S(ERROR) << "libclang generic failure for " << filepath
|
||||
<< " with args " << StringJoin(args);
|
||||
@ -57,8 +55,8 @@ std::unique_ptr<TranslationUnit> TranslationUnit::Create(
|
||||
}
|
||||
|
||||
// static
|
||||
std::unique_ptr<TranslationUnit> TranslationUnit::Reparse(
|
||||
std::unique_ptr<TranslationUnit> tu,
|
||||
std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Reparse(
|
||||
std::unique_ptr<ClangTranslationUnit> tu,
|
||||
std::vector<CXUnsavedFile>& unsaved) {
|
||||
int error_code = clang_reparseTranslationUnit(
|
||||
tu->cx_tu, (unsigned)unsaved.size(), unsaved.data(),
|
||||
@ -83,10 +81,8 @@ std::unique_ptr<TranslationUnit> TranslationUnit::Reparse(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TranslationUnit::TranslationUnit(CXTranslationUnit tu) : cx_tu(tu) {}
|
||||
ClangTranslationUnit::ClangTranslationUnit(CXTranslationUnit tu) : cx_tu(tu) {}
|
||||
|
||||
TranslationUnit::~TranslationUnit() {
|
||||
ClangTranslationUnit::~ClangTranslationUnit() {
|
||||
clang_disposeTranslationUnit(cx_tu);
|
||||
}
|
||||
|
||||
} // namespace clang
|
32
src/clang_translation_unit.h
Normal file
32
src/clang_translation_unit.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "clang_cursor.h"
|
||||
#include "clang_index.h"
|
||||
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// RAII wrapper around CXTranslationUnit which also makes it much more
|
||||
// challenging to use a CXTranslationUnit instance that is not correctly
|
||||
// initialized.
|
||||
class ClangTranslationUnit {
|
||||
public:
|
||||
static std::unique_ptr<ClangTranslationUnit> Create(
|
||||
ClangIndex* index,
|
||||
const std::string& filepath,
|
||||
const std::vector<std::string>& arguments,
|
||||
std::vector<CXUnsavedFile> unsaved_files,
|
||||
unsigned flags);
|
||||
|
||||
static std::unique_ptr<ClangTranslationUnit> Reparse(
|
||||
std::unique_ptr<ClangTranslationUnit> tu,
|
||||
std::vector<CXUnsavedFile>& unsaved);
|
||||
|
||||
explicit ClangTranslationUnit(CXTranslationUnit tu);
|
||||
~ClangTranslationUnit();
|
||||
|
||||
CXTranslationUnit cx_tu;
|
||||
};
|
@ -835,7 +835,7 @@ enum class FileParseQuery { NeedsParse, DoesNotNeedParse, NoSuchFile };
|
||||
std::vector<Index_DoIdMap> DoParseFile(
|
||||
Config* config,
|
||||
WorkingFiles* working_files,
|
||||
clang::Index* index,
|
||||
ClangIndex* index,
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
TimestampManager* timestamp_manager,
|
||||
ImportManager* import_manager,
|
||||
@ -1018,14 +1018,14 @@ std::vector<Index_DoIdMap> DoParseFile(
|
||||
void IndexWithTuFromCodeCompletion(
|
||||
QueueManager* queue,
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
clang::TranslationUnit* tu,
|
||||
ClangTranslationUnit* tu,
|
||||
const std::vector<CXUnsavedFile>& file_contents,
|
||||
const std::string& path,
|
||||
const std::vector<std::string>& args) {
|
||||
file_consumer_shared->Reset(path);
|
||||
|
||||
PerformanceImportFile perf;
|
||||
clang::Index index(0, 0);
|
||||
ClangIndex index;
|
||||
std::vector<std::unique_ptr<IndexFile>> indexes = ParseWithTu(
|
||||
file_consumer_shared, &perf, tu, &index, path, args, file_contents);
|
||||
|
||||
@ -1050,7 +1050,7 @@ void IndexWithTuFromCodeCompletion(
|
||||
std::vector<Index_DoIdMap> ParseFile(
|
||||
Config* config,
|
||||
WorkingFiles* working_files,
|
||||
clang::Index* index,
|
||||
ClangIndex* index,
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
TimestampManager* timestamp_manager,
|
||||
ImportManager* import_manager,
|
||||
@ -1079,7 +1079,7 @@ bool IndexMain_DoParse(Config* config,
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
TimestampManager* timestamp_manager,
|
||||
ImportManager* import_manager,
|
||||
clang::Index* index) {
|
||||
ClangIndex* index) {
|
||||
optional<Index_Request> request = queue->index_request.TryDequeue();
|
||||
if (!request)
|
||||
return false;
|
||||
@ -1216,7 +1216,7 @@ WorkThread::Result IndexMain(Config* config,
|
||||
EmitProgress(queue);
|
||||
|
||||
// TODO: dispose of index after it is not used for a while.
|
||||
clang::Index index(1, 0);
|
||||
ClangIndex index;
|
||||
|
||||
// TODO: process all off IndexMain_DoIndex before calling
|
||||
// IndexMain_DoCreateIndexUpdate for
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include "clang_cursor.h"
|
||||
#include "clang_utils.h"
|
||||
#include "libclangmm/Index.h"
|
||||
#include "libclangmm/TranslationUnit.h"
|
||||
#include "platform.h"
|
||||
#include "serializer.h"
|
||||
#include "timer.h"
|
||||
@ -208,13 +206,13 @@ struct IndexParam {
|
||||
// translation unit.
|
||||
IndexFile* primary_file = nullptr;
|
||||
|
||||
clang::TranslationUnit* tu = nullptr;
|
||||
ClangTranslationUnit* tu = nullptr;
|
||||
|
||||
FileConsumer* file_consumer = nullptr;
|
||||
NamespaceHelper ns;
|
||||
ConstructorCache ctors;
|
||||
|
||||
IndexParam(clang::TranslationUnit* tu, FileConsumer* file_consumer)
|
||||
IndexParam(ClangTranslationUnit* tu, FileConsumer* file_consumer)
|
||||
: tu(tu), file_consumer(file_consumer) {}
|
||||
};
|
||||
|
||||
@ -1592,7 +1590,7 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<FileContents>& file_contents,
|
||||
PerformanceImportFile* perf,
|
||||
clang::Index* index,
|
||||
ClangIndex* index,
|
||||
bool dump_ast) {
|
||||
if (!config->enableIndexing)
|
||||
return {};
|
||||
@ -1610,7 +1608,7 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
unsaved_files.push_back(unsaved);
|
||||
}
|
||||
|
||||
std::unique_ptr<clang::TranslationUnit> tu = clang::TranslationUnit::Create(
|
||||
std::unique_ptr<ClangTranslationUnit> tu = ClangTranslationUnit::Create(
|
||||
index, file, args, unsaved_files,
|
||||
CXTranslationUnit_KeepGoing |
|
||||
CXTranslationUnit_DetailedPreprocessingRecord);
|
||||
@ -1629,8 +1627,8 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
PerformanceImportFile* perf,
|
||||
clang::TranslationUnit* tu,
|
||||
clang::Index* index,
|
||||
ClangTranslationUnit* tu,
|
||||
ClangIndex* index,
|
||||
const std::string& file,
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<CXUnsavedFile>& file_contents) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "clang_index.h"
|
||||
#include "clang_translation_unit.h"
|
||||
#include "clang_utils.h"
|
||||
#include "file_consumer.h"
|
||||
#include "language_server_api.h"
|
||||
#include "libclangmm/Index.h"
|
||||
#include "libclangmm/TranslationUnit.h"
|
||||
#include "performance.h"
|
||||
#include "position.h"
|
||||
#include "serializer.h"
|
||||
@ -525,13 +525,13 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<FileContents>& file_contents,
|
||||
PerformanceImportFile* perf,
|
||||
clang::Index* index,
|
||||
ClangIndex* index,
|
||||
bool dump_ast = false);
|
||||
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
PerformanceImportFile* perf,
|
||||
clang::TranslationUnit* tu,
|
||||
clang::Index* index,
|
||||
ClangTranslationUnit* tu,
|
||||
ClangIndex* index,
|
||||
const std::string& file,
|
||||
const std::vector<std::string>& args,
|
||||
const std::vector<CXUnsavedFile>& file_contents);
|
||||
|
@ -1,9 +0,0 @@
|
||||
#include "Index.h"
|
||||
|
||||
clang::Index::Index(int excludeDeclarationsFromPCH, int displayDiagnostics) {
|
||||
cx_index = clang_createIndex(excludeDeclarationsFromPCH, displayDiagnostics);
|
||||
}
|
||||
|
||||
clang::Index::~Index() {
|
||||
clang_disposeIndex(cx_index);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#ifndef INDEX_H_
|
||||
#define INDEX_H_
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
namespace clang {
|
||||
class Index {
|
||||
public:
|
||||
Index(int excludeDeclarationsFromPCH, int displayDiagnostics);
|
||||
~Index();
|
||||
CXIndex cx_index;
|
||||
};
|
||||
} // namespace clang
|
||||
#endif // INDEX_H_
|
@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../clang_cursor.h"
|
||||
#include "Index.h"
|
||||
|
||||
#include <clang-c/Index.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace clang {
|
||||
|
||||
class TranslationUnit {
|
||||
public:
|
||||
static std::unique_ptr<TranslationUnit> Create(
|
||||
Index* index,
|
||||
const std::string& filepath,
|
||||
const std::vector<std::string>& arguments,
|
||||
std::vector<CXUnsavedFile> unsaved_files,
|
||||
unsigned flags);
|
||||
|
||||
static std::unique_ptr<TranslationUnit> Reparse(
|
||||
std::unique_ptr<TranslationUnit> tu,
|
||||
std::vector<CXUnsavedFile>& unsaved);
|
||||
|
||||
explicit TranslationUnit(CXTranslationUnit tu);
|
||||
~TranslationUnit();
|
||||
|
||||
CXTranslationUnit cx_tu;
|
||||
};
|
||||
|
||||
} // namespace clang
|
@ -269,7 +269,7 @@ std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
|
||||
for (unsigned j = 0; j < num_args; ++j)
|
||||
entry.args.push_back(
|
||||
ToString(clang_CompileCommand_getArg(cx_command, j)));
|
||||
clang_time.Pause(); // TODO: don't call clang::ToString in this block.
|
||||
clang_time.Pause(); // TODO: don't call ToString in this block.
|
||||
|
||||
our_time.Resume();
|
||||
std::string absolute_filename;
|
||||
|
@ -113,7 +113,7 @@ void RunTests() {
|
||||
|
||||
// TODO: Assert that we need to be on clang >= 3.9.1
|
||||
bool update_all = false;
|
||||
clang::Index index(1, 0);
|
||||
ClangIndex index;
|
||||
|
||||
for (std::string path : GetFilesInFolder("tests", true /*recursive*/,
|
||||
true /*add_folder_to_path*/)) {
|
||||
|
Loading…
Reference in New Issue
Block a user