This commit is contained in:
Jacob Dufault 2017-02-25 17:08:05 -08:00
parent b7d9a0f815
commit 243ed8dfa5
5 changed files with 41 additions and 23 deletions

View File

@ -87,9 +87,6 @@ IndexedTypeDef::IndexedTypeDef(TypeId id, const std::string& usr) : def(id, usr)
}
void IndexedTypeDef::AddUsage(Location loc, bool insert_if_not_present) {
if (is_system_def)
return;
for (int i = uses.size() - 1; i >= 0; --i) {
if (uses[i].IsEqualTo(loc)) {
if (loc.interesting)
@ -435,7 +432,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
VarId var_id = db->ToVarId(decl->entityInfo->USR);
IndexedVarDef* var_def = db->Resolve(var_id);
var_def->is_system_def = is_system_def;
var_def->is_bad_def = is_system_def;
// TODO: Eventually run with this if. Right now I want to iron out bugs this may shadow.
// TODO: Verify this gets called multiple times
@ -482,7 +479,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
FuncId func_id = db->ToFuncId(decl->entityInfo->USR);
IndexedFuncDef* func_def = db->Resolve(func_id);
func_def->is_system_def = is_system_def;
func_def->is_bad_def = is_system_def;
// TODO: Eventually run with this if. Right now I want to iron out bugs this may shadow.
//if (!decl->isRedeclaration) {
@ -599,7 +596,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
TypeId type_id = db->ToTypeId(decl->entityInfo->USR);
IndexedTypeDef* type_def = db->Resolve(type_id);
type_def->is_system_def = is_system_def;
type_def->is_bad_def = is_system_def;
if (alias_of)
type_def->def.alias_of = alias_of.value();
@ -621,7 +618,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
TypeId type_id = db->ToTypeId(decl->entityInfo->USR);
IndexedTypeDef* type_def = db->Resolve(type_id);
type_def->is_system_def = is_system_def;
type_def->is_bad_def = is_system_def;
// TODO: Eventually run with this if. Right now I want to iron out bugs this may shadow.
// TODO: For type section, verify if this ever runs for non definitions?
@ -778,6 +775,14 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
TypeId referenced_id = db->ToTypeId(ref->referencedEntity->USR);
IndexedTypeDef* referenced_def = db->Resolve(referenced_id);
// We will not get a declaration visit for forward declared types. Try to mark them as non-bad
// defs here so we will output usages/etc.
if (referenced_def->is_bad_def) {
bool is_system_def = clang_Location_isInSystemHeader(clang_getCursorLocation(ref->referencedEntity->cursor));
Location loc = db->file_db->Resolve(ref->referencedEntity->cursor, false /*interesting*/);
if (!is_system_def && loc.raw_file_id != -1)
referenced_def->is_bad_def = false;
}
//
// The following will generate two TypeRefs to Foo, both located at the
// same spot (line 3, column 3). One of the parents will be set to
@ -942,7 +947,7 @@ void WriteToFile(const std::string& filename, const std::string& content) {
file << content;
}
int main(int argc, char** argv) {
int main55555(int argc, char** argv) {
// TODO: Assert that we need to be on clang >= 3.9.1
/*
@ -956,7 +961,7 @@ int main(int argc, char** argv) {
DUMP_AST = false;
for (std::string path : GetFilesInFolder("tests")) {
//if (path != "tests/declaration_vs_definition/class_member_static.cc") continue;
//if (path != "tests/usage/type_usage_declare_field.cc") continue;
//if (path != "tests/enums/enum_class_decl.cc") continue;
//if (path != "tests/constructors/constructor.cc") continue;
//if (path == "tests/constructors/destructor.cc") continue;

View File

@ -225,7 +225,7 @@ struct FileDb {
unsigned int line, column, offset;
clang_getSpellingLocation(cx_loc, &file, &line, &column, &offset);
FileId file_id;
FileId file_id(-1, -1);
if (file != nullptr) {
std::string path = clang::ToString(clang_getFileName(file));
@ -356,7 +356,7 @@ struct IndexedTypeDef {
// NOTE: Do not insert directly! Use AddUsage instead.
std::vector<Location> uses;
bool is_system_def = false;
bool is_bad_def = true;
IndexedTypeDef(TypeId id, const std::string& usr);
void AddUsage(Location loc, bool insert_if_not_present = true);
@ -437,7 +437,7 @@ struct IndexedFuncDef {
// All usages. For interesting usages, see callees.
std::vector<Location> uses;
bool is_system_def = false;
bool is_bad_def = true;
IndexedFuncDef(FuncId id, const std::string& usr) : def(id, usr) {
assert(usr.size() > 0);
@ -500,7 +500,7 @@ struct IndexedVarDef {
// Usages.
std::vector<Location> uses;
bool is_system_def = false;
bool is_bad_def = true;
IndexedVarDef(VarId id, const std::string& usr) : def(id, usr) {
assert(usr.size() > 0);

View File

@ -38,6 +38,9 @@ struct IdMap {
template<typename TId>
inline TId GenericRemap(GroupMap<TId>* map, int64_t* next_id, TId from) {
if (from.group == target_group)
return from;
// PERF: If this function is a hot-spot we can pull the group computation
// out, ie,
//
@ -89,6 +92,11 @@ struct IdMap {
std::vector<TId> result;
result.reserve(from.size());
for (TId id : from) {
if (id.group == target_group) {
result.push_back(id);
continue;
}
// Lookup the id from the group or add it.
auto it = group.find(id);
if (it == group.end()) {
@ -489,7 +497,13 @@ void CompareGroups(
while (prev_it != previous_data.end() && curr_it != current_data.end()) {
// same id
if (prev_it->def.id == curr_it->def.id) {
if (!prev_it->is_bad_def && !curr_it->is_bad_def)
on_found(&*prev_it, &*curr_it);
else if (prev_it->is_bad_def)
on_added(&*curr_it);
else if (curr_it->is_bad_def)
on_removed(&*curr_it);
++prev_it;
++curr_it;
}
@ -606,7 +620,7 @@ void ApplyIndexUpdate(const IndexUpdate& update, QueryableDatabase* db) {
int ma333in(int argc, char** argv) {
int main(int argc, char** argv) {
// TODO: Unify UserToIdResolver and FileDb
UsrToIdResolver usr_to_id(1);
FileDb file_db(1);

View File

@ -101,7 +101,8 @@ void Serialize(Writer& writer, IndexedFile* file) {
writer.Key("types");
writer.StartArray();
for (IndexedTypeDef& def : file->types) {
if (def.is_system_def) continue;
if (def.is_bad_def)
continue;
writer.StartObject();
SERIALIZE("id", def.id);
@ -124,7 +125,8 @@ void Serialize(Writer& writer, IndexedFile* file) {
writer.Key("functions");
writer.StartArray();
for (IndexedFuncDef& def : file->funcs) {
if (def.is_system_def) continue;
if (def.is_bad_def)
continue;
writer.StartObject();
SERIALIZE("id", def.id);
@ -148,7 +150,8 @@ void Serialize(Writer& writer, IndexedFile* file) {
writer.Key("variables");
writer.StartArray();
for (IndexedVarDef& def : file->vars) {
if (def.is_system_def) continue;
if (def.is_bad_def)
continue;
writer.StartObject();
SERIALIZE("id", def.id);

View File

@ -49,10 +49,6 @@ OUTPUT:
"parents": [1],
"derived": [5],
"uses": ["*1:11:7", "*1:13:56"]
}, {
"id": 4,
"usr": "c:class_inherit_templated_parent.cc@154",
"uses": ["*1:11:24"]
}, {
"id": 5,
"usr": "c:@S@Derived",