2017-02-23 09:23:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-02-26 08:11:47 +00:00
|
|
|
#include "indexer.h"
|
2017-03-07 09:32:29 +00:00
|
|
|
#include "serializer.h"
|
2017-02-26 08:11:47 +00:00
|
|
|
|
2017-04-19 05:45:37 +00:00
|
|
|
#include <sparsepp/spp.h>
|
2017-04-08 01:35:12 +00:00
|
|
|
|
2017-04-17 20:40:50 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
struct QueryFile;
|
|
|
|
struct QueryType;
|
|
|
|
struct QueryFunc;
|
|
|
|
struct QueryVar;
|
|
|
|
struct QueryDatabase;
|
2017-04-07 06:57:26 +00:00
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
using QueryFileId = Id<QueryFile>;
|
|
|
|
using QueryTypeId = Id<QueryType>;
|
|
|
|
using QueryFuncId = Id<QueryFunc>;
|
|
|
|
using QueryVarId = Id<QueryVar>;
|
2017-04-07 06:57:26 +00:00
|
|
|
|
2017-04-07 08:01:58 +00:00
|
|
|
struct IdMap;
|
2017-04-07 07:30:08 +00:00
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
struct QueryLocation {
|
2017-04-08 07:21:00 +00:00
|
|
|
QueryFileId path;
|
2017-04-07 06:20:30 +00:00
|
|
|
Range range;
|
2017-04-08 00:34:13 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
QueryLocation() {} // Do not use, needed for reflect.
|
|
|
|
QueryLocation(QueryFileId path, Range range) : path(path), range(range) {}
|
2017-04-07 06:20:30 +00:00
|
|
|
|
2017-05-21 23:22:00 +00:00
|
|
|
QueryLocation OffsetStartColumn(int16_t offset) const {
|
2017-04-15 05:41:35 +00:00
|
|
|
QueryLocation result = *this;
|
2017-04-07 06:20:30 +00:00
|
|
|
result.range.start.column += offset;
|
|
|
|
return result;
|
2017-04-03 01:34:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 06:31:43 +00:00
|
|
|
bool HasValue() const { return range.HasValue(); }
|
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
bool operator==(const QueryLocation& other) const {
|
2017-09-22 01:14:57 +00:00
|
|
|
return path == other.path && range == other.range;
|
|
|
|
}
|
|
|
|
bool operator!=(const QueryLocation& other) const {
|
|
|
|
return !(*this == other);
|
2017-02-27 02:03:14 +00:00
|
|
|
}
|
2017-04-15 05:41:35 +00:00
|
|
|
bool operator<(const QueryLocation& o) const {
|
2018-01-15 18:08:03 +00:00
|
|
|
if (path != o.path)
|
|
|
|
return path < o.path;
|
|
|
|
return range < o.range;
|
2017-04-05 08:06:18 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-19 07:02:01 +00:00
|
|
|
MAKE_REFLECT_STRUCT(QueryLocation, path, range);
|
2017-07-19 07:12:04 +00:00
|
|
|
MAKE_HASHABLE(QueryLocation, t.path, t.range);
|
2017-04-05 08:06:18 +00:00
|
|
|
|
2017-11-17 14:26:25 +00:00
|
|
|
namespace std {
|
2017-11-18 17:29:48 +00:00
|
|
|
template <>
|
|
|
|
struct hash<::SymbolKind> {
|
|
|
|
size_t operator()(const ::SymbolKind& instance) const {
|
2017-11-17 14:26:25 +00:00
|
|
|
return std::hash<int>()(static_cast<int>(instance));
|
|
|
|
}
|
|
|
|
};
|
2017-11-18 17:29:48 +00:00
|
|
|
} // namespace std
|
2017-11-17 14:26:25 +00:00
|
|
|
|
2017-04-08 07:11:57 +00:00
|
|
|
struct SymbolIdx {
|
|
|
|
SymbolKind kind;
|
|
|
|
size_t idx;
|
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
SymbolIdx()
|
|
|
|
: kind(SymbolKind::Invalid),
|
|
|
|
idx((size_t)-1) {} // Default ctor needed by stdlib. Do not use.
|
2017-04-08 07:11:57 +00:00
|
|
|
SymbolIdx(SymbolKind kind, uint64_t idx) : kind(kind), idx(idx) {}
|
|
|
|
|
|
|
|
bool operator==(const SymbolIdx& that) const {
|
|
|
|
return kind == that.kind && idx == that.idx;
|
|
|
|
}
|
|
|
|
bool operator!=(const SymbolIdx& that) const { return !(*this == that); }
|
|
|
|
bool operator<(const SymbolIdx& that) const {
|
2018-01-15 18:08:03 +00:00
|
|
|
if (kind != that.kind)
|
|
|
|
return kind < that.kind;
|
|
|
|
return idx < that.idx;
|
2017-04-08 07:11:57 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-19 07:02:01 +00:00
|
|
|
MAKE_REFLECT_STRUCT(SymbolIdx, kind, idx);
|
2017-11-09 07:06:32 +00:00
|
|
|
MAKE_HASHABLE(SymbolIdx, t.kind, t.idx);
|
2017-04-08 07:11:57 +00:00
|
|
|
|
|
|
|
struct SymbolRef {
|
|
|
|
SymbolIdx idx;
|
2018-01-29 04:39:41 +00:00
|
|
|
SymbolRole role;
|
2017-04-15 05:41:35 +00:00
|
|
|
QueryLocation loc;
|
2017-04-08 07:11:57 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
SymbolRef() {} // Do not use, needed for reflect.
|
2018-01-29 04:39:41 +00:00
|
|
|
SymbolRef(SymbolIdx idx, SymbolRole role, QueryLocation loc)
|
|
|
|
: idx(idx), role(role), loc(loc) {}
|
2017-04-08 07:11:57 +00:00
|
|
|
|
|
|
|
bool operator==(const SymbolRef& that) const {
|
|
|
|
return idx == that.idx && loc == that.loc;
|
|
|
|
}
|
|
|
|
bool operator!=(const SymbolRef& that) const { return !(*this == that); }
|
|
|
|
bool operator<(const SymbolRef& that) const {
|
2018-01-15 18:08:03 +00:00
|
|
|
if (idx != that.idx)
|
|
|
|
return idx < that.idx;
|
|
|
|
return loc < that.loc;
|
2017-04-08 07:11:57 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-19 07:02:01 +00:00
|
|
|
MAKE_REFLECT_STRUCT(SymbolRef, idx, loc);
|
2017-04-08 07:11:57 +00:00
|
|
|
|
2017-04-08 08:04:38 +00:00
|
|
|
struct QueryFuncRef {
|
2017-06-14 06:50:30 +00:00
|
|
|
// NOTE: id_ can be -1 if the function call is not coming from a function.
|
|
|
|
QueryFuncId id_;
|
2017-04-15 05:41:35 +00:00
|
|
|
QueryLocation loc;
|
2017-05-23 06:57:46 +00:00
|
|
|
bool is_implicit = false;
|
2017-04-08 08:04:38 +00:00
|
|
|
|
2017-11-30 03:18:58 +00:00
|
|
|
bool has_id() const { return id_.id != static_cast<size_t>(-1); }
|
2017-06-14 06:50:30 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
QueryFuncRef() {} // Do not use, needed for reflect.
|
|
|
|
QueryFuncRef(QueryFuncId id, QueryLocation loc, bool is_implicit)
|
|
|
|
: id_(id), loc(loc), is_implicit(is_implicit) {}
|
2017-04-08 08:04:38 +00:00
|
|
|
|
|
|
|
bool operator==(const QueryFuncRef& that) const {
|
2017-09-22 01:14:57 +00:00
|
|
|
return id_ == that.id_ && loc == that.loc &&
|
|
|
|
is_implicit == that.is_implicit;
|
2017-04-08 08:04:38 +00:00
|
|
|
}
|
|
|
|
bool operator!=(const QueryFuncRef& that) const { return !(*this == that); }
|
|
|
|
bool operator<(const QueryFuncRef& that) const {
|
2018-01-15 18:08:03 +00:00
|
|
|
if (id_ != that.id_)
|
2018-01-30 00:27:43 +00:00
|
|
|
return id_ < that.id_;
|
2018-01-15 18:08:03 +00:00
|
|
|
if (loc != that.loc)
|
|
|
|
return loc < that.loc;
|
|
|
|
return is_implicit < that.is_implicit;
|
2017-04-08 08:04:38 +00:00
|
|
|
}
|
|
|
|
};
|
2017-06-14 06:50:30 +00:00
|
|
|
MAKE_REFLECT_STRUCT(QueryFuncRef, id_, loc, is_implicit);
|
2017-04-08 08:04:38 +00:00
|
|
|
|
2017-02-26 08:11:47 +00:00
|
|
|
// There are two sources of reindex updates: the (single) definition of a
|
|
|
|
// symbol has changed, or one of many users of the symbol has changed.
|
|
|
|
//
|
|
|
|
// For simplicitly, if the single definition has changed, we update all of the
|
|
|
|
// associated single-owner definition data. See |Update*DefId|.
|
|
|
|
//
|
|
|
|
// If one of the many symbol users submits an update, we store the update such
|
|
|
|
// that it can be merged with other updates before actually being applied to
|
|
|
|
// the main database. See |MergeableUpdate|.
|
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
template <typename TId, typename TValue>
|
2017-02-26 08:11:47 +00:00
|
|
|
struct MergeableUpdate {
|
|
|
|
// The type/func/var which is getting new usages.
|
2017-04-15 05:24:49 +00:00
|
|
|
TId id;
|
2017-02-26 08:11:47 +00:00
|
|
|
// Entries to add and remove.
|
|
|
|
std::vector<TValue> to_add;
|
|
|
|
std::vector<TValue> to_remove;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
2017-04-15 05:24:49 +00:00
|
|
|
MergeableUpdate(TId id, const std::vector<TValue>& to_add)
|
2017-09-22 01:14:57 +00:00
|
|
|
: id(id), to_add(to_add) {}
|
|
|
|
MergeableUpdate(TId id,
|
|
|
|
const std::vector<TValue>& to_add,
|
|
|
|
const std::vector<TValue>& to_remove)
|
|
|
|
: id(id), to_add(to_add), to_remove(to_remove) {}
|
2017-02-27 07:23:43 +00:00
|
|
|
};
|
2017-09-22 01:14:57 +00:00
|
|
|
template <typename TVisitor, typename TId, typename TValue>
|
2017-05-19 07:02:01 +00:00
|
|
|
void Reflect(TVisitor& visitor, MergeableUpdate<TId, TValue>& value) {
|
2018-01-08 04:10:16 +00:00
|
|
|
REFLECT_MEMBER_START();
|
2017-05-19 07:02:01 +00:00
|
|
|
REFLECT_MEMBER(id);
|
|
|
|
REFLECT_MEMBER(to_add);
|
|
|
|
REFLECT_MEMBER(to_remove);
|
|
|
|
REFLECT_MEMBER_END();
|
|
|
|
}
|
2017-02-27 07:23:43 +00:00
|
|
|
|
2017-12-12 07:56:50 +00:00
|
|
|
template <typename T>
|
|
|
|
struct WithUsr {
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr usr;
|
2017-12-12 07:56:50 +00:00
|
|
|
T value;
|
|
|
|
|
2018-01-13 08:10:39 +00:00
|
|
|
WithUsr(Usr usr, const T& value) : usr(usr), value(value) {}
|
2017-12-12 07:56:50 +00:00
|
|
|
};
|
|
|
|
template <typename TVisitor, typename T>
|
|
|
|
void Reflect(TVisitor& visitor, WithUsr<T>& value) {
|
2018-01-08 04:10:16 +00:00
|
|
|
REFLECT_MEMBER_START();
|
2017-12-12 07:56:50 +00:00
|
|
|
REFLECT_MEMBER(usr);
|
|
|
|
REFLECT_MEMBER(value);
|
|
|
|
REFLECT_MEMBER_END();
|
|
|
|
}
|
|
|
|
|
2018-01-30 05:34:28 +00:00
|
|
|
template <typename T>
|
|
|
|
struct WithFileContent {
|
|
|
|
T value;
|
|
|
|
std::string file_content;
|
|
|
|
|
|
|
|
WithFileContent(const T& value, const std::string& file_content) : value(value), file_content(file_content) {}
|
|
|
|
};
|
|
|
|
template <typename TVisitor, typename T>
|
|
|
|
void Reflect(TVisitor& visitor, WithFileContent<T>& value) {
|
|
|
|
REFLECT_MEMBER_START();
|
|
|
|
REFLECT_MEMBER(value);
|
|
|
|
REFLECT_MEMBER(file_content);
|
|
|
|
REFLECT_MEMBER_END();
|
|
|
|
}
|
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
struct QueryFile {
|
2017-04-07 05:42:57 +00:00
|
|
|
struct Def {
|
2017-04-15 05:41:35 +00:00
|
|
|
std::string path;
|
2017-11-30 03:47:29 +00:00
|
|
|
// Language identifier
|
|
|
|
std::string language;
|
2017-05-21 03:46:15 +00:00
|
|
|
// Includes in the file.
|
|
|
|
std::vector<IndexInclude> includes;
|
2017-04-07 05:42:57 +00:00
|
|
|
// Outline of the file (ie, for code lens).
|
2017-04-08 07:11:57 +00:00
|
|
|
std::vector<SymbolRef> outline;
|
2017-04-07 05:42:57 +00:00
|
|
|
// Every symbol found in the file (ie, for goto definition)
|
2017-04-08 07:11:57 +00:00
|
|
|
std::vector<SymbolRef> all_symbols;
|
2017-10-28 22:09:14 +00:00
|
|
|
// Parts of the file which are disabled.
|
|
|
|
std::vector<Range> inactive_regions;
|
2018-01-27 17:29:28 +00:00
|
|
|
// Used by |$cquery/freshenIndex|.
|
|
|
|
std::vector<std::string> dependencies;
|
2017-04-07 05:42:57 +00:00
|
|
|
};
|
2017-02-27 07:23:43 +00:00
|
|
|
|
2018-01-30 05:34:28 +00:00
|
|
|
using DefUpdate = WithFileContent<Def>;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
2018-01-30 05:34:28 +00:00
|
|
|
optional<Def> def;
|
2018-02-02 01:59:01 +00:00
|
|
|
size_t symbol_idx = (size_t)-1;
|
2017-04-07 05:42:57 +00:00
|
|
|
|
2017-12-12 07:56:50 +00:00
|
|
|
explicit QueryFile(const std::string& path) {
|
2018-01-30 05:34:28 +00:00
|
|
|
def = Def();
|
2017-10-17 05:44:58 +00:00
|
|
|
def->path = path;
|
|
|
|
}
|
2017-02-26 08:11:47 +00:00
|
|
|
};
|
2017-10-28 22:09:14 +00:00
|
|
|
MAKE_REFLECT_STRUCT(QueryFile::Def,
|
|
|
|
path,
|
2017-11-30 03:47:29 +00:00
|
|
|
language,
|
2017-10-28 22:09:14 +00:00
|
|
|
outline,
|
|
|
|
all_symbols,
|
2018-01-27 17:29:28 +00:00
|
|
|
inactive_regions,
|
|
|
|
dependencies);
|
2017-03-14 08:33:39 +00:00
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
struct QueryType {
|
2017-12-12 07:56:50 +00:00
|
|
|
using Def = TypeDefDefinitionData<QueryTypeId,
|
|
|
|
QueryFuncId,
|
|
|
|
QueryVarId,
|
|
|
|
QueryLocation>;
|
|
|
|
using DefUpdate = WithUsr<Def>;
|
2017-04-15 05:24:49 +00:00
|
|
|
using DerivedUpdate = MergeableUpdate<QueryTypeId, QueryTypeId>;
|
2017-04-21 07:03:33 +00:00
|
|
|
using InstancesUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
|
2017-04-15 05:41:35 +00:00
|
|
|
using UsesUpdate = MergeableUpdate<QueryTypeId, QueryLocation>;
|
2017-02-27 02:03:14 +00:00
|
|
|
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr usr;
|
2017-12-12 07:56:50 +00:00
|
|
|
optional<Def> def;
|
2017-04-08 07:52:57 +00:00
|
|
|
std::vector<QueryTypeId> derived;
|
2017-04-21 07:03:33 +00:00
|
|
|
std::vector<QueryVarId> instances;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryLocation> uses;
|
2018-02-02 01:59:01 +00:00
|
|
|
size_t symbol_idx = (size_t)-1;
|
2017-02-26 08:11:47 +00:00
|
|
|
|
2017-12-12 07:56:50 +00:00
|
|
|
explicit QueryType(const Usr& usr) : usr(usr) {}
|
2017-02-26 08:11:47 +00:00
|
|
|
};
|
2017-03-14 08:33:39 +00:00
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
struct QueryFunc {
|
2017-12-12 07:56:50 +00:00
|
|
|
using Def = FuncDefDefinitionData<QueryTypeId,
|
|
|
|
QueryFuncId,
|
|
|
|
QueryVarId,
|
|
|
|
QueryFuncRef,
|
|
|
|
QueryLocation>;
|
|
|
|
using DefUpdate = WithUsr<Def>;
|
2017-04-15 05:41:35 +00:00
|
|
|
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, QueryLocation>;
|
2017-04-15 05:24:49 +00:00
|
|
|
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
|
|
|
|
using CallersUpdate = MergeableUpdate<QueryFuncId, QueryFuncRef>;
|
2017-02-27 02:03:14 +00:00
|
|
|
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr usr;
|
2017-12-12 07:56:50 +00:00
|
|
|
optional<Def> def;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryLocation> declarations;
|
2017-04-08 08:04:38 +00:00
|
|
|
std::vector<QueryFuncId> derived;
|
|
|
|
std::vector<QueryFuncRef> callers;
|
2018-02-02 01:59:01 +00:00
|
|
|
size_t symbol_idx = (size_t)-1;
|
2017-02-26 08:11:47 +00:00
|
|
|
|
2017-12-12 07:56:50 +00:00
|
|
|
explicit QueryFunc(const Usr& usr) : usr(usr) {}
|
2017-02-26 08:11:47 +00:00
|
|
|
};
|
2017-03-14 08:33:39 +00:00
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
struct QueryVar {
|
2017-12-12 07:56:50 +00:00
|
|
|
using Def =
|
2017-09-22 01:14:57 +00:00
|
|
|
VarDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryLocation>;
|
2017-12-12 07:56:50 +00:00
|
|
|
using DefUpdate = WithUsr<Def>;
|
2018-01-27 05:50:17 +00:00
|
|
|
using DeclarationsUpdate = MergeableUpdate<QueryVarId, QueryLocation>;
|
2017-04-15 05:41:35 +00:00
|
|
|
using UsesUpdate = MergeableUpdate<QueryVarId, QueryLocation>;
|
2017-02-26 08:11:47 +00:00
|
|
|
|
2017-12-12 07:56:50 +00:00
|
|
|
Usr usr;
|
|
|
|
optional<Def> def;
|
2018-01-27 05:50:17 +00:00
|
|
|
std::vector<QueryLocation> declarations;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryLocation> uses;
|
2018-02-02 01:59:01 +00:00
|
|
|
size_t symbol_idx = (size_t)-1;
|
2017-02-26 08:11:47 +00:00
|
|
|
|
2017-12-12 07:56:50 +00:00
|
|
|
explicit QueryVar(const Usr& usr) : usr(usr) {}
|
2017-02-26 08:11:47 +00:00
|
|
|
};
|
2017-03-14 08:33:39 +00:00
|
|
|
|
2017-02-27 07:23:43 +00:00
|
|
|
struct IndexUpdate {
|
2017-04-08 06:45:28 +00:00
|
|
|
// Creates a new IndexUpdate based on the delta from previous to current. If
|
|
|
|
// no delta computation should be done just pass null for previous.
|
2017-09-22 01:14:57 +00:00
|
|
|
static IndexUpdate CreateDelta(const IdMap* previous_id_map,
|
|
|
|
const IdMap* current_id_map,
|
|
|
|
IndexFile* previous,
|
|
|
|
IndexFile* current);
|
2017-04-07 05:42:57 +00:00
|
|
|
|
|
|
|
// Merge |update| into this update; this can reduce overhead / index update
|
|
|
|
// work can be parallelized.
|
|
|
|
void Merge(const IndexUpdate& update);
|
|
|
|
|
2017-05-19 07:02:01 +00:00
|
|
|
// Dump the update to a string.
|
|
|
|
std::string ToString();
|
|
|
|
|
2017-02-27 07:23:43 +00:00
|
|
|
// File updates.
|
2018-01-26 06:42:58 +00:00
|
|
|
std::vector<std::string> files_removed;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryFile::DefUpdate> files_def_update;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
|
|
|
// Type updates.
|
|
|
|
std::vector<Usr> types_removed;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryType::DefUpdate> types_def_update;
|
|
|
|
std::vector<QueryType::DerivedUpdate> types_derived;
|
2017-04-21 07:03:33 +00:00
|
|
|
std::vector<QueryType::InstancesUpdate> types_instances;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryType::UsesUpdate> types_uses;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
|
|
|
// Function updates.
|
|
|
|
std::vector<Usr> funcs_removed;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryFunc::DefUpdate> funcs_def_update;
|
|
|
|
std::vector<QueryFunc::DeclarationsUpdate> funcs_declarations;
|
|
|
|
std::vector<QueryFunc::DerivedUpdate> funcs_derived;
|
|
|
|
std::vector<QueryFunc::CallersUpdate> funcs_callers;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
|
|
|
// Variable updates.
|
|
|
|
std::vector<Usr> vars_removed;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryVar::DefUpdate> vars_def_update;
|
2018-01-27 05:50:17 +00:00
|
|
|
std::vector<QueryVar::DeclarationsUpdate> vars_declarations;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryVar::UsesUpdate> vars_uses;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
2017-04-07 05:42:57 +00:00
|
|
|
private:
|
2017-02-27 07:23:43 +00:00
|
|
|
// Creates an index update assuming that |previous| is already
|
|
|
|
// in the index, so only the delta between |previous| and |current|
|
|
|
|
// will be applied.
|
2017-09-22 01:14:57 +00:00
|
|
|
IndexUpdate(const IdMap& previous_id_map,
|
|
|
|
const IdMap& current_id_map,
|
|
|
|
IndexFile& previous,
|
|
|
|
IndexFile& current);
|
2017-02-27 07:23:43 +00:00
|
|
|
};
|
2017-09-22 01:14:57 +00:00
|
|
|
// NOTICE: We're not reflecting on files_removed or files_def_update, it is too
|
|
|
|
// much output when logging
|
2017-05-19 07:02:01 +00:00
|
|
|
MAKE_REFLECT_STRUCT(IndexUpdate,
|
2017-09-22 01:14:57 +00:00
|
|
|
types_removed,
|
|
|
|
types_def_update,
|
|
|
|
types_derived,
|
|
|
|
types_instances,
|
|
|
|
types_uses,
|
|
|
|
funcs_removed,
|
|
|
|
funcs_def_update,
|
|
|
|
funcs_declarations,
|
|
|
|
funcs_derived,
|
|
|
|
funcs_callers,
|
|
|
|
vars_removed,
|
|
|
|
vars_def_update,
|
2018-01-27 05:50:17 +00:00
|
|
|
vars_declarations,
|
2017-09-22 01:14:57 +00:00
|
|
|
vars_uses);
|
2017-02-27 07:23:43 +00:00
|
|
|
|
2018-01-30 00:55:51 +00:00
|
|
|
struct NormalizedPath {
|
|
|
|
explicit NormalizedPath(const std::string& path);
|
|
|
|
bool operator==(const NormalizedPath& rhs) const;
|
|
|
|
bool operator!=(const NormalizedPath& rhs) const;
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
};
|
|
|
|
MAKE_HASHABLE(NormalizedPath, t.path);
|
|
|
|
|
2017-02-27 07:23:43 +00:00
|
|
|
// The query database is heavily optimized for fast queries. It is stored
|
|
|
|
// in-memory.
|
2017-04-15 05:41:35 +00:00
|
|
|
struct QueryDatabase {
|
2018-02-02 01:59:01 +00:00
|
|
|
// All File/Func/Type/Var symbols.
|
2017-02-27 07:23:43 +00:00
|
|
|
std::vector<SymbolIdx> symbols;
|
|
|
|
|
2017-04-22 07:32:29 +00:00
|
|
|
// Raw data storage. Accessible via SymbolIdx instances.
|
2017-10-17 05:44:58 +00:00
|
|
|
std::vector<QueryFile> files;
|
|
|
|
std::vector<QueryType> types;
|
|
|
|
std::vector<QueryFunc> funcs;
|
|
|
|
std::vector<QueryVar> vars;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
|
|
|
// Lookup symbol based on a usr.
|
2018-01-30 00:55:51 +00:00
|
|
|
spp::sparse_hash_map<NormalizedPath, QueryFileId> usr_to_file;
|
2017-05-09 04:20:28 +00:00
|
|
|
spp::sparse_hash_map<Usr, QueryTypeId> usr_to_type;
|
|
|
|
spp::sparse_hash_map<Usr, QueryFuncId> usr_to_func;
|
|
|
|
spp::sparse_hash_map<Usr, QueryVarId> usr_to_var;
|
2017-02-27 07:23:43 +00:00
|
|
|
|
2017-04-19 06:56:37 +00:00
|
|
|
// Marks the given Usrs as invalid.
|
2017-05-09 04:20:28 +00:00
|
|
|
void RemoveUsrs(SymbolKind usr_kind, const std::vector<Usr>& to_remove);
|
2017-02-27 07:23:43 +00:00
|
|
|
// Insert the contents of |update| into |db|.
|
|
|
|
void ApplyIndexUpdate(IndexUpdate* update);
|
2017-04-15 05:41:35 +00:00
|
|
|
void ImportOrUpdate(const std::vector<QueryFile::DefUpdate>& updates);
|
|
|
|
void ImportOrUpdate(const std::vector<QueryType::DefUpdate>& updates);
|
|
|
|
void ImportOrUpdate(const std::vector<QueryFunc::DefUpdate>& updates);
|
|
|
|
void ImportOrUpdate(const std::vector<QueryVar::DefUpdate>& updates);
|
2018-02-02 01:59:01 +00:00
|
|
|
void UpdateSymbols(size_t* symbol_idx, SymbolKind kind, size_t idx);
|
|
|
|
std::string_view GetSymbolDetailedName(size_t symbol_idx) const;
|
|
|
|
std::string_view GetSymbolShortName(size_t symbol_idx) const;
|
2018-01-20 16:57:41 +00:00
|
|
|
|
|
|
|
// Query the indexing structure to look up symbol id for given Usr.
|
2018-01-20 18:32:39 +00:00
|
|
|
optional<QueryFileId> GetQueryFileIdFromPath(const std::string& path);
|
|
|
|
optional<QueryTypeId> GetQueryTypeIdFromUsr(Usr usr);
|
|
|
|
optional<QueryFuncId> GetQueryFuncIdFromUsr(Usr usr);
|
|
|
|
optional<QueryVarId> GetQueryVarIdFromUsr(Usr usr);
|
2017-04-07 08:01:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IdMap {
|
|
|
|
const IdCache& local_ids;
|
2017-04-08 07:21:00 +00:00
|
|
|
QueryFileId primary_file;
|
2017-04-07 08:01:58 +00:00
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
IdMap(QueryDatabase* query_db, const IdCache& local_ids);
|
2017-04-07 08:01:58 +00:00
|
|
|
|
2017-04-15 05:41:35 +00:00
|
|
|
QueryLocation ToQuery(Range range) const;
|
2017-04-08 07:11:57 +00:00
|
|
|
QueryTypeId ToQuery(IndexTypeId id) const;
|
|
|
|
QueryFuncId ToQuery(IndexFuncId id) const;
|
|
|
|
QueryVarId ToQuery(IndexVarId id) const;
|
2017-04-08 08:04:38 +00:00
|
|
|
QueryFuncRef ToQuery(IndexFuncRef ref) const;
|
2017-05-27 21:09:20 +00:00
|
|
|
QueryLocation ToQuery(IndexFunc::Declaration decl) const;
|
2017-04-15 05:41:35 +00:00
|
|
|
optional<QueryLocation> ToQuery(optional<Range> range) const;
|
2017-04-08 07:52:57 +00:00
|
|
|
optional<QueryTypeId> ToQuery(optional<IndexTypeId> id) const;
|
|
|
|
optional<QueryFuncId> ToQuery(optional<IndexFuncId> id) const;
|
|
|
|
optional<QueryVarId> ToQuery(optional<IndexVarId> id) const;
|
2017-04-08 08:04:38 +00:00
|
|
|
optional<QueryFuncRef> ToQuery(optional<IndexFuncRef> ref) const;
|
2017-05-27 21:09:20 +00:00
|
|
|
optional<QueryLocation> ToQuery(optional<IndexFunc::Declaration> decl) const;
|
2017-04-15 05:41:35 +00:00
|
|
|
std::vector<QueryLocation> ToQuery(std::vector<Range> ranges) const;
|
2017-04-08 07:52:57 +00:00
|
|
|
std::vector<QueryTypeId> ToQuery(std::vector<IndexTypeId> ids) const;
|
|
|
|
std::vector<QueryFuncId> ToQuery(std::vector<IndexFuncId> ids) const;
|
|
|
|
std::vector<QueryVarId> ToQuery(std::vector<IndexVarId> ids) const;
|
2017-04-08 08:04:38 +00:00
|
|
|
std::vector<QueryFuncRef> ToQuery(std::vector<IndexFuncRef> refs) const;
|
2017-09-22 01:14:57 +00:00
|
|
|
std::vector<QueryLocation> ToQuery(
|
|
|
|
std::vector<IndexFunc::Declaration> decls) const;
|
2017-04-08 07:52:57 +00:00
|
|
|
|
2017-04-08 07:11:57 +00:00
|
|
|
SymbolIdx ToSymbol(IndexTypeId id) const;
|
|
|
|
SymbolIdx ToSymbol(IndexFuncId id) const;
|
|
|
|
SymbolIdx ToSymbol(IndexVarId id) const;
|
2017-09-22 01:14:57 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-19 05:45:37 +00:00
|
|
|
spp::sparse_hash_map<IndexTypeId, QueryTypeId> cached_type_ids_;
|
|
|
|
spp::sparse_hash_map<IndexFuncId, QueryFuncId> cached_func_ids_;
|
|
|
|
spp::sparse_hash_map<IndexVarId, QueryVarId> cached_var_ids_;
|
2017-04-07 08:01:58 +00:00
|
|
|
};
|