diff --git a/index_tests/enums/enum_usage.cc b/index_tests/enums/enum_usage.cc index 80563ab02..befc145fc 100644 --- a/index_tests/enums/enum_usage.cc +++ b/index_tests/enums/enum_usage.cc @@ -68,7 +68,6 @@ Foo x = Foo::A; "definition_extent": "6:1-6:15", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/foobar.cc b/index_tests/foobar.cc index d70e8cf58..3e9323058 100644 --- a/index_tests/foobar.cc +++ b/index_tests/foobar.cc @@ -85,7 +85,6 @@ Foo b; "definition_extent": "9:1-9:16", "variable_type": 3, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -99,7 +98,6 @@ Foo b; "definition_extent": "10:1-10:9", "variable_type": 2, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/inheritance/class_inherit_templated_parent.cc b/index_tests/inheritance/class_inherit_templated_parent.cc index 24da1657e..fab4568ef 100644 --- a/index_tests/inheritance/class_inherit_templated_parent.cc +++ b/index_tests/inheritance/class_inherit_templated_parent.cc @@ -132,7 +132,6 @@ class Derived : Base1<3>, Base2, Derived1<4>, Derived2 {}; "definition_extent": "7:10-7:24", "variable_type": 3, "uses": ["8:24-8:25"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 25, "storage": 0 diff --git a/index_tests/lambdas/lambda.cc b/index_tests/lambdas/lambda.cc index a52a6495b..b946312e4 100644 --- a/index_tests/lambdas/lambda.cc +++ b/index_tests/lambdas/lambda.cc @@ -110,7 +110,6 @@ void foo() { "definition_extent": "4:27-4:32", "variable_type": 0, "uses": ["6:7-6:8"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 25, "storage": 1 diff --git a/index_tests/macros/complex.cc b/index_tests/macros/complex.cc index 0284af9da..3f5cbf68c 100644 --- a/index_tests/macros/complex.cc +++ b/index_tests/macros/complex.cc @@ -77,7 +77,6 @@ FOO(make1(), make2); "definition_extent": "9:1-9:20", "variable_type": 0, "uses": ["12:14-12:19"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -91,7 +90,6 @@ FOO(make1(), make2); "definition_spelling": "1:9-1:12", "definition_extent": "1:9-3:32", "uses": ["12:1-12:4"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 4, "storage": 0 diff --git a/index_tests/macros/foo.cc b/index_tests/macros/foo.cc index b9da0979b..0e3493795 100644 --- a/index_tests/macros/foo.cc +++ b/index_tests/macros/foo.cc @@ -69,7 +69,6 @@ int x = A; "definition_extent": "8:1-8:10", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -83,7 +82,6 @@ int x = A; "definition_spelling": "1:9-1:10", "definition_extent": "1:9-1:12", "uses": ["8:9-8:10"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 4, "storage": 0 @@ -97,7 +95,6 @@ int x = A; "definition_spelling": "2:9-2:17", "definition_extent": "2:9-2:46", "uses": ["5:3-5:11"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 4, "storage": 0 diff --git a/index_tests/multi_file/impl.cc b/index_tests/multi_file/impl.cc index 75f5cfe2e..e03f44976 100644 --- a/index_tests/multi_file/impl.cc +++ b/index_tests/multi_file/impl.cc @@ -171,7 +171,6 @@ OUTPUT: header.h "definition_extent": "17:1-17:9", "variable_type": 5, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -185,7 +184,6 @@ OUTPUT: header.h "definition_extent": "18:1-18:16", "variable_type": 5, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 diff --git a/index_tests/preprocessor/include_guard.cc b/index_tests/preprocessor/include_guard.cc index ef7aee591..f9822a68e 100644 --- a/index_tests/preprocessor/include_guard.cc +++ b/index_tests/preprocessor/include_guard.cc @@ -20,7 +20,6 @@ "definition_spelling": "2:9-2:12", "definition_extent": "2:9-2:12", "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 4, "storage": 0 diff --git a/index_tests/templates/specialization.cc b/index_tests/templates/specialization.cc index d09bdd2af..713e9f05e 100644 --- a/index_tests/templates/specialization.cc +++ b/index_tests/templates/specialization.cc @@ -323,7 +323,6 @@ void foo(float Value); "definition_extent": "7:1-7:22", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -337,7 +336,6 @@ void foo(float Value); "definition_extent": "30:1-30:16", "variable_type": 5, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -351,7 +349,6 @@ void foo(float Value); "definition_extent": "31:1-31:17", "variable_type": 6, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -365,7 +362,6 @@ void foo(float Value); "definition_extent": "32:1-32:15", "variable_type": 5, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -379,7 +375,6 @@ void foo(float Value); "definition_extent": "33:1-33:15", "variable_type": 5, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -437,7 +432,6 @@ void foo(float Value); "definition_extent": "41:1-41:27", "variable_type": 13, "uses": ["43:27-43:32"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 diff --git a/index_tests/templates/template_class_func_usage_folded_into_one.cc b/index_tests/templates/template_class_func_usage_folded_into_one.cc index baef20ec3..f9667ee0b 100644 --- a/index_tests/templates/template_class_func_usage_folded_into_one.cc +++ b/index_tests/templates/template_class_func_usage_folded_into_one.cc @@ -70,7 +70,6 @@ int b = Foo::foo(); "definition_extent": "8:1-8:24", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -85,7 +84,6 @@ int b = Foo::foo(); "definition_extent": "9:1-9:25", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/templates/template_class_template_func_usage_folded_into_one.cc b/index_tests/templates/template_class_template_func_usage_folded_into_one.cc index 88c5e458b..9ab36e05f 100644 --- a/index_tests/templates/template_class_template_func_usage_folded_into_one.cc +++ b/index_tests/templates/template_class_template_func_usage_folded_into_one.cc @@ -71,7 +71,6 @@ int b = Foo::foo(); "definition_extent": "9:1-9:31", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -86,7 +85,6 @@ int b = Foo::foo(); "definition_extent": "10:1-10:33", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/templates/template_class_type_usage_folded_into_one.cc b/index_tests/templates/template_class_type_usage_folded_into_one.cc index 9d870c284..26c5e9457 100644 --- a/index_tests/templates/template_class_type_usage_folded_into_one.cc +++ b/index_tests/templates/template_class_type_usage_folded_into_one.cc @@ -104,7 +104,6 @@ VarDecl b "definition_extent": "9:1-9:16", "variable_type": 3, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -118,7 +117,6 @@ VarDecl b "definition_extent": "10:1-10:16", "variable_type": 3, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/templates/template_class_var_usage_folded_into_one.cc b/index_tests/templates/template_class_var_usage_folded_into_one.cc index 596fe7b9a..a32f1576c 100644 --- a/index_tests/templates/template_class_var_usage_folded_into_one.cc +++ b/index_tests/templates/template_class_var_usage_folded_into_one.cc @@ -50,7 +50,6 @@ int b = Foo::var; "declarations": ["3:24-3:27"], "variable_type": 1, "uses": ["6:19-6:22", "7:20-7:23"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 21, "storage": 3 @@ -65,7 +64,6 @@ int b = Foo::var; "definition_extent": "6:1-6:22", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -80,7 +78,6 @@ int b = Foo::var; "definition_extent": "7:1-7:23", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/templates/template_func_usage_folded_into_one.cc b/index_tests/templates/template_func_usage_folded_into_one.cc index c6a732dbc..e8669137e 100644 --- a/index_tests/templates/template_func_usage_folded_into_one.cc +++ b/index_tests/templates/template_func_usage_folded_into_one.cc @@ -55,7 +55,6 @@ int b = foo(); "definition_extent": "6:1-6:19", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -70,7 +69,6 @@ int b = foo(); "definition_extent": "7:1-7:20", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/templates/template_type_usage_folded_into_one.cc b/index_tests/templates/template_type_usage_folded_into_one.cc index b721af04f..9ebcaeed4 100644 --- a/index_tests/templates/template_type_usage_folded_into_one.cc +++ b/index_tests/templates/template_type_usage_folded_into_one.cc @@ -36,7 +36,6 @@ Foo b; "definition_extent": "4:1-4:11", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -50,7 +49,6 @@ Foo b; "definition_extent": "5:1-5:12", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/templates/template_var_usage_folded_into_one.cc b/index_tests/templates/template_var_usage_folded_into_one.cc index e18c88b6e..e8d80cd58 100644 --- a/index_tests/templates/template_var_usage_folded_into_one.cc +++ b/index_tests/templates/template_var_usage_folded_into_one.cc @@ -89,7 +89,6 @@ UnexposedDecl var "definition_spelling": "5:3-5:6", "definition_extent": "5:1-5:12", "uses": ["7:7-7:10", "8:7-8:10"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -104,7 +103,6 @@ UnexposedDecl var "definition_extent": "7:1-7:13", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 @@ -119,7 +117,6 @@ UnexposedDecl var "definition_extent": "8:1-8:13", "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/unions/union_usage.cc b/index_tests/unions/union_usage.cc index 7a575fcbc..b51de4909 100644 --- a/index_tests/unions/union_usage.cc +++ b/index_tests/unions/union_usage.cc @@ -114,7 +114,6 @@ void act(Foo*) { "definition_extent": "6:1-6:6", "variable_type": 0, "uses": ["9:3-9:4"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 1 diff --git a/index_tests/usage/func_called_from_macro_argument.cc b/index_tests/usage/func_called_from_macro_argument.cc index f2d825c17..59978e845 100644 --- a/index_tests/usage/func_called_from_macro_argument.cc +++ b/index_tests/usage/func_called_from_macro_argument.cc @@ -56,7 +56,6 @@ void caller() { "definition_spelling": "1:9-1:19", "definition_extent": "1:9-1:24", "uses": ["6:3-6:13"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 4, "storage": 0 diff --git a/index_tests/usage/type_usage_as_template_parameter.cc b/index_tests/usage/type_usage_as_template_parameter.cc index c5c32ca89..73e0400cb 100644 --- a/index_tests/usage/type_usage_as_template_parameter.cc +++ b/index_tests/usage/type_usage_as_template_parameter.cc @@ -72,7 +72,6 @@ unique_ptr* return_type() { "definition_extent": "6:1-6:27", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 @@ -86,7 +85,6 @@ unique_ptr* return_type() { "definition_extent": "7:1-7:24", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 diff --git a/index_tests/usage/type_usage_as_template_parameter_complex.cc b/index_tests/usage/type_usage_as_template_parameter_complex.cc index 7187bfa32..5cdfa0edf 100644 --- a/index_tests/usage/type_usage_as_template_parameter_complex.cc +++ b/index_tests/usage/type_usage_as_template_parameter_complex.cc @@ -213,7 +213,6 @@ unique_ptr* Foo::foo() { return nullptr; } "declarations": ["15:43-15:44"], "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 2 diff --git a/index_tests/usage/type_usage_as_template_parameter_simple.cc b/index_tests/usage/type_usage_as_template_parameter_simple.cc index 2551c5561..ea43b600d 100644 --- a/index_tests/usage/type_usage_as_template_parameter_simple.cc +++ b/index_tests/usage/type_usage_as_template_parameter_simple.cc @@ -50,7 +50,6 @@ static unique_ptr foo; "definition_extent": "6:1-6:25", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 diff --git a/index_tests/usage/type_usage_declare_extern.cc b/index_tests/usage/type_usage_declare_extern.cc index 1a188326e..a940dd6ed 100644 --- a/index_tests/usage/type_usage_declare_extern.cc +++ b/index_tests/usage/type_usage_declare_extern.cc @@ -31,7 +31,6 @@ extern T t; "declarations": ["3:10-3:11"], "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 2 diff --git a/index_tests/usage/type_usage_declare_static.cc b/index_tests/usage/type_usage_declare_static.cc index 8a2d7b55d..09fb7325e 100644 --- a/index_tests/usage/type_usage_declare_static.cc +++ b/index_tests/usage/type_usage_declare_static.cc @@ -32,7 +32,6 @@ static Type t; "definition_extent": "2:1-2:14", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 diff --git a/index_tests/usage/type_usage_various.cc b/index_tests/usage/type_usage_various.cc index a4c477afb..0d18e1234 100644 --- a/index_tests/usage/type_usage_various.cc +++ b/index_tests/usage/type_usage_various.cc @@ -74,7 +74,6 @@ extern Foo foo; "declarations": ["10:12-10:15"], "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 2 diff --git a/index_tests/usage/var_usage_class_member_static.cc b/index_tests/usage/var_usage_class_member_static.cc index c998aad8c..fdf380177 100644 --- a/index_tests/usage/var_usage_class_member_static.cc +++ b/index_tests/usage/var_usage_class_member_static.cc @@ -84,7 +84,6 @@ void foo() { "declarations": ["2:14-2:15"], "variable_type": 1, "uses": ["8:15-8:16"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 21, "storage": 3 diff --git a/index_tests/usage/var_usage_extern.cc b/index_tests/usage/var_usage_extern.cc index 238a20401..3ce890875 100644 --- a/index_tests/usage/var_usage_extern.cc +++ b/index_tests/usage/var_usage_extern.cc @@ -46,7 +46,6 @@ void foo() { "declarations": ["1:12-1:13"], "variable_type": 0, "uses": ["4:3-4:4"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 2 diff --git a/index_tests/usage/var_usage_static.cc b/index_tests/usage/var_usage_static.cc index b4b2bd1b8..8bd7fdad7 100644 --- a/index_tests/usage/var_usage_static.cc +++ b/index_tests/usage/var_usage_static.cc @@ -49,7 +49,6 @@ void foo() { "definition_extent": "1:1-1:13", "variable_type": 0, "uses": ["4:3-4:4"], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 diff --git a/index_tests/vars/class_static_member_decl_only.cc b/index_tests/vars/class_static_member_decl_only.cc index fa3e3c173..ed4da667f 100644 --- a/index_tests/vars/class_static_member_decl_only.cc +++ b/index_tests/vars/class_static_member_decl_only.cc @@ -44,7 +44,6 @@ class Foo { "declarations": ["2:14-2:20"], "variable_type": 1, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 21, "storage": 3 diff --git a/index_tests/vars/global_variable.cc b/index_tests/vars/global_variable.cc index 43e381030..057908449 100644 --- a/index_tests/vars/global_variable.cc +++ b/index_tests/vars/global_variable.cc @@ -30,7 +30,6 @@ static int global = 0; "definition_extent": "1:1-1:22", "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 3 diff --git a/index_tests/vars/global_variable_decl_only.cc b/index_tests/vars/global_variable_decl_only.cc index f81ca342e..f904efdbe 100644 --- a/index_tests/vars/global_variable_decl_only.cc +++ b/index_tests/vars/global_variable_decl_only.cc @@ -27,7 +27,6 @@ extern int global; "declarations": ["1:12-1:18"], "variable_type": 0, "uses": [], - "parent_id": 18446744073709551615, "parent_kind": 0, "kind": 13, "storage": 2 diff --git a/src/indexer.cc b/src/indexer.cc index 913416f37..56d78211b 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1464,12 +1464,12 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { IndexFuncId parent_func_id = db->ToFuncId(decl->semanticContainer->cursor); var->def.parent_kind = SymbolKind::Func; - var->def.parent_id = size_t(parent_func_id); + var->def.parent_id = Id(parent_func_id); } else if (IsTypeDefinition(decl->semanticContainer)) { IndexTypeId parent_type_id = db->ToTypeId(decl->semanticContainer->cursor); var->def.parent_kind = SymbolKind::Type; - var->def.parent_id = size_t(parent_type_id); + var->def.parent_id = Id(parent_type_id); db->Resolve(parent_type_id)->def.vars.push_back(var_id); } } diff --git a/src/indexer.h b/src/indexer.h index 295c0a998..37b1dd70d 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -36,20 +36,22 @@ struct IndexVar; enum class SymbolKind : uint8_t { Invalid, File, Type, Func, Var }; MAKE_REFLECT_TYPE_PROXY(SymbolKind); +using RawId = uint32_t; + template struct Id { - size_t id; + RawId id; // Invalid id. Id() : id(-1) {} - explicit Id(size_t id) : id(id) {} + explicit Id(RawId id) : id(id) {} template explicit Id(Id o) : id(o.id) {} // Needed for google::dense_hash_map. - explicit operator size_t() const { return id; } + explicit operator RawId() const { return id; } - bool HasValue() const { return id != size_t(-1); } + bool HasValue() const { return id != RawId(-1); } bool operator==(const Id& other) const { return id == other.id; } @@ -99,7 +101,7 @@ struct IndexFuncRef { IndexFuncRef(IndexFuncId id, Range loc, bool is_implicit) : id(id), loc(loc), is_implicit(is_implicit) {} IndexFuncRef(Range loc, bool is_implicit) - : id(IndexFuncId((size_t)-1)), loc(loc), is_implicit(is_implicit) {} + : loc(loc), is_implicit(is_implicit) {} inline bool operator==(const IndexFuncRef& other) { return id == other.id && loc == other.loc && @@ -109,12 +111,11 @@ struct IndexFuncRef { return !(*this == other); } inline bool operator<(const IndexFuncRef& other) const { - if (id < other.id) - return true; - if (id == other.id && loc < other.loc) - return true; - return id == other.id && loc == other.loc && - is_implicit < other.is_implicit; + if (id != other.id) + return id < other.id; + if (loc != other.loc) + return loc < other.loc; + return is_implicit < other.is_implicit; } }; @@ -144,12 +145,11 @@ inline void Reflect(Writer& visitor, IndexFuncRef& value) { if (value.is_implicit) s += "~"; - // id.id is unsigned, special case 0 value - if (value.id.id == static_cast(-1)) { - s += "-1"; - } else { + // id.id is unsigned, special case -1 value + if (value.id.HasValue()) s += std::to_string(value.id.id); - } + else + s += "-1"; s += "@" + value.loc.ToString(); visitor.String(s.c_str()); @@ -403,7 +403,7 @@ struct VarDefDefinitionData { Maybe variable_type; // Function/type which declares this one. - size_t parent_id = size_t(-1); + Maybe> parent_id; int16_t short_name_offset = 0; int16_t short_name_size = 0; SymbolKind parent_kind = SymbolKind::Invalid; diff --git a/src/message_handler.cc b/src/message_handler.cc index 0fc409fd2..95c2bcc26 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -54,7 +54,7 @@ bool FindFileOrFail(QueryDatabase* db, } if (out_file_id) - *out_file_id = QueryFileId((size_t)-1); + *out_file_id = QueryFileId(); bool indexing = project->absolute_path_to_entry_index_.find(absolute_path) != project->absolute_path_to_entry_index_.end(); diff --git a/src/query.cc b/src/query.cc index 665c1a646..b681b1fc9 100644 --- a/src/query.cc +++ b/src/query.cc @@ -304,7 +304,7 @@ Maybe GetQueryFileIdFromPath(QueryDatabase* query_db, if (!create_if_missing) return {}; - size_t idx = query_db->files.size(); + RawId idx = query_db->files.size(); query_db->usr_to_file[normalized_path] = QueryFileId(idx); query_db->files.push_back(QueryFile(path)); return QueryFileId(idx); @@ -319,7 +319,7 @@ Maybe GetQueryTypeIdFromUsr(QueryDatabase* query_db, if (!create_if_missing) return {}; - size_t idx = query_db->types.size(); + RawId idx = query_db->types.size(); query_db->usr_to_type[usr] = QueryTypeId(idx); query_db->types.push_back(QueryType(usr)); return QueryTypeId(idx); @@ -334,7 +334,7 @@ Maybe GetQueryFuncIdFromUsr(QueryDatabase* query_db, if (!create_if_missing) return {}; - size_t idx = query_db->funcs.size(); + RawId idx = query_db->funcs.size(); query_db->usr_to_func[usr] = QueryFuncId(idx); query_db->funcs.push_back(QueryFunc(usr)); return QueryFuncId(idx); @@ -349,7 +349,7 @@ Maybe GetQueryVarIdFromUsr(QueryDatabase* query_db, if (!create_if_missing) return {}; - size_t idx = query_db->vars.size(); + RawId idx = query_db->vars.size(); query_db->usr_to_var[usr] = QueryVarId(idx); query_db->vars.push_back(QueryVar(usr)); return QueryVarId(idx); @@ -956,15 +956,15 @@ void QueryDatabase::ImportOrUpdate( void QueryDatabase::UpdateSymbols(Maybe>* symbol_idx, SymbolKind kind, - size_t idx) { + RawId idx) { if (!symbol_idx->has_value()) { *symbol_idx = Id(symbols.size()); symbols.push_back(SymbolIdx(kind, idx)); } } -std::string_view QueryDatabase::GetSymbolDetailedName(size_t symbol_idx) const { - size_t idx = symbols[symbol_idx].idx; +std::string_view QueryDatabase::GetSymbolDetailedName(RawId symbol_idx) const { + RawId idx = symbols[symbol_idx].idx; switch (symbols[symbol_idx].kind) { default: break; @@ -988,8 +988,8 @@ std::string_view QueryDatabase::GetSymbolDetailedName(size_t symbol_idx) const { return ""; } -std::string_view QueryDatabase::GetSymbolShortName(size_t symbol_idx) const { - size_t idx = symbols[symbol_idx].idx; +std::string_view QueryDatabase::GetSymbolShortName(RawId symbol_idx) const { + RawId idx = symbols[symbol_idx].idx; switch (symbols[symbol_idx].kind) { default: break; diff --git a/src/query.h b/src/query.h index 60df5141c..91c008f2a 100644 --- a/src/query.h +++ b/src/query.h @@ -61,12 +61,12 @@ struct hash<::SymbolKind> { struct SymbolIdx { SymbolKind kind; - size_t idx; + RawId idx; SymbolIdx() : kind(SymbolKind::Invalid), - idx((size_t)-1) {} // Default ctor needed by stdlib. Do not use. - SymbolIdx(SymbolKind kind, uint64_t idx) : kind(kind), idx(idx) {} + 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; @@ -386,9 +386,9 @@ struct QueryDatabase { void ImportOrUpdate(const std::vector& updates); void ImportOrUpdate(const std::vector& updates); void ImportOrUpdate(const std::vector& updates); - void UpdateSymbols(Maybe>* 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; + void UpdateSymbols(Maybe>* symbol_idx, SymbolKind kind, RawId idx); + std::string_view GetSymbolDetailedName(RawId symbol_idx) const; + std::string_view GetSymbolShortName(RawId symbol_idx) const; // Query the indexing structure to look up symbol id for given Usr. Maybe GetQueryFileIdFromPath(const std::string& path);