mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-22 00:19:28 +00:00
misc chagnes
This commit is contained in:
parent
a37d402ce2
commit
05af433b5a
@ -71,7 +71,7 @@ bool HasOption(const std::unordered_map<std::string, std::string>& options, cons
|
|||||||
return options.find(option) != options.end();
|
return options.find(option) != options.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main2(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
std::unordered_map<std::string, std::string> options = ParseOptions(argc, argv);
|
std::unordered_map<std::string, std::string> options = ParseOptions(argc, argv);
|
||||||
|
|
||||||
if (argc == 1 || options.find("--help") != options.end()) {
|
if (argc == 1 || options.find("--help") != options.end()) {
|
||||||
@ -158,11 +158,13 @@ int main2(int argc, char** argv) {
|
|||||||
std::vector<CompilationEntry> entries = LoadCompilationEntriesFromDirectory(options["--project"]);
|
std::vector<CompilationEntry> entries = LoadCompilationEntriesFromDirectory(options["--project"]);
|
||||||
|
|
||||||
|
|
||||||
std::vector<IndexedFile> dbs;
|
|
||||||
for (const CompilationEntry& entry : entries) {
|
for (const CompilationEntry& entry : entries) {
|
||||||
std::cout << "Parsing " << entry.filename << std::endl;
|
std::cout << "Parsing " << entry.filename << std::endl;
|
||||||
//IndexedFile db = Parse(2, entry.filename, entry.args);
|
QueryableDatabase db;
|
||||||
//dbs.emplace_back(db);
|
IndexedFile file = Parse(entry.filename, entry.args);
|
||||||
|
|
||||||
|
IndexUpdate update(file);
|
||||||
|
db.ApplyIndexUpdate(&update);
|
||||||
//std::cout << db.ToString() << std::endl << std::endl;
|
//std::cout << db.ToString() << std::endl << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
66
indexer.cpp
66
indexer.cpp
@ -2,51 +2,51 @@
|
|||||||
|
|
||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
|
|
||||||
IndexedFile::IndexedFile(const std::string& path, IdCache* id_cache)
|
IndexedFile::IndexedFile(const std::string& path)
|
||||||
: path(path), id_cache(id_cache) {
|
: 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(IndexedTypeDef(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(IndexedFuncDef(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(IndexedVarDef(entry.second, entry.first));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize for const char*?
|
// TODO: Optimize for const char*?
|
||||||
TypeId IndexedFile::ToTypeId(const std::string& usr) {
|
TypeId IndexedFile::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;
|
||||||
|
|
||||||
TypeId id(types.size());
|
TypeId id(types.size());
|
||||||
types.push_back(IndexedTypeDef(id, usr));
|
types.push_back(IndexedTypeDef(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;
|
||||||
}
|
}
|
||||||
FuncId IndexedFile::ToFuncId(const std::string& usr) {
|
FuncId IndexedFile::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;
|
||||||
|
|
||||||
FuncId id(funcs.size());
|
FuncId id(funcs.size());
|
||||||
funcs.push_back(IndexedFuncDef(id, usr));
|
funcs.push_back(IndexedFuncDef(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;
|
||||||
}
|
}
|
||||||
VarId IndexedFile::ToVarId(const std::string& usr) {
|
VarId IndexedFile::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;
|
||||||
|
|
||||||
VarId id(vars.size());
|
VarId id(vars.size());
|
||||||
vars.push_back(IndexedVarDef(id, usr));
|
vars.push_back(IndexedVarDef(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +364,7 @@ void VisitDeclForTypeUsageVisitorHandler(clang::Cursor cursor, VisitDeclForTypeU
|
|||||||
|
|
||||||
if (param->is_interesting) {
|
if (param->is_interesting) {
|
||||||
IndexedTypeDef* ref_type_def = db->Resolve(ref_type_id);
|
IndexedTypeDef* ref_type_def = db->Resolve(ref_type_id);
|
||||||
Location loc = db->id_cache->Resolve(cursor, true /*interesting*/);
|
Location loc = db->id_cache.Resolve(cursor, true /*interesting*/);
|
||||||
ref_type_def->AddUsage(loc);
|
ref_type_def->AddUsage(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,7 +487,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
var_def->def.qualified_name = ns->QualifiedName(decl->semanticContainer, var_def->def.short_name);
|
var_def->def.qualified_name = ns->QualifiedName(decl->semanticContainer, var_def->def.short_name);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Location decl_loc = db->id_cache->Resolve(decl->loc, false /*interesting*/);
|
Location decl_loc = db->id_cache.Resolve(decl->loc, false /*interesting*/);
|
||||||
if (decl->isDefinition)
|
if (decl->isDefinition)
|
||||||
var_def->def.definition = decl_loc;
|
var_def->def.definition = decl_loc;
|
||||||
else
|
else
|
||||||
@ -533,7 +533,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
func_def->def.qualified_name = ns->QualifiedName(decl->semanticContainer, func_def->def.short_name);
|
func_def->def.qualified_name = ns->QualifiedName(decl->semanticContainer, func_def->def.short_name);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Location decl_loc = db->id_cache->Resolve(decl->loc, false /*interesting*/);
|
Location decl_loc = db->id_cache.Resolve(decl->loc, false /*interesting*/);
|
||||||
if (decl->isDefinition)
|
if (decl->isDefinition)
|
||||||
func_def->def.definition = decl_loc;
|
func_def->def.definition = decl_loc;
|
||||||
else
|
else
|
||||||
@ -650,7 +650,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
type_def->def.short_name = decl->entityInfo->name;
|
type_def->def.short_name = decl->entityInfo->name;
|
||||||
type_def->def.qualified_name = ns->QualifiedName(decl->semanticContainer, type_def->def.short_name);
|
type_def->def.qualified_name = ns->QualifiedName(decl->semanticContainer, type_def->def.short_name);
|
||||||
|
|
||||||
Location decl_loc = db->id_cache->Resolve(decl->loc, true /*interesting*/);
|
Location decl_loc = db->id_cache.Resolve(decl->loc, true /*interesting*/);
|
||||||
type_def->def.definition = decl_loc.WithInteresting(false);
|
type_def->def.definition = decl_loc.WithInteresting(false);
|
||||||
type_def->AddUsage(decl_loc);
|
type_def->AddUsage(decl_loc);
|
||||||
break;
|
break;
|
||||||
@ -684,7 +684,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
assert(decl->isDefinition);
|
assert(decl->isDefinition);
|
||||||
Location decl_loc = db->id_cache->Resolve(decl->loc, true /*interesting*/);
|
Location decl_loc = db->id_cache.Resolve(decl->loc, true /*interesting*/);
|
||||||
type_def->def.definition = decl_loc.WithInteresting(false);
|
type_def->def.definition = decl_loc.WithInteresting(false);
|
||||||
type_def->AddUsage(decl_loc);
|
type_def->AddUsage(decl_loc);
|
||||||
|
|
||||||
@ -713,7 +713,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
std::cout << "!! Unhandled indexDeclaration: " << clang::Cursor(decl->cursor).ToString() << " at " << db->id_cache->Resolve(decl->loc, false /*interesting*/).ToString() << std::endl;
|
std::cout << "!! Unhandled indexDeclaration: " << clang::Cursor(decl->cursor).ToString() << " at " << db->id_cache.Resolve(decl->loc, false /*interesting*/).ToString() << std::endl;
|
||||||
std::cout << " entityInfo->kind = " << decl->entityInfo->kind << std::endl;
|
std::cout << " entityInfo->kind = " << decl->entityInfo->kind << std::endl;
|
||||||
std::cout << " entityInfo->USR = " << decl->entityInfo->USR << std::endl;
|
std::cout << " entityInfo->USR = " << decl->entityInfo->USR << std::endl;
|
||||||
if (decl->declAsContainer)
|
if (decl->declAsContainer)
|
||||||
@ -749,7 +749,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
|
|||||||
{
|
{
|
||||||
VarId var_id = db->ToVarId(ref->referencedEntity->cursor);
|
VarId var_id = db->ToVarId(ref->referencedEntity->cursor);
|
||||||
IndexedVarDef* var_def = db->Resolve(var_id);
|
IndexedVarDef* var_def = db->Resolve(var_id);
|
||||||
var_def->uses.push_back(db->id_cache->Resolve(ref->loc, false /*interesting*/));
|
var_def->uses.push_back(db->id_cache.Resolve(ref->loc, false /*interesting*/));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,7 +771,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
|
|||||||
|
|
||||||
// Don't report duplicate usages.
|
// Don't report duplicate usages.
|
||||||
// TODO: search full history?
|
// TODO: search full history?
|
||||||
Location loc = db->id_cache->Resolve(ref->loc, false /*interesting*/);
|
Location loc = db->id_cache.Resolve(ref->loc, false /*interesting*/);
|
||||||
if (param->last_func_usage_location == loc) break;
|
if (param->last_func_usage_location == loc) break;
|
||||||
param->last_func_usage_location = loc;
|
param->last_func_usage_location = loc;
|
||||||
|
|
||||||
@ -799,8 +799,8 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
|
|||||||
if (ref->referencedEntity->kind == CXIdxEntity_CXXConstructor ||
|
if (ref->referencedEntity->kind == CXIdxEntity_CXXConstructor ||
|
||||||
ref->referencedEntity->kind == CXIdxEntity_CXXDestructor) {
|
ref->referencedEntity->kind == CXIdxEntity_CXXDestructor) {
|
||||||
|
|
||||||
Location parent_loc = db->id_cache->Resolve(ref->parentEntity->cursor, true /*interesting*/);
|
Location parent_loc = db->id_cache.Resolve(ref->parentEntity->cursor, true /*interesting*/);
|
||||||
Location our_loc = db->id_cache->Resolve(ref->loc, true /*is_interesting*/);
|
Location our_loc = db->id_cache.Resolve(ref->loc, true /*is_interesting*/);
|
||||||
if (!parent_loc.IsEqualTo(our_loc)) {
|
if (!parent_loc.IsEqualTo(our_loc)) {
|
||||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
IndexedFuncDef* called_def = db->Resolve(called_id);
|
||||||
assert(called_def->def.declaring_type.has_value());
|
assert(called_def->def.declaring_type.has_value());
|
||||||
@ -825,7 +825,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
|
|||||||
// defs here so we will output usages/etc.
|
// defs here so we will output usages/etc.
|
||||||
if (referenced_def->is_bad_def) {
|
if (referenced_def->is_bad_def) {
|
||||||
bool is_system_def = clang_Location_isInSystemHeader(clang_getCursorLocation(ref->referencedEntity->cursor));
|
bool is_system_def = clang_Location_isInSystemHeader(clang_getCursorLocation(ref->referencedEntity->cursor));
|
||||||
Location loc = db->id_cache->Resolve(ref->referencedEntity->cursor, false /*interesting*/);
|
Location loc = db->id_cache.Resolve(ref->referencedEntity->cursor, false /*interesting*/);
|
||||||
if (!is_system_def && loc.raw_file_id != -1)
|
if (!is_system_def && loc.raw_file_id != -1)
|
||||||
referenced_def->is_bad_def = false;
|
referenced_def->is_bad_def = false;
|
||||||
}
|
}
|
||||||
@ -844,16 +844,16 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
|
|||||||
// Foo f;
|
// Foo f;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
referenced_def->AddUsage(db->id_cache->Resolve(ref->loc, false /*interesting*/));
|
referenced_def->AddUsage(db->id_cache.Resolve(ref->loc, false /*interesting*/));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
std::cout << "!! Unhandled indexEntityReference: " << cursor.ToString() << " at " << db->id_cache->Resolve(ref->loc, false /*interesting*/).ToString() << std::endl;
|
std::cout << "!! Unhandled indexEntityReference: " << cursor.ToString() << " at " << db->id_cache.Resolve(ref->loc, false /*interesting*/).ToString() << std::endl;
|
||||||
std::cout << " ref->referencedEntity->kind = " << ref->referencedEntity->kind << std::endl;
|
std::cout << " ref->referencedEntity->kind = " << ref->referencedEntity->kind << std::endl;
|
||||||
if (ref->parentEntity)
|
if (ref->parentEntity)
|
||||||
std::cout << " ref->parentEntity->kind = " << ref->parentEntity->kind << std::endl;
|
std::cout << " ref->parentEntity->kind = " << ref->parentEntity->kind << std::endl;
|
||||||
std::cout << " ref->loc = " << db->id_cache->Resolve(ref->loc, false /*interesting*/).ToString() << std::endl;
|
std::cout << " ref->loc = " << db->id_cache.Resolve(ref->loc, false /*interesting*/).ToString() << std::endl;
|
||||||
std::cout << " ref->kind = " << ref->kind << std::endl;
|
std::cout << " ref->kind = " << ref->kind << std::endl;
|
||||||
if (ref->parentEntity)
|
if (ref->parentEntity)
|
||||||
std::cout << " parentEntity = " << clang::Cursor(ref->parentEntity->cursor).ToString() << std::endl;
|
std::cout << " parentEntity = " << clang::Cursor(ref->parentEntity->cursor).ToString() << std::endl;
|
||||||
@ -866,7 +866,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IndexedFile Parse(IdCache* id_cache, std::string filename, std::vector<std::string> args, bool dump_ast) {
|
IndexedFile Parse(std::string filename, std::vector<std::string> args, bool dump_ast) {
|
||||||
clang::Index index(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/);
|
clang::Index index(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/);
|
||||||
clang::TranslationUnit tu(index, filename, args);
|
clang::TranslationUnit tu(index, filename, args);
|
||||||
|
|
||||||
@ -889,7 +889,7 @@ IndexedFile Parse(IdCache* id_cache, std::string filename, std::vector<std::stri
|
|||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
IndexedFile db(filename, id_cache);
|
IndexedFile db(filename);
|
||||||
NamespaceHelper ns;
|
NamespaceHelper ns;
|
||||||
IndexParam param(&db, &ns);
|
IndexParam param(&db, &ns);
|
||||||
clang_indexTranslationUnit(index_action, ¶m, callbacks, sizeof(callbacks),
|
clang_indexTranslationUnit(index_action, ¶m, callbacks, sizeof(callbacks),
|
||||||
|
@ -473,7 +473,7 @@ struct IdCache {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct IndexedFile {
|
struct IndexedFile {
|
||||||
IdCache* id_cache;
|
IdCache id_cache;
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ struct IndexedFile {
|
|||||||
std::vector<IndexedFuncDef> funcs;
|
std::vector<IndexedFuncDef> funcs;
|
||||||
std::vector<IndexedVarDef> vars;
|
std::vector<IndexedVarDef> vars;
|
||||||
|
|
||||||
IndexedFile(const std::string& path, IdCache* id_cache);
|
IndexedFile(const std::string& path);
|
||||||
|
|
||||||
TypeId ToTypeId(const std::string& usr);
|
TypeId ToTypeId(const std::string& usr);
|
||||||
FuncId ToFuncId(const std::string& usr);
|
FuncId ToFuncId(const std::string& usr);
|
||||||
@ -498,4 +498,4 @@ struct IndexedFile {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
IndexedFile Parse(IdCache* id_cache, std::string filename, std::vector<std::string> args, bool dump_ast = false);
|
IndexedFile Parse(std::string filename, std::vector<std::string> args, bool dump_ast = false);
|
78
query.cc
78
query.cc
@ -37,42 +37,42 @@ std::vector<Out> Transform(const std::vector<In>& input, std::function<Out(In)>
|
|||||||
result.push_back(op(in));
|
result.push_back(op(in));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Usr MapIdToUsr(IdCache& id_cache, const TypeId& id) {
|
Usr MapIdToUsr(const IdCache& id_cache, const TypeId& id) {
|
||||||
return id_cache.type_id_to_usr[id];
|
return id_cache.type_id_to_usr.find(id)->second;
|
||||||
}
|
}
|
||||||
Usr MapIdToUsr(IdCache& id_cache, const FuncId& id) {
|
Usr MapIdToUsr(const IdCache& id_cache, const FuncId& id) {
|
||||||
return id_cache.func_id_to_usr[id];
|
return id_cache.func_id_to_usr.find(id)->second;
|
||||||
}
|
}
|
||||||
Usr MapIdToUsr(IdCache& id_cache, const VarId& id) {
|
Usr MapIdToUsr(const IdCache& id_cache, const VarId& id) {
|
||||||
return id_cache.var_id_to_usr[id];
|
return id_cache.var_id_to_usr.find(id)->second;
|
||||||
}
|
}
|
||||||
QueryableLocation MapIdToUsr(IdCache& id_cache, const Location& id) {
|
QueryableLocation MapIdToUsr(const IdCache& id_cache, const Location& id) {
|
||||||
return QueryableLocation(id_cache.file_id_to_file_path[id.file_id()], id.line, id.column, id.interesting);
|
return QueryableLocation(id_cache.file_id_to_file_path.find(id.file_id())->second, id.line, id.column, id.interesting);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Usr> MapIdToUsr(IdCache& id_cache, const std::vector<TypeId>& ids) {
|
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<TypeId>& ids) {
|
||||||
return Transform<TypeId, Usr>(ids, [&](TypeId id) { return id_cache.type_id_to_usr[id]; });
|
return Transform<TypeId, Usr>(ids, [&](TypeId id) { return id_cache.type_id_to_usr.find(id)->second; });
|
||||||
}
|
}
|
||||||
std::vector<Usr> MapIdToUsr(IdCache& id_cache, const std::vector<FuncId>& ids) {
|
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<FuncId>& ids) {
|
||||||
return Transform<FuncId, Usr>(ids, [&](FuncId id) { return id_cache.func_id_to_usr[id]; });
|
return Transform<FuncId, Usr>(ids, [&](FuncId id) { return id_cache.func_id_to_usr.find(id)->second; });
|
||||||
}
|
}
|
||||||
std::vector<Usr> MapIdToUsr(IdCache& id_cache, const std::vector<VarId>& ids) {
|
std::vector<Usr> MapIdToUsr(const IdCache& id_cache, const std::vector<VarId>& ids) {
|
||||||
return Transform<VarId, Usr>(ids, [&](VarId id) { return id_cache.var_id_to_usr[id]; });
|
return Transform<VarId, Usr>(ids, [&](VarId id) { return id_cache.var_id_to_usr.find(id)->second; });
|
||||||
}
|
}
|
||||||
std::vector<UsrRef> MapIdToUsr(IdCache& id_cache, const std::vector<FuncRef>& ids) {
|
std::vector<UsrRef> MapIdToUsr(const IdCache& id_cache, const std::vector<FuncRef>& ids) {
|
||||||
return Transform<FuncRef, UsrRef>(ids, [&](FuncRef ref) {
|
return Transform<FuncRef, UsrRef>(ids, [&](FuncRef ref) {
|
||||||
UsrRef result;
|
UsrRef result;
|
||||||
result.loc = MapIdToUsr(id_cache, ref.loc);
|
result.loc = MapIdToUsr(id_cache, ref.loc);
|
||||||
result.usr = id_cache.func_id_to_usr[ref.id];
|
result.usr = id_cache.func_id_to_usr.find(ref.id)->second;
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
std::vector<QueryableLocation> MapIdToUsr(IdCache& id_cache, const std::vector<Location>& ids) {
|
std::vector<QueryableLocation> MapIdToUsr(const IdCache& id_cache, const std::vector<Location>& ids) {
|
||||||
return Transform<Location, QueryableLocation>(ids, [&](Location id) {
|
return Transform<Location, QueryableLocation>(ids, [&](Location id) {
|
||||||
return QueryableLocation(id_cache.file_id_to_file_path[id.file_id()], id.line, id.column, id.interesting);
|
return QueryableLocation(id_cache.file_id_to_file_path.find(id.file_id())->second, id.line, id.column, id.interesting);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
QueryableTypeDef::DefUpdate MapIdToUsr(IdCache& id_cache, const TypeDefDefinitionData<>& def) {
|
QueryableTypeDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const TypeDefDefinitionData<>& def) {
|
||||||
QueryableTypeDef::DefUpdate result(def.usr);
|
QueryableTypeDef::DefUpdate result(def.usr);
|
||||||
if (result.definition)
|
if (result.definition)
|
||||||
result.definition = MapIdToUsr(id_cache, def.definition.value());
|
result.definition = MapIdToUsr(id_cache, def.definition.value());
|
||||||
@ -84,7 +84,7 @@ QueryableTypeDef::DefUpdate MapIdToUsr(IdCache& id_cache, const TypeDefDefinitio
|
|||||||
result.vars = MapIdToUsr(id_cache, def.vars);
|
result.vars = MapIdToUsr(id_cache, def.vars);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
QueryableFuncDef::DefUpdate MapIdToUsr(IdCache& id_cache, const FuncDefDefinitionData<>& def) {
|
QueryableFuncDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const FuncDefDefinitionData<>& def) {
|
||||||
QueryableFuncDef::DefUpdate result(def.usr);
|
QueryableFuncDef::DefUpdate result(def.usr);
|
||||||
if (result.definition)
|
if (result.definition)
|
||||||
result.definition = MapIdToUsr(id_cache, def.definition.value());
|
result.definition = MapIdToUsr(id_cache, def.definition.value());
|
||||||
@ -96,7 +96,7 @@ QueryableFuncDef::DefUpdate MapIdToUsr(IdCache& id_cache, const FuncDefDefinitio
|
|||||||
result.callees = MapIdToUsr(id_cache, def.callees);
|
result.callees = MapIdToUsr(id_cache, def.callees);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
QueryableVarDef::DefUpdate MapIdToUsr(IdCache& id_cache, const VarDefDefinitionData<>& def) {
|
QueryableVarDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const VarDefDefinitionData<>& def) {
|
||||||
QueryableVarDef::DefUpdate result(def.usr);
|
QueryableVarDef::DefUpdate result(def.usr);
|
||||||
if (result.declaration)
|
if (result.declaration)
|
||||||
result.declaration = MapIdToUsr(id_cache, def.declaration.value());
|
result.declaration = MapIdToUsr(id_cache, def.declaration.value());
|
||||||
@ -113,7 +113,7 @@ QueryableFile::QueryableFile(const IndexedFile& indexed)
|
|||||||
: file_id(indexed.path) {
|
: file_id(indexed.path) {
|
||||||
|
|
||||||
auto add_outline = [this, &indexed](Usr usr, Location location) {
|
auto add_outline = [this, &indexed](Usr usr, Location location) {
|
||||||
outline.push_back(UsrRef(usr, MapIdToUsr(*indexed.id_cache, location)));
|
outline.push_back(UsrRef(usr, MapIdToUsr(indexed.id_cache, location)));
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const IndexedTypeDef& def : indexed.types) {
|
for (const IndexedTypeDef& def : indexed.types) {
|
||||||
@ -336,11 +336,11 @@ void CompareGroups(
|
|||||||
IndexUpdate::IndexUpdate(IndexedFile& file) {
|
IndexUpdate::IndexUpdate(IndexedFile& file) {
|
||||||
files_added.push_back(QueryableFile(file));
|
files_added.push_back(QueryableFile(file));
|
||||||
for (const IndexedTypeDef& def : file.types)
|
for (const IndexedTypeDef& def : file.types)
|
||||||
types_added.push_back(QueryableTypeDef(*file.id_cache, def));
|
types_added.push_back(QueryableTypeDef(file.id_cache, def));
|
||||||
for (const IndexedFuncDef& def : file.funcs)
|
for (const IndexedFuncDef& def : file.funcs)
|
||||||
funcs_added.push_back(QueryableFuncDef(*file.id_cache, def));
|
funcs_added.push_back(QueryableFuncDef(file.id_cache, def));
|
||||||
for (const IndexedVarDef& def : file.vars)
|
for (const IndexedVarDef& def : file.vars)
|
||||||
vars_added.push_back(QueryableVarDef(*file.id_cache, def));
|
vars_added.push_back(QueryableVarDef(file.id_cache, def));
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file) {
|
IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file) {
|
||||||
@ -353,8 +353,8 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
/* Check for changes. */ \
|
/* Check for changes. */ \
|
||||||
std::vector<type> removed, added; \
|
std::vector<type> removed, added; \
|
||||||
bool did_add = ComputeDifferenceForUpdate( \
|
bool did_add = ComputeDifferenceForUpdate( \
|
||||||
MapIdToUsr(*previous_file.id_cache, JOIN(previous_def->, index_name)), \
|
MapIdToUsr(previous_file.id_cache, JOIN(previous_def->, index_name)), \
|
||||||
MapIdToUsr(*current_file.id_cache, JOIN(current_def->, index_name)), \
|
MapIdToUsr(current_file.id_cache, JOIN(current_def->, index_name)), \
|
||||||
&removed, &added); \
|
&removed, &added); \
|
||||||
if (did_add) {\
|
if (did_add) {\
|
||||||
std::cout << "Adding mergeable update on " << current_def->def.short_name << " (" << current_def->def.usr << ") for field " << #index_name << std::endl; \
|
std::cout << "Adding mergeable update on " << current_def->def.short_name << " (" << current_def->def.usr << ") for field " << #index_name << std::endl; \
|
||||||
@ -387,11 +387,11 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
types_removed.push_back(def->def.usr);
|
types_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_file](IndexedTypeDef* def) {
|
/*onAdded:*/[this, ¤t_file](IndexedTypeDef* def) {
|
||||||
types_added.push_back(QueryableTypeDef(*current_file.id_cache, *def));
|
types_added.push_back(QueryableTypeDef(current_file.id_cache, *def));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
|
/*onFound:*/[this, &previous_file, ¤t_file](IndexedTypeDef* previous_def, IndexedTypeDef* current_def) {
|
||||||
QueryableTypeDef::DefUpdate previous_remapped_def = MapIdToUsr(*previous_file.id_cache, previous_def->def);
|
QueryableTypeDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
||||||
QueryableTypeDef::DefUpdate current_remapped_def = MapIdToUsr(*current_file.id_cache, current_def->def);
|
QueryableTypeDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
||||||
if (previous_remapped_def != current_remapped_def)
|
if (previous_remapped_def != current_remapped_def)
|
||||||
types_def_changed.push_back(current_remapped_def);
|
types_def_changed.push_back(current_remapped_def);
|
||||||
|
|
||||||
@ -405,11 +405,11 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
funcs_removed.push_back(def->def.usr);
|
funcs_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_file](IndexedFuncDef* def) {
|
/*onAdded:*/[this, ¤t_file](IndexedFuncDef* def) {
|
||||||
funcs_added.push_back(QueryableFuncDef(*current_file.id_cache, *def));
|
funcs_added.push_back(QueryableFuncDef(current_file.id_cache, *def));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
|
/*onFound:*/[this, &previous_file, ¤t_file](IndexedFuncDef* previous_def, IndexedFuncDef* current_def) {
|
||||||
QueryableFuncDef::DefUpdate previous_remapped_def = MapIdToUsr(*previous_file.id_cache, previous_def->def);
|
QueryableFuncDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
||||||
QueryableFuncDef::DefUpdate current_remapped_def = MapIdToUsr(*current_file.id_cache, current_def->def);
|
QueryableFuncDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
||||||
if (previous_remapped_def != current_remapped_def)
|
if (previous_remapped_def != current_remapped_def)
|
||||||
funcs_def_changed.push_back(current_remapped_def);
|
funcs_def_changed.push_back(current_remapped_def);
|
||||||
|
|
||||||
@ -425,11 +425,11 @@ IndexUpdate::IndexUpdate(IndexedFile& previous_file, IndexedFile& current_file)
|
|||||||
vars_removed.push_back(def->def.usr);
|
vars_removed.push_back(def->def.usr);
|
||||||
},
|
},
|
||||||
/*onAdded:*/[this, ¤t_file](IndexedVarDef* def) {
|
/*onAdded:*/[this, ¤t_file](IndexedVarDef* def) {
|
||||||
vars_added.push_back(QueryableVarDef(*current_file.id_cache, *def));
|
vars_added.push_back(QueryableVarDef(current_file.id_cache, *def));
|
||||||
},
|
},
|
||||||
/*onFound:*/[this, &previous_file, ¤t_file](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
|
/*onFound:*/[this, &previous_file, ¤t_file](IndexedVarDef* previous_def, IndexedVarDef* current_def) {
|
||||||
QueryableVarDef::DefUpdate previous_remapped_def = MapIdToUsr(*previous_file.id_cache, previous_def->def);
|
QueryableVarDef::DefUpdate previous_remapped_def = MapIdToUsr(previous_file.id_cache, previous_def->def);
|
||||||
QueryableVarDef::DefUpdate current_remapped_def = MapIdToUsr(*current_file.id_cache, current_def->def);
|
QueryableVarDef::DefUpdate current_remapped_def = MapIdToUsr(current_file.id_cache, current_def->def);
|
||||||
if (previous_remapped_def != current_remapped_def)
|
if (previous_remapped_def != current_remapped_def)
|
||||||
vars_def_changed.push_back(current_remapped_def);
|
vars_def_changed.push_back(current_remapped_def);
|
||||||
|
|
||||||
@ -619,13 +619,11 @@ void QueryableDatabase::ApplyIndexUpdate(IndexUpdate* update) {
|
|||||||
|
|
||||||
|
|
||||||
int main233(int argc, char** argv) {
|
int main233(int argc, char** argv) {
|
||||||
IdCache id_cache;
|
IndexedFile indexed_file_a = Parse("full_tests/index_delta/a_v0.cc", {});
|
||||||
|
|
||||||
IndexedFile indexed_file_a = Parse(&id_cache, "full_tests/index_delta/a_v0.cc", {});
|
|
||||||
std::cout << indexed_file_a.ToString() << std::endl;
|
std::cout << indexed_file_a.ToString() << std::endl;
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
IndexedFile indexed_file_b = Parse(&id_cache, "full_tests/index_delta/a_v1.cc", {});
|
IndexedFile indexed_file_b = Parse("full_tests/index_delta/a_v1.cc", {});
|
||||||
std::cout << indexed_file_b.ToString() << std::endl;
|
std::cout << indexed_file_b.ToString() << std::endl;
|
||||||
// TODO: We don't need to do ID remapping when computting a diff. Well, we need to do it for the IndexUpdate.
|
// TODO: We don't need to do ID remapping when computting a diff. Well, we need to do it for the IndexUpdate.
|
||||||
IndexUpdate import(indexed_file_a);
|
IndexUpdate import(indexed_file_a);
|
||||||
|
@ -87,8 +87,8 @@ void Serialize(Writer& writer, const char* key, uint64_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Serialize(Writer& writer, IndexedFile* file) {
|
void Serialize(Writer& writer, IndexedFile* file) {
|
||||||
auto it = file->id_cache->usr_to_type_id.find("");
|
auto it = file->id_cache.usr_to_type_id.find("");
|
||||||
if (it != file->id_cache->usr_to_type_id.end()) {
|
if (it != file->id_cache.usr_to_type_id.end()) {
|
||||||
file->Resolve(it->second)->def.short_name = "<fundamental>";
|
file->Resolve(it->second)->def.short_name = "<fundamental>";
|
||||||
assert(file->Resolve(it->second)->uses.size() == 0);
|
assert(file->Resolve(it->second)->uses.size() == 0);
|
||||||
}
|
}
|
||||||
|
5
test.cc
5
test.cc
@ -90,7 +90,7 @@ void WriteToFile(const std::string& filename, const std::string& content) {
|
|||||||
file << content;
|
file << content;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main2222222(int argc, char** argv) {
|
||||||
// TODO: Assert that we need to be on clang >= 3.9.1
|
// TODO: Assert that we need to be on clang >= 3.9.1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -127,8 +127,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
// Run test.
|
// Run test.
|
||||||
std::cout << "[START] " << path << std::endl;
|
std::cout << "[START] " << path << std::endl;
|
||||||
IdCache id_cache;
|
IndexedFile db = Parse(path, {}, true /*dump_ast*/);
|
||||||
IndexedFile db = Parse(&id_cache, path, {}, true /*dump_ast*/);
|
|
||||||
std::string actual_output = db.ToString();
|
std::string actual_output = db.ToString();
|
||||||
|
|
||||||
//WriteToFile("output.json", actual_output);
|
//WriteToFile("output.json", actual_output);
|
||||||
|
Loading…
Reference in New Issue
Block a user