ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK

Overview

ClangQL - Clang AST Query Language


Crates.io Deps GitHub issues GitHub

ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK.

animated


Samples

Note that all Keywords in ClangQL are case-insensitive, similar to SQL.

SELECT 1
SELECT 1 + 2
SELECT LEN("Clang Query Language")
SELECT "One" IN ("One", "Two", "Three")
SELECT "Clang Query Language" LIKE "%Query%"

SELECT * FROM functions
SELECT COUNT(name) from functions WHERE return_type = "int"
SELECT DISTINCT name AS function_name FROM functions

SELECT * FROM globals
SELECT COUNT(name) from globals WHERE type = "int"
SELECT * FROM globals WHERE is_volatile

Tables structures

Classes table
Name Type Description
name Text Class variable name
is_struct Boolean True if it 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 Return true if a C++ member function or member function template is explicitly declared 'virtual' or if it overrides a virtual method from one of the base classes
is_pure_virtual Boolean Return ture if a C++ member function or member function template is pure virtual
is_static Boolean Return ture if a C++ member function is static
is_const Boolean Return ture if a C++ member function is const
has_template Boolean True if it's has template
access_modifier Integer Returns the access control level for method, 1 for public, 2 protected, 3 provide, 0 for invalid
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

Download or Install

Note that Building from source or installing from Cargo.io requires LibClang 17 to be installed

  • Install from Cargo.io
cargo install clangql
  • Install from Homebrew
brew install clangql
  • Build from source code
git clone https://github.com/AmrDeveloper/clangql.git
cd clangql
cargo build

Run ClangQL

ClangQL is a SQL like query language to run on local files
Usage: ClangQL [OPTIONS]

Options:
  -f,  --files <paths>        Path for local files to run query on
  -q,  --query <GQL Query>    ClangQL query to run on selected files
  -p,  --pagination           Enable print result with pagination
  -ps, --pagesize             Set pagination page size [default: 10]
  -o,  --output               Set output format [render, json, csv]
  -a,  --analysis             Print Query analysis
  -h,  --help                 Print ClangQL help
  -v,  --version              Print ClangQL Current Version

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.
Comments
  • Add support for token location for each node

    Add support for token location for each node

    Each table row should contain source code information like file, column, and row This info should be used later in refactoring and searching tools

    • Extend the current tables to add 3 columns (file, column, row)
    • Extend the visitors to collect this info and DataProvider to put them on table
    enhancement 
    opened by AmrDeveloper 1
  • Create table and fields for classes and structs enhancement

    Create table and fields for classes and structs enhancement

    After reading how ClangQL get function information it's time to add support for another node kind like classes,

    • Find what info we can read it using libclang.
    • Define the classes table with fields and fields types.
    • Extend our DataProvider component to add visitors for enums.
    • Update the readme file to explain table structure and add samples

    Resources: https://github.com/AmrDeveloper/ClangQL/blob/master/src/clang_function_visitor.rs

    https://amrdeveloper.github.io/GQL/sdk/

    enhancement 
    opened by AmrDeveloper 1
  • Create table and fields for enumerations (enums)

    Create table and fields for enumerations (enums)

    After reading how ClangQL get function information it's time to add support for another node kind like an enum,

    • Find what info we can read it using libclang.
    • Define the enums table with fields and fields types.
    • Extend our DataProvider component to add visitors for enums.
    • Update the readme file to explain table structure and add samples

    Resources: https://github.com/AmrDeveloper/ClangQL/blob/master/src/clang_function_visitor.rs

    https://amrdeveloper.github.io/GQL/sdk/

    enhancement 
    opened by AmrDeveloper 1
  • Cache TranslationUnit per files

    Cache TranslationUnit per files

    We can query information from any node kind with in the same TranslationUnit no need to re parse the files over and over so we should cashe it and only perform parsing for new files

    enhancement 
    opened by AmrDeveloper 0
  • Crash on macOS: dyld[50112]: Library not loaded: @rpath/libclang.dylib

    Crash on macOS: dyld[50112]: Library not loaded: @rpath/libclang.dylib

    Describe the bug Built clangql from git on macOS Sonoma 14.4.1 with rust 1.71.1 and the resulting binary is crashing due to unset LC_RPATH, and hence the binary fails to load libclang.dylib

    $ clangql
    dyld[50112]: Library not loaded: @rpath/libclang.dylib
      Referenced from: <2E046823-CCFD-39AC-8724-B8765694F2F4> /usr/local/bin/clangql
      Reason: no LC_RPATH's found
    Abort trap: 6
    
    Has solution 
    opened by mario-grgic 5
  • Improve Visiting multi files in parallel

    Improve Visiting multi files in parallel

    Currently the DataProvider work with files one by one but we can change this to work in parallel so we can go faster

    • Read the DataProvider file and think how we can be faster and work in parallel.
    • Bench mark the performance while working on large files
    enhancement 
    opened by AmrDeveloper 0
  • Setup workflows for Ci/CD

    Setup workflows for Ci/CD

    Extend the CI/CD pipeline actions from GitQL repo to add support for installing libclang and allow releasing for Windows, MacOS and Linux

    https://github.com/AmrDeveloper/GQL/tree/master/.github/workflows

    DevOps 
    opened by AmrDeveloper 0
