mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 21:58:08 +00:00
Simplify operator==
This commit is contained in:
parent
65d7edd9b9
commit
d573a68130
107
src/indexer.h
107
src/indexer.h
@ -53,9 +53,9 @@ struct Id {
|
||||
|
||||
bool HasValue() const { return id != RawId(-1); }
|
||||
|
||||
bool operator==(const Id<T>& other) const { return id == other.id; }
|
||||
|
||||
bool operator<(const Id<T>& other) const { return id < other.id; }
|
||||
bool operator==(const Id<T>& o) const { return id == o.id; }
|
||||
bool operator!=(const Id<T>& o) const { return id != o.id; }
|
||||
bool operator<(const Id<T>& o) const { return id < o.id; }
|
||||
};
|
||||
|
||||
namespace std {
|
||||
@ -65,23 +65,9 @@ struct hash<Id<T>> {
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
template <typename T>
|
||||
bool operator==(const Id<T>& a, const Id<T>& b) {
|
||||
assert(a.group == b.group && "Cannot compare Ids from different groups");
|
||||
return a.id == b.id;
|
||||
}
|
||||
template <typename T>
|
||||
bool operator!=(const Id<T>& a, const Id<T>& b) {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Reflect(Reader& visitor, Id<T>& id) {
|
||||
id.id = visitor.GetUint64();
|
||||
}
|
||||
template <typename T>
|
||||
void Reflect(Writer& visitor, Id<T>& value) {
|
||||
visitor.Uint64(value.id);
|
||||
template <typename TVisitor, typename T>
|
||||
void Reflect(TVisitor& visitor, Id<T>& id) {
|
||||
Reflect(visitor, id.id);
|
||||
}
|
||||
|
||||
using IndexTypeId = Id<IndexType>;
|
||||
@ -103,29 +89,16 @@ struct IndexFuncRef {
|
||||
IndexFuncRef(Range loc, bool is_implicit)
|
||||
: loc(loc), is_implicit(is_implicit) {}
|
||||
|
||||
inline bool operator==(const IndexFuncRef& other) {
|
||||
return id == other.id && loc == other.loc &&
|
||||
is_implicit == other.is_implicit;
|
||||
std::tuple<IndexFuncId, Range, bool> ToTuple() const {
|
||||
return {id, loc, is_implicit};
|
||||
}
|
||||
inline bool operator!=(const IndexFuncRef& other) {
|
||||
return !(*this == other);
|
||||
}
|
||||
inline bool operator<(const IndexFuncRef& other) const {
|
||||
if (id != other.id)
|
||||
return id < other.id;
|
||||
if (loc != other.loc)
|
||||
return loc < other.loc;
|
||||
return is_implicit < other.is_implicit;
|
||||
bool operator==(const IndexFuncRef& o) { return ToTuple() == o.ToTuple(); }
|
||||
bool operator!=(const IndexFuncRef& o) { return !(*this == o); }
|
||||
bool operator<(const IndexFuncRef& o) const {
|
||||
return ToTuple() < o.ToTuple();
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==(const IndexFuncRef& a, const IndexFuncRef& b) {
|
||||
return a.id == b.id && a.loc == b.loc;
|
||||
}
|
||||
inline bool operator!=(const IndexFuncRef& a, const IndexFuncRef& b) {
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
inline void Reflect(Reader& visitor, IndexFuncRef& value) {
|
||||
std::string s = visitor.GetString();
|
||||
const char* str_value = s.c_str();
|
||||
@ -190,19 +163,16 @@ struct TypeDefDefinitionData {
|
||||
int16_t short_name_size = 0;
|
||||
ClangSymbolKind kind = ClangSymbolKind::Unknown;
|
||||
|
||||
bool operator==(
|
||||
const TypeDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||
return detailed_name == other.detailed_name &&
|
||||
definition_spelling == other.definition_spelling &&
|
||||
definition_extent == other.definition_extent &&
|
||||
alias_of == other.alias_of && parents == other.parents &&
|
||||
types == other.types && funcs == other.funcs && vars == other.vars &&
|
||||
hover == other.hover && comments == other.comments;
|
||||
bool operator==(const TypeDefDefinitionData& o) const {
|
||||
return detailed_name == o.detailed_name &&
|
||||
definition_spelling == o.definition_spelling &&
|
||||
definition_extent == o.definition_extent && alias_of == o.alias_of &&
|
||||
parents == o.parents && types == o.types && funcs == o.funcs &&
|
||||
vars == o.vars && kind == o.kind && hover == o.hover &&
|
||||
kind == o.kind && hover == o.hover && comments == o.comments;
|
||||
}
|
||||
|
||||
bool operator!=(
|
||||
const TypeDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||
return !(*this == other);
|
||||
bool operator!=(const TypeDefDefinitionData& o) const {
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
std::string_view ShortName() const {
|
||||
@ -290,20 +260,16 @@ struct FuncDefDefinitionData {
|
||||
ClangSymbolKind kind = ClangSymbolKind::Unknown;
|
||||
StorageClass storage = StorageClass::Invalid;
|
||||
|
||||
bool operator==(
|
||||
const FuncDefDefinitionData<TypeId, FuncId, VarId, FuncRef, Range>& other)
|
||||
const {
|
||||
return detailed_name == other.detailed_name && hover == other.hover &&
|
||||
definition_spelling == other.definition_spelling &&
|
||||
definition_extent == other.definition_extent &&
|
||||
declaring_type == other.declaring_type && base == other.base &&
|
||||
locals == other.locals && callees == other.callees &&
|
||||
hover == other.hover && comments == other.comments;
|
||||
bool operator==(const FuncDefDefinitionData& o) const {
|
||||
return detailed_name == o.detailed_name &&
|
||||
definition_spelling == o.definition_spelling &&
|
||||
definition_extent == o.definition_extent &&
|
||||
declaring_type == o.declaring_type && base == o.base &&
|
||||
locals == o.locals && callees == o.callees && kind == o.kind &&
|
||||
storage == o.storage && hover == o.hover && comments == o.comments;
|
||||
}
|
||||
bool operator!=(
|
||||
const FuncDefDefinitionData<TypeId, FuncId, VarId, FuncRef, Range>& other)
|
||||
const {
|
||||
return !(*this == other);
|
||||
bool operator!=(const FuncDefDefinitionData& o) const {
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
std::string_view ShortName() const {
|
||||
@ -419,12 +385,13 @@ struct VarDefDefinitionData {
|
||||
}
|
||||
bool is_macro() const { return kind == ClangSymbolKind::Macro; }
|
||||
|
||||
bool operator==(
|
||||
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||
return detailed_name == other.detailed_name && hover == other.hover &&
|
||||
definition_spelling == other.definition_spelling &&
|
||||
definition_extent == other.definition_extent &&
|
||||
variable_type == other.variable_type && comments == other.comments;
|
||||
bool operator==(const VarDefDefinitionData& o) const {
|
||||
return detailed_name == o.detailed_name &&
|
||||
definition_spelling == o.definition_spelling &&
|
||||
definition_extent == o.definition_extent &&
|
||||
variable_type == o.variable_type && parent_id == o.parent_id &&
|
||||
parent_kind == o.parent_kind && kind == o.kind &&
|
||||
storage == o.storage && hover == o.hover && comments == o.comments;
|
||||
}
|
||||
bool operator!=(
|
||||
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||
|
66
src/query.h
66
src/query.h
@ -62,12 +62,10 @@ struct QueryLocation {
|
||||
|
||||
bool HasValue() const { return range.HasValue(); }
|
||||
|
||||
bool operator==(const QueryLocation& other) const {
|
||||
return path == other.path && range == other.range;
|
||||
}
|
||||
bool operator!=(const QueryLocation& other) const {
|
||||
return !(*this == other);
|
||||
bool operator==(const QueryLocation& o) const {
|
||||
return path == o.path && range == o.range;
|
||||
}
|
||||
bool operator!=(const QueryLocation& o) const { return !(*this == o); }
|
||||
bool operator<(const QueryLocation& o) const {
|
||||
if (path != o.path)
|
||||
return path < o.path;
|
||||
@ -95,14 +93,14 @@ struct SymbolIdx {
|
||||
idx(RawId(-1)) {} // Default ctor needed by stdlib. Do not use.
|
||||
SymbolIdx(SymbolKind kind, RawId idx) : kind(kind), idx(idx) {}
|
||||
|
||||
bool operator==(const SymbolIdx& that) const {
|
||||
return kind == that.kind && idx == that.idx;
|
||||
bool operator==(const SymbolIdx& o) const {
|
||||
return kind == o.kind && idx == o.idx;
|
||||
}
|
||||
bool operator!=(const SymbolIdx& that) const { return !(*this == that); }
|
||||
bool operator<(const SymbolIdx& that) const {
|
||||
if (kind != that.kind)
|
||||
return kind < that.kind;
|
||||
return idx < that.idx;
|
||||
bool operator!=(const SymbolIdx& o) const { return !(*this == o); }
|
||||
bool operator<(const SymbolIdx& o) const {
|
||||
if (kind != o.kind)
|
||||
return kind < o.kind;
|
||||
return idx < o.idx;
|
||||
}
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(SymbolIdx, kind, idx);
|
||||
@ -117,15 +115,12 @@ struct SymbolRef {
|
||||
SymbolRef(SymbolIdx idx, SymbolRole role, QueryLocation loc)
|
||||
: idx(idx), role(role), loc(loc) {}
|
||||
|
||||
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 {
|
||||
if (idx != that.idx)
|
||||
return idx < that.idx;
|
||||
return loc < that.loc;
|
||||
std::tuple<SymbolIdx, SymbolRole, QueryLocation> ToTuple() const {
|
||||
return {idx, role, loc};
|
||||
}
|
||||
bool operator==(const SymbolRef& o) const { return ToTuple() == o.ToTuple(); }
|
||||
bool operator!=(const SymbolRef& o) const { return !(*this == o); }
|
||||
bool operator<(const SymbolRef& o) const { return ToTuple() < o.ToTuple(); }
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(SymbolRef, idx, loc);
|
||||
|
||||
@ -141,17 +136,15 @@ struct QueryFuncRef {
|
||||
QueryFuncRef(QueryFuncId id, QueryLocation loc, bool is_implicit)
|
||||
: id_(id), loc(loc), is_implicit(is_implicit) {}
|
||||
|
||||
bool operator==(const QueryFuncRef& that) const {
|
||||
return id_ == that.id_ && loc == that.loc &&
|
||||
is_implicit == that.is_implicit;
|
||||
std::tuple<QueryFuncId, QueryLocation, bool> ToTuple() const {
|
||||
return {id_, loc, is_implicit};
|
||||
}
|
||||
bool operator!=(const QueryFuncRef& that) const { return !(*this == that); }
|
||||
bool operator<(const QueryFuncRef& that) const {
|
||||
if (id_ != that.id_)
|
||||
return id_ < that.id_;
|
||||
if (loc != that.loc)
|
||||
return loc < that.loc;
|
||||
return is_implicit < that.is_implicit;
|
||||
bool operator==(const QueryFuncRef& o) const {
|
||||
return ToTuple() == o.ToTuple();
|
||||
}
|
||||
bool operator!=(const QueryFuncRef& o) const { return !(*this == o); }
|
||||
bool operator<(const QueryFuncRef& o) const {
|
||||
return ToTuple() < o.ToTuple();
|
||||
}
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(QueryFuncRef, id_, loc, is_implicit);
|
||||
@ -176,23 +169,10 @@ struct MergeableUpdate {
|
||||
|
||||
MergeableUpdate(TId id, const std::vector<TValue>& to_add)
|
||||
: id(id), to_add(to_add) {}
|
||||
MergeableUpdate(TId id, const std::vector<WithGen<TValue>>& to_add) : id(id) {
|
||||
for (auto& x : to_add)
|
||||
this->to_add.push_back(x.value);
|
||||
}
|
||||
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) {}
|
||||
MergeableUpdate(TId id,
|
||||
const std::vector<WithGen<TValue>>& to_add,
|
||||
const std::vector<WithGen<TValue>>& to_remove)
|
||||
: id(id) {
|
||||
for (auto& x : to_add)
|
||||
this->to_add.push_back(x.value);
|
||||
for (auto& x : to_remove)
|
||||
this->to_remove.push_back(x.value);
|
||||
}
|
||||
};
|
||||
template <typename TVisitor, typename TId, typename TValue>
|
||||
void Reflect(TVisitor& visitor, MergeableUpdate<TId, TValue>& value) {
|
||||
|
2
wscript
2
wscript
@ -142,7 +142,7 @@ def configure(ctx):
|
||||
# /wd4722: ignores warning C4722 (destructor never returns) in loguru
|
||||
# /wd4267: ignores warning C4267 (conversion from 'size_t' to 'type'), roughly -Wno-sign-compare
|
||||
# /MD: use multithread c library from DLL
|
||||
cxxflags = ['/nologo', '/FS', '/EHsc', '/Zi', '/W3', '/WX', '/wd4996', '/wd4722', '/wd4267', '/wd4800', '/MD']
|
||||
cxxflags = ['/nologo', '/FS', '/EHsc', '/Zi', '/W3', '/wd4996', '/wd4722', '/wd4267', '/wd4800', '/MD']
|
||||
if 'release' in ctx.options.variant:
|
||||
cxxflags.append('/O2') # There is no O3
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user