Fangrui Song
7 years ago
27 changed files with 171 additions and 491 deletions
@ -1,83 +0,0 @@ |
|||
#include "iindexer.h" |
|||
|
|||
#include "indexer.h" |
|||
|
|||
namespace { |
|||
struct ClangIndexer : IIndexer { |
|||
~ClangIndexer() override = default; |
|||
|
|||
std::vector<std::unique_ptr<IndexFile>> Index( |
|||
FileConsumerSharedState* file_consumer_shared, |
|||
std::string file, |
|||
const std::vector<std::string>& args, |
|||
const std::vector<FileContents>& file_contents, |
|||
PerformanceImportFile* perf) override { |
|||
return Parse(file_consumer_shared, file, args, file_contents, perf, &index); |
|||
} |
|||
|
|||
// Note: constructing this acquires a global lock
|
|||
ClangIndex index; |
|||
}; |
|||
|
|||
struct TestIndexer : IIndexer { |
|||
static std::unique_ptr<TestIndexer> FromEntries( |
|||
const std::vector<TestEntry>& entries) { |
|||
auto result = std::make_unique<TestIndexer>(); |
|||
|
|||
for (const TestEntry& entry : entries) { |
|||
std::vector<std::unique_ptr<IndexFile>> indexes; |
|||
|
|||
if (entry.num_indexes > 0) |
|||
indexes.push_back(std::make_unique<IndexFile>(entry.path, "<empty>")); |
|||
for (int i = 1; i < entry.num_indexes; ++i) { |
|||
indexes.push_back(std::make_unique<IndexFile>( |
|||
entry.path + "_extra_" + std::to_string(i) + ".h", "<empty>")); |
|||
} |
|||
|
|||
result->indexes.insert(std::make_pair(entry.path, std::move(indexes))); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
~TestIndexer() override = default; |
|||
|
|||
std::vector<std::unique_ptr<IndexFile>> Index( |
|||
FileConsumerSharedState* file_consumer_shared, |
|||
std::string file, |
|||
const std::vector<std::string>& args, |
|||
const std::vector<FileContents>& file_contents, |
|||
PerformanceImportFile* perf) override { |
|||
auto it = indexes.find(file); |
|||
if (it == indexes.end()) { |
|||
// Don't return any indexes for unexpected data.
|
|||
assert(false && "no indexes"); |
|||
return {}; |
|||
} |
|||
|
|||
// FIXME: allow user to control how many times we return the index for a
|
|||
// specific file (atm it is always 1)
|
|||
auto result = std::move(it->second); |
|||
indexes.erase(it); |
|||
return result; |
|||
} |
|||
|
|||
std::unordered_map<std::string, std::vector<std::unique_ptr<IndexFile>>> |
|||
indexes; |
|||
}; |
|||
|
|||
} // namespace
|
|||
|
|||
IIndexer::TestEntry::TestEntry(const std::string& path, int num_indexes) |
|||
: path(path), num_indexes(num_indexes) {} |
|||
|
|||
// static
|
|||
std::unique_ptr<IIndexer> IIndexer::MakeClangIndexer() { |
|||
return std::make_unique<ClangIndexer>(); |
|||
} |
|||
|
|||
// static
|
|||
std::unique_ptr<IIndexer> IIndexer::MakeTestIndexer( |
|||
std::initializer_list<TestEntry> entries) { |
|||
return TestIndexer::FromEntries(entries); |
|||
} |
@ -1,42 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include <optional> |
|||
|
|||
#include <initializer_list> |
|||
#include <memory> |
|||
#include <string> |
|||
#include <vector> |
|||
|
|||
// TODO:
|
|||
// - rename indexer.h to clang_indexer.h and pull out non-clang specific code
|
|||
// like IndexFile
|
|||
// - rename this file to indexer.h
|
|||
|
|||
struct IndexFile; |
|||
struct FileContents; |
|||
struct FileConsumerSharedState; |
|||
struct PerformanceImportFile; |
|||
|
|||
// Abstracts away the actual indexing process. Each IIndexer instance is
|
|||
// per-thread and constructing an instance may be extremely expensive (ie,
|
|||
// acquire a lock) and should be done as rarely as possible.
|
|||
struct IIndexer { |
|||
struct TestEntry { |
|||
std::string path; |
|||
int num_indexes = 0; |
|||
|
|||
TestEntry(const std::string& path, int num_indexes); |
|||
}; |
|||
|
|||
static std::unique_ptr<IIndexer> MakeClangIndexer(); |
|||
static std::unique_ptr<IIndexer> MakeTestIndexer( |
|||
std::initializer_list<TestEntry> entries); |
|||
|
|||
virtual ~IIndexer() = default; |
|||
virtual std::vector<std::unique_ptr<IndexFile>> Index( |
|||
FileConsumerSharedState* file_consumer_shared, |
|||
std::string file, |
|||
const std::vector<std::string>& args, |
|||
const std::vector<FileContents>& file_contents, |
|||
PerformanceImportFile* perf) = 0; |
|||
}; |
@ -1,182 +0,0 @@ |
|||
#include "standard_includes.h" |
|||
|
|||
// See http://stackoverflow.com/a/2029106.
|
|||
const char* kStandardLibraryIncludes[177] = { |
|||
"aio.h", |
|||
"algorithm", |
|||
"any", |
|||
"arpa/inet.h", |
|||
"array", |
|||
"assert.h", |
|||
"atomic", |
|||
"bitset", |
|||
"cassert", |
|||
"ccomplex", |
|||
"cctype", |
|||
"cerrno", |
|||
"cfenv", |
|||
"cfloat", |
|||
"chrono", |
|||
"cinttypes", |
|||
"ciso646", |
|||
"climits", |
|||
"clocale", |
|||
"cmath", |
|||
"codecvt", |
|||
"complex", |
|||
"complex.h", |
|||
"condition_variable", |
|||
"cpio.h", |
|||
"csetjmp", |
|||
"csignal", |
|||
"cstdalign", |
|||
"cstdarg", |
|||
"cstdbool", |
|||
"cstddef", |
|||
"cstdint", |
|||
"cstdio", |
|||
"cstdlib", |
|||
"cstring", |
|||
"ctgmath", |
|||
"ctime", |
|||
"ctype.h", |
|||
"cuchar", |
|||
"curses.h", |
|||
"cwchar", |
|||
"cwctype", |
|||
"deque", |
|||
"dirent.h", |
|||
"dlfcn.h", |
|||
"errno.h", |
|||
"exception", |
|||
"execution", |
|||
"fcntl.h", |
|||
"fenv.h", |
|||
"filesystem", |
|||
"float.h", |
|||
"fmtmsg.h", |
|||
"fnmatch.h", |
|||
"forward_list", |
|||
"fstream", |
|||
"ftw.h", |
|||
"functional", |
|||
"future", |
|||
"glob.h", |
|||
"grp.h", |
|||
"iconv.h", |
|||
"initializer_list", |
|||
"inttypes.h", |
|||
"iomanip", |
|||
"ios", |
|||
"iosfwd", |
|||
"iostream", |
|||
"iso646.h", |
|||
"istream", |
|||
"iterator", |
|||
"langinfo.h", |
|||
"libgen.h", |
|||
"limits", |
|||
"limits.h", |
|||
"list", |
|||
"locale", |
|||
"locale.h", |
|||
"map", |
|||
"math.h", |
|||
"memory", |
|||
"memory_resource", |
|||
"monetary.h", |
|||
"mqueue.h", |
|||
"mutex", |
|||
"ndbm.h", |
|||
"net/if.h", |
|||
"netdb.h", |
|||
"netinet/in.h", |
|||
"netinet/tcp.h", |
|||
"new", |
|||
"nl_types.h", |
|||
"numeric", |
|||
"std::optional", |
|||
"ostream", |
|||
"poll.h", |
|||
"pthread.h", |
|||
"pwd.h", |
|||
"queue", |
|||
"random", |
|||
"ratio", |
|||
"regex", |
|||
"regex.h", |
|||
"sched.h", |
|||
"scoped_allocator", |
|||
"search.h", |
|||
"semaphore.h", |
|||
"set", |
|||
"setjmp.h", |
|||
"shared_mutex", |
|||
"signal.h", |
|||
"spawn.h", |
|||
"sstream", |
|||
"stack", |
|||
"stdalign.h", |
|||
"stdarg.h", |
|||
"stdatomic.h", |
|||
"stdbool.h", |
|||
"stddef.h", |
|||
"stdexcept", |
|||
"stdint.h", |
|||
"stdio.h", |
|||
"stdlib.h", |
|||
"stdnoreturn.h", |
|||
"streambuf", |
|||
"string", |
|||
"string.h", |
|||
"string_view", |
|||
"strings.h", |
|||
"stropts.h", |
|||
"strstream", |
|||
"sys/ipc.h", |
|||
"sys/mman.h", |
|||
"sys/msg.h", |
|||
"sys/resource.h", |
|||
"sys/select.h", |
|||
"sys/sem.h", |
|||
"sys/shm.h", |
|||
"sys/socket.h", |
|||
"sys/stat.h", |
|||
"sys/statvfs.h", |
|||
"sys/time.h", |
|||
"sys/times.h", |
|||
"sys/types.h", |
|||
"sys/uio.h", |
|||
"sys/un.h", |
|||
"sys/utsname.h", |
|||
"sys/wait.h", |
|||
"syslog.h", |
|||
"system_error", |
|||
"tar.h", |
|||
"term.h", |
|||
"termios.h", |
|||
"tgmath.h", |
|||
"thread", |
|||
"threads.h", |
|||
"time.h", |
|||
"trace.h", |
|||
"tuple", |
|||
"type_traits", |
|||
"typeindex", |
|||
"typeinfo", |
|||
"uchar.h", |
|||
"ulimit.h", |
|||
"uncntrl.h", |
|||
"unistd.h", |
|||
"unordered_map", |
|||
"unordered_set", |
|||
"utility", |
|||
"utime.h", |
|||
"utmpx.h", |
|||
"valarray", |
|||
"variant", |
|||
"vector", |
|||
"wchar.h", |
|||
"wctype.h", |
|||
"wordexp.h", |
|||
}; |
@ -1,4 +0,0 @@ |
|||
#pragma once |
|||
|
|||
// A set of standard libary header names, ie, "vector".
|
|||
extern const char* kStandardLibraryIncludes[177]; |
@ -1,27 +0,0 @@ |
|||
#include "timestamp_manager.h" |
|||
|
|||
#include "cache_manager.h" |
|||
#include "indexer.h" |
|||
|
|||
std::optional<int64_t> TimestampManager::GetLastCachedModificationTime( |
|||
ICacheManager* cache_manager, |
|||
const std::string& path) { |
|||
{ |
|||
std::lock_guard<std::mutex> guard(mutex_); |
|||
auto it = timestamps_.find(path); |
|||
if (it != timestamps_.end()) |
|||
return it->second; |
|||
} |
|||
IndexFile* file = cache_manager->TryLoad(path); |
|||
if (!file) |
|||
return std::nullopt; |
|||
|
|||
UpdateCachedModificationTime(path, file->last_modification_time); |
|||
return file->last_modification_time; |
|||
} |
|||
|
|||
void TimestampManager::UpdateCachedModificationTime(const std::string& path, |
|||
int64_t timestamp) { |
|||
std::lock_guard<std::mutex> guard(mutex_); |
|||
timestamps_[path] = timestamp; |
|||
} |
@ -1,22 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include <optional> |
|||
|
|||
#include <mutex> |
|||
#include <unordered_map> |
|||
|
|||
struct ICacheManager; |
|||
|
|||
// Caches timestamps of cc files so we can avoid a filesystem reads. This is
|
|||
// important for import perf, as during dependency checking the same files are
|
|||
// checked over and over again if they are common headers.
|
|||
struct TimestampManager { |
|||
std::optional<int64_t> GetLastCachedModificationTime(ICacheManager* cache_manager, |
|||
const std::string& path); |
|||
|
|||
void UpdateCachedModificationTime(const std::string& path, int64_t timestamp); |
|||
|
|||
// TODO: use std::shared_mutex so we can have multiple readers.
|
|||
std::mutex mutex_; |
|||
std::unordered_map<std::string, int64_t> timestamps_; |
|||
}; |
Loading…
Reference in new issue