Releases(0.6.0)
  • 0.6.0(Jun 14, 2024)

  • 0.5.0(Jun 12, 2024)

  • 0.3.0(May 10, 2024)

    • Support query name, is_struct, location for classes.
    • Support query methods_count, fields_count for class.
    • Support query bases_count for class
    • Speedup parsing functions.
    • Support query struct and class info.
    • Support query enum name, constants_count and type_literal.
    • Support query size and align of class.
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Apr 26, 2024)

    • Support query name, class_name, return_type for methods in structs or classes.
    • Support query is_template option in Function model.
    • Support query is_static, is_const option in Function model.
    • Support query is_method, is_variadic option in Function model.
    • Support query is_virtual, is_pure_virtual option in Function model.
    • Support query access_modifier option in Function model.
    • Support query global variables name, type and is_volatile
    Source code(tar.gz)
    Source code(zip)
Owner
Amr Hesham
Compilers, Language Design and Tools
Amr Hesham
Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Sleek: SQL Formatter ✨ Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability an

Nick Rempel 40 Apr 20, 2023
Fgr - Find & Grep utility with SQL-like query language

fgr Find & Grep utility with SQL-like query language. Examples # Find all files with name equal to sample under the current directory: fgr -e name=sam

Igor 3 Dec 22, 2022
A CLI tool that allow you to create a temporary new rust project using cargo with already installed dependencies

cargo-temp A CLI tool that allow you to create a new rust project in a temporary directory with already installed dependencies. Install Requires Rust

Yohan Boogaert 61 Oct 31, 2022
A SQL query parser written using nom.

sqlparser-nom A SQL query parser written using nom. Query Select From Where Order by Limit CTE Group by Having Aggregate Window Pratt Parsing Friendly

SystemX Labs 27 Sep 28, 2023
qsv - Performant CLI tool to query CSVs through SQL

qsv Performant CLI tool to query CSVs through SQL Installation After cloning the repository, you can install a binary locally using cargo install --pa

Dermot Haughey 3 Oct 28, 2021
fas stand for Find all stuff and it's a go app that simplify the find command and allow you to easily search everything you nedd

fas fas stands for Find all stuff and it's a rust app that simplify the find command and allow you to easily search everything you need. Note: current

M4jrT0m 1 Dec 24, 2021
Like a cell, but make lifetimes dynamic instead of ownership

LendingCell is a mutable container that allows you to get an owned reference to the same object. When the owned reference is dropped, ownership return

Kalle Samuels 19 Dec 15, 2022
Tool to allow parsing large JSON files without laoding into memory

Tool to allow parsing large JSON files without laoding into memory. Developed in Rust with adapters in other programming langauges for easy adoption

Salaah Amin 7 Jul 11, 2023
An alternative to `qcell` and `ghost-cell` that instead uses const generics

Purpose This crate is another attempt at the ghost-cell / qcell saga of cell crates. This provides an alternative to std::cell::RefCell that can allow

SpencerBeige 5 Feb 9, 2023
A bit like tee, a bit like script, but all with a fake tty. Lets you remote control and watch a process

teetty teetty is a wrapper binary to execute a command in a pty while providing remote control facilities. This allows logging the stdout of a process

Armin Ronacher 259 Jan 3, 2023
CLI application to run clang-format on a set of files specified using globs in a JSON configuration file.

run_clang_format CLI application for running clang-format for an existing .clang-format file on a set of files, specified using globs in a .json confi

martin 6 Dec 16, 2022
CLI application to run clang-tidy on a set of files specified using globs in a JSON configuration file.

run-clang-tidy CLI application for running clang-tidy for an existing .clang-tidy file on a set of files, specified using globs in a .json configurati

martin 7 Nov 4, 2022
koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

null 3 Nov 27, 2021
Code-shape is a tool for extracting definitions from source code files

Code-shape Code-shape is a tool that uses Tree-sitter to extract a shape of code definitions from a source code file. The tool uses the same language

Andrew Hlynskyi 3 Apr 21, 2023
Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're working with files or directories, this tool simplifies common file operations with ease.

Rust FileOps Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're w

Harikesh Ranjan Sinha 5 May 2, 2024
A CLI tool you can pipe code and then ask for changes, add documentation, etc, using the OpenAI API.

AiBro This is your own little coding bro, immersed in the world of AI, crypto, and all other types of over hyped tech trends. You can pipe it code and

Josh Bainbridge 5 Sep 5, 2023
VEP-like tool for sequence ontology and HGVS annotation of VCF files

Mehari Mehari is a software package for annotating VCF files with variant effect/consequence. The program uses hgvs-rs for projecting genomic variants

Berlin Institute of Health 5 Mar 31, 2023
AskBend: SQL-based Knowledge Base Search and Completion using Databend

AskBend: SQL-based Knowledge Base Search and Completion using Databend AskBend is a Rust project that utilizes the power of Databend and OpenAI to cre

Databend Labs 87 Apr 7, 2023
Terminal based, feature rich, interactive SQL tool

datafusion-tui (dft) DataFusion-tui provides a feature rich terminal application, built with tui-rs, for using DataFusion (and eventually Ballista). I

null 49 Dec 24, 2022