You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In general, for each codebase three different virtual tables can be queried: a `symbols` table will contain information about every symbol in the codebase, a `base_of` table will contain information about what symbols are base classes of what symbols, and a `overridden_by` table will contain information about what symbols are overridden by what symbols.
58
+
Searching for all declarations inside of the `std` namespace:
59
+
60
+
sqlite> SELECT decl.Name FROM llvm_symbols AS decl INNER JOIN llvm_refs AS ref ON ref.SymbolId = decl.Id WHERE decl.Scope = "std::" AND ref.Declaration = 1;
61
+
Name
62
+
---------------------
63
+
align_val_t
64
+
__unexpected
65
+
is_execution_policy
66
+
__terminate
67
+
is_execution_policy_v
68
+
69
+
In general, for each codebase four different virtual tables can be queried: a `symbols` table will contain information about every symbol in the codebase, a `base_of` table will contain information about what symbols are base classes of what symbols, a `overridden_by` table will contain information about what symbols are overridden by what symbols, and a `refs` table will contain information about symbol references.
58
70
59
71
The syntax for instantiating the tables is the following:
60
72
61
73
CREATE VIRTUAL TABLE my_symbols USING clangql (symbols, host:port);
62
74
CREATE VIRTUAL TABLE my_base_of USING clangql (base_of, host:port);
63
75
CREATE VIRTUAL TABLE my_overridden_by USING clangql (overridden_by, host:port);
76
+
CREATE VIRTUAL TABLE my_refs USING clangql (refs, host:port);
64
77
65
78
`my_*` names are not important and can be anything, the first parameter to the creation of the virtual tables is important and must be left as-is, the second parameter is the connection string. Currently, only unencrypted gRPC connections are supported.
66
79
@@ -82,6 +95,15 @@ The meaning is as follows: if a row `(S, O)` is present in `base_of`, then `S` i
82
95
83
96
Please note that it is only possible to query these two tables by their `Subject`, querying by `Object` is not possible due to limitations in the clangd protocol.
Please note that querying `refs` without a `SymbolId` will return 0 rows.
106
+
85
107
## How do I build it?
86
108
87
109
ClangQL uses CMake, Protocol Buffers and gRPC. On Windows I used vcpkg to manage the two dependencies. I'm afraid I'm not knowledgeable enough with Linux and/or macOS to give precise indications on how to build it there, but I'm guessing that as long as you have the correct development packages installed and visible on your system, CMake will be able to locate them.
@@ -90,7 +112,7 @@ Once the repository is cloned, run:
to configure the build. Adjust `CMAKE_BUILD_TYPE`, `VCPKG_TARGET_TRIPLET`, `CMAKE_TOOLCHAIN_FILE` and the generator type to suit your system and needs the best. Please not that the `sqlite` CLI tool and the extension must have the same bitness, at least on Windows. A 32-bit CLI (such as the precompiled one from SQLite.org) _will not_ load a 64-bit extension.
115
+
to configure the build. Adjust `CMAKE_BUILD_TYPE`, `VCPKG_TARGET_TRIPLET`, `CMAKE_TOOLCHAIN_FILE` and the generator type to suit your system and needs the best. Please note that the `sqlite` CLI tool and the extension must have the same bitness, at least on Windows. A 32-bit CLI (such as the precompiled one from SQLite.org) _will not_ load a 64-bit extension.
94
116
95
117
Once configured, run:
96
118
@@ -108,6 +130,8 @@ Also, there is currently no way to i.e. obtain all possible relations between tw
108
130
109
131
Not all queries are equally fast: querying on symbol id, name or scope is fast, everything else needs to happen client side and is potentially slow.
110
132
111
-
Similarly, when querying the `base_of` or `overridden_by` relations, only one of the two directions is possible, the other is not currently possible due to protocol limitations.
133
+
Similarly, when querying the `base_of` or `overridden_by` relations, only one of the two directions is possible, the other is not currently possible due to protocol limitations. Also, not specifying a `Subject` will result in 0 rows being returned.
134
+
135
+
Querying `refs` without specifying a `SymbolId` will result in 0 rows being produced. Specifying any one of `Definition`, `Declaration`, `Reference` or `Spelled` will generate more specific requests to the clangd server, all other fields are scanned client side.
112
136
113
137
Error checking is nonexistant. This is not ready for production use and was mostly made for fun, to explore to what extent the clangd interface was suitable for use with SQLite, and to learn about the SQLite virtual table system.
0 commit comments