Renames and fix some operator < implementations

This commit is contained in:
Jacob Dufault 2017-05-11 23:08:15 -07:00
parent 61aaf4509c
commit ff421723a5
12 changed files with 209 additions and 195 deletions

View File

@ -20,7 +20,7 @@ std::string GetCachedBaseFileName(const std::string& cache_directory,
} // namespace
std::unique_ptr<IndexedFile> LoadCachedIndex(IndexerConfig* config,
std::unique_ptr<IndexFile> LoadCachedIndex(IndexerConfig* config,
const std::string& filename) {
if (!config->enableCacheRead)
return nullptr;
@ -30,9 +30,9 @@ std::unique_ptr<IndexedFile> LoadCachedIndex(IndexerConfig* config,
if (!file_content)
return nullptr;
optional<IndexedFile> indexed = Deserialize(filename, *file_content);
if (indexed && indexed->version == IndexedFile::kCurrentVersion)
return MakeUnique<IndexedFile>(indexed.value());
optional<IndexFile> indexed = Deserialize(filename, *file_content);
if (indexed && indexed->version == IndexFile::kCurrentVersion)
return MakeUnique<IndexFile>(indexed.value());
return nullptr;
}
@ -47,7 +47,7 @@ optional<std::string> LoadCachedFileContents(IndexerConfig* config,
void WriteToCache(IndexerConfig* config,
const std::string& filename,
IndexedFile& file) {
IndexFile& file) {
if (!config->enableCacheWrite)
return;

View File

@ -8,9 +8,9 @@ using std::experimental::optional;
using std::experimental::nullopt;
struct IndexerConfig;
struct IndexedFile;
struct IndexFile;
std::unique_ptr<IndexedFile> LoadCachedIndex(IndexerConfig* config,
std::unique_ptr<IndexFile> LoadCachedIndex(IndexerConfig* config,
const std::string& filename);
optional<std::string> LoadCachedFileContents(IndexerConfig* config,
@ -18,4 +18,4 @@ optional<std::string> LoadCachedFileContents(IndexerConfig* config,
void WriteToCache(IndexerConfig* config,
const std::string& filename,
IndexedFile& file);
IndexFile& file);

View File

@ -772,21 +772,21 @@ struct Index_DoIndex {
};
struct Index_DoIdMap {
std::unique_ptr<IndexedFile> previous;
std::unique_ptr<IndexedFile> current;
std::unique_ptr<IndexFile> previous;
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)) {}
explicit Index_DoIdMap(std::unique_ptr<IndexedFile> previous,
std::unique_ptr<IndexedFile> current)
explicit Index_DoIdMap(std::unique_ptr<IndexFile> previous,
std::unique_ptr<IndexFile> current)
: previous(std::move(previous)),
current(std::move(current)) {}
};
struct Index_OnIdMapped {
std::unique_ptr<IndexedFile> previous_index;
std::unique_ptr<IndexedFile> current_index;
std::unique_ptr<IndexFile> previous_index;
std::unique_ptr<IndexFile> current_index;
std::unique_ptr<IdMap> previous_id_map;
std::unique_ptr<IdMap> current_id_map;
};
@ -942,7 +942,7 @@ bool ImportCachedIndex(IndexerConfig* config,
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);
if (!cache)
return true;
@ -952,7 +952,7 @@ bool ImportCachedIndex(IndexerConfig* config,
// Import all dependencies.
for (auto& dependency_path : cache->dependencies) {
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)
file_consumer_shared->Mark(cache->path);
else
@ -977,21 +977,21 @@ void ParseFile(IndexerConfig* config,
const Project::Entry& entry) {
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;
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,
tu_path, tu_args);
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;
// 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)
cached_index = std::move(cache_for_args);
else
@ -1037,7 +1037,7 @@ bool ResetStaleFiles(IndexerConfig* config,
const std::string& tu_path) {
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);
if (!cache) {
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
for (auto& dependency_path : cache->dependencies) {
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) {
needs_reparse = true;
file_consumer_shared->Reset(cache->path);

View File

@ -32,7 +32,7 @@ void FileConsumer::SharedState::Reset(const std::string& file) {
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);
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.
bool did_insert = shared_->Mark(file_name);
*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();
}
IndexedFile* FileConsumer::ForceLocal(CXFile file) {
IndexFile* FileConsumer::ForceLocal(CXFile file) {
// Try to fetch the file using the normal system, which will insert the file
// usage into global storage.
{
bool is_first;
IndexedFile* cache = TryConsumeFile(file, &is_first);
IndexFile* cache = TryConsumeFile(file, &is_first);
if (cache)
return cache;
}
@ -76,13 +76,13 @@ IndexedFile* FileConsumer::ForceLocal(CXFile file) {
auto it = local_.find(file_id);
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());
return local_[file_id].get();
}
std::vector<std::unique_ptr<IndexedFile>> FileConsumer::TakeLocalState() {
std::vector<std::unique_ptr<IndexedFile>> result;
std::vector<std::unique_ptr<IndexFile>> FileConsumer::TakeLocalState() {
std::vector<std::unique_ptr<IndexFile>> result;
for (auto& entry : local_) {
if (entry.second)
result.push_back(std::move(entry.second));

View File

@ -9,7 +9,7 @@
#include <unordered_set>
#include <unordered_map>
struct IndexedFile;
struct IndexFile;
// Needed for unordered_map usage below.
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
// 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
// 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.
IndexedFile* ForceLocal(CXFile file);
IndexFile* ForceLocal(CXFile file);
// Returns and passes ownership of all local state.
std::vector<std::unique_ptr<IndexedFile>> TakeLocalState();
std::vector<std::unique_ptr<IndexFile>> TakeLocalState();
private:
std::unordered_map<CXFileUniqueID, std::unique_ptr<IndexedFile>> local_;
std::unordered_map<CXFileUniqueID, std::unique_ptr<IndexFile>> local_;
SharedState* shared_;
};

View File

@ -48,79 +48,79 @@ Range ResolveExtent(const CXCursor& cx_cursor) {
} // 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.
// Preallocate any existing resolved ids.
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)
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)
vars.push_back(IndexedVarDef(entry.second, entry.first));
vars.push_back(IndexVar(entry.second, entry.first));
}
// 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);
if (it != id_cache.usr_to_type_id.end())
return it->second;
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.type_id_to_usr[id] = usr;
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);
if (it != id_cache.usr_to_func_id.end())
return it->second;
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.func_id_to_usr[id] = usr;
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);
if (it != id_cache.usr_to_var_id.end())
return it->second;
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.var_id_to_usr[id] = usr;
return id;
}
IndexTypeId IndexedFile::ToTypeId(const CXCursor& cursor) {
IndexTypeId IndexFile::ToTypeId(const CXCursor& cursor) {
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());
}
IndexVarId IndexedFile::ToVarId(const CXCursor& cursor) {
IndexVarId IndexFile::ToVarId(const CXCursor& cursor) {
return ToVarId(clang::Cursor(cursor).get_usr());
}
IndexedTypeDef* IndexedFile::Resolve(IndexTypeId id) {
IndexType* IndexFile::Resolve(IndexTypeId id) {
return &types[id.id];
}
IndexedFuncDef* IndexedFile::Resolve(IndexFuncId id) {
IndexFunc* IndexFile::Resolve(IndexFuncId id) {
return &funcs[id.id];
}
IndexedVarDef* IndexedFile::Resolve(IndexVarId id) {
IndexVar* IndexFile::Resolve(IndexVarId id) {
return &vars[id.id];
}
std::string IndexedFile::ToString() {
std::string IndexFile::ToString() {
return Serialize(*this);
}
IndexedTypeDef::IndexedTypeDef(IndexTypeId id, const std::string& usr)
IndexType::IndexType(IndexTypeId id, const std::string& usr)
: def(usr), id(id) {
assert(usr.size() > 0);
// std::cerr << "Creating type with usr " << usr << std::endl;
@ -195,12 +195,12 @@ struct NamespaceHelper {
struct IndexParam {
// 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|.
//
// This can be null if we're not generating an index for the primary
// translation unit.
IndexedFile* primary_file;
IndexFile* primary_file;
FileConsumer* file_consumer;
NamespaceHelper ns;
@ -231,7 +231,7 @@ void diagnostic(CXClientData client_data,
unsigned int line, column;
clang_getSpellingLocation(diag_loc, &file, &line, &column, nullptr);
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)
continue;
if (is_first_time_visiting_file && param->primary_file)
@ -380,18 +380,18 @@ bool IsTypeDefinition(const CXIdxContainerInfo* container) {
}
struct VisitDeclForTypeUsageParam {
IndexedFile* db;
IndexFile* db;
int has_processed_any = false;
optional<clang::Cursor> previous_cursor;
optional<IndexTypeId> initial_type;
VisitDeclForTypeUsageParam(IndexedFile* db) : db(db) {}
VisitDeclForTypeUsageParam(IndexFile* db) : db(db) {}
};
void VisitDeclForTypeUsageVisitorHandler(clang::Cursor cursor,
VisitDeclForTypeUsageParam* param) {
param->has_processed_any = true;
IndexedFile* db = param->db;
IndexFile* db = param->db;
std::string referenced_usr =
cursor.get_referenced()
@ -406,7 +406,7 @@ void VisitDeclForTypeUsageVisitorHandler(clang::Cursor cursor,
if (!param->initial_type)
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
// def? Try adding assert on |loc| later.
Range loc = ResolveSpelling(cursor.cx_cursor);
@ -451,7 +451,7 @@ clang::VisiterResult VisitDeclForTypeUsageVisitor(
// strips
// qualifies from |cursor| (ie, Foo* => Foo) and removes template arguments
// (ie, Foo<A,B> => Foo<*,*>).
optional<IndexTypeId> ResolveToDeclarationType(IndexedFile* db,
optional<IndexTypeId> ResolveToDeclarationType(IndexFile* db,
clang::Cursor cursor) {
clang::Cursor 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
// ResolveToDeclarationType, which works in more scenarios.
optional<IndexTypeId> AddDeclTypeUsages(
IndexedFile* db,
IndexFile* db,
clang::Cursor decl_cursor,
const CXIdxContainerInfo* semantic_container,
const CXIdxContainerInfo* lexical_container) {
@ -604,7 +604,7 @@ optional<IndexTypeId> AddDeclTypeUsages(
// for template arguments.
clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor,
clang::Cursor parent,
IndexedFile* db) {
IndexFile* db) {
/*
We need to index the |DeclRefExpr| below (ie, |var| inside of
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
// << " at " << loc.ToString() << std::endl;
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);
break;
}
@ -658,7 +658,7 @@ clang::VisiterResult AddDeclInitializerUsagesVisitor(clang::Cursor cursor,
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);
}
@ -738,7 +738,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(decl->loc), &file, nullptr, nullptr, nullptr);
IndexParam* param = static_cast<IndexParam*>(client_data);
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)
return;
@ -773,7 +773,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
std::string decl_usr = decl_cursor.get_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
// this may shadow.
@ -827,7 +827,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
if (decl->isDefinition && IsTypeDefinition(decl->semanticContainer)) {
IndexTypeId declaring_type_id =
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;
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();
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
// as an interesting usage.
@ -908,7 +908,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
if (IsTypeDefinition(decl->semanticContainer)) {
IndexTypeId declaring_type_id =
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;
// 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) {
clang::Cursor parent = overridden[i];
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->def.base = parent_id;
@ -1007,7 +1007,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
decl->semanticContainer, decl->lexicalContainer);
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)
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);
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
// this may shadow.
@ -1075,9 +1075,9 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
optional<IndexTypeId> parent_type_id =
ResolveToDeclarationType(db, base_class->cursor);
// 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) {
IndexedTypeDef* parent_type_def =
IndexType* parent_type_def =
db->Resolve(parent_type_id.value());
parent_type_def->derived.push_back(type_id);
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);
IndexParam* param = static_cast<IndexParam*>(client_data);
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)
return;
@ -1207,7 +1207,7 @@ void indexEntityReference(CXClientData client_data,
// ref->loc 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));
//Range loc_spelling = param->db->id_cache.ForceResolveSpelling(ref->cursor, false /*interesting*/);
//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();
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);
break;
}
@ -1267,13 +1267,13 @@ void indexEntityReference(CXClientData client_data,
IndexFuncId called_id = db->ToFuncId(ref->referencedEntity->USR);
if (IsFunctionCallContext(ref->container->cursor.kind)) {
IndexFuncId caller_id = db->ToFuncId(ref->container->cursor);
IndexedFuncDef* caller_def = db->Resolve(caller_id);
IndexedFuncDef* called_def = db->Resolve(called_id);
IndexFunc* caller_def = db->Resolve(caller_id);
IndexFunc* called_def = db->Resolve(called_id);
AddFuncRef(&caller_def->def.callees, IndexFuncRef(called_id, loc_spelling));
AddFuncRef(&called_def->callers, IndexFuncRef(caller_id, loc_spelling));
} else {
IndexedFuncDef* called_def = db->Resolve(called_id);
IndexFunc* called_def = db->Resolve(called_id);
AddFuncRef(&called_def->callers, IndexFuncRef(loc_spelling));
}
@ -1292,7 +1292,7 @@ void indexEntityReference(CXClientData client_data,
referenced = referenced.template_specialization_to_template_definition();
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
@ -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,
std::string file,
std::vector<std::string> args,

View File

@ -21,9 +21,9 @@
#include <unordered_map>
#include <vector>
struct IndexedTypeDef;
struct IndexedFuncDef;
struct IndexedVarDef;
struct IndexType;
struct IndexFunc;
struct IndexVar;
using namespace std::experimental;
@ -59,9 +59,9 @@ bool operator!=(const Id<T>& a, const Id<T>& b) {
return !(a == b);
}
using IndexTypeId = Id<IndexedTypeDef>;
using IndexFuncId = Id<IndexedFuncDef>;
using IndexVarId = Id<IndexedVarDef>;
using IndexTypeId = Id<IndexType>;
using IndexFuncId = Id<IndexFunc>;
using IndexVarId = Id<IndexVar>;
struct IdCache;
@ -103,7 +103,7 @@ bool operator!=(const Ref<T>& a, const Ref<T>& 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
// set to false.
@ -196,7 +196,7 @@ void Reflect(TVisitor& visitor,
REFLECT_MEMBER_END();
}
struct IndexedTypeDef {
struct IndexType {
using Def = TypeDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
Def def;
@ -212,9 +212,9 @@ struct IndexedTypeDef {
// NOTE: Do not insert directly! Use AddUsage instead.
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 {
return
@ -224,12 +224,12 @@ struct IndexedTypeDef {
!uses.empty();
}
bool operator<(const IndexedTypeDef& other) const {
bool operator<(const IndexType& other) const {
return def.usr < other.def.usr;
}
};
MAKE_HASHABLE(IndexedTypeDef, t.def.usr);
MAKE_HASHABLE(IndexType, t.def.usr);
template <typename TypeId,
typename FuncId,
@ -311,7 +311,7 @@ void Reflect(
REFLECT_MEMBER_END();
}
struct IndexedFuncDef {
struct IndexFunc {
using Def = FuncDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, IndexFuncRef, Range>;
Def def;
@ -330,8 +330,8 @@ struct IndexedFuncDef {
// def.definition_spelling.
std::vector<IndexFuncRef> callers;
IndexedFuncDef() {} // For reflection.
IndexedFuncDef(IndexFuncId id, const std::string& usr) : def(usr), id(id) {
IndexFunc() {} // For reflection.
IndexFunc(IndexFuncId id, const std::string& usr) : def(usr), id(id) {
// assert(usr.size() > 0);
}
@ -344,11 +344,11 @@ struct IndexedFuncDef {
!callers.empty();
}
bool operator<(const IndexedFuncDef& other) const {
bool operator<(const IndexFunc& other) const {
return def.usr < other.def.usr;
}
};
MAKE_HASHABLE(IndexedFuncDef, t.def.usr);
MAKE_HASHABLE(IndexFunc, t.def.usr);
template <typename TypeId,
typename FuncId,
@ -418,7 +418,7 @@ void Reflect(TVisitor& visitor,
REFLECT_MEMBER_END();
}
struct IndexedVarDef {
struct IndexVar {
using Def = VarDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
Def def;
@ -427,9 +427,9 @@ struct IndexedVarDef {
// Usages.
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);
}
@ -439,11 +439,11 @@ struct IndexedVarDef {
!uses.empty();
}
bool operator<(const IndexedVarDef& other) const {
bool operator<(const IndexVar& other) const {
return def.usr < other.def.usr;
}
};
MAKE_HASHABLE(IndexedVarDef, t.def.usr);
MAKE_HASHABLE(IndexVar, t.def.usr);
struct IdCache {
std::string primary_file;
@ -457,7 +457,7 @@ struct IdCache {
IdCache(const std::string& primary_file);
};
struct IndexedFile {
struct IndexFile {
IdCache id_cache;
static constexpr int kCurrentVersion = 2;
@ -468,7 +468,7 @@ struct IndexedFile {
int64_t last_modification_time = 0;
// 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
// header we need to lookup the original translation unit and reindex that.
std::string import_file;
@ -480,11 +480,11 @@ struct IndexedFile {
NonElidedVector<lsDiagnostic> diagnostics;
std::vector<std::string> dependencies;
std::vector<IndexedTypeDef> types;
std::vector<IndexedFuncDef> funcs;
std::vector<IndexedVarDef> vars;
std::vector<IndexType> types;
std::vector<IndexFunc> funcs;
std::vector<IndexVar> vars;
IndexedFile(const std::string& path);
IndexFile(const std::string& path);
IndexTypeId ToTypeId(const std::string& usr);
IndexFuncId ToFuncId(const std::string& usr);
@ -492,9 +492,9 @@ struct IndexedFile {
IndexTypeId ToTypeId(const CXCursor& usr);
IndexFuncId ToFuncId(const CXCursor& usr);
IndexVarId ToVarId(const CXCursor& usr);
IndexedTypeDef* Resolve(IndexTypeId id);
IndexedFuncDef* Resolve(IndexFuncId id);
IndexedVarDef* Resolve(IndexVarId id);
IndexType* Resolve(IndexTypeId id);
IndexFunc* Resolve(IndexFuncId id);
IndexVar* Resolve(IndexVarId id);
std::string ToString();
};
@ -502,7 +502,7 @@ struct IndexedFile {
// |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.
// |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,
std::string file,
std::vector<std::string> args,

View File

@ -17,7 +17,7 @@
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);
result.short_name = type.short_name;
result.detailed_name = type.detailed_name;
@ -31,7 +31,7 @@ QueryType::DefUpdate ToQuery(const IdMap& id_map, const IndexedTypeDef::Def& typ
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);
result.short_name = func.short_name;
result.detailed_name = func.detailed_name;
@ -44,7 +44,7 @@ QueryFunc::DefUpdate ToQuery(const IdMap& id_map, const IndexedFuncDef::Def& fun
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);
result.short_name = var.short_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;
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)));
};
for (const IndexedTypeDef& def : indexed.types) {
if (def.def.definition_spelling.has_value())
add_all_symbols(id_map.ToSymbol(def.id), def.def.definition_spelling.value());
if (def.def.definition_extent.has_value())
add_outline(id_map.ToSymbol(def.id), def.def.definition_extent.value());
for (const Range& use : def.uses)
add_all_symbols(id_map.ToSymbol(def.id), use);
for (const IndexType& type : indexed.types) {
if (type.def.definition_spelling.has_value())
add_all_symbols(id_map.ToSymbol(type.id), type.def.definition_spelling.value());
if (type.def.definition_extent.has_value())
add_outline(id_map.ToSymbol(type.id), type.def.definition_extent.value());
for (const Range& use : type.uses)
add_all_symbols(id_map.ToSymbol(type.id), use);
}
for (const IndexedFuncDef& def : indexed.funcs) {
if (def.def.definition_spelling.has_value())
add_all_symbols(id_map.ToSymbol(def.id), def.def.definition_spelling.value());
if (def.def.definition_extent.has_value())
add_outline(id_map.ToSymbol(def.id), def.def.definition_extent.value());
for (Range decl : def.declarations) {
add_all_symbols(id_map.ToSymbol(def.id), decl);
add_outline(id_map.ToSymbol(def.id), decl);
for (const IndexFunc& func : indexed.funcs) {
if (func.def.definition_spelling.has_value())
add_all_symbols(id_map.ToSymbol(func.id), func.def.definition_spelling.value());
if (func.def.definition_extent.has_value())
add_outline(id_map.ToSymbol(func.id), func.def.definition_extent.value());
for (Range decl : func.declarations) {
add_all_symbols(id_map.ToSymbol(func.id), decl);
add_outline(id_map.ToSymbol(func.id), decl);
}
for (const IndexFuncRef& caller : def.callers)
add_all_symbols(id_map.ToSymbol(def.id), caller.loc);
for (const IndexFuncRef& caller : func.callers)
add_all_symbols(id_map.ToSymbol(func.id), caller.loc);
}
for (const IndexedVarDef& def : indexed.vars) {
if (def.def.definition_spelling.has_value())
add_all_symbols(id_map.ToSymbol(def.id), def.def.definition_spelling.value());
if (def.def.definition_extent.has_value())
add_outline(id_map.ToSymbol(def.id), def.def.definition_extent.value());
for (const Range& use : def.uses)
add_all_symbols(id_map.ToSymbol(def.id), use);
for (const IndexVar& var : indexed.vars) {
if (var.def.definition_spelling.has_value())
add_all_symbols(id_map.ToSymbol(var.id), var.def.definition_spelling.value());
if (var.def.definition_extent.has_value())
add_outline(id_map.ToSymbol(var.id), var.def.definition_extent.value());
for (const Range& use : var.uses)
add_all_symbols(id_map.ToSymbol(var.id), use);
}
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
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.
if (!previous_id_map) {
assert(!previous);
IndexedFile previous(current->path);
IndexFile previous(current->path);
return IndexUpdate(*current_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.
// |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));
// Types
CompareGroups<IndexedTypeDef>(previous_file.types, current_file.types,
/*onRemoved:*/[this](IndexedTypeDef* def) {
CompareGroups<IndexType>(previous_file.types, current_file.types,
/*onRemoved:*/[this](IndexType* def) {
types_removed.push_back(def->def.usr);
},
/*onAdded:*/[this, &current_id_map](IndexedTypeDef* type) {
/*onAdded:*/[this, &current_id_map](IndexType* type) {
if (!type->def.detailed_name.empty())
types_def_update.push_back(ToQuery(current_id_map, type->def));
if (!type->derived.empty())
@ -458,7 +458,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
if (!type->uses.empty())
types_uses.push_back(QueryType::UsesUpdate(current_id_map.ToQuery(type->id), current_id_map.ToQuery(type->uses)));
},
/*onFound:*/[this, &previous_id_map, &current_id_map](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
/*onFound:*/[this, &previous_id_map, &current_id_map](IndexType* previous_def, IndexType* current_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);
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
CompareGroups<IndexedFuncDef>(previous_file.funcs, current_file.funcs,
/*onRemoved:*/[this](IndexedFuncDef* def) {
CompareGroups<IndexFunc>(previous_file.funcs, current_file.funcs,
/*onRemoved:*/[this](IndexFunc* def) {
funcs_removed.push_back(def->def.usr);
},
/*onAdded:*/[this, &current_id_map](IndexedFuncDef* func) {
/*onAdded:*/[this, &current_id_map](IndexFunc* func) {
if (!func->def.detailed_name.empty())
funcs_def_update.push_back(ToQuery(current_id_map, func->def));
if (!func->declarations.empty())
@ -484,7 +484,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map, const IdMap& current_id_m
if (!func->callers.empty())
funcs_callers.push_back(QueryFunc::CallersUpdate(current_id_map.ToQuery(func->id), current_id_map.ToQuery(func->callers)));
},
/*onFound:*/[this, &previous_id_map, &current_id_map](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
/*onFound:*/[this, &previous_id_map, &current_id_map](IndexFunc* previous_def, IndexFunc* current_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);
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
CompareGroups<IndexedVarDef>(previous_file.vars, current_file.vars,
/*onRemoved:*/[this](IndexedVarDef* def) {
CompareGroups<IndexVar>(previous_file.vars, current_file.vars,
/*onRemoved:*/[this](IndexVar* def) {
vars_removed.push_back(def->def.usr);
},
/*onAdded:*/[this, &current_id_map](IndexedVarDef* var) {
/*onAdded:*/[this, &current_id_map](IndexVar* var) {
if (!var->def.detailed_name.empty())
vars_def_update.push_back(ToQuery(current_id_map, var->def));
if (!var->uses.empty())
vars_uses.push_back(QueryVar::UsesUpdate(current_id_map.ToQuery(var->id), current_id_map.ToQuery(var->uses)));
},
/*onFound:*/[this, &previous_id_map, &current_id_map](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
/*onFound:*/[this, &previous_id_map, &current_id_map](IndexVar* previous_def, IndexVar* current_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);
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;
}
}
#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, &current_map, &previous, &current);
}
#endif

View File

@ -205,7 +205,7 @@ struct QueryVar {
struct IndexUpdate {
// Creates a new IndexUpdate based on the delta from previous to current. If
// 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
// work can be parallelized.
@ -238,7 +238,7 @@ struct IndexUpdate {
// Creates an index update assuming that |previous| is already
// in the index, so only the delta between |previous| and |current|
// 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);
};

View File

@ -75,16 +75,16 @@ void Reflect(Writer& visitor, Id<T>& value) {
}
// Ref<IndexedFuncDef>
void Reflect(Reader& visitor, Ref<IndexedFuncDef>& value) {
// Ref<IndexFunc>
void Reflect(Reader& visitor, Ref<IndexFunc>& value) {
const char* str_value = visitor.GetString();
uint64_t id = atol(str_value);
const char* loc_string = strchr(str_value, '@') + 1;
value.id_ = Id<IndexedFuncDef>(id);
value.id_ = Id<IndexFunc>(id);
value.loc = Range(loc_string);
}
void Reflect(Writer& visitor, Ref<IndexedFuncDef>& value) {
void Reflect(Writer& visitor, Ref<IndexFunc>& value) {
if (value.id_.id == -1) {
std::string s = "-1@" + value.loc.ToString();
visitor.String(s.c_str());
@ -105,12 +105,12 @@ void Reflect(Writer& visitor, Ref<IndexedFuncDef>& value) {
// TODO: Rename indexer.cpp to indexer.cc
// TODO: Do not serialize a USR if it has no usages/etc outside of USR info.
// IndexedTypeDef
bool ReflectMemberStart(Reader& reader, IndexedTypeDef& value) {
// IndexType
bool ReflectMemberStart(Reader& reader, IndexType& value) {
//value.is_bad_def = false;
return true;
}
bool ReflectMemberStart(Writer& writer, IndexedTypeDef& value) {
bool ReflectMemberStart(Writer& writer, IndexType& value) {
// TODO: this is crashing
// if (!value.HasInterestingState())
// std::cerr << "bad";
@ -122,7 +122,7 @@ bool ReflectMemberStart(Writer& writer, IndexedTypeDef& value) {
return true;
}
template<typename TVisitor>
void Reflect(TVisitor& visitor, IndexedTypeDef& value) {
void Reflect(TVisitor& visitor, IndexType& value) {
REFLECT_MEMBER_START();
REFLECT_MEMBER2("id", value.id);
REFLECT_MEMBER2("usr", value.def.usr);
@ -142,12 +142,12 @@ void Reflect(TVisitor& visitor, IndexedTypeDef& value) {
}
// IndexedFuncDef
bool ReflectMemberStart(Reader& reader, IndexedFuncDef& value) {
// IndexFunc
bool ReflectMemberStart(Reader& reader, IndexFunc& value) {
//value.is_bad_def = false;
return true;
}
bool ReflectMemberStart(Writer& writer, IndexedFuncDef& value) {
bool ReflectMemberStart(Writer& writer, IndexFunc& value) {
// TODO: this is crashing
// if (!value.HasInterestingState())
// std::cerr << "bad";
@ -159,7 +159,7 @@ bool ReflectMemberStart(Writer& writer, IndexedFuncDef& value) {
return true;
}
template<typename TVisitor>
void Reflect(TVisitor& visitor, IndexedFuncDef& value) {
void Reflect(TVisitor& visitor, IndexFunc& value) {
REFLECT_MEMBER_START();
REFLECT_MEMBER2("id", value.id);
REFLECT_MEMBER2("usr", value.def.usr);
@ -178,12 +178,12 @@ void Reflect(TVisitor& visitor, IndexedFuncDef& value) {
}
// IndexedVarDef
bool ReflectMemberStart(Reader& reader, IndexedVarDef& value) {
// IndexVar
bool ReflectMemberStart(Reader& reader, IndexVar& value) {
//value.is_bad_def = false;
return true;
}
bool ReflectMemberStart(Writer& writer, IndexedVarDef& value) {
bool ReflectMemberStart(Writer& writer, IndexVar& value) {
// TODO: this is crashing
// if (!value.HasInterestingState())
// std::cerr << "bad";
@ -195,7 +195,7 @@ bool ReflectMemberStart(Writer& writer, IndexedVarDef& value) {
return true;
}
template<typename TVisitor>
void Reflect(TVisitor& visitor, IndexedVarDef& value) {
void Reflect(TVisitor& visitor, IndexVar& value) {
REFLECT_MEMBER_START();
REFLECT_MEMBER2("id", value.id);
REFLECT_MEMBER2("usr", value.def.usr);
@ -211,20 +211,20 @@ void Reflect(TVisitor& visitor, IndexedVarDef& value) {
}
// IndexedFile
bool ReflectMemberStart(Writer& visitor, IndexedFile& value) {
// IndexFile
bool ReflectMemberStart(Writer& visitor, IndexFile& value) {
auto it = value.id_cache.usr_to_type_id.find("");
if (it != value.id_cache.usr_to_type_id.end()) {
value.Resolve(it->second)->def.short_name = "<fundamental>";
assert(value.Resolve(it->second)->uses.size() == 0);
}
value.version = IndexedFile::kCurrentVersion;
value.version = IndexFile::kCurrentVersion;
DefaultReflectMemberStart(visitor);
return true;
}
template<typename TVisitor>
void Reflect(TVisitor& visitor, IndexedFile& value) {
void Reflect(TVisitor& visitor, IndexFile& value) {
REFLECT_MEMBER_START();
if (!gTestOutputMode) {
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::PrettyWriter<rapidjson::StringBuffer> writer(output);
//Writer writer(output);
@ -259,13 +259,13 @@ std::string Serialize(IndexedFile& file) {
return output.GetString();
}
optional<IndexedFile> Deserialize(std::string path, std::string serialized) {
optional<IndexFile> Deserialize(std::string path, std::string serialized) {
rapidjson::Document reader;
reader.Parse(serialized.c_str());
if (reader.HasParseError())
return nullopt;
IndexedFile file(path);
IndexFile file(path);
Reflect(reader, file);
// Restore non-serialized state.

View File

@ -14,7 +14,7 @@ using std::experimental::nullopt;
using Reader = rapidjson::GenericValue<rapidjson::UTF8<>>;
using Writer = rapidjson::Writer<rapidjson::StringBuffer>;
struct IndexedFile;
struct IndexFile;
#define REFLECT_MEMBER_START() \
if (!ReflectMemberStart(visitor, value)) return
@ -206,7 +206,7 @@ void ReflectMember(Reader& visitor, const char* name, T& value) {
}
}
std::string Serialize(IndexedFile& file);
optional<IndexedFile> Deserialize(std::string path, std::string serialized);
std::string Serialize(IndexFile& file);
optional<IndexFile> Deserialize(std::string path, std::string serialized);
void SetTestOutputMode();

View File

@ -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 actual = Deserialize("--.cc", Serialize(*file)).value().ToString();
if (expected != actual) {
@ -103,7 +103,7 @@ std::string FindExpectedOutputForFilename(std::string filename, const std::unord
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) {
if (EndsWith(db->path, path))
return db.get();
@ -137,7 +137,7 @@ void RunTests() {
// Run test.
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,
path,
{
@ -184,7 +184,7 @@ void RunTests() {
const std::string& expected_output = entry.second;
// Get output from index operation.
IndexedFile* db = FindDbForPathEnding(expected_path, dbs);
IndexFile* db = FindDbForPathEnding(expected_path, dbs);
std::string actual_output = "{}";
if (db) {
VerifySerializeToFrom(db);
@ -227,6 +227,5 @@ void RunTests() {
}
// TODO: ctor/dtor, copy ctor
// TODO: Always pass IndexedFile by pointer, ie, search and remove all IndexedFile& refs.
// TODO: Rename IndexedFile to IndexFile
// TODO: Always pass IndexFile by pointer, ie, search and remove all IndexFile& refs.