mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
Renames and fix some operator < implementations
This commit is contained in:
parent
61aaf4509c
commit
ff421723a5
10
src/cache.cc
10
src/cache.cc
@ -20,7 +20,7 @@ std::string GetCachedBaseFileName(const std::string& cache_directory,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::unique_ptr<IndexedFile> LoadCachedIndex(IndexerConfig* config,
|
std::unique_ptr<IndexFile> LoadCachedIndex(IndexerConfig* config,
|
||||||
const std::string& filename) {
|
const std::string& filename) {
|
||||||
if (!config->enableCacheRead)
|
if (!config->enableCacheRead)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -30,9 +30,9 @@ std::unique_ptr<IndexedFile> LoadCachedIndex(IndexerConfig* config,
|
|||||||
if (!file_content)
|
if (!file_content)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
optional<IndexedFile> indexed = Deserialize(filename, *file_content);
|
optional<IndexFile> indexed = Deserialize(filename, *file_content);
|
||||||
if (indexed && indexed->version == IndexedFile::kCurrentVersion)
|
if (indexed && indexed->version == IndexFile::kCurrentVersion)
|
||||||
return MakeUnique<IndexedFile>(indexed.value());
|
return MakeUnique<IndexFile>(indexed.value());
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ optional<std::string> LoadCachedFileContents(IndexerConfig* config,
|
|||||||
|
|
||||||
void WriteToCache(IndexerConfig* config,
|
void WriteToCache(IndexerConfig* config,
|
||||||
const std::string& filename,
|
const std::string& filename,
|
||||||
IndexedFile& file) {
|
IndexFile& file) {
|
||||||
if (!config->enableCacheWrite)
|
if (!config->enableCacheWrite)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ using std::experimental::optional;
|
|||||||
using std::experimental::nullopt;
|
using std::experimental::nullopt;
|
||||||
|
|
||||||
struct IndexerConfig;
|
struct IndexerConfig;
|
||||||
struct IndexedFile;
|
struct IndexFile;
|
||||||
|
|
||||||
std::unique_ptr<IndexedFile> LoadCachedIndex(IndexerConfig* config,
|
std::unique_ptr<IndexFile> LoadCachedIndex(IndexerConfig* config,
|
||||||
const std::string& filename);
|
const std::string& filename);
|
||||||
|
|
||||||
optional<std::string> LoadCachedFileContents(IndexerConfig* config,
|
optional<std::string> LoadCachedFileContents(IndexerConfig* config,
|
||||||
@ -18,4 +18,4 @@ optional<std::string> LoadCachedFileContents(IndexerConfig* config,
|
|||||||
|
|
||||||
void WriteToCache(IndexerConfig* config,
|
void WriteToCache(IndexerConfig* config,
|
||||||
const std::string& filename,
|
const std::string& filename,
|
||||||
IndexedFile& file);
|
IndexFile& file);
|
@ -772,21 +772,21 @@ struct Index_DoIndex {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Index_DoIdMap {
|
struct Index_DoIdMap {
|
||||||
std::unique_ptr<IndexedFile> previous;
|
std::unique_ptr<IndexFile> previous;
|
||||||
std::unique_ptr<IndexedFile> current;
|
std::unique_ptr<IndexFile> current;
|
||||||
|
|
||||||
explicit Index_DoIdMap(std::unique_ptr<IndexedFile> current)
|
explicit Index_DoIdMap(std::unique_ptr<IndexFile> current)
|
||||||
: current(std::move(current)) {}
|
: current(std::move(current)) {}
|
||||||
|
|
||||||
explicit Index_DoIdMap(std::unique_ptr<IndexedFile> previous,
|
explicit Index_DoIdMap(std::unique_ptr<IndexFile> previous,
|
||||||
std::unique_ptr<IndexedFile> current)
|
std::unique_ptr<IndexFile> current)
|
||||||
: previous(std::move(previous)),
|
: previous(std::move(previous)),
|
||||||
current(std::move(current)) {}
|
current(std::move(current)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Index_OnIdMapped {
|
struct Index_OnIdMapped {
|
||||||
std::unique_ptr<IndexedFile> previous_index;
|
std::unique_ptr<IndexFile> previous_index;
|
||||||
std::unique_ptr<IndexedFile> current_index;
|
std::unique_ptr<IndexFile> current_index;
|
||||||
std::unique_ptr<IdMap> previous_id_map;
|
std::unique_ptr<IdMap> previous_id_map;
|
||||||
std::unique_ptr<IdMap> current_id_map;
|
std::unique_ptr<IdMap> current_id_map;
|
||||||
};
|
};
|
||||||
@ -942,7 +942,7 @@ bool ImportCachedIndex(IndexerConfig* config,
|
|||||||
|
|
||||||
Timer time;
|
Timer time;
|
||||||
|
|
||||||
std::unique_ptr<IndexedFile> cache = LoadCachedIndex(config, tu_path);
|
std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, tu_path);
|
||||||
time.ResetAndPrint("Reading cached index from disk " + tu_path);
|
time.ResetAndPrint("Reading cached index from disk " + tu_path);
|
||||||
if (!cache)
|
if (!cache)
|
||||||
return true;
|
return true;
|
||||||
@ -952,7 +952,7 @@ bool ImportCachedIndex(IndexerConfig* config,
|
|||||||
// Import all dependencies.
|
// Import all dependencies.
|
||||||
for (auto& dependency_path : cache->dependencies) {
|
for (auto& dependency_path : cache->dependencies) {
|
||||||
std::cerr << "- Got dependency " << dependency_path << std::endl;
|
std::cerr << "- Got dependency " << dependency_path << std::endl;
|
||||||
std::unique_ptr<IndexedFile> cache = LoadCachedIndex(config, dependency_path);
|
std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, dependency_path);
|
||||||
if (cache && GetLastModificationTime(cache->path) == cache->last_modification_time)
|
if (cache && GetLastModificationTime(cache->path) == cache->last_modification_time)
|
||||||
file_consumer_shared->Mark(cache->path);
|
file_consumer_shared->Mark(cache->path);
|
||||||
else
|
else
|
||||||
@ -977,21 +977,21 @@ void ParseFile(IndexerConfig* config,
|
|||||||
const Project::Entry& entry) {
|
const Project::Entry& entry) {
|
||||||
Timer time;
|
Timer time;
|
||||||
|
|
||||||
std::unique_ptr<IndexedFile> cache_for_args = LoadCachedIndex(config, entry.filename);
|
std::unique_ptr<IndexFile> cache_for_args = LoadCachedIndex(config, entry.filename);
|
||||||
|
|
||||||
std::string tu_path = cache_for_args ? cache_for_args->import_file : entry.filename;
|
std::string tu_path = cache_for_args ? cache_for_args->import_file : entry.filename;
|
||||||
const std::vector<std::string>& tu_args = entry.args;
|
const std::vector<std::string>& tu_args = entry.args;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<IndexedFile>> indexes = Parse(
|
std::vector<std::unique_ptr<IndexFile>> indexes = Parse(
|
||||||
config, file_consumer_shared,
|
config, file_consumer_shared,
|
||||||
tu_path, tu_args);
|
tu_path, tu_args);
|
||||||
time.ResetAndPrint("Parsing/indexing " + tu_path);
|
time.ResetAndPrint("Parsing/indexing " + tu_path);
|
||||||
|
|
||||||
for (std::unique_ptr<IndexedFile>& new_index : indexes) {
|
for (std::unique_ptr<IndexFile>& new_index : indexes) {
|
||||||
std::cerr << "Got index for " << new_index->path << std::endl;
|
std::cerr << "Got index for " << new_index->path << std::endl;
|
||||||
|
|
||||||
// Load the cached index.
|
// Load the cached index.
|
||||||
std::unique_ptr<IndexedFile> cached_index;
|
std::unique_ptr<IndexFile> cached_index;
|
||||||
if (cache_for_args && new_index->path == cache_for_args->path)
|
if (cache_for_args && new_index->path == cache_for_args->path)
|
||||||
cached_index = std::move(cache_for_args);
|
cached_index = std::move(cache_for_args);
|
||||||
else
|
else
|
||||||
@ -1037,7 +1037,7 @@ bool ResetStaleFiles(IndexerConfig* config,
|
|||||||
const std::string& tu_path) {
|
const std::string& tu_path) {
|
||||||
Timer time;
|
Timer time;
|
||||||
|
|
||||||
std::unique_ptr<IndexedFile> cache = LoadCachedIndex(config, tu_path);
|
std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, tu_path);
|
||||||
time.ResetAndPrint("Reading cached index from disk " + tu_path);
|
time.ResetAndPrint("Reading cached index from disk " + tu_path);
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
std::cerr << "[indexer] Unable to load existing index from file when freshening (dependences will not be freshened)" << std::endl;
|
std::cerr << "[indexer] Unable to load existing index from file when freshening (dependences will not be freshened)" << std::endl;
|
||||||
@ -1050,7 +1050,7 @@ bool ResetStaleFiles(IndexerConfig* config,
|
|||||||
// Check dependencies
|
// Check dependencies
|
||||||
for (auto& dependency_path : cache->dependencies) {
|
for (auto& dependency_path : cache->dependencies) {
|
||||||
std::cerr << "- Got dependency " << dependency_path << std::endl;
|
std::cerr << "- Got dependency " << dependency_path << std::endl;
|
||||||
std::unique_ptr<IndexedFile> cache = LoadCachedIndex(config, dependency_path);
|
std::unique_ptr<IndexFile> cache = LoadCachedIndex(config, dependency_path);
|
||||||
if (GetLastModificationTime(cache->path) != cache->last_modification_time) {
|
if (GetLastModificationTime(cache->path) != cache->last_modification_time) {
|
||||||
needs_reparse = true;
|
needs_reparse = true;
|
||||||
file_consumer_shared->Reset(cache->path);
|
file_consumer_shared->Reset(cache->path);
|
||||||
|
@ -32,7 +32,7 @@ void FileConsumer::SharedState::Reset(const std::string& file) {
|
|||||||
|
|
||||||
FileConsumer::FileConsumer(SharedState* shared_state) : shared_(shared_state) {}
|
FileConsumer::FileConsumer(SharedState* shared_state) : shared_(shared_state) {}
|
||||||
|
|
||||||
IndexedFile* FileConsumer::TryConsumeFile(CXFile file, bool* is_first_ownership) {
|
IndexFile* FileConsumer::TryConsumeFile(CXFile file, bool* is_first_ownership) {
|
||||||
assert(is_first_ownership);
|
assert(is_first_ownership);
|
||||||
|
|
||||||
CXFileUniqueID file_id;
|
CXFileUniqueID file_id;
|
||||||
@ -53,16 +53,16 @@ IndexedFile* FileConsumer::TryConsumeFile(CXFile file, bool* is_first_ownership)
|
|||||||
// No result in local; we need to query global.
|
// No result in local; we need to query global.
|
||||||
bool did_insert = shared_->Mark(file_name);
|
bool did_insert = shared_->Mark(file_name);
|
||||||
*is_first_ownership = did_insert;
|
*is_first_ownership = did_insert;
|
||||||
local_[file_id] = did_insert ? MakeUnique<IndexedFile>(file_name) : nullptr;
|
local_[file_id] = did_insert ? MakeUnique<IndexFile>(file_name) : nullptr;
|
||||||
return local_[file_id].get();
|
return local_[file_id].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexedFile* FileConsumer::ForceLocal(CXFile file) {
|
IndexFile* FileConsumer::ForceLocal(CXFile file) {
|
||||||
// Try to fetch the file using the normal system, which will insert the file
|
// Try to fetch the file using the normal system, which will insert the file
|
||||||
// usage into global storage.
|
// usage into global storage.
|
||||||
{
|
{
|
||||||
bool is_first;
|
bool is_first;
|
||||||
IndexedFile* cache = TryConsumeFile(file, &is_first);
|
IndexFile* cache = TryConsumeFile(file, &is_first);
|
||||||
if (cache)
|
if (cache)
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
@ -76,13 +76,13 @@ IndexedFile* FileConsumer::ForceLocal(CXFile file) {
|
|||||||
|
|
||||||
auto it = local_.find(file_id);
|
auto it = local_.find(file_id);
|
||||||
if (it == local_.end() || !it->second)
|
if (it == local_.end() || !it->second)
|
||||||
local_[file_id] = MakeUnique<IndexedFile>(FileName(file));
|
local_[file_id] = MakeUnique<IndexFile>(FileName(file));
|
||||||
assert(local_.find(file_id) != local_.end());
|
assert(local_.find(file_id) != local_.end());
|
||||||
return local_[file_id].get();
|
return local_[file_id].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<IndexedFile>> FileConsumer::TakeLocalState() {
|
std::vector<std::unique_ptr<IndexFile>> FileConsumer::TakeLocalState() {
|
||||||
std::vector<std::unique_ptr<IndexedFile>> result;
|
std::vector<std::unique_ptr<IndexFile>> result;
|
||||||
for (auto& entry : local_) {
|
for (auto& entry : local_) {
|
||||||
if (entry.second)
|
if (entry.second)
|
||||||
result.push_back(std::move(entry.second));
|
result.push_back(std::move(entry.second));
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
struct IndexedFile;
|
struct IndexFile;
|
||||||
|
|
||||||
// Needed for unordered_map usage below.
|
// Needed for unordered_map usage below.
|
||||||
MAKE_HASHABLE(CXFileUniqueID, t.data[0], t.data[1], t.data[2]);
|
MAKE_HASHABLE(CXFileUniqueID, t.data[0], t.data[1], t.data[2]);
|
||||||
@ -38,18 +38,18 @@ struct FileConsumer {
|
|||||||
// Returns true if this instance owns given |file|. This will also attempt to
|
// Returns true if this instance owns given |file|. This will also attempt to
|
||||||
// take ownership over |file|.
|
// take ownership over |file|.
|
||||||
//
|
//
|
||||||
// Returns IndexedFile for the file or nullptr. |is_first_ownership| is set
|
// Returns IndexFile for the file or nullptr. |is_first_ownership| is set
|
||||||
// to true iff the function just took ownership over the file. Otherwise it
|
// to true iff the function just took ownership over the file. Otherwise it
|
||||||
// is set to false.
|
// is set to false.
|
||||||
IndexedFile* TryConsumeFile(CXFile file, bool* is_first_ownership);
|
IndexFile* TryConsumeFile(CXFile file, bool* is_first_ownership);
|
||||||
|
|
||||||
// Forcibly create a local file, even if it has already been parsed.
|
// Forcibly create a local file, even if it has already been parsed.
|
||||||
IndexedFile* ForceLocal(CXFile file);
|
IndexFile* ForceLocal(CXFile file);
|
||||||
|
|
||||||
// Returns and passes ownership of all local state.
|
// Returns and passes ownership of all local state.
|
||||||
std::vector<std::unique_ptr<IndexedFile>> TakeLocalState();
|
std::vector<std::unique_ptr<IndexFile>> TakeLocalState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<CXFileUniqueID, std::unique_ptr<IndexedFile>> local_;
|
std::unordered_map<CXFileUniqueID, std::unique_ptr<IndexFile>> local_;
|
||||||
SharedState* shared_;
|
SharedState* shared_;
|
||||||
};
|
};
|
@ -48,79 +48,79 @@ Range ResolveExtent(const CXCursor& cx_cursor) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
IndexedFile::IndexedFile(const std::string& path) : id_cache(path), path(path) {
|
IndexFile::IndexFile(const std::string& path) : id_cache(path), path(path) {
|
||||||
// TODO: Reconsider if we should still be reusing the same id_cache.
|
// TODO: Reconsider if we should still be reusing the same id_cache.
|
||||||
// Preallocate any existing resolved ids.
|
// Preallocate any existing resolved ids.
|
||||||
for (const auto& entry : id_cache.usr_to_type_id)
|
for (const auto& entry : id_cache.usr_to_type_id)
|
||||||
types.push_back(IndexedTypeDef(entry.second, entry.first));
|
types.push_back(IndexType(entry.second, entry.first));
|
||||||
for (const auto& entry : id_cache.usr_to_func_id)
|
for (const auto& entry : id_cache.usr_to_func_id)
|
||||||
funcs.push_back(IndexedFuncDef(entry.second, entry.first));
|
funcs.push_back(IndexFunc(entry.second, entry.first));
|
||||||
for (const auto& entry : id_cache.usr_to_var_id)
|
for (const auto& entry : id_cache.usr_to_var_id)
|
||||||
vars.push_back(IndexedVarDef(entry.second, entry.first));
|
vars.push_back(IndexVar(entry.second, entry.first));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize for const char*?
|
// TODO: Optimize for const char*?
|
||||||
IndexTypeId IndexedFile::ToTypeId(const std::string& usr) {
|
IndexTypeId IndexFile::ToTypeId(const std::string& usr) {
|
||||||
auto it = id_cache.usr_to_type_id.find(usr);
|
auto it = id_cache.usr_to_type_id.find(usr);
|
||||||
if (it != id_cache.usr_to_type_id.end())
|
if (it != id_cache.usr_to_type_id.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
||||||
IndexTypeId id(types.size());
|
IndexTypeId id(types.size());
|
||||||
types.push_back(IndexedTypeDef(id, usr));
|
types.push_back(IndexType(id, usr));
|
||||||
id_cache.usr_to_type_id[usr] = id;
|
id_cache.usr_to_type_id[usr] = id;
|
||||||
id_cache.type_id_to_usr[id] = usr;
|
id_cache.type_id_to_usr[id] = usr;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
IndexFuncId IndexedFile::ToFuncId(const std::string& usr) {
|
IndexFuncId IndexFile::ToFuncId(const std::string& usr) {
|
||||||
auto it = id_cache.usr_to_func_id.find(usr);
|
auto it = id_cache.usr_to_func_id.find(usr);
|
||||||
if (it != id_cache.usr_to_func_id.end())
|
if (it != id_cache.usr_to_func_id.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
||||||
IndexFuncId id(funcs.size());
|
IndexFuncId id(funcs.size());
|
||||||
funcs.push_back(IndexedFuncDef(id, usr));
|
funcs.push_back(IndexFunc(id, usr));
|
||||||
id_cache.usr_to_func_id[usr] = id;
|
id_cache.usr_to_func_id[usr] = id;
|
||||||
id_cache.func_id_to_usr[id] = usr;
|
id_cache.func_id_to_usr[id] = usr;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
IndexVarId IndexedFile::ToVarId(const std::string& usr) {
|
IndexVarId IndexFile::ToVarId(const std::string& usr) {
|
||||||
auto it = id_cache.usr_to_var_id.find(usr);
|
auto it = id_cache.usr_to_var_id.find(usr);
|
||||||
if (it != id_cache.usr_to_var_id.end())
|
if (it != id_cache.usr_to_var_id.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
||||||
IndexVarId id(vars.size());
|
IndexVarId id(vars.size());
|
||||||
vars.push_back(IndexedVarDef(id, usr));
|
vars.push_back(IndexVar(id, usr));
|
||||||
id_cache.usr_to_var_id[usr] = id;
|
id_cache.usr_to_var_id[usr] = id;
|
||||||
id_cache.var_id_to_usr[id] = usr;
|
id_cache.var_id_to_usr[id] = usr;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexTypeId IndexedFile::ToTypeId(const CXCursor& cursor) {
|
IndexTypeId IndexFile::ToTypeId(const CXCursor& cursor) {
|
||||||
return ToTypeId(clang::Cursor(cursor).get_usr());
|
return ToTypeId(clang::Cursor(cursor).get_usr());
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexFuncId IndexedFile::ToFuncId(const CXCursor& cursor) {
|
IndexFuncId IndexFile::ToFuncId(const CXCursor& cursor) {
|
||||||
return ToFuncId(clang::Cursor(cursor).get_usr());
|
return ToFuncId(clang::Cursor(cursor).get_usr());
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexVarId IndexedFile::ToVarId(const CXCursor& cursor) {
|
IndexVarId IndexFile::ToVarId(const CXCursor& cursor) {
|
||||||
return ToVarId(clang::Cursor(cursor).get_usr());
|
return ToVarId(clang::Cursor(cursor).get_usr());
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexedTypeDef* IndexedFile::Resolve(IndexTypeId id) {
|
IndexType* IndexFile::Resolve(IndexTypeId id) {
|
||||||
return &types[id.id];
|
return &types[id.id];
|
||||||
}
|
}
|
||||||
IndexedFuncDef* IndexedFile::Resolve(IndexFuncId id) {
|
IndexFunc* IndexFile::Resolve(IndexFuncId id) {
|
||||||
return &funcs[id.id];
|
return &funcs[id.id];
|
||||||
}
|
}
|
||||||
IndexedVarDef* IndexedFile::Resolve(IndexVarId id) {
|
IndexVar* IndexFile::Resolve(IndexVarId id) {
|
||||||
return &vars[id.id];
|
return &vars[id.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IndexedFile::ToString() {
|
std::string IndexFile::ToString() {
|
||||||
return Serialize(*this);
|
return Serialize(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexedTypeDef::IndexedTypeDef(IndexTypeId id, const std::string& usr)
|
IndexType::IndexType(IndexTypeId id, const std::string& usr)
|
||||||
: def(usr), id(id) {
|
: def(usr), id(id) {
|
||||||
assert(usr.size() > 0);
|
assert(usr.size() > 0);
|
||||||
// std::cerr << "Creating type with usr " << usr << std::endl;
|
// std::cerr << "Creating type with usr " << usr << std::endl;
|
||||||
@ -195,12 +195,12 @@ struct NamespaceHelper {
|
|||||||
|
|
||||||
struct IndexParam {
|
struct IndexParam {
|
||||||
// Only use this when strictly needed (ie, primary translation unit is
|
// Only use this when strictly needed (ie, primary translation unit is
|
||||||
// needed). Most logic should get the IndexedFile instance via
|
// needed). Most logic should get the IndexFile instance via
|
||||||
// |file_consumer|.
|
// |file_consumer|.
|
||||||
//
|
//
|
||||||
// This can be null if we're not generating an index for the primary
|
// This can be null if we're not generating an index for the primary
|
||||||
// translation unit.
|
// translation unit.
|
||||||
IndexedFile* primary_file;
|
IndexFile* primary_file;
|
||||||
|
|
||||||
FileConsumer* file_consumer;
|
FileConsumer* file_consumer;
|
||||||
NamespaceHelper ns;
|
NamespaceHelper ns;
|
||||||
@ -231,7 +231,7 @@ void diagnostic(CXClientData client_data,
|
|||||||
unsigned int line, column;
|
unsigned int line, column;
|
||||||
clang_getSpellingLocation(diag_loc, &file, &line, &column, nullptr);
|
clang_getSpellingLocation(diag_loc, &file, &line, &column, nullptr);
|
||||||
bool is_first_time_visiting_file = false;
|
bool is_first_time_visiting_file = false;
|
||||||
IndexedFile* db = param->file_consumer->TryConsumeFile(file, &is_first_time_visiting_file);
|
IndexFile* db = param->file_consumer->TryConsumeFile(file, &is_first_time_visiting_file);
|
||||||
if (!db)
|
if (!db)
|
||||||
continue;
|
continue;
|
||||||
if (is_first_time_visiting_file && param->primary_file)
|
if (is_first_time_visiting_file && param->primary_file)
|
||||||
@ -380,18 +380,18 @@ bool IsTypeDefinition(const CXIdxContainerInfo* container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct VisitDeclForTypeUsageParam {
|
struct VisitDeclForTypeUsageParam {
|
||||||
IndexedFile* db;
|
IndexFile* db;
|
||||||
int has_processed_any = false;
|
int has_processed_any = false;
|
||||||
optional<clang::Cursor> previous_cursor;
|
optional<clang::Cursor> previous_cursor;
|
||||||
optional<IndexTypeId> initial_type;
|
optional<IndexTypeId> initial_type;
|
||||||
|
|
||||||
VisitDeclForTypeUsageParam(IndexedFile* db) : db(db) {}
|
VisitDeclForTypeUsageParam(IndexFile* db) : db(db) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void VisitDeclForTypeUsageVisitorHandler(clang::Cursor cursor,
|
void VisitDeclForTypeUsageVisitorHandler(clang::Cursor cursor,
|
||||||
VisitDeclForTypeUsageParam* param) {
|
VisitDeclForTypeUsageParam* param) {
|
||||||
param->has_processed_any = true;
|
param->has_processed_any = true;
|
||||||
IndexedFile* db = param->db;
|
IndexFile* db = param->db;
|
||||||
|
|
||||||
std::string referenced_usr =
|
std::string referenced_usr =
|
||||||
cursor.get_referenced()
|
cursor.get_referenced()
|
||||||
@ -406,7 +406,7 @@ void VisitDeclForTypeUsageVisitorHandler(clang::Cursor cursor,
|
|||||||
if (!param->initial_type)
|
if (!param->initial_type)
|
||||||
param->initial_type = ref_type_id;
|
param->initial_type = ref_type_id;
|
||||||
|
|
||||||
IndexedTypeDef* ref_type_def = db->Resolve(ref_type_id);
|
IndexType* ref_type_def = db->Resolve(ref_type_id);
|
||||||
// TODO: Should we even be visiting this if the file is not from the main
|
// TODO: Should we even be visiting this if the file is not from the main
|
||||||
// def? Try adding assert on |loc| later.
|
// def? Try adding assert on |loc| later.
|
||||||
Range loc = ResolveSpelling(cursor.cx_cursor);
|
Range loc = ResolveSpelling(cursor.cx_cursor);
|
||||||
@ -451,7 +451,7 @@ clang::VisiterResult VisitDeclForTypeUsageVisitor(
|
|||||||
// strips
|
// strips
|
||||||
// qualifies from |cursor| (ie, Foo* => Foo) and removes template arguments
|
// qualifies from |cursor| (ie, Foo* => Foo) and removes template arguments
|
||||||
// (ie, Foo<A,B> => Foo<*,*>).
|
// (ie, Foo<A,B> => Foo<*,*>).
|
||||||
optional<IndexTypeId> ResolveToDeclarationType(IndexedFile* db,
|
optional<IndexTypeId> ResolveToDeclarationType(IndexFile* db,
|
||||||
clang::Cursor cursor) {
|
clang::Cursor cursor) {
|
||||||
clang::Cursor declaration =
|
clang::Cursor declaration =
|
||||||
cursor.get_type().strip_qualifiers().get_declaration();
|
cursor.get_type().strip_qualifiers().get_declaration();
|
||||||
@ -468,7 +468,7 @@ optional<IndexTypeId> ResolveToDeclarationType(IndexedFile* db,
|
|||||||
// trying to generally resolve a cursor to a type, use
|
// trying to generally resolve a cursor to a type, use
|
||||||
// ResolveToDeclarationType, which works in more scenarios.
|
// ResolveToDeclarationType, which works in more scenarios.
|
||||||
optional<IndexTypeId> AddDeclTypeUsages(
|
optional<IndexTypeId> AddDeclTypeUsages(
|
||||||
IndexedFile* db,
|
IndexFile* db,
|
||||||
clang::Cursor decl_cursor,
|
clang::Cursor decl_cursor,
|
||||||
const CXIdxContainerInfo* semantic_container,
|
const CXIdxContainerInfo* semantic_container,
|
||||||
const CXIdxContainerInfo* lexical_container) {
|
const CXIdxContainerInfo* lexical_container) {
|
||||||
@ -604,7 +604,7 @@ optional<IndexTypeId> AddDeclTypeUsages(
|
|||||||
// for template arguments.
|
// for template arguments.
|
||||||
clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor,
|
clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor,
|
||||||
clang::Cursor parent,
|
clang::Cursor parent,
|
||||||
IndexedFile* db) {
|
IndexFile* db) {
|
||||||
/*
|
/*
|
||||||
We need to index the |DeclRefExpr| below (ie, |var| inside of
|
We need to index the |DeclRefExpr| below (ie, |var| inside of
|
||||||
Foo<int>::var).
|
Foo<int>::var).
|
||||||
@ -650,7 +650,7 @@ clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor,
|
|||||||
// std::cerr << "Adding usage to id=" << ref_id.id << " usr=" << ref_usr
|
// std::cerr << "Adding usage to id=" << ref_id.id << " usr=" << ref_usr
|
||||||
// << " at " << loc.ToString() << std::endl;
|
// << " at " << loc.ToString() << std::endl;
|
||||||
IndexVarId ref_id = db->ToVarId(ref_usr);
|
IndexVarId ref_id = db->ToVarId(ref_usr);
|
||||||
IndexedVarDef* ref_def = db->Resolve(ref_id);
|
IndexVar* ref_def = db->Resolve(ref_id);
|
||||||
UniqueAdd(ref_def->uses, loc);
|
UniqueAdd(ref_def->uses, loc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -658,7 +658,7 @@ clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor,
|
|||||||
return clang::VisiterResult::Recurse;
|
return clang::VisiterResult::Recurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddDeclInitializerUsages(IndexedFile* db, clang::Cursor decl_cursor) {
|
void AddDeclInitializerUsages(IndexFile* db, clang::Cursor decl_cursor) {
|
||||||
decl_cursor.VisitChildren(&AddDeclInitializerUsagesVisitor, db);
|
decl_cursor.VisitChildren(&AddDeclInitializerUsagesVisitor, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,7 +738,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(decl->loc), &file, nullptr, nullptr, nullptr);
|
clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(decl->loc), &file, nullptr, nullptr, nullptr);
|
||||||
IndexParam* param = static_cast<IndexParam*>(client_data);
|
IndexParam* param = static_cast<IndexParam*>(client_data);
|
||||||
bool is_first_time_visiting_file = false;
|
bool is_first_time_visiting_file = false;
|
||||||
IndexedFile* db = param->file_consumer->TryConsumeFile(file, &is_first_time_visiting_file);
|
IndexFile* db = param->file_consumer->TryConsumeFile(file, &is_first_time_visiting_file);
|
||||||
if (!db)
|
if (!db)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -773,7 +773,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
std::string decl_usr = decl_cursor.get_usr();
|
std::string decl_usr = decl_cursor.get_usr();
|
||||||
|
|
||||||
IndexVarId var_id = db->ToVarId(decl->entityInfo->USR);
|
IndexVarId var_id = db->ToVarId(decl->entityInfo->USR);
|
||||||
IndexedVarDef* var_def = db->Resolve(var_id);
|
IndexVar* var_def = db->Resolve(var_id);
|
||||||
|
|
||||||
// TODO: Eventually run with this if. Right now I want to iron out bugs
|
// TODO: Eventually run with this if. Right now I want to iron out bugs
|
||||||
// this may shadow.
|
// this may shadow.
|
||||||
@ -827,7 +827,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
if (decl->isDefinition && IsTypeDefinition(decl->semanticContainer)) {
|
if (decl->isDefinition && IsTypeDefinition(decl->semanticContainer)) {
|
||||||
IndexTypeId declaring_type_id =
|
IndexTypeId declaring_type_id =
|
||||||
db->ToTypeId(decl->semanticContainer->cursor);
|
db->ToTypeId(decl->semanticContainer->cursor);
|
||||||
IndexedTypeDef* declaring_type_def = db->Resolve(declaring_type_id);
|
IndexType* declaring_type_def = db->Resolve(declaring_type_id);
|
||||||
var_def->def.declaring_type = declaring_type_id;
|
var_def->def.declaring_type = declaring_type_id;
|
||||||
declaring_type_def->def.vars.push_back(var_id);
|
declaring_type_def->def.vars.push_back(var_id);
|
||||||
}
|
}
|
||||||
@ -848,7 +848,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
decl_cursor.template_specialization_to_template_definition();
|
decl_cursor.template_specialization_to_template_definition();
|
||||||
|
|
||||||
IndexFuncId func_id = db->ToFuncId(resolved.cx_cursor);
|
IndexFuncId func_id = db->ToFuncId(resolved.cx_cursor);
|
||||||
IndexedFuncDef* func_def = db->Resolve(func_id);
|
IndexFunc* func_def = db->Resolve(func_id);
|
||||||
|
|
||||||
// We don't actually need to know the return type, but we need to mark it
|
// We don't actually need to know the return type, but we need to mark it
|
||||||
// as an interesting usage.
|
// as an interesting usage.
|
||||||
@ -908,7 +908,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
if (IsTypeDefinition(decl->semanticContainer)) {
|
if (IsTypeDefinition(decl->semanticContainer)) {
|
||||||
IndexTypeId declaring_type_id =
|
IndexTypeId declaring_type_id =
|
||||||
db->ToTypeId(decl->semanticContainer->cursor);
|
db->ToTypeId(decl->semanticContainer->cursor);
|
||||||
IndexedTypeDef* declaring_type_def = db->Resolve(declaring_type_id);
|
IndexType* declaring_type_def = db->Resolve(declaring_type_id);
|
||||||
func_def->def.declaring_type = declaring_type_id;
|
func_def->def.declaring_type = declaring_type_id;
|
||||||
|
|
||||||
// Mark a type reference at the ctor/dtor location.
|
// Mark a type reference at the ctor/dtor location.
|
||||||
@ -972,7 +972,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
for (unsigned int i = 0; i < num_overridden; ++i) {
|
for (unsigned int i = 0; i < num_overridden; ++i) {
|
||||||
clang::Cursor parent = overridden[i];
|
clang::Cursor parent = overridden[i];
|
||||||
IndexFuncId parent_id = db->ToFuncId(parent.get_usr());
|
IndexFuncId parent_id = db->ToFuncId(parent.get_usr());
|
||||||
IndexedFuncDef* parent_def = db->Resolve(parent_id);
|
IndexFunc* parent_def = db->Resolve(parent_id);
|
||||||
func_def = db->Resolve(func_id); // ToFuncId invalidated func_def
|
func_def = db->Resolve(func_id); // ToFuncId invalidated func_def
|
||||||
|
|
||||||
func_def->def.base = parent_id;
|
func_def->def.base = parent_id;
|
||||||
@ -1007,7 +1007,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
decl->semanticContainer, decl->lexicalContainer);
|
decl->semanticContainer, decl->lexicalContainer);
|
||||||
|
|
||||||
IndexTypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
IndexTypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
||||||
IndexedTypeDef* type_def = db->Resolve(type_id);
|
IndexType* type_def = db->Resolve(type_id);
|
||||||
|
|
||||||
if (alias_of)
|
if (alias_of)
|
||||||
type_def->def.alias_of = alias_of.value();
|
type_def->def.alias_of = alias_of.value();
|
||||||
@ -1029,7 +1029,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
Range decl_loc_spelling = ResolveSpelling(decl->cursor);
|
Range decl_loc_spelling = ResolveSpelling(decl->cursor);
|
||||||
|
|
||||||
IndexTypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
IndexTypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
||||||
IndexedTypeDef* type_def = db->Resolve(type_id);
|
IndexType* type_def = db->Resolve(type_id);
|
||||||
|
|
||||||
// TODO: Eventually run with this if. Right now I want to iron out bugs
|
// TODO: Eventually run with this if. Right now I want to iron out bugs
|
||||||
// this may shadow.
|
// this may shadow.
|
||||||
@ -1075,9 +1075,9 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
optional<IndexTypeId> parent_type_id =
|
optional<IndexTypeId> parent_type_id =
|
||||||
ResolveToDeclarationType(db, base_class->cursor);
|
ResolveToDeclarationType(db, base_class->cursor);
|
||||||
// type_def ptr could be invalidated by ResolveToDeclarationType.
|
// type_def ptr could be invalidated by ResolveToDeclarationType.
|
||||||
IndexedTypeDef* type_def = db->Resolve(type_id);
|
IndexType* type_def = db->Resolve(type_id);
|
||||||
if (parent_type_id) {
|
if (parent_type_id) {
|
||||||
IndexedTypeDef* parent_type_def =
|
IndexType* parent_type_def =
|
||||||
db->Resolve(parent_type_id.value());
|
db->Resolve(parent_type_id.value());
|
||||||
parent_type_def->derived.push_back(type_id);
|
parent_type_def->derived.push_back(type_id);
|
||||||
type_def->def.parents.push_back(parent_type_id.value());
|
type_def->def.parents.push_back(parent_type_id.value());
|
||||||
@ -1196,7 +1196,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(ref->loc), &file, nullptr, nullptr, nullptr);
|
clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(ref->loc), &file, nullptr, nullptr, nullptr);
|
||||||
IndexParam* param = static_cast<IndexParam*>(client_data);
|
IndexParam* param = static_cast<IndexParam*>(client_data);
|
||||||
bool is_first_time_visiting_file = false;
|
bool is_first_time_visiting_file = false;
|
||||||
IndexedFile* db = param->file_consumer->TryConsumeFile(file, &is_first_time_visiting_file);
|
IndexFile* db = param->file_consumer->TryConsumeFile(file, &is_first_time_visiting_file);
|
||||||
if (!db)
|
if (!db)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1207,7 +1207,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
// ref->loc mainFile=1
|
// ref->loc mainFile=1
|
||||||
// ref->referencedEntity mainFile=1
|
// ref->referencedEntity mainFile=1
|
||||||
//
|
//
|
||||||
// Regardless, we need to do more advanced location processing to handle multiple output IndexedFile instances.
|
// Regardless, we need to do more advanced location processing to handle multiple output IndexFile instances.
|
||||||
//bool mainFile = clang_Location_isFromMainFile(clang_indexLoc_getCXSourceLocation(ref->loc));
|
//bool mainFile = clang_Location_isFromMainFile(clang_indexLoc_getCXSourceLocation(ref->loc));
|
||||||
//Range loc_spelling = param->db->id_cache.ForceResolveSpelling(ref->cursor, false /*interesting*/);
|
//Range loc_spelling = param->db->id_cache.ForceResolveSpelling(ref->cursor, false /*interesting*/);
|
||||||
//std::cerr << "mainFile: " << mainFile << ", loc: " << loc_spelling.ToString() << std::endl;
|
//std::cerr << "mainFile: " << mainFile << ", loc: " << loc_spelling.ToString() << std::endl;
|
||||||
@ -1240,7 +1240,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
referenced = referenced.template_specialization_to_template_definition();
|
referenced = referenced.template_specialization_to_template_definition();
|
||||||
|
|
||||||
IndexVarId var_id = db->ToVarId(referenced.get_usr());
|
IndexVarId var_id = db->ToVarId(referenced.get_usr());
|
||||||
IndexedVarDef* var_def = db->Resolve(var_id);
|
IndexVar* var_def = db->Resolve(var_id);
|
||||||
UniqueAdd(var_def->uses, loc_spelling);
|
UniqueAdd(var_def->uses, loc_spelling);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1267,13 +1267,13 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
IndexFuncId called_id = db->ToFuncId(ref->referencedEntity->USR);
|
IndexFuncId called_id = db->ToFuncId(ref->referencedEntity->USR);
|
||||||
if (IsFunctionCallContext(ref->container->cursor.kind)) {
|
if (IsFunctionCallContext(ref->container->cursor.kind)) {
|
||||||
IndexFuncId caller_id = db->ToFuncId(ref->container->cursor);
|
IndexFuncId caller_id = db->ToFuncId(ref->container->cursor);
|
||||||
IndexedFuncDef* caller_def = db->Resolve(caller_id);
|
IndexFunc* caller_def = db->Resolve(caller_id);
|
||||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
IndexFunc* called_def = db->Resolve(called_id);
|
||||||
|
|
||||||
AddFuncRef(&caller_def->def.callees, IndexFuncRef(called_id, loc_spelling));
|
AddFuncRef(&caller_def->def.callees, IndexFuncRef(called_id, loc_spelling));
|
||||||
AddFuncRef(&called_def->callers, IndexFuncRef(caller_id, loc_spelling));
|
AddFuncRef(&called_def->callers, IndexFuncRef(caller_id, loc_spelling));
|
||||||
} else {
|
} else {
|
||||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
IndexFunc* called_def = db->Resolve(called_id);
|
||||||
AddFuncRef(&called_def->callers, IndexFuncRef(loc_spelling));
|
AddFuncRef(&called_def->callers, IndexFuncRef(loc_spelling));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1292,7 +1292,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
referenced = referenced.template_specialization_to_template_definition();
|
referenced = referenced.template_specialization_to_template_definition();
|
||||||
IndexTypeId referenced_id = db->ToTypeId(referenced.get_usr());
|
IndexTypeId referenced_id = db->ToTypeId(referenced.get_usr());
|
||||||
|
|
||||||
IndexedTypeDef* referenced_def = db->Resolve(referenced_id);
|
IndexType* referenced_def = db->Resolve(referenced_id);
|
||||||
|
|
||||||
//
|
//
|
||||||
// The following will generate two TypeRefs to Foo, both located at the
|
// The following will generate two TypeRefs to Foo, both located at the
|
||||||
@ -1376,7 +1376,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<IndexedFile>> Parse(
|
std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||||
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
||||||
std::string file,
|
std::string file,
|
||||||
std::vector<std::string> args,
|
std::vector<std::string> args,
|
||||||
|
@ -21,9 +21,9 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct IndexedTypeDef;
|
struct IndexType;
|
||||||
struct IndexedFuncDef;
|
struct IndexFunc;
|
||||||
struct IndexedVarDef;
|
struct IndexVar;
|
||||||
|
|
||||||
using namespace std::experimental;
|
using namespace std::experimental;
|
||||||
|
|
||||||
@ -59,9 +59,9 @@ bool operator!=(const Id<T>& a, const Id<T>& b) {
|
|||||||
return !(a == b);
|
return !(a == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
using IndexTypeId = Id<IndexedTypeDef>;
|
using IndexTypeId = Id<IndexType>;
|
||||||
using IndexFuncId = Id<IndexedFuncDef>;
|
using IndexFuncId = Id<IndexFunc>;
|
||||||
using IndexVarId = Id<IndexedVarDef>;
|
using IndexVarId = Id<IndexVar>;
|
||||||
|
|
||||||
struct IdCache;
|
struct IdCache;
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ bool operator!=(const Ref<T>& a, const Ref<T>& b) {
|
|||||||
return !(a == b);
|
return !(a == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
using IndexFuncRef = Ref<IndexedFuncDef>;
|
using IndexFuncRef = Ref<IndexFunc>;
|
||||||
|
|
||||||
// TODO: skip as much forward-processing as possible when |is_system_def| is
|
// TODO: skip as much forward-processing as possible when |is_system_def| is
|
||||||
// set to false.
|
// set to false.
|
||||||
@ -196,7 +196,7 @@ void Reflect(TVisitor& visitor,
|
|||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IndexedTypeDef {
|
struct IndexType {
|
||||||
using Def = TypeDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
using Def = TypeDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
||||||
Def def;
|
Def def;
|
||||||
|
|
||||||
@ -212,9 +212,9 @@ struct IndexedTypeDef {
|
|||||||
// NOTE: Do not insert directly! Use AddUsage instead.
|
// NOTE: Do not insert directly! Use AddUsage instead.
|
||||||
std::vector<Range> uses;
|
std::vector<Range> uses;
|
||||||
|
|
||||||
IndexedTypeDef() : def("") {} // For serialization
|
IndexType() : def("") {} // For serialization
|
||||||
|
|
||||||
IndexedTypeDef(IndexTypeId id, const std::string& usr);
|
IndexType(IndexTypeId id, const std::string& usr);
|
||||||
|
|
||||||
bool HasInterestingState() const {
|
bool HasInterestingState() const {
|
||||||
return
|
return
|
||||||
@ -224,12 +224,12 @@ struct IndexedTypeDef {
|
|||||||
!uses.empty();
|
!uses.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const IndexedTypeDef& other) const {
|
bool operator<(const IndexType& other) const {
|
||||||
return def.usr < other.def.usr;
|
return def.usr < other.def.usr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MAKE_HASHABLE(IndexedTypeDef, t.def.usr);
|
MAKE_HASHABLE(IndexType, t.def.usr);
|
||||||
|
|
||||||
template <typename TypeId,
|
template <typename TypeId,
|
||||||
typename FuncId,
|
typename FuncId,
|
||||||
@ -311,7 +311,7 @@ void Reflect(
|
|||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IndexedFuncDef {
|
struct IndexFunc {
|
||||||
using Def = FuncDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, IndexFuncRef, Range>;
|
using Def = FuncDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, IndexFuncRef, Range>;
|
||||||
Def def;
|
Def def;
|
||||||
|
|
||||||
@ -330,8 +330,8 @@ struct IndexedFuncDef {
|
|||||||
// def.definition_spelling.
|
// def.definition_spelling.
|
||||||
std::vector<IndexFuncRef> callers;
|
std::vector<IndexFuncRef> callers;
|
||||||
|
|
||||||
IndexedFuncDef() {} // For reflection.
|
IndexFunc() {} // For reflection.
|
||||||
IndexedFuncDef(IndexFuncId id, const std::string& usr) : def(usr), id(id) {
|
IndexFunc(IndexFuncId id, const std::string& usr) : def(usr), id(id) {
|
||||||
// assert(usr.size() > 0);
|
// assert(usr.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,11 +344,11 @@ struct IndexedFuncDef {
|
|||||||
!callers.empty();
|
!callers.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const IndexedFuncDef& other) const {
|
bool operator<(const IndexFunc& other) const {
|
||||||
return def.usr < other.def.usr;
|
return def.usr < other.def.usr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MAKE_HASHABLE(IndexedFuncDef, t.def.usr);
|
MAKE_HASHABLE(IndexFunc, t.def.usr);
|
||||||
|
|
||||||
template <typename TypeId,
|
template <typename TypeId,
|
||||||
typename FuncId,
|
typename FuncId,
|
||||||
@ -418,7 +418,7 @@ void Reflect(TVisitor& visitor,
|
|||||||
REFLECT_MEMBER_END();
|
REFLECT_MEMBER_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IndexedVarDef {
|
struct IndexVar {
|
||||||
using Def = VarDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
using Def = VarDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
||||||
Def def;
|
Def def;
|
||||||
|
|
||||||
@ -427,9 +427,9 @@ struct IndexedVarDef {
|
|||||||
// Usages.
|
// Usages.
|
||||||
std::vector<Range> uses;
|
std::vector<Range> uses;
|
||||||
|
|
||||||
IndexedVarDef() : def("") {} // For serialization
|
IndexVar() : def("") {} // For serialization
|
||||||
|
|
||||||
IndexedVarDef(IndexVarId id, const std::string& usr) : def(usr), id(id) {
|
IndexVar(IndexVarId id, const std::string& usr) : def(usr), id(id) {
|
||||||
// assert(usr.size() > 0);
|
// assert(usr.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,11 +439,11 @@ struct IndexedVarDef {
|
|||||||
!uses.empty();
|
!uses.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const IndexedVarDef& other) const {
|
bool operator<(const IndexVar& other) const {
|
||||||
return def.usr < other.def.usr;
|
return def.usr < other.def.usr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MAKE_HASHABLE(IndexedVarDef, t.def.usr);
|
MAKE_HASHABLE(IndexVar, t.def.usr);
|
||||||
|
|
||||||
struct IdCache {
|
struct IdCache {
|
||||||
std::string primary_file;
|
std::string primary_file;
|
||||||
@ -457,7 +457,7 @@ struct IdCache {
|
|||||||
IdCache(const std::string& primary_file);
|
IdCache(const std::string& primary_file);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IndexedFile {
|
struct IndexFile {
|
||||||
IdCache id_cache;
|
IdCache id_cache;
|
||||||
|
|
||||||
static constexpr int kCurrentVersion = 2;
|
static constexpr int kCurrentVersion = 2;
|
||||||
@ -468,7 +468,7 @@ struct IndexedFile {
|
|||||||
int64_t last_modification_time = 0;
|
int64_t last_modification_time = 0;
|
||||||
|
|
||||||
// The path to the translation unit cc file which caused the creation of this
|
// The path to the translation unit cc file which caused the creation of this
|
||||||
// IndexedFile. When parsing a translation unit we generate many IndexedFile
|
// IndexFile. When parsing a translation unit we generate many IndexFile
|
||||||
// instances (ie, each header has a separate one). When the user edits a
|
// instances (ie, each header has a separate one). When the user edits a
|
||||||
// header we need to lookup the original translation unit and reindex that.
|
// header we need to lookup the original translation unit and reindex that.
|
||||||
std::string import_file;
|
std::string import_file;
|
||||||
@ -480,11 +480,11 @@ struct IndexedFile {
|
|||||||
NonElidedVector<lsDiagnostic> diagnostics;
|
NonElidedVector<lsDiagnostic> diagnostics;
|
||||||
|
|
||||||
std::vector<std::string> dependencies;
|
std::vector<std::string> dependencies;
|
||||||
std::vector<IndexedTypeDef> types;
|
std::vector<IndexType> types;
|
||||||
std::vector<IndexedFuncDef> funcs;
|
std::vector<IndexFunc> funcs;
|
||||||
std::vector<IndexedVarDef> vars;
|
std::vector<IndexVar> vars;
|
||||||
|
|
||||||
IndexedFile(const std::string& path);
|
IndexFile(const std::string& path);
|
||||||
|
|
||||||
IndexTypeId ToTypeId(const std::string& usr);
|
IndexTypeId ToTypeId(const std::string& usr);
|
||||||
IndexFuncId ToFuncId(const std::string& usr);
|
IndexFuncId ToFuncId(const std::string& usr);
|
||||||
@ -492,9 +492,9 @@ struct IndexedFile {
|
|||||||
IndexTypeId ToTypeId(const CXCursor& usr);
|
IndexTypeId ToTypeId(const CXCursor& usr);
|
||||||
IndexFuncId ToFuncId(const CXCursor& usr);
|
IndexFuncId ToFuncId(const CXCursor& usr);
|
||||||
IndexVarId ToVarId(const CXCursor& usr);
|
IndexVarId ToVarId(const CXCursor& usr);
|
||||||
IndexedTypeDef* Resolve(IndexTypeId id);
|
IndexType* Resolve(IndexTypeId id);
|
||||||
IndexedFuncDef* Resolve(IndexFuncId id);
|
IndexFunc* Resolve(IndexFuncId id);
|
||||||
IndexedVarDef* Resolve(IndexVarId id);
|
IndexVar* Resolve(IndexVarId id);
|
||||||
|
|
||||||
std::string ToString();
|
std::string ToString();
|
||||||
};
|
};
|
||||||
@ -502,7 +502,7 @@ struct IndexedFile {
|
|||||||
// |import_file| is the cc file which is what gets passed to clang.
|
// |import_file| is the cc file which is what gets passed to clang.
|
||||||
// |desired_index_file| is the (h or cc) file which has actually changed.
|
// |desired_index_file| is the (h or cc) file which has actually changed.
|
||||||
// |dependencies| are the existing dependencies of |import_file| if this is a reparse.
|
// |dependencies| are the existing dependencies of |import_file| if this is a reparse.
|
||||||
std::vector<std::unique_ptr<IndexedFile>> Parse(
|
std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||||
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared,
|
||||||
std::string file,
|
std::string file,
|
||||||
std::vector<std::string> args,
|
std::vector<std::string> args,
|
||||||
|
101
src/query.cc
101
src/query.cc
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QueryType::DefUpdate ToQuery(const IdMap& id_map, const IndexedTypeDef::Def& type) {
|
QueryType::DefUpdate ToQuery(const IdMap& id_map, const IndexType::Def& type) {
|
||||||
QueryType::DefUpdate result(type.usr);
|
QueryType::DefUpdate result(type.usr);
|
||||||
result.short_name = type.short_name;
|
result.short_name = type.short_name;
|
||||||
result.detailed_name = type.detailed_name;
|
result.detailed_name = type.detailed_name;
|
||||||
@ -31,7 +31,7 @@ QueryType::DefUpdate ToQuery(const IdMap& id_map, const IndexedTypeDef::Def& typ
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryFunc::DefUpdate ToQuery(const IdMap& id_map, const IndexedFuncDef::Def& func) {
|
QueryFunc::DefUpdate ToQuery(const IdMap& id_map, const IndexFunc::Def& func) {
|
||||||
QueryFunc::DefUpdate result(func.usr);
|
QueryFunc::DefUpdate result(func.usr);
|
||||||
result.short_name = func.short_name;
|
result.short_name = func.short_name;
|
||||||
result.detailed_name = func.detailed_name;
|
result.detailed_name = func.detailed_name;
|
||||||
@ -44,7 +44,7 @@ QueryFunc::DefUpdate ToQuery(const IdMap& id_map, const IndexedFuncDef::Def& fun
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryVar::DefUpdate ToQuery(const IdMap& id_map, const IndexedVarDef::Def& var) {
|
QueryVar::DefUpdate ToQuery(const IdMap& id_map, const IndexVar::Def& var) {
|
||||||
QueryVar::DefUpdate result(var.usr);
|
QueryVar::DefUpdate result(var.usr);
|
||||||
result.short_name = var.short_name;
|
result.short_name = var.short_name;
|
||||||
result.detailed_name = var.detailed_name;
|
result.detailed_name = var.detailed_name;
|
||||||
@ -159,7 +159,7 @@ void CompareGroups(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexedFile& indexed) {
|
QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) {
|
||||||
QueryFile::Def def;
|
QueryFile::Def def;
|
||||||
def.path = indexed.path;
|
def.path = indexed.path;
|
||||||
|
|
||||||
@ -170,33 +170,33 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexedFile& indexed) {
|
|||||||
def.all_symbols.push_back(SymbolRef(idx, id_map.ToQuery(range)));
|
def.all_symbols.push_back(SymbolRef(idx, id_map.ToQuery(range)));
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const IndexedTypeDef& def : indexed.types) {
|
for (const IndexType& type : indexed.types) {
|
||||||
if (def.def.definition_spelling.has_value())
|
if (type.def.definition_spelling.has_value())
|
||||||
add_all_symbols(id_map.ToSymbol(def.id), def.def.definition_spelling.value());
|
add_all_symbols(id_map.ToSymbol(type.id), type.def.definition_spelling.value());
|
||||||
if (def.def.definition_extent.has_value())
|
if (type.def.definition_extent.has_value())
|
||||||
add_outline(id_map.ToSymbol(def.id), def.def.definition_extent.value());
|
add_outline(id_map.ToSymbol(type.id), type.def.definition_extent.value());
|
||||||
for (const Range& use : def.uses)
|
for (const Range& use : type.uses)
|
||||||
add_all_symbols(id_map.ToSymbol(def.id), use);
|
add_all_symbols(id_map.ToSymbol(type.id), use);
|
||||||
}
|
}
|
||||||
for (const IndexedFuncDef& def : indexed.funcs) {
|
for (const IndexFunc& func : indexed.funcs) {
|
||||||
if (def.def.definition_spelling.has_value())
|
if (func.def.definition_spelling.has_value())
|
||||||
add_all_symbols(id_map.ToSymbol(def.id), def.def.definition_spelling.value());
|
add_all_symbols(id_map.ToSymbol(func.id), func.def.definition_spelling.value());
|
||||||
if (def.def.definition_extent.has_value())
|
if (func.def.definition_extent.has_value())
|
||||||
add_outline(id_map.ToSymbol(def.id), def.def.definition_extent.value());
|
add_outline(id_map.ToSymbol(func.id), func.def.definition_extent.value());
|
||||||
for (Range decl : def.declarations) {
|
for (Range decl : func.declarations) {
|
||||||
add_all_symbols(id_map.ToSymbol(def.id), decl);
|
add_all_symbols(id_map.ToSymbol(func.id), decl);
|
||||||
add_outline(id_map.ToSymbol(def.id), decl);
|
add_outline(id_map.ToSymbol(func.id), decl);
|
||||||
}
|
}
|
||||||
for (const IndexFuncRef& caller : def.callers)
|
for (const IndexFuncRef& caller : func.callers)
|
||||||
add_all_symbols(id_map.ToSymbol(def.id), caller.loc);
|
add_all_symbols(id_map.ToSymbol(func.id), caller.loc);
|
||||||
}
|
}
|
||||||
for (const IndexedVarDef& def : indexed.vars) {
|
for (const IndexVar& var : indexed.vars) {
|
||||||
if (def.def.definition_spelling.has_value())
|
if (var.def.definition_spelling.has_value())
|
||||||
add_all_symbols(id_map.ToSymbol(def.id), def.def.definition_spelling.value());
|
add_all_symbols(id_map.ToSymbol(var.id), var.def.definition_spelling.value());
|
||||||
if (def.def.definition_extent.has_value())
|
if (var.def.definition_extent.has_value())
|
||||||
add_outline(id_map.ToSymbol(def.id), def.def.definition_extent.value());
|
add_outline(id_map.ToSymbol(var.id), var.def.definition_extent.value());
|
||||||
for (const Range& use : def.uses)
|
for (const Range& use : var.uses)
|
||||||
add_all_symbols(id_map.ToSymbol(def.id), use);
|
add_all_symbols(id_map.ToSymbol(var.id), use);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(def.outline.begin(), def.outline.end(), [](const SymbolRef& a, const SymbolRef& b) {
|
std::sort(def.outline.begin(), def.outline.end(), [](const SymbolRef& a, const SymbolRef& b) {
|
||||||
@ -409,18 +409,18 @@ SymbolIdx IdMap::ToSymbol(IndexVarId id) const {
|
|||||||
// ----------------------
|
// ----------------------
|
||||||
|
|
||||||
// static
|
// static
|
||||||
IndexUpdate IndexUpdate::CreateDelta(const IdMap* previous_id_map, const IdMap* current_id_map, IndexedFile* previous, IndexedFile* current) {
|
IndexUpdate IndexUpdate::CreateDelta(const IdMap* previous_id_map, const IdMap* current_id_map, IndexFile* previous, IndexFile* current) {
|
||||||
// This function runs on an indexer thread.
|
// This function runs on an indexer thread.
|
||||||
|
|
||||||
if (!previous_id_map) {
|
if (!previous_id_map) {
|
||||||
assert(!previous);
|
assert(!previous);
|
||||||
IndexedFile previous(current->path);
|
IndexFile previous(current->path);
|
||||||
return IndexUpdate(*current_id_map, *current_id_map, previous, *current);
|
return IndexUpdate(*current_id_map, *current_id_map, previous, *current);
|
||||||
}
|
}
|
||||||
return IndexUpdate(*previous_id_map, *current_id_map, *previous, *current);
|
return IndexUpdate(*previous_id_map, *current_id_map, *previous, *current);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_map, IndexedFile& previous_file, IndexedFile& current_file) {
|
IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_map, IndexFile& previous_file, IndexFile& current_file) {
|
||||||
// This function runs on an indexer thread.
|
// This function runs on an indexer thread.
|
||||||
|
|
||||||
// |query_name| is the name of the variable on the query type.
|
// |query_name| is the name of the variable on the query type.
|
||||||
@ -444,11 +444,11 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
|
|||||||
files_def_update.push_back(BuildFileDef(current_id_map, current_file));
|
files_def_update.push_back(BuildFileDef(current_id_map, current_file));
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
CompareGroups<IndexedTypeDef>(previous_file.types, current_file.types,
|
CompareGroups<IndexType>(previous_file.types, current_file.types,
|
||||||
/*onRemoved:*/[this](IndexedTypeDef* def) {
|
/*onRemoved:*/[this](IndexType* def) {
|
||||||
types_removed.push_back(def->def.usr);
|
types_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_id_map](IndexedTypeDef* type) {
|
/*onAdded:*/[this, ¤t_id_map](IndexType* type) {
|
||||||
if (!type->def.detailed_name.empty())
|
if (!type->def.detailed_name.empty())
|
||||||
types_def_update.push_back(ToQuery(current_id_map, type->def));
|
types_def_update.push_back(ToQuery(current_id_map, type->def));
|
||||||
if (!type->derived.empty())
|
if (!type->derived.empty())
|
||||||
@ -458,7 +458,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
|
|||||||
if (!type->uses.empty())
|
if (!type->uses.empty())
|
||||||
types_uses.push_back(QueryType::UsesUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->uses)));
|
types_uses.push_back(QueryType::UsesUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->uses)));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
|
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexType* previous_def, IndexType* current_def) {
|
||||||
optional<QueryType::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
|
optional<QueryType::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
|
||||||
optional<QueryType::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
|
optional<QueryType::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
|
||||||
if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty())
|
if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty())
|
||||||
@ -470,11 +470,11 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
CompareGroups<IndexedFuncDef>(previous_file.funcs, current_file.funcs,
|
CompareGroups<IndexFunc>(previous_file.funcs, current_file.funcs,
|
||||||
/*onRemoved:*/[this](IndexedFuncDef* def) {
|
/*onRemoved:*/[this](IndexFunc* def) {
|
||||||
funcs_removed.push_back(def->def.usr);
|
funcs_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_id_map](IndexedFuncDef* func) {
|
/*onAdded:*/[this, ¤t_id_map](IndexFunc* func) {
|
||||||
if (!func->def.detailed_name.empty())
|
if (!func->def.detailed_name.empty())
|
||||||
funcs_def_update.push_back(ToQuery(current_id_map, func->def));
|
funcs_def_update.push_back(ToQuery(current_id_map, func->def));
|
||||||
if (!func->declarations.empty())
|
if (!func->declarations.empty())
|
||||||
@ -484,7 +484,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
|
|||||||
if (!func->callers.empty())
|
if (!func->callers.empty())
|
||||||
funcs_callers.push_back(QueryFunc::CallersUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->callers)));
|
funcs_callers.push_back(QueryFunc::CallersUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->callers)));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
|
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexFunc* previous_def, IndexFunc* current_def) {
|
||||||
optional<QueryFunc::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
|
optional<QueryFunc::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
|
||||||
optional<QueryFunc::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
|
optional<QueryFunc::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
|
||||||
if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty())
|
if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty())
|
||||||
@ -496,17 +496,17 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
CompareGroups<IndexedVarDef>(previous_file.vars, current_file.vars,
|
CompareGroups<IndexVar>(previous_file.vars, current_file.vars,
|
||||||
/*onRemoved:*/[this](IndexedVarDef* def) {
|
/*onRemoved:*/[this](IndexVar* def) {
|
||||||
vars_removed.push_back(def->def.usr);
|
vars_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_id_map](IndexedVarDef* var) {
|
/*onAdded:*/[this, ¤t_id_map](IndexVar* var) {
|
||||||
if (!var->def.detailed_name.empty())
|
if (!var->def.detailed_name.empty())
|
||||||
vars_def_update.push_back(ToQuery(current_id_map, var->def));
|
vars_def_update.push_back(ToQuery(current_id_map, var->def));
|
||||||
if (!var->uses.empty())
|
if (!var->uses.empty())
|
||||||
vars_uses.push_back(QueryVar::UsesUpdate(current_id_map.ToQuery(var->id), current_id_map.ToQuery(var->uses)));
|
vars_uses.push_back(QueryVar::UsesUpdate(current_id_map.ToQuery(var->id), current_id_map.ToQuery(var->uses)));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
|
/*onFound:*/[this, &previous_id_map, ¤t_id_map](IndexVar* previous_def, IndexVar* current_def) {
|
||||||
optional<QueryVar::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
|
optional<QueryVar::DefUpdate> previous_remapped_def = ToQuery(previous_id_map, previous_def->def);
|
||||||
optional<QueryVar::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
|
optional<QueryVar::DefUpdate> current_remapped_def = ToQuery(current_id_map, current_def->def);
|
||||||
if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty())
|
if (current_remapped_def && previous_remapped_def != current_remapped_def && !current_remapped_def->detailed_name.empty())
|
||||||
@ -754,3 +754,18 @@ void QueryDatabase::UpdateDetailedNames(size_t* qualified_name_index, SymbolKind
|
|||||||
detailed_names[*qualified_name_index] = name;
|
detailed_names[*qualified_name_index] = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if false
|
||||||
|
void DoTest() {
|
||||||
|
IndexFile previous("foo.cc");
|
||||||
|
IndexFile current("foo.cc");
|
||||||
|
QueryDatabase db;
|
||||||
|
|
||||||
|
IndexFunc* func = previous.Resolve(previous.ToFuncId("usr"));
|
||||||
|
|
||||||
|
|
||||||
|
IdMap previous_map(&db, previous.id_cache);
|
||||||
|
IdMap current_map(&db, current.id_cache);
|
||||||
|
IndexUpdate::CreateDelta(&previous_map, ¤t_map, &previous, ¤t);
|
||||||
|
}
|
||||||
|
#endif
|
@ -205,7 +205,7 @@ struct QueryVar {
|
|||||||
struct IndexUpdate {
|
struct IndexUpdate {
|
||||||
// Creates a new IndexUpdate based on the delta from previous to current. If
|
// Creates a new IndexUpdate based on the delta from previous to current. If
|
||||||
// no delta computation should be done just pass null for previous.
|
// no delta computation should be done just pass null for previous.
|
||||||
static IndexUpdate CreateDelta(const IdMap* previous_id_map, const IdMap* current_id_map, IndexedFile* previous, IndexedFile* current);
|
static IndexUpdate CreateDelta(const IdMap* previous_id_map, const IdMap* current_id_map, IndexFile* previous, IndexFile* current);
|
||||||
|
|
||||||
// Merge |update| into this update; this can reduce overhead / index update
|
// Merge |update| into this update; this can reduce overhead / index update
|
||||||
// work can be parallelized.
|
// work can be parallelized.
|
||||||
@ -238,7 +238,7 @@ struct IndexUpdate {
|
|||||||
// Creates an index update assuming that |previous| is already
|
// Creates an index update assuming that |previous| is already
|
||||||
// in the index, so only the delta between |previous| and |current|
|
// in the index, so only the delta between |previous| and |current|
|
||||||
// will be applied.
|
// will be applied.
|
||||||
IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_map, IndexedFile& previous, IndexedFile& current);
|
IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_map, IndexFile& previous, IndexFile& current);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,16 +75,16 @@ void Reflect(Writer& visitor, Id<T>& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Ref<IndexedFuncDef>
|
// Ref<IndexFunc>
|
||||||
void Reflect(Reader& visitor, Ref<IndexedFuncDef>& value) {
|
void Reflect(Reader& visitor, Ref<IndexFunc>& value) {
|
||||||
const char* str_value = visitor.GetString();
|
const char* str_value = visitor.GetString();
|
||||||
uint64_t id = atol(str_value);
|
uint64_t id = atol(str_value);
|
||||||
const char* loc_string = strchr(str_value, '@') + 1;
|
const char* loc_string = strchr(str_value, '@') + 1;
|
||||||
|
|
||||||
value.id_ = Id<IndexedFuncDef>(id);
|
value.id_ = Id<IndexFunc>(id);
|
||||||
value.loc = Range(loc_string);
|
value.loc = Range(loc_string);
|
||||||
}
|
}
|
||||||
void Reflect(Writer& visitor, Ref<IndexedFuncDef>& value) {
|
void Reflect(Writer& visitor, Ref<IndexFunc>& value) {
|
||||||
if (value.id_.id == -1) {
|
if (value.id_.id == -1) {
|
||||||
std::string s = "-1@" + value.loc.ToString();
|
std::string s = "-1@" + value.loc.ToString();
|
||||||
visitor.String(s.c_str());
|
visitor.String(s.c_str());
|
||||||
@ -105,12 +105,12 @@ void Reflect(Writer& visitor, Ref<IndexedFuncDef>& value) {
|
|||||||
// TODO: Rename indexer.cpp to indexer.cc
|
// TODO: Rename indexer.cpp to indexer.cc
|
||||||
// TODO: Do not serialize a USR if it has no usages/etc outside of USR info.
|
// TODO: Do not serialize a USR if it has no usages/etc outside of USR info.
|
||||||
|
|
||||||
// IndexedTypeDef
|
// IndexType
|
||||||
bool ReflectMemberStart(Reader& reader, IndexedTypeDef& value) {
|
bool ReflectMemberStart(Reader& reader, IndexType& value) {
|
||||||
//value.is_bad_def = false;
|
//value.is_bad_def = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ReflectMemberStart(Writer& writer, IndexedTypeDef& value) {
|
bool ReflectMemberStart(Writer& writer, IndexType& value) {
|
||||||
// TODO: this is crashing
|
// TODO: this is crashing
|
||||||
// if (!value.HasInterestingState())
|
// if (!value.HasInterestingState())
|
||||||
// std::cerr << "bad";
|
// std::cerr << "bad";
|
||||||
@ -122,7 +122,7 @@ bool ReflectMemberStart(Writer& writer, IndexedTypeDef& value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IndexedTypeDef& value) {
|
void Reflect(TVisitor& visitor, IndexType& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER2("id", value.id);
|
REFLECT_MEMBER2("id", value.id);
|
||||||
REFLECT_MEMBER2("usr", value.def.usr);
|
REFLECT_MEMBER2("usr", value.def.usr);
|
||||||
@ -142,12 +142,12 @@ void Reflect(TVisitor& visitor, IndexedTypeDef& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// IndexedFuncDef
|
// IndexFunc
|
||||||
bool ReflectMemberStart(Reader& reader, IndexedFuncDef& value) {
|
bool ReflectMemberStart(Reader& reader, IndexFunc& value) {
|
||||||
//value.is_bad_def = false;
|
//value.is_bad_def = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ReflectMemberStart(Writer& writer, IndexedFuncDef& value) {
|
bool ReflectMemberStart(Writer& writer, IndexFunc& value) {
|
||||||
// TODO: this is crashing
|
// TODO: this is crashing
|
||||||
// if (!value.HasInterestingState())
|
// if (!value.HasInterestingState())
|
||||||
// std::cerr << "bad";
|
// std::cerr << "bad";
|
||||||
@ -159,7 +159,7 @@ bool ReflectMemberStart(Writer& writer, IndexedFuncDef& value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IndexedFuncDef& value) {
|
void Reflect(TVisitor& visitor, IndexFunc& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER2("id", value.id);
|
REFLECT_MEMBER2("id", value.id);
|
||||||
REFLECT_MEMBER2("usr", value.def.usr);
|
REFLECT_MEMBER2("usr", value.def.usr);
|
||||||
@ -178,12 +178,12 @@ void Reflect(TVisitor& visitor, IndexedFuncDef& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// IndexedVarDef
|
// IndexVar
|
||||||
bool ReflectMemberStart(Reader& reader, IndexedVarDef& value) {
|
bool ReflectMemberStart(Reader& reader, IndexVar& value) {
|
||||||
//value.is_bad_def = false;
|
//value.is_bad_def = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ReflectMemberStart(Writer& writer, IndexedVarDef& value) {
|
bool ReflectMemberStart(Writer& writer, IndexVar& value) {
|
||||||
// TODO: this is crashing
|
// TODO: this is crashing
|
||||||
// if (!value.HasInterestingState())
|
// if (!value.HasInterestingState())
|
||||||
// std::cerr << "bad";
|
// std::cerr << "bad";
|
||||||
@ -195,7 +195,7 @@ bool ReflectMemberStart(Writer& writer, IndexedVarDef& value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IndexedVarDef& value) {
|
void Reflect(TVisitor& visitor, IndexVar& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
REFLECT_MEMBER2("id", value.id);
|
REFLECT_MEMBER2("id", value.id);
|
||||||
REFLECT_MEMBER2("usr", value.def.usr);
|
REFLECT_MEMBER2("usr", value.def.usr);
|
||||||
@ -211,20 +211,20 @@ void Reflect(TVisitor& visitor, IndexedVarDef& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// IndexedFile
|
// IndexFile
|
||||||
bool ReflectMemberStart(Writer& visitor, IndexedFile& value) {
|
bool ReflectMemberStart(Writer& visitor, IndexFile& value) {
|
||||||
auto it = value.id_cache.usr_to_type_id.find("");
|
auto it = value.id_cache.usr_to_type_id.find("");
|
||||||
if (it != value.id_cache.usr_to_type_id.end()) {
|
if (it != value.id_cache.usr_to_type_id.end()) {
|
||||||
value.Resolve(it->second)->def.short_name = "<fundamental>";
|
value.Resolve(it->second)->def.short_name = "<fundamental>";
|
||||||
assert(value.Resolve(it->second)->uses.size() == 0);
|
assert(value.Resolve(it->second)->uses.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
value.version = IndexedFile::kCurrentVersion;
|
value.version = IndexFile::kCurrentVersion;
|
||||||
DefaultReflectMemberStart(visitor);
|
DefaultReflectMemberStart(visitor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<typename TVisitor>
|
template<typename TVisitor>
|
||||||
void Reflect(TVisitor& visitor, IndexedFile& value) {
|
void Reflect(TVisitor& visitor, IndexFile& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
if (!gTestOutputMode) {
|
if (!gTestOutputMode) {
|
||||||
REFLECT_MEMBER(version);
|
REFLECT_MEMBER(version);
|
||||||
@ -246,7 +246,7 @@ void Reflect(TVisitor& visitor, IndexedFile& value) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string Serialize(IndexedFile& file) {
|
std::string Serialize(IndexFile& file) {
|
||||||
rapidjson::StringBuffer output;
|
rapidjson::StringBuffer output;
|
||||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(output);
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(output);
|
||||||
//Writer writer(output);
|
//Writer writer(output);
|
||||||
@ -259,13 +259,13 @@ std::string Serialize(IndexedFile& file) {
|
|||||||
return output.GetString();
|
return output.GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<IndexedFile> Deserialize(std::string path, std::string serialized) {
|
optional<IndexFile> Deserialize(std::string path, std::string serialized) {
|
||||||
rapidjson::Document reader;
|
rapidjson::Document reader;
|
||||||
reader.Parse(serialized.c_str());
|
reader.Parse(serialized.c_str());
|
||||||
if (reader.HasParseError())
|
if (reader.HasParseError())
|
||||||
return nullopt;
|
return nullopt;
|
||||||
|
|
||||||
IndexedFile file(path);
|
IndexFile file(path);
|
||||||
Reflect(reader, file);
|
Reflect(reader, file);
|
||||||
|
|
||||||
// Restore non-serialized state.
|
// Restore non-serialized state.
|
||||||
|
@ -14,7 +14,7 @@ using std::experimental::nullopt;
|
|||||||
|
|
||||||
using Reader = rapidjson::GenericValue<rapidjson::UTF8<>>;
|
using Reader = rapidjson::GenericValue<rapidjson::UTF8<>>;
|
||||||
using Writer = rapidjson::Writer<rapidjson::StringBuffer>;
|
using Writer = rapidjson::Writer<rapidjson::StringBuffer>;
|
||||||
struct IndexedFile;
|
struct IndexFile;
|
||||||
|
|
||||||
#define REFLECT_MEMBER_START() \
|
#define REFLECT_MEMBER_START() \
|
||||||
if (!ReflectMemberStart(visitor, value)) return
|
if (!ReflectMemberStart(visitor, value)) return
|
||||||
@ -206,7 +206,7 @@ void ReflectMember(Reader& visitor, const char* name, T& value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Serialize(IndexedFile& file);
|
std::string Serialize(IndexFile& file);
|
||||||
optional<IndexedFile> Deserialize(std::string path, std::string serialized);
|
optional<IndexFile> Deserialize(std::string path, std::string serialized);
|
||||||
|
|
||||||
void SetTestOutputMode();
|
void SetTestOutputMode();
|
11
src/test.cc
11
src/test.cc
@ -82,7 +82,7 @@ void DiffDocuments(std::string path, std::string path_section, rapidjson::Docume
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VerifySerializeToFrom(IndexedFile* file) {
|
void VerifySerializeToFrom(IndexFile* file) {
|
||||||
std::string expected = file->ToString();
|
std::string expected = file->ToString();
|
||||||
std::string actual = Deserialize("--.cc", Serialize(*file)).value().ToString();
|
std::string actual = Deserialize("--.cc", Serialize(*file)).value().ToString();
|
||||||
if (expected != actual) {
|
if (expected != actual) {
|
||||||
@ -103,7 +103,7 @@ std::string FindExpectedOutputForFilename(std::string filename, const std::unord
|
|||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexedFile* FindDbForPathEnding(const std::string& path, const std::vector<std::unique_ptr<IndexedFile>>& dbs) {
|
IndexFile* FindDbForPathEnding(const std::string& path, const std::vector<std::unique_ptr<IndexFile>>& dbs) {
|
||||||
for (auto& db : dbs) {
|
for (auto& db : dbs) {
|
||||||
if (EndsWith(db->path, path))
|
if (EndsWith(db->path, path))
|
||||||
return db.get();
|
return db.get();
|
||||||
@ -137,7 +137,7 @@ void RunTests() {
|
|||||||
|
|
||||||
// Run test.
|
// Run test.
|
||||||
std::cout << "[START] " << path << std::endl;
|
std::cout << "[START] " << path << std::endl;
|
||||||
std::vector<std::unique_ptr<IndexedFile>> dbs = Parse(
|
std::vector<std::unique_ptr<IndexFile>> dbs = Parse(
|
||||||
&config, &file_consumer_shared,
|
&config, &file_consumer_shared,
|
||||||
path,
|
path,
|
||||||
{
|
{
|
||||||
@ -184,7 +184,7 @@ void RunTests() {
|
|||||||
const std::string& expected_output = entry.second;
|
const std::string& expected_output = entry.second;
|
||||||
|
|
||||||
// Get output from index operation.
|
// Get output from index operation.
|
||||||
IndexedFile* db = FindDbForPathEnding(expected_path, dbs);
|
IndexFile* db = FindDbForPathEnding(expected_path, dbs);
|
||||||
std::string actual_output = "{}";
|
std::string actual_output = "{}";
|
||||||
if (db) {
|
if (db) {
|
||||||
VerifySerializeToFrom(db);
|
VerifySerializeToFrom(db);
|
||||||
@ -227,6 +227,5 @@ void RunTests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ctor/dtor, copy ctor
|
// TODO: ctor/dtor, copy ctor
|
||||||
// TODO: Always pass IndexedFile by pointer, ie, search and remove all IndexedFile& refs.
|
// TODO: Always pass IndexFile by pointer, ie, search and remove all IndexFile& refs.
|
||||||
// TODO: Rename IndexedFile to IndexFile
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user