ccls/query.h

140 lines
3.7 KiB
C
Raw Normal View History

2017-02-23 09:23:23 +00:00
#pragma once
2017-02-26 08:11:47 +00:00
#include "indexer.h"
2017-02-23 09:23:23 +00:00
// NOTE: If updating this enum, make sure to also update the parser and the
// help text.
enum class Command {
Callees,
Callers,
FindAllUsages,
FindInterestingUsages,
GotoReferenced,
Hierarchy,
Outline,
Search
};
// NOTE: If updating this enum, make sure to also update the parser and the
// help text.
enum class PreferredSymbolLocation {
Declaration,
Definition
2017-02-26 08:11:47 +00:00
};
using Usr = std::string;
2017-02-27 02:03:14 +00:00
// TODO: Switch over to QueryableLocation. Figure out if there is
// a good way to get the indexer using it. I don't think so
// since we may discover more files while indexing a file.
//
// We could also reuse planned USR caching system for file
// paths.
struct QueryableLocation {
Usr path;
int line;
int column;
bool interesting;
QueryableLocation()
: path(""), line(-1), column(-1), interesting(false) {}
QueryableLocation(Usr path, int line, int column, bool interesting)
: path(path), line(line), column(column), interesting(interesting) {}
bool operator==(const QueryableLocation& other) const {
// Note: We ignore |is_interesting|.
return
path == other.path &&
line == other.line &&
column == other.column;
}
};
2017-02-26 19:45:59 +00:00
struct UsrRef {
Usr usr;
2017-02-27 02:03:14 +00:00
QueryableLocation loc;
2017-02-26 08:11:47 +00:00
2017-02-26 19:45:59 +00:00
bool operator==(const UsrRef& other) const {
return usr == other.usr && loc == other.loc;
}
};
2017-02-26 08:11:47 +00:00
2017-02-27 02:03:14 +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-02-26 19:45:59 +00:00
template<typename TValue>
2017-02-26 08:11:47 +00:00
struct MergeableUpdate {
// The type/func/var which is getting new usages.
2017-02-26 19:45:59 +00:00
Usr usr;
2017-02-26 08:11:47 +00:00
// Entries to add and remove.
std::vector<TValue> to_add;
std::vector<TValue> to_remove;
};
struct QueryableTypeDef {
2017-02-27 02:03:14 +00:00
using DefUpdate = TypeDefDefinitionData<Usr, Usr, Usr, QueryableLocation>;
2017-02-26 19:45:59 +00:00
using DerivedUpdate = MergeableUpdate<Usr>;
2017-02-27 02:03:14 +00:00
using UsesUpdate = MergeableUpdate<QueryableLocation>;
DefUpdate def;
std::vector<Usr> derived;
std::vector<QueryableLocation> uses;
2017-02-26 08:11:47 +00:00
2017-02-26 19:45:59 +00:00
QueryableTypeDef(IdCache& id_cache, IndexedTypeDef& indexed);
2017-02-26 08:11:47 +00:00
};
struct QueryableFuncDef {
2017-02-27 02:03:14 +00:00
using DefUpdate = FuncDefDefinitionData<Usr, Usr, Usr, UsrRef, QueryableLocation>;
using DeclarationsUpdate = MergeableUpdate<QueryableLocation>;
2017-02-26 19:45:59 +00:00
using DerivedUpdate = MergeableUpdate<Usr>;
using CallersUpdate = MergeableUpdate<UsrRef>;
2017-02-27 02:03:14 +00:00
using UsesUpdate = MergeableUpdate<QueryableLocation>;
DefUpdate def;
std::vector<QueryableLocation> declarations;
std::vector<Usr> derived;
std::vector<UsrRef> callers;
std::vector<QueryableLocation> uses;
2017-02-26 08:11:47 +00:00
2017-02-26 19:45:59 +00:00
QueryableFuncDef(IdCache& id_cache, IndexedFuncDef& indexed);
2017-02-26 08:11:47 +00:00
};
struct QueryableVarDef {
2017-02-27 02:03:14 +00:00
using DefUpdate = VarDefDefinitionData<Usr, Usr, Usr, QueryableLocation>;
using UsesUpdate = MergeableUpdate<QueryableLocation>;
2017-02-26 08:11:47 +00:00
2017-02-27 02:03:14 +00:00
DefUpdate def;
std::vector<QueryableLocation> uses;
2017-02-26 08:11:47 +00:00
2017-02-26 19:45:59 +00:00
QueryableVarDef(IdCache& id_cache, IndexedVarDef& indexed);
2017-02-26 08:11:47 +00:00
};
2017-02-27 02:03:14 +00:00
enum class SymbolKind { Invalid, File, Type, Func, Var };
2017-02-26 08:11:47 +00:00
struct SymbolIdx {
SymbolKind kind;
2017-02-26 19:45:59 +00:00
uint64_t idx;
SymbolIdx() : kind(SymbolKind::Invalid), idx(-1) {} // Default ctor needed by stdlib. Do not use.
SymbolIdx(SymbolKind kind, uint64_t idx) : kind(kind), idx(idx) {}
2017-02-26 08:11:47 +00:00
};
struct QueryableFile {
FileId file_id;
// Symbols declared in the file.
std::vector<SymbolIdx> declared_symbols;
// Symbols which have definitions in the file.
std::vector<SymbolIdx> defined_symbols;
2017-02-23 09:23:23 +00:00
};