2017-02-22 08:52:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-01-13 06:13:08 +00:00
|
|
|
#include "clang_cursor.h"
|
2017-11-11 19:41:09 +00:00
|
|
|
#include "clang_translation_unit.h"
|
2017-11-04 22:29:03 +00:00
|
|
|
#include "clang_utils.h"
|
2017-04-08 22:54:36 +00:00
|
|
|
#include "file_consumer.h"
|
2018-02-20 03:06:48 +00:00
|
|
|
#include "language.h"
|
2018-02-24 00:12:39 +00:00
|
|
|
#include "lsp.h"
|
2018-02-02 05:31:56 +00:00
|
|
|
#include "maybe.h"
|
2018-02-11 22:08:05 +00:00
|
|
|
#include "nt_string.h"
|
2017-05-17 07:08:45 +00:00
|
|
|
#include "performance.h"
|
2017-09-22 01:14:57 +00:00
|
|
|
#include "position.h"
|
|
|
|
#include "serializer.h"
|
2018-02-13 01:15:19 +00:00
|
|
|
#include "symbol.h"
|
2017-09-22 01:14:57 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
2018-03-31 05:05:21 +00:00
|
|
|
#include <stdint.h>
|
2017-03-25 20:32:44 +00:00
|
|
|
#include <algorithm>
|
2018-03-31 05:05:21 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
2018-05-04 04:20:10 +00:00
|
|
|
#include <unordered_map>
|
2017-04-14 22:30:33 +00:00
|
|
|
#include <vector>
|
2017-03-25 20:32:44 +00:00
|
|
|
|
2018-02-08 03:14:44 +00:00
|
|
|
struct IndexFile;
|
2017-05-12 06:08:15 +00:00
|
|
|
struct IndexType;
|
|
|
|
struct IndexFunc;
|
|
|
|
struct IndexVar;
|
2018-02-20 03:06:48 +00:00
|
|
|
struct QueryFile;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-02-03 18:33:22 +00:00
|
|
|
using RawId = uint32_t;
|
|
|
|
|
2018-02-11 18:25:37 +00:00
|
|
|
struct SymbolIdx {
|
2018-04-30 04:49:03 +00:00
|
|
|
Usr usr;
|
2018-02-11 18:25:37 +00:00
|
|
|
SymbolKind kind;
|
|
|
|
|
|
|
|
bool operator==(const SymbolIdx& o) const {
|
2018-04-30 04:49:03 +00:00
|
|
|
return usr == o.usr && kind == o.kind;
|
2018-02-11 18:25:37 +00:00
|
|
|
}
|
|
|
|
bool operator<(const SymbolIdx& o) const {
|
2018-04-30 04:49:03 +00:00
|
|
|
return usr != o.usr ? usr < o.usr : kind < o.kind;
|
2018-02-11 18:25:37 +00:00
|
|
|
}
|
|
|
|
};
|
2018-04-30 04:49:03 +00:00
|
|
|
MAKE_REFLECT_STRUCT(SymbolIdx, usr, kind);
|
2018-02-11 18:25:37 +00:00
|
|
|
|
2018-02-08 18:38:27 +00:00
|
|
|
struct Reference {
|
|
|
|
Range range;
|
2018-04-30 04:49:03 +00:00
|
|
|
Usr usr;
|
2018-02-09 17:42:10 +00:00
|
|
|
SymbolKind kind;
|
2018-02-11 04:01:10 +00:00
|
|
|
Role role;
|
2018-02-08 18:38:27 +00:00
|
|
|
|
2018-04-08 06:32:35 +00:00
|
|
|
bool Valid() const { return range.Valid(); }
|
2018-04-30 04:49:03 +00:00
|
|
|
operator SymbolIdx() const { return {usr, kind}; }
|
|
|
|
std::tuple<Range, Usr, SymbolKind, Role> ToTuple() const {
|
|
|
|
return std::make_tuple(range, usr, kind, role);
|
2018-02-08 18:38:27 +00:00
|
|
|
}
|
2018-02-22 07:34:32 +00:00
|
|
|
bool operator==(const Reference& o) const { return ToTuple() == o.ToTuple(); }
|
|
|
|
bool operator<(const Reference& o) const { return ToTuple() < o.ToTuple(); }
|
2018-02-08 02:29:34 +00:00
|
|
|
};
|
|
|
|
|
2018-02-10 20:53:18 +00:00
|
|
|
// |id,kind| refer to the referenced entity.
|
|
|
|
struct SymbolRef : Reference {
|
|
|
|
SymbolRef() = default;
|
2018-04-30 04:49:03 +00:00
|
|
|
SymbolRef(Range range, Usr usr, SymbolKind kind, Role role)
|
|
|
|
: Reference{range, usr, kind, role} {}
|
2018-02-10 20:53:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Represents an occurrence of a variable/type, |id,kind| refer to the lexical
|
|
|
|
// parent.
|
|
|
|
struct Use : Reference {
|
2018-02-12 04:22:47 +00:00
|
|
|
// |file| is used in Query* but not in Index*
|
2018-04-30 04:49:03 +00:00
|
|
|
int file_id = -1;
|
2017-02-22 08:52:00 +00:00
|
|
|
};
|
|
|
|
|
2018-02-08 18:38:27 +00:00
|
|
|
void Reflect(Reader& visitor, Reference& value);
|
|
|
|
void Reflect(Writer& visitor, Reference& value);
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-04-06 00:00:07 +00:00
|
|
|
template <typename D>
|
|
|
|
struct NameMixin {
|
|
|
|
std::string_view Name(bool qualified) const {
|
|
|
|
auto self = static_cast<const D*>(this);
|
|
|
|
return qualified ? std::string_view(
|
|
|
|
self->detailed_name.c_str() + self->qual_name_offset,
|
|
|
|
self->short_name_offset - self->qual_name_offset +
|
|
|
|
self->short_name_size)
|
|
|
|
: std::string_view(self->detailed_name.c_str() +
|
|
|
|
self->short_name_offset,
|
|
|
|
self->short_name_size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
struct FuncDef : NameMixin<FuncDef> {
|
2017-02-22 08:52:00 +00:00
|
|
|
// General metadata.
|
2017-04-15 04:58:07 +00:00
|
|
|
std::string detailed_name;
|
2018-02-11 22:08:05 +00:00
|
|
|
NtString hover;
|
|
|
|
NtString comments;
|
2018-02-11 04:01:10 +00:00
|
|
|
Maybe<Use> spell;
|
|
|
|
Maybe<Use> extent;
|
2017-04-05 08:06:18 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
// Method this method overrides.
|
|
|
|
std::vector<Usr> bases;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
// Local variables or parameters.
|
|
|
|
std::vector<Usr> vars;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
// Functions that this function calls.
|
|
|
|
std::vector<SymbolRef> callees;
|
2018-02-08 03:14:44 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
// Type which declares this one (ie, it is a method)
|
|
|
|
Usr declaring_type = 0;
|
2018-04-06 00:00:07 +00:00
|
|
|
int16_t qual_name_offset = 0;
|
2018-01-31 07:01:45 +00:00
|
|
|
int16_t short_name_offset = 0;
|
|
|
|
int16_t short_name_size = 0;
|
2018-02-18 19:29:38 +00:00
|
|
|
lsSymbolKind kind = lsSymbolKind::Unknown;
|
2018-04-30 04:49:03 +00:00
|
|
|
StorageClass storage = StorageClass::Invalid;
|
2018-01-31 07:01:45 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
bool operator==(const FuncDef& o) const {
|
2018-02-22 07:34:32 +00:00
|
|
|
return detailed_name == o.detailed_name && spell == o.spell &&
|
2018-04-30 04:49:03 +00:00
|
|
|
extent == o.extent && declaring_type == o.declaring_type &&
|
|
|
|
bases == o.bases && vars == o.vars && callees == o.callees &&
|
|
|
|
kind == o.kind && storage == o.storage && hover == o.hover &&
|
|
|
|
comments == o.comments;
|
2017-02-25 23:59:09 +00:00
|
|
|
}
|
2017-02-25 06:08:14 +00:00
|
|
|
};
|
2018-04-30 04:49:03 +00:00
|
|
|
MAKE_REFLECT_STRUCT(FuncDef,
|
|
|
|
detailed_name,
|
|
|
|
qual_name_offset,
|
|
|
|
short_name_offset,
|
|
|
|
short_name_size,
|
|
|
|
kind,
|
|
|
|
storage,
|
|
|
|
hover,
|
|
|
|
comments,
|
|
|
|
spell,
|
|
|
|
extent,
|
|
|
|
declaring_type,
|
|
|
|
bases,
|
|
|
|
vars,
|
|
|
|
callees);
|
2017-02-25 06:08:14 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
struct IndexFunc : NameMixin<IndexFunc> {
|
|
|
|
using Def = FuncDef;
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr usr;
|
2017-12-12 07:56:50 +00:00
|
|
|
Def def;
|
2018-02-20 21:56:56 +00:00
|
|
|
std::vector<Use> declarations;
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> uses;
|
2018-04-30 04:49:03 +00:00
|
|
|
std::vector<Usr> derived;
|
2017-02-22 08:52:00 +00:00
|
|
|
};
|
2017-02-25 23:59:09 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
struct TypeDef : NameMixin<TypeDef> {
|
2017-02-22 08:52:00 +00:00
|
|
|
// General metadata.
|
2017-04-15 04:58:07 +00:00
|
|
|
std::string detailed_name;
|
2018-02-11 22:08:05 +00:00
|
|
|
NtString hover;
|
|
|
|
NtString comments;
|
2018-04-30 04:49:03 +00:00
|
|
|
|
|
|
|
// While a class/type can technically have a separate declaration/definition,
|
|
|
|
// it doesn't really happen in practice. The declaration never contains
|
|
|
|
// comments or insightful information. The user always wants to jump from
|
|
|
|
// the declaration to the definition - never the other way around like in
|
|
|
|
// functions and (less often) variables.
|
|
|
|
//
|
|
|
|
// It's also difficult to identify a `class Foo;` statement with the clang
|
|
|
|
// indexer API (it's doable using cursor AST traversal), so we don't bother
|
|
|
|
// supporting the feature.
|
2018-02-11 04:30:27 +00:00
|
|
|
Maybe<Use> spell;
|
|
|
|
Maybe<Use> extent;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
// Immediate parent types.
|
|
|
|
std::vector<Usr> bases;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
// Types, functions, and variables defined in this type.
|
|
|
|
std::vector<Usr> types;
|
|
|
|
std::vector<Usr> funcs;
|
|
|
|
std::vector<Usr> vars;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
// If set, then this is the same underlying type as the given value (ie, this
|
|
|
|
// type comes from a using or typedef statement).
|
|
|
|
Usr alias_of = 0;
|
2017-02-25 06:08:14 +00:00
|
|
|
|
2018-04-06 00:00:07 +00:00
|
|
|
int16_t qual_name_offset = 0;
|
2018-01-31 07:01:45 +00:00
|
|
|
int16_t short_name_offset = 0;
|
|
|
|
int16_t short_name_size = 0;
|
2018-02-18 19:29:38 +00:00
|
|
|
lsSymbolKind kind = lsSymbolKind::Unknown;
|
2018-01-31 06:39:39 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
bool operator==(const TypeDef& o) const {
|
2018-02-22 07:34:32 +00:00
|
|
|
return detailed_name == o.detailed_name && spell == o.spell &&
|
2018-04-30 04:49:03 +00:00
|
|
|
extent == o.extent && alias_of == o.alias_of && bases == o.bases &&
|
|
|
|
types == o.types && funcs == o.funcs && vars == o.vars &&
|
|
|
|
kind == o.kind && hover == o.hover && comments == o.comments;
|
2017-03-17 07:58:41 +00:00
|
|
|
}
|
2017-02-25 06:08:14 +00:00
|
|
|
};
|
2018-04-30 04:49:03 +00:00
|
|
|
MAKE_REFLECT_STRUCT(TypeDef,
|
|
|
|
detailed_name,
|
|
|
|
qual_name_offset,
|
|
|
|
short_name_offset,
|
|
|
|
short_name_size,
|
|
|
|
kind,
|
|
|
|
hover,
|
|
|
|
comments,
|
|
|
|
spell,
|
|
|
|
extent,
|
|
|
|
alias_of,
|
|
|
|
bases,
|
|
|
|
types,
|
|
|
|
funcs,
|
|
|
|
vars);
|
2017-02-25 06:08:14 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
struct IndexType {
|
|
|
|
using Def = TypeDef;
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr usr;
|
2017-12-12 07:56:50 +00:00
|
|
|
Def def;
|
2018-04-30 04:49:03 +00:00
|
|
|
std::vector<Use> declarations;
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> uses;
|
2018-04-30 04:49:03 +00:00
|
|
|
std::vector<Usr> derived;
|
|
|
|
std::vector<Usr> instances;
|
2017-02-22 08:52:00 +00:00
|
|
|
};
|
2017-02-25 23:59:09 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
struct VarDef : NameMixin<VarDef> {
|
2017-02-22 08:52:00 +00:00
|
|
|
// General metadata.
|
2017-04-15 04:58:07 +00:00
|
|
|
std::string detailed_name;
|
2018-02-11 22:08:05 +00:00
|
|
|
NtString hover;
|
|
|
|
NtString comments;
|
2017-04-05 08:06:18 +00:00
|
|
|
// TODO: definitions should be a list of ranges, since there can be more
|
|
|
|
// than one - when??
|
2018-02-11 04:01:10 +00:00
|
|
|
Maybe<Use> spell;
|
|
|
|
Maybe<Use> extent;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
|
|
|
// Type of the variable.
|
2018-04-30 04:49:03 +00:00
|
|
|
Usr type = 0;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-01-28 04:25:14 +00:00
|
|
|
// Function/type which declares this one.
|
2018-04-06 00:00:07 +00:00
|
|
|
int16_t qual_name_offset = 0;
|
2018-01-31 07:01:45 +00:00
|
|
|
int16_t short_name_offset = 0;
|
|
|
|
int16_t short_name_size = 0;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-02-18 19:29:38 +00:00
|
|
|
lsSymbolKind kind = lsSymbolKind::Unknown;
|
2018-01-28 04:25:14 +00:00
|
|
|
// Note a variable may have instances of both |None| and |Extern|
|
|
|
|
// (declaration).
|
|
|
|
StorageClass storage = StorageClass::Invalid;
|
2018-01-15 18:08:03 +00:00
|
|
|
|
2018-02-22 07:34:32 +00:00
|
|
|
bool is_local() const { return kind == lsSymbolKind::Variable; }
|
2017-05-21 01:26:50 +00:00
|
|
|
|
2018-04-06 00:00:07 +00:00
|
|
|
bool operator==(const VarDef& o) const {
|
2018-02-11 18:25:37 +00:00
|
|
|
return detailed_name == o.detailed_name && spell == o.spell &&
|
2018-02-22 07:34:32 +00:00
|
|
|
extent == o.extent && type == o.type && kind == o.kind &&
|
|
|
|
storage == o.storage && hover == o.hover && comments == o.comments;
|
2017-02-25 23:59:09 +00:00
|
|
|
}
|
2017-02-25 06:08:14 +00:00
|
|
|
};
|
2018-04-30 04:49:03 +00:00
|
|
|
MAKE_REFLECT_STRUCT(VarDef,
|
|
|
|
detailed_name,
|
|
|
|
qual_name_offset,
|
|
|
|
short_name_offset,
|
|
|
|
short_name_size,
|
|
|
|
hover,
|
|
|
|
comments,
|
|
|
|
spell,
|
|
|
|
extent,
|
|
|
|
type,
|
|
|
|
kind,
|
|
|
|
storage);
|
2017-03-14 08:33:39 +00:00
|
|
|
|
2017-05-12 06:08:15 +00:00
|
|
|
struct IndexVar {
|
2018-04-30 04:49:03 +00:00
|
|
|
using Def = VarDef;
|
2018-01-13 08:10:39 +00:00
|
|
|
Usr usr;
|
2017-12-12 07:56:50 +00:00
|
|
|
Def def;
|
2018-02-12 04:22:47 +00:00
|
|
|
std::vector<Use> declarations;
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> uses;
|
2017-02-25 23:59:09 +00:00
|
|
|
};
|
|
|
|
|
2017-05-21 03:46:15 +00:00
|
|
|
struct IndexInclude {
|
|
|
|
// Line that has the include directive. We don't have complete range
|
|
|
|
// information - a line is good enough for clicking.
|
|
|
|
int line = 0;
|
|
|
|
// Absolute path to the index.
|
|
|
|
std::string resolved_path;
|
|
|
|
};
|
|
|
|
|
2017-05-12 06:08:15 +00:00
|
|
|
struct IndexFile {
|
2018-01-28 05:47:37 +00:00
|
|
|
// For both JSON and MessagePack cache files.
|
|
|
|
static const int kMajorVersion;
|
|
|
|
// For MessagePack cache files.
|
2018-01-28 03:21:35 +00:00
|
|
|
// JSON has good forward compatibility because field addition/deletion do not
|
|
|
|
// harm but currently no efforts have been made to make old MessagePack cache
|
2018-03-31 03:16:33 +00:00
|
|
|
// files accepted by newer ccls.
|
2018-01-28 05:47:37 +00:00
|
|
|
static const int kMinorVersion;
|
2017-04-20 06:02:24 +00:00
|
|
|
|
2017-02-27 07:23:43 +00:00
|
|
|
std::string path;
|
2017-04-21 04:06:15 +00:00
|
|
|
std::vector<std::string> args;
|
2017-04-20 04:57:44 +00:00
|
|
|
int64_t last_modification_time = 0;
|
2017-11-30 21:56:55 +00:00
|
|
|
LanguageId language = LanguageId::Unknown;
|
2017-04-20 04:57:44 +00:00
|
|
|
|
2017-04-20 07:25:38 +00:00
|
|
|
// The path to the translation unit cc file which caused the creation of this
|
2017-05-12 06:08:15 +00:00
|
|
|
// IndexFile. When parsing a translation unit we generate many IndexFile
|
2017-04-20 07:25:38 +00:00
|
|
|
// 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;
|
|
|
|
|
2017-05-20 21:45:46 +00:00
|
|
|
// Source ranges that were not processed.
|
|
|
|
std::vector<Range> skipped_by_preprocessor;
|
|
|
|
|
2017-05-21 03:46:15 +00:00
|
|
|
std::vector<IndexInclude> includes;
|
2017-04-11 05:26:27 +00:00
|
|
|
std::vector<std::string> dependencies;
|
2018-04-30 04:49:03 +00:00
|
|
|
std::unordered_map<Usr, IndexFunc> usr2func;
|
|
|
|
std::unordered_map<Usr, IndexType> usr2type;
|
|
|
|
std::unordered_map<Usr, IndexVar> usr2var;
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2017-06-20 01:52:25 +00:00
|
|
|
// Diagnostics found when indexing this file. Not serialized.
|
2017-12-12 05:20:29 +00:00
|
|
|
std::vector<lsDiagnostic> diagnostics_;
|
2017-07-30 04:24:02 +00:00
|
|
|
// File contents at the time of index. Not serialized.
|
2018-01-30 05:34:28 +00:00
|
|
|
std::string file_contents;
|
2017-06-20 01:52:25 +00:00
|
|
|
|
2018-01-30 05:34:28 +00:00
|
|
|
IndexFile(const std::string& path, const std::string& contents);
|
2017-02-22 08:52:00 +00:00
|
|
|
|
2018-04-30 04:49:03 +00:00
|
|
|
IndexFunc& ToFunc(Usr usr);
|
|
|
|
IndexType& ToType(Usr usr);
|
|
|
|
IndexVar& ToVar(Usr usr);
|
|
|
|
IndexFunc& ToFunc(const ClangCursor& c) { return ToFunc(c.get_usr_hash()); }
|
|
|
|
IndexType& ToType(const ClangCursor& c) { return ToType(c.get_usr_hash()); }
|
|
|
|
IndexVar& ToVar(const ClangCursor& c) { return ToVar(c.get_usr_hash()); }
|
2017-02-22 08:52:00 +00:00
|
|
|
|
|
|
|
std::string ToString();
|
|
|
|
};
|
|
|
|
|
2017-12-29 09:19:02 +00:00
|
|
|
struct NamespaceHelper {
|
|
|
|
std::unordered_map<ClangCursor, std::string>
|
|
|
|
container_cursor_to_qualified_name;
|
|
|
|
|
2018-04-06 00:00:07 +00:00
|
|
|
std::tuple<std::string, int16_t, int16_t> QualifiedName(
|
|
|
|
const CXIdxContainerInfo* container,
|
|
|
|
std::string_view unqualified_name);
|
2017-12-29 09:19:02 +00:00
|
|
|
};
|
|
|
|
|
2017-04-20 07:25:38 +00:00
|
|
|
// |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.
|
2017-09-22 01:14:57 +00:00
|
|
|
// |dependencies| are the existing dependencies of |import_file| if this is a
|
|
|
|
// reparse.
|
2018-04-02 07:22:12 +00:00
|
|
|
std::vector<std::unique_ptr<IndexFile>> Parse(
|
2017-12-29 16:29:47 +00:00
|
|
|
FileConsumerSharedState* file_consumer_shared,
|
2017-04-24 01:01:51 +00:00
|
|
|
std::string file,
|
2017-09-27 06:03:43 +00:00
|
|
|
const std::vector<std::string>& args,
|
|
|
|
const std::vector<FileContents>& file_contents,
|
2017-05-17 07:08:45 +00:00
|
|
|
PerformanceImportFile* perf,
|
2018-04-09 07:52:04 +00:00
|
|
|
ClangIndex* index);
|
2018-04-02 07:22:12 +00:00
|
|
|
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
2017-12-29 16:29:47 +00:00
|
|
|
FileConsumerSharedState* file_consumer_shared,
|
2017-09-27 06:03:43 +00:00
|
|
|
PerformanceImportFile* perf,
|
2017-11-11 19:41:09 +00:00
|
|
|
ClangTranslationUnit* tu,
|
|
|
|
ClangIndex* index,
|
2017-09-27 06:03:43 +00:00
|
|
|
const std::string& file,
|
|
|
|
const std::vector<std::string>& args,
|
|
|
|
const std::vector<CXUnsavedFile>& file_contents);
|
|
|
|
|
2018-04-06 00:00:07 +00:00
|
|
|
bool ConcatTypeAndName(std::string& type, const std::string& name);
|
2017-12-30 21:11:55 +00:00
|
|
|
|
2017-04-17 20:40:50 +00:00
|
|
|
void IndexInit();
|
2018-04-22 17:01:44 +00:00
|
|
|
|
|
|
|
// Abstracts away the actual indexing process. Each IIndexer instance is
|
|
|
|
// per-thread and constructing an instance may be extremely expensive (ie,
|
|
|
|
// acquire a lock) and should be done as rarely as possible.
|
|
|
|
struct IIndexer {
|
|
|
|
struct TestEntry {
|
|
|
|
std::string path;
|
|
|
|
int num_indexes = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::unique_ptr<IIndexer> MakeTestIndexer(
|
|
|
|
std::initializer_list<TestEntry> entries);
|
|
|
|
|
|
|
|
virtual ~IIndexer() = default;
|
|
|
|
virtual std::vector<std::unique_ptr<IndexFile>> Index(
|
|
|
|
FileConsumerSharedState* file_consumer_shared,
|
|
|
|
std::string file,
|
|
|
|
const std::vector<std::string>& args,
|
|
|
|
const std::vector<FileContents>& file_contents,
|
|
|
|
PerformanceImportFile* perf) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ClangIndexer : IIndexer {
|
|
|
|
std::vector<std::unique_ptr<IndexFile>> Index(
|
|
|
|
FileConsumerSharedState* file_consumer_shared,
|
|
|
|
std::string file,
|
|
|
|
const std::vector<std::string>& args,
|
|
|
|
const std::vector<FileContents>& file_contents,
|
|
|
|
PerformanceImportFile* perf) override {
|
|
|
|
return Parse(file_consumer_shared, file, args, file_contents, perf, &index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: constructing this acquires a global lock
|
|
|
|
ClangIndex index;
|
|
|
|
};
|