ClangQL
ClangQL is a neat tool that lets you run SQL-like queries on C or C++ code. It uses the GitQL SDK to make this happen. This tool is great for developers who want to analyze and query their code in a structured and efficient way.
Key Features
ClangQL has several cool features that make it powerful for developers:
- SQL-Like Query Language: ClangQL lets you run queries similar to SQL on C or C++ code. You can select specific elements, count things, and filter based on different criteria.
- Case-Insensitive Keywords: All keywords in ClangQL are case-insensitive, just like in SQL.
- Support for Multiple Tables: ClangQL can query different tables like classes, enums, unions, functions, and globals.
Sample Queries
Here are some examples of queries you can run using ClangQL:
SELECT 1SELECT 1 + 2SELECT LEN("Clang Query Language")SELECT "One" IN ("One", "Two", "Three")SELECT "Clang Query Language" LIKE "%Query%"SELECT * FROM functionsSELECT COUNT(name) FROM functions WHERE return_type = "int"SELECT DISTINCT name AS function_name FROM functionsSELECT * FROM globalsSELECT COUNT(name) FROM globals WHERE type = "int"SELECT * FROM globals WHERE is_volatile
Table Structures
Classes Table
| Name | Type | Description |
|---|---|---|
| name | Text | Class variable name |
| is_struct | Boolean | True if it is a struct declaration |
| bases_count | Integer | Number of bases for this class |
| methods_count | Integer | Number of methods declarations |
| fields_count | Integer | Number of fields declarations |
| size | Integer | The size of class in bits |
| align | Integer | The align of class in bits |
| file | Text | File path |
| line | Integer | Line at the file path |
| column | Integer | Column at the file path |
| offset | Integer | Offset at the file path |
Enums Table
| Name | Type | Description |
|---|---|---|
| name | Text | Enumeration name |
| constants_count | Integer | Number of constants in this enum |
| type_literal | Text | Type literal for enum constants |
| file | Text | File path |
| line | Integer | Line at the file path |
| column | Integer | Column at the file path |
| offset | Integer | Offset at the file path |
Unions Table
| Name | Type | Description |
|---|---|---|
| name | Text | Union name |
| size | Integer | The size of union in bits |
| fields_count | Integer | Number of fields declarations |
| file | Text | File path |
| line | Integer | Line at the file path |
| column | Integer | Column at the file path |
| offset | Integer | Offset at the file path |
Functions Table
| Name | Type | Description |
|---|---|---|
| name | Text | Function or Method name |
| signature | Text | Parameters and return type literal |
| args_count | Integer | Number of arguments |
| class_name | Text | Return class name for method |
| return_type | Text | Return type literal |
| is_method | Boolean | True if it''s a method |
| is_virtual | Boolean | True if it''s a virtual method |
| ispurevirtual | Boolean | True if it''s a pure virtual method |
| is_static | Boolean | True if it''s a static method |
| is_const | Boolean | True if it''s a const method |
| has_template | Boolean | True if it has template |
| access_modifier | Integer | Access control level for method |
| is_variadic | Boolean | True if function type is variadic |
| file | Text | File path |
| line | Integer | Line at the file path |
| column | Integer | Column at the file path |
| offset | Integer | Offset at the file path |
Globals Table
| Name | Type | Description |
|---|---|---|
| name | Text | Global variable name |
| type | Text | Global variable type literal |
| is_volatile | Boolean | True if variable type is volatile |
| file | Text | File path |
| line | Integer | Line at the file path |
| column | Integer | Column at the file path |
| offset | Integer | Offset at the file path |
Installation and Usage
Installation
To install ClangQL, you can use the following command:
cargo install clangql
Alternatively, you can build from the source code:
git clone https://github.com/AmrDeveloper/clangql.git
cd clangql
cargo build
Running ClangQL
ClangQL can be run using the following command:
ClangQL [OPTIONS]
Options include:
f, files: Path for local files to run query onq, query: ClangQL query to run on selected filesp, pagination: Enable print result with paginationps, pagesize: Set pagination page size [default: 10]o, output: Set output format [render, json, csv]a, analysis: Print Query analysish, help: Print ClangQL helpv, version: Print ClangQL Current Version
License
ClangQL is licensed under the MIT License.
MIT License
Copyright (c) 2024 Amr Hesham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Additional Information
For more details, you can visit the GitHub repository or the Product Hunt page.
This content is either user submitted or generated using AI technology (including, but not limited to, Google Gemini API, Llama, Grok, and Mistral), based on automated research and analysis of public data sources from search engines like DuckDuckGo, Google Search, and SearXNG, and directly from the tool's own website and with minimal to no human editing/review. THEJO AI is not affiliated with or endorsed by the AI tools or services mentioned. This is provided for informational and reference purposes only, is not an endorsement or official advice, and may contain inaccuracies or biases. Please verify details with original sources.
Comments
Please log in to post a comment.