From 8e4581b34c9584a49bc595d65c48167b9ecbe34f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 21 Jan 2026 12:21:38 +0100 Subject: tools/clang/codesearch: index struct references Update #6469 --- pkg/codesearch/testdata/query-file-index-source | 1 + .../testdata/query-find-references-struct | 15 +++++++++ pkg/codesearch/testdata/source0.c | 6 ++++ pkg/codesearch/testdata/source0.c.json | 37 ++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 pkg/codesearch/testdata/query-find-references-struct (limited to 'pkg/codesearch/testdata') diff --git a/pkg/codesearch/testdata/query-file-index-source b/pkg/codesearch/testdata/query-file-index-source index 3263deca3..af52513b7 100644 --- a/pkg/codesearch/testdata/query-file-index-source +++ b/pkg/codesearch/testdata/query-file-index-source @@ -3,6 +3,7 @@ file-index source0.c file source0.c defines the following entities: function close +function func_accepting_a_struct function function_with_comment_in_header function open struct struct_in_c_file diff --git a/pkg/codesearch/testdata/query-find-references-struct b/pkg/codesearch/testdata/query-find-references-struct new file mode 100644 index 000000000..cfb266dc7 --- /dev/null +++ b/pkg/codesearch/testdata/query-find-references-struct @@ -0,0 +1,15 @@ +find-references source0.c some_struct "" 1 10 + +some_struct has 2 references: + +function func_accepting_a_struct uses it at source0.c:29 + 29: int func_accepting_a_struct(struct some_struct* p) + 30: { + + +function func_accepting_a_struct uses it at source0.c:31 + 30: { + 31: return ((some_struct_t*)p)->x + + 32: ((union some_union*)p)->x; + + diff --git a/pkg/codesearch/testdata/source0.c b/pkg/codesearch/testdata/source0.c index 2d312ff99..5ac117cab 100644 --- a/pkg/codesearch/testdata/source0.c +++ b/pkg/codesearch/testdata/source0.c @@ -25,3 +25,9 @@ void function_with_comment_in_header() { same_name_in_several_files(); } + +int func_accepting_a_struct(struct some_struct* p) +{ + return ((some_struct_t*)p)->x + + ((union some_union*)p)->x; +} diff --git a/pkg/codesearch/testdata/source0.c.json b/pkg/codesearch/testdata/source0.c.json index ba6b41751..1732d7c97 100644 --- a/pkg/codesearch/testdata/source0.c.json +++ b/pkg/codesearch/testdata/source0.c.json @@ -21,6 +21,43 @@ }, "comment": {} }, + { + "kind": "function", + "name": "func_accepting_a_struct", + "type": "int (struct some_struct *)", + "body": { + "file": "source0.c", + "start_line": 29, + "end_line": 33 + }, + "comment": {}, + "refs": [ + { + "kind": "uses", + "entity_kind": "struct", + "name": "some_struct", + "line": 29 + }, + { + "kind": "uses", + "entity_kind": "typedef", + "name": "some_struct_t", + "line": 31 + }, + { + "kind": "uses", + "entity_kind": "struct", + "name": "some_struct", + "line": 31 + }, + { + "kind": "uses", + "entity_kind": "union", + "name": "some_union", + "line": 32 + } + ] + }, { "kind": "function", "name": "func_in_header", -- cgit mrf-deployment