mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
USR -> Usr
This commit is contained in:
parent
14a213d407
commit
da2cbe4152
@ -60,7 +60,7 @@ std::string ClangType::get_usr() const {
|
|||||||
return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr();
|
return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr();
|
||||||
}
|
}
|
||||||
|
|
||||||
USR ClangType::get_usr_hash() const {
|
Usr ClangType::get_usr_hash() const {
|
||||||
return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr_hash();
|
return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr_hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,9 +172,9 @@ std::string ClangCursor::get_usr() const {
|
|||||||
return ::ToString(clang_getCursorUSR(cx_cursor));
|
return ::ToString(clang_getCursorUSR(cx_cursor));
|
||||||
}
|
}
|
||||||
|
|
||||||
USR ClangCursor::get_usr_hash() const {
|
Usr ClangCursor::get_usr_hash() const {
|
||||||
CXString usr = clang_getCursorUSR(cx_cursor);
|
CXString usr = clang_getCursorUSR(cx_cursor);
|
||||||
USR ret = HashUSR(clang_getCString(usr));
|
Usr ret = HashUSR(clang_getCString(usr));
|
||||||
clang_disposeString(usr);
|
clang_disposeString(usr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using USR = uint64_t;
|
using Usr = uint64_t;
|
||||||
|
|
||||||
Range ResolveCXSourceRange(const CXSourceRange& range,
|
Range ResolveCXSourceRange(const CXSourceRange& range,
|
||||||
CXFile* cx_file = nullptr);
|
CXFile* cx_file = nullptr);
|
||||||
|
|
||||||
USR HashUSR(const char* usr);
|
Usr HashUSR(const char* usr);
|
||||||
|
|
||||||
class ClangType {
|
class ClangType {
|
||||||
public:
|
public:
|
||||||
@ -29,7 +29,7 @@ class ClangType {
|
|||||||
// ClangCursor is not defined so we have to return CXCursor
|
// ClangCursor is not defined so we have to return CXCursor
|
||||||
CXCursor get_declaration() const;
|
CXCursor get_declaration() const;
|
||||||
std::string get_usr() const;
|
std::string get_usr() const;
|
||||||
USR get_usr_hash() const;
|
Usr get_usr_hash() const;
|
||||||
std::string get_spelling() const;
|
std::string get_spelling() const;
|
||||||
ClangType get_canonical() const;
|
ClangType get_canonical() const;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ class ClangCursor {
|
|||||||
Range get_extent() const;
|
Range get_extent() const;
|
||||||
std::string get_display_name() const;
|
std::string get_display_name() const;
|
||||||
std::string get_usr() const;
|
std::string get_usr() const;
|
||||||
USR get_usr_hash() const;
|
Usr get_usr_hash() const;
|
||||||
|
|
||||||
bool is_definition() const;
|
bool is_definition() const;
|
||||||
|
|
||||||
|
@ -112,10 +112,10 @@ ClangSymbolKind GetSymbolKind(CXIdxEntityKind kind) {
|
|||||||
// constructor we will not be able to attribute the constructor call correctly.
|
// constructor we will not be able to attribute the constructor call correctly.
|
||||||
struct ConstructorCache {
|
struct ConstructorCache {
|
||||||
struct Constructor {
|
struct Constructor {
|
||||||
USR usr;
|
Usr usr;
|
||||||
std::vector<std::string> param_type_desc;
|
std::vector<std::string> param_type_desc;
|
||||||
};
|
};
|
||||||
std::unordered_map<USR, std::vector<Constructor>> constructors_;
|
std::unordered_map<Usr, std::vector<Constructor>> constructors_;
|
||||||
|
|
||||||
// This should be called whenever there is a constructor declaration.
|
// This should be called whenever there is a constructor declaration.
|
||||||
void NotifyConstructor(ClangCursor ctor_cursor) {
|
void NotifyConstructor(ClangCursor ctor_cursor) {
|
||||||
@ -142,8 +142,8 @@ struct ConstructorCache {
|
|||||||
|
|
||||||
// Tries to lookup a constructor in |type_usr| that takes arguments most
|
// Tries to lookup a constructor in |type_usr| that takes arguments most
|
||||||
// closely aligned to |param_type_desc|.
|
// closely aligned to |param_type_desc|.
|
||||||
optional<USR> TryFindConstructorUsr(
|
optional<Usr> TryFindConstructorUsr(
|
||||||
USR type_usr,
|
Usr type_usr,
|
||||||
const std::vector<std::string>& param_type_desc) {
|
const std::vector<std::string>& param_type_desc) {
|
||||||
auto count_matching_prefix_length = [](const char* a, const char* b) {
|
auto count_matching_prefix_length = [](const char* a, const char* b) {
|
||||||
int matched = 0;
|
int matched = 0;
|
||||||
@ -170,7 +170,7 @@ struct ConstructorCache {
|
|||||||
if (ctors.empty())
|
if (ctors.empty())
|
||||||
return nullopt;
|
return nullopt;
|
||||||
|
|
||||||
USR best_usr;
|
Usr best_usr;
|
||||||
int best_score = INT_MIN;
|
int best_score = INT_MIN;
|
||||||
|
|
||||||
// Scan constructors for the best possible match.
|
// Scan constructors for the best possible match.
|
||||||
@ -487,7 +487,7 @@ IndexFile::IndexFile(const std::string& path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize for const char*?
|
// TODO: Optimize for const char*?
|
||||||
IndexTypeId IndexFile::ToTypeId(USR usr) {
|
IndexTypeId IndexFile::ToTypeId(Usr usr) {
|
||||||
auto it = id_cache.usr_to_type_id.find(usr);
|
auto it = id_cache.usr_to_type_id.find(usr);
|
||||||
if (it != id_cache.usr_to_type_id.end())
|
if (it != id_cache.usr_to_type_id.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
@ -498,7 +498,7 @@ IndexTypeId IndexFile::ToTypeId(USR usr) {
|
|||||||
id_cache.type_id_to_usr[id] = usr;
|
id_cache.type_id_to_usr[id] = usr;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
IndexFuncId IndexFile::ToFuncId(USR usr) {
|
IndexFuncId IndexFile::ToFuncId(Usr usr) {
|
||||||
auto it = id_cache.usr_to_func_id.find(usr);
|
auto it = id_cache.usr_to_func_id.find(usr);
|
||||||
if (it != id_cache.usr_to_func_id.end())
|
if (it != id_cache.usr_to_func_id.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
@ -509,7 +509,7 @@ IndexFuncId IndexFile::ToFuncId(USR usr) {
|
|||||||
id_cache.func_id_to_usr[id] = usr;
|
id_cache.func_id_to_usr[id] = usr;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
IndexVarId IndexFile::ToVarId(USR usr) {
|
IndexVarId IndexFile::ToVarId(Usr usr) {
|
||||||
auto it = id_cache.usr_to_var_id.find(usr);
|
auto it = id_cache.usr_to_var_id.find(usr);
|
||||||
if (it != id_cache.usr_to_var_id.end())
|
if (it != id_cache.usr_to_var_id.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
@ -547,7 +547,7 @@ std::string IndexFile::ToString() {
|
|||||||
return Serialize(SerializeFormat::Json, *this);
|
return Serialize(SerializeFormat::Json, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexType::IndexType(IndexTypeId id, USR usr) : usr(usr), id(id) {}
|
IndexType::IndexType(IndexTypeId id, Usr usr) : usr(usr), id(id) {}
|
||||||
|
|
||||||
void RemoveItem(std::vector<Range>& ranges, Range to_remove) {
|
void RemoveItem(std::vector<Range>& ranges, Range to_remove) {
|
||||||
auto it = std::find(ranges.begin(), ranges.end(), to_remove);
|
auto it = std::find(ranges.begin(), ranges.end(), to_remove);
|
||||||
@ -951,7 +951,7 @@ ClangCursor::VisitResult AddDeclInitializerUsagesVisitor(ClangCursor cursor,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: when we resolve the template type to the definition, we get a
|
// TODO: when we resolve the template type to the definition, we get a
|
||||||
// different USR.
|
// different Usr.
|
||||||
|
|
||||||
// ClangCursor ref =
|
// ClangCursor ref =
|
||||||
// cursor.get_referenced().template_specialization_to_template_definition().get_type().strip_qualifiers().get_usr_hash();
|
// cursor.get_referenced().template_specialization_to_template_definition().get_type().strip_qualifiers().get_usr_hash();
|
||||||
@ -1011,7 +1011,7 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor,
|
|||||||
// only real difference will be that we show 'callers' instead of 'refs'
|
// only real difference will be that we show 'callers' instead of 'refs'
|
||||||
// (especially since macros cannot have overrides)
|
// (especially since macros cannot have overrides)
|
||||||
|
|
||||||
USR decl_usr;
|
Usr decl_usr;
|
||||||
if (cursor.get_kind() == CXCursor_MacroDefinition)
|
if (cursor.get_kind() == CXCursor_MacroDefinition)
|
||||||
decl_usr = cursor.get_usr_hash();
|
decl_usr = cursor.get_usr_hash();
|
||||||
else
|
else
|
||||||
@ -1777,7 +1777,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
|
|||||||
// the constructor function we add a usage to.
|
// the constructor function we add a usage to.
|
||||||
optional<ClangCursor> opt_found_type = FindType(ref->cursor);
|
optional<ClangCursor> opt_found_type = FindType(ref->cursor);
|
||||||
if (opt_found_type) {
|
if (opt_found_type) {
|
||||||
USR ctor_type_usr = opt_found_type->get_referenced().get_usr_hash();
|
Usr ctor_type_usr = opt_found_type->get_referenced().get_usr_hash();
|
||||||
ClangCursor call_cursor = ref->cursor;
|
ClangCursor call_cursor = ref->cursor;
|
||||||
|
|
||||||
// Build a type description from the parameters of the call, so we
|
// Build a type description from the parameters of the call, so we
|
||||||
@ -1790,7 +1790,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the constructor and add a reference.
|
// Try to find the constructor and add a reference.
|
||||||
optional<USR> ctor_usr =
|
optional<Usr> ctor_usr =
|
||||||
param->ctors.TryFindConstructorUsr(ctor_type_usr, call_type_desc);
|
param->ctors.TryFindConstructorUsr(ctor_type_usr, call_type_desc);
|
||||||
if (ctor_usr) {
|
if (ctor_usr) {
|
||||||
IndexFunc* ctor = db->Resolve(db->ToFuncId(*ctor_usr));
|
IndexFunc* ctor = db->Resolve(db->ToFuncId(*ctor_usr));
|
||||||
|
@ -260,7 +260,7 @@ struct IndexType {
|
|||||||
using Def =
|
using Def =
|
||||||
TypeDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
TypeDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
||||||
|
|
||||||
USR usr;
|
Usr usr;
|
||||||
IndexTypeId id;
|
IndexTypeId id;
|
||||||
|
|
||||||
Def def;
|
Def def;
|
||||||
@ -276,7 +276,7 @@ struct IndexType {
|
|||||||
std::vector<Range> uses;
|
std::vector<Range> uses;
|
||||||
|
|
||||||
IndexType() {} // For serialization.
|
IndexType() {} // For serialization.
|
||||||
IndexType(IndexTypeId id, USR usr);
|
IndexType(IndexTypeId id, Usr usr);
|
||||||
|
|
||||||
bool operator<(const IndexType& other) const { return id < other.id; }
|
bool operator<(const IndexType& other) const { return id < other.id; }
|
||||||
};
|
};
|
||||||
@ -362,7 +362,7 @@ struct IndexFunc {
|
|||||||
IndexFuncRef,
|
IndexFuncRef,
|
||||||
Range>;
|
Range>;
|
||||||
|
|
||||||
USR usr;
|
Usr usr;
|
||||||
IndexFuncId id;
|
IndexFuncId id;
|
||||||
|
|
||||||
Def def;
|
Def def;
|
||||||
@ -392,7 +392,7 @@ struct IndexFunc {
|
|||||||
std::vector<IndexFuncRef> callers;
|
std::vector<IndexFuncRef> callers;
|
||||||
|
|
||||||
IndexFunc() {} // For serialization.
|
IndexFunc() {} // For serialization.
|
||||||
IndexFunc(IndexFuncId id, USR usr) : usr(usr), id(id) {
|
IndexFunc(IndexFuncId id, Usr usr) : usr(usr), id(id) {
|
||||||
// assert(usr.size() > 0);
|
// assert(usr.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,7 +469,7 @@ void Reflect(TVisitor& visitor,
|
|||||||
struct IndexVar {
|
struct IndexVar {
|
||||||
using Def = VarDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
using Def = VarDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
||||||
|
|
||||||
USR usr;
|
Usr usr;
|
||||||
IndexVarId id;
|
IndexVarId id;
|
||||||
|
|
||||||
Def def;
|
Def def;
|
||||||
@ -478,7 +478,7 @@ struct IndexVar {
|
|||||||
std::vector<Range> uses;
|
std::vector<Range> uses;
|
||||||
|
|
||||||
IndexVar() {} // For serialization.
|
IndexVar() {} // For serialization.
|
||||||
IndexVar(IndexVarId id, USR usr) : usr(usr), id(id) {
|
IndexVar(IndexVarId id, Usr usr) : usr(usr), id(id) {
|
||||||
// assert(usr.size() > 0);
|
// assert(usr.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,12 +488,12 @@ MAKE_HASHABLE(IndexVar, t.id);
|
|||||||
|
|
||||||
struct IdCache {
|
struct IdCache {
|
||||||
std::string primary_file;
|
std::string primary_file;
|
||||||
std::unordered_map<USR, IndexTypeId> usr_to_type_id;
|
std::unordered_map<Usr, IndexTypeId> usr_to_type_id;
|
||||||
std::unordered_map<USR, IndexFuncId> usr_to_func_id;
|
std::unordered_map<Usr, IndexFuncId> usr_to_func_id;
|
||||||
std::unordered_map<USR, IndexVarId> usr_to_var_id;
|
std::unordered_map<Usr, IndexVarId> usr_to_var_id;
|
||||||
std::unordered_map<IndexTypeId, USR> type_id_to_usr;
|
std::unordered_map<IndexTypeId, Usr> type_id_to_usr;
|
||||||
std::unordered_map<IndexFuncId, USR> func_id_to_usr;
|
std::unordered_map<IndexFuncId, Usr> func_id_to_usr;
|
||||||
std::unordered_map<IndexVarId, USR> var_id_to_usr;
|
std::unordered_map<IndexVarId, Usr> var_id_to_usr;
|
||||||
|
|
||||||
IdCache(const std::string& primary_file);
|
IdCache(const std::string& primary_file);
|
||||||
};
|
};
|
||||||
@ -545,9 +545,9 @@ struct IndexFile {
|
|||||||
|
|
||||||
IndexFile(const std::string& path, const optional<std::string>& contents);
|
IndexFile(const std::string& path, const optional<std::string>& contents);
|
||||||
|
|
||||||
IndexTypeId ToTypeId(USR usr);
|
IndexTypeId ToTypeId(Usr usr);
|
||||||
IndexFuncId ToFuncId(USR usr);
|
IndexFuncId ToFuncId(Usr usr);
|
||||||
IndexVarId ToVarId(USR usr);
|
IndexVarId ToVarId(Usr usr);
|
||||||
IndexTypeId ToTypeId(const CXCursor& usr);
|
IndexTypeId ToTypeId(const CXCursor& usr);
|
||||||
IndexFuncId ToFuncId(const CXCursor& usr);
|
IndexFuncId ToFuncId(const CXCursor& usr);
|
||||||
IndexVarId ToVarId(const CXCursor& usr);
|
IndexVarId ToVarId(const CXCursor& usr);
|
||||||
|
@ -291,7 +291,7 @@ QueryFileId GetQueryFileIdFromPath(QueryDatabase* query_db,
|
|||||||
return QueryFileId(idx);
|
return QueryFileId(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryTypeId GetQueryTypeIdFromUsr(QueryDatabase* query_db, USR usr) {
|
QueryTypeId GetQueryTypeIdFromUsr(QueryDatabase* query_db, Usr usr) {
|
||||||
auto it = query_db->usr_to_type.find(usr);
|
auto it = query_db->usr_to_type.find(usr);
|
||||||
if (it != query_db->usr_to_type.end())
|
if (it != query_db->usr_to_type.end())
|
||||||
return QueryTypeId(it->second.id);
|
return QueryTypeId(it->second.id);
|
||||||
@ -302,7 +302,7 @@ QueryTypeId GetQueryTypeIdFromUsr(QueryDatabase* query_db, USR usr) {
|
|||||||
return QueryTypeId(idx);
|
return QueryTypeId(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryFuncId GetQueryFuncIdFromUsr(QueryDatabase* query_db, USR usr) {
|
QueryFuncId GetQueryFuncIdFromUsr(QueryDatabase* query_db, Usr usr) {
|
||||||
auto it = query_db->usr_to_func.find(usr);
|
auto it = query_db->usr_to_func.find(usr);
|
||||||
if (it != query_db->usr_to_func.end())
|
if (it != query_db->usr_to_func.end())
|
||||||
return QueryFuncId(it->second.id);
|
return QueryFuncId(it->second.id);
|
||||||
|
10
src/query.h
10
src/query.h
@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
using Usr = USR;
|
|
||||||
|
|
||||||
struct QueryFile;
|
struct QueryFile;
|
||||||
struct QueryType;
|
struct QueryType;
|
||||||
struct QueryFunc;
|
struct QueryFunc;
|
||||||
@ -170,10 +168,10 @@ void Reflect(TVisitor& visitor, MergeableUpdate<TId, TValue>& value) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct WithUsr {
|
struct WithUsr {
|
||||||
USR usr;
|
Usr usr;
|
||||||
T value;
|
T value;
|
||||||
|
|
||||||
WithUsr(USR usr, const T& value) : usr(usr), value(value) {}
|
WithUsr(Usr usr, const T& value) : usr(usr), value(value) {}
|
||||||
};
|
};
|
||||||
template <typename TVisitor, typename T>
|
template <typename TVisitor, typename T>
|
||||||
void Reflect(TVisitor& visitor, WithUsr<T>& value) {
|
void Reflect(TVisitor& visitor, WithUsr<T>& value) {
|
||||||
@ -225,7 +223,7 @@ struct QueryType {
|
|||||||
using InstancesUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
|
using InstancesUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
|
||||||
using UsesUpdate = MergeableUpdate<QueryTypeId, QueryLocation>;
|
using UsesUpdate = MergeableUpdate<QueryTypeId, QueryLocation>;
|
||||||
|
|
||||||
USR usr;
|
Usr usr;
|
||||||
optional<Def> def;
|
optional<Def> def;
|
||||||
std::vector<QueryTypeId> derived;
|
std::vector<QueryTypeId> derived;
|
||||||
std::vector<QueryVarId> instances;
|
std::vector<QueryVarId> instances;
|
||||||
@ -246,7 +244,7 @@ struct QueryFunc {
|
|||||||
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
|
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
|
||||||
using CallersUpdate = MergeableUpdate<QueryFuncId, QueryFuncRef>;
|
using CallersUpdate = MergeableUpdate<QueryFuncId, QueryFuncRef>;
|
||||||
|
|
||||||
USR usr;
|
Usr usr;
|
||||||
optional<Def> def;
|
optional<Def> def;
|
||||||
std::vector<QueryLocation> declarations;
|
std::vector<QueryLocation> declarations;
|
||||||
std::vector<QueryFuncId> derived;
|
std::vector<QueryFuncId> derived;
|
||||||
|
Loading…
Reference in New Issue
Block a user