{"id":13418713,"url":"https://github.com/standardese/cppast","last_synced_at":"2026-04-05T17:35:57.458Z","repository":{"id":39616082,"uuid":"87620978","full_name":"standardese/cppast","owner":"standardese","description":"Library to parse and work with the C++ AST","archived":false,"fork":false,"pushed_at":"2024-06-13T23:30:18.000Z","size":1266,"stargazers_count":1762,"open_issues_count":32,"forks_count":175,"subscribers_count":46,"default_branch":"main","last_synced_at":"2026-01-17T03:47:48.319Z","etag":null,"topics":["ast","cplusplus","libclang","parser-library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/standardese.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"foonathan","custom":["https://jonathanmueller.dev/support-me/"]}},"created_at":"2017-04-08T08:52:17.000Z","updated_at":"2026-01-02T06:36:01.000Z","dependencies_parsed_at":"2022-07-13T10:30:36.788Z","dependency_job_id":"a6bc5f76-238b-4dae-8430-10ab2926a6d3","html_url":"https://github.com/standardese/cppast","commit_stats":{"total_commits":458,"total_committers":25,"mean_commits":18.32,"dds":0.08951965065502188,"last_synced_commit":"f00df6675d87c6983033d270728c57a55cd3db22"},"previous_names":["standardese/cppast","foonathan/cppast"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/standardese/cppast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standardese%2Fcppast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standardese%2Fcppast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standardese%2Fcppast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standardese%2Fcppast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/standardese","download_url":"https://codeload.github.com/standardese/cppast/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/standardese%2Fcppast/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31444702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T15:22:31.103Z","status":"ssl_error","status_checked_at":"2026-04-05T15:22:00.205Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","cplusplus","libclang","parser-library"],"created_at":"2024-07-30T22:01:05.907Z","updated_at":"2026-04-05T17:35:57.428Z","avatar_url":"https://github.com/standardese.png","language":"C++","readme":"# cppast\n\nLibrary interface to the C++ AST \u0026mdash; parse source files, synthesize entities, get documentation comments and generate code.\n\n## Motivation\n\nIf you're writing a tool that needs access to the C++ AST (i.e. documentation generator, reflection library, …), your only option apart from writing your own parser is to use [clang](https://clang.llvm.org).\nIt offers [three interfaces for tools](https://clang.llvm.org/docs/Tooling.html), but the only one that really works for standalone applications is [libclang](http://clang.llvm.org/doxygen/group__CINDEX.html).\nHowever, libclang has various limitations and does not expose the entire AST.\n\nSo there is no feasible option \u0026mdash; except for this library.\nIt was originally a part of the [standardese documentation generator](http://standardese.foonathan.net), but has been extracted into an independent library.\n\nSee [this blog post](http://foonathan.net/blog/2017/04/20/cppast.html) for more information about the motiviation and design.\n\n## Features\n\n* Exposes (almost) all C++ entities: Supports everything from functions to classes, templates to friend declarations, macros to enums;\n* Exposes full information about C++ types;\n* Supports and exposes documentation comments in various formats with smart entity matching;\n* Supports C++11 attributes (including user-defined ones);\n* AST hierarchy completely decoupled from parser: This allows synthesizing AST entities and multiple parsing backends;\n* Parser based on libclang: While libclang does have its limitations and/or bugs, the implemented parser uses various workarounds/hacks to provide a parser that breaks only in rare edge cases you won't notice. See [issues tagged with `libclang-parser` for a list](https://github.com/foonathan/cppast/issues?q=is%3Aissue+is%3Aopen+label%3Alibclang-parser);\n* Simple yet customizable code generation interface.\n\n## Missing features\n\n* Support modification of parsed entities: they're currently all immutable, need to find a decent way of implementing that\n* Full support for expressions: currently only literal expressions are exposed;\n* Support for statements: currently function bodies aren't parsed at all;\n* Support for member specialization: members of a template can be specialized separately, this is not supported.\n\n## Example\n\nSee [tool/main.cpp](tool/main.cpp) for a simple application of the library that prints the AST.\n\n## Documentation\n\nTODO, refer to documentation comments in header file.\n\n### Installation\n\nThe library can be used as CMake subdirectory, download it and call `add_subdirectory(path/to/cppast)`, then link to the `cppast` target and enable C++11 or higher.\n\nThe parser needs `libclang` and the `clang++` binary, at least version 4.0.0.\nThe `clang++` binary will be found in `PATH` and in the same directory as the program that is being executed.\n\n*Note: The project will drop support for older LLVM versions very soon; this minimizes the workaround code when the `libclang` API catches up.*\n\nThe CMake code requires `llvm-config`, you may need to install `llvm` and not just `clang` to get it (e.g. on ArchLinux).\nIf `llvm-config` is in your path and the version is compatible, it should just work out of the box.\nElse you need to set the CMake variable `LLVM_CONFIG_BINARY` to the proper path.\n\nIf you don't have a proper clang version installed, it can also be downloaded.\nFor that you need to set `LLVM_DOWNLOAD_OS_NAME`.\nThis is the name of the operating system used on the [LLVM pre-built binary archive](http://releases.llvm.org/download.html#4.0.0), e.g. `x86_64-linux-gnu-ubuntu-16.10` for Ubuntu 16.10.\n\nYou can also set `LLVM_DOWNLOAD_URL` to a custom url, to download a specific version or from a mirror.\n\nIf you don't have `llvm-config`, you need to pass the locations explictly.\nFor that set the option `LLVM_VERSION_EXPLICIT` to the version you're using,\n`LIBCLANG_LIBRARY` to the location of the libclang library file,\n`LIBCLANG_INCLUDE_DIR` to the directory where the header files are located (so they can be included with `clang-c/Index.h`),\nand `CLANG_BINARY` to the full path of the `clang++` exectuable.\n\nThe other dependencies like [type_safe](http://type_safe.foonathan.net) are installed automatically with FetchContent, if they're not installed already.\n\nIf you run into any issues with the installation, please report them.\n\n### Installation on Windows\n\nSimilar to the above instructions for `cppast`, there are a couple extra requirements for Windows.\n\nThe LLVM team does not currently distribute `llvm-config.exe` as part of the release binaries, so the only way to get it is through manual compilation or from 3rd parties. To prevent version mismatches, it's best to compile LLVM, libclang, and `llvm-config.exe` from source to ensure proper version matching. However, this is a non-trivial task, requiring a lot of time. The easiest way to work with LLVM and `llvm-config.exe` is to leverage the [Chocolatey](https://chocolatey.org/) `llvm` package, and then compile the `llvm-config.exe` tool as a standalone binary.\n\n* Install Visual Studio 2017 with the Desktop C++ development feature enabled.\n* Install `llvm` and `clang` with `choco install llvm` \n* Check the version with `clang.exe --version`\n* Clone the LLVM project: `git clone https://github.com/llvm/llvm-project`\n* Checkout a release version matching the version output, such as 7.0.1, with `git checkout llvmorg-7.0.1`\n* `cd llvm-project \u0026\u0026 mkdir build \u0026\u0026 cd build` to prep the build environment.\n* `cmake -DLLVM_ENABLE_PROJECTS=\"clang\" -DLLVM_TARGETS_TO_BUILD=\"X86\" -G \"Visual Studio 15 2017\" -Thost=x64 ..\\llvm`\n  * This will configure clang and LLVM using a 64-bit toolchain. You'll have all the necessary projects configured for building clang, if you need other LLVM tools. See the [LLVM documentation](https://llvm.org/docs/CMake.html) and [clang documentation](http://clang.llvm.org/get_started.html) if you only need more assistance.\n* Open the `LLVM.sln` solution, and set the build type to be \"Release\".\n* Build the `Tools/llvm-config` target.\n* Copy the release binary to from `build\\Release\\bin\\llvm-config.exe` to `C:\\Program Files\\LLVM\\bin\\llvm-config.exe`\n* Open a new Powershell window and test accessiblity of `llvm-config.exe`, it should return with it's help message.\n\nIn your `cppast` based project, if you run into issues with cmake not finding libclang, set `LIBCLANG_LIBRARY` to be `C:/Program Files/LLVM/lib` in your CMakeLists.txt file.\n\n### Quick API Overview\n\nThere are three class hierarchies that represent the AST:\n\n* `cpp_entity`: This is the base class for all C++ *entities*, i.e. declarations/definitions or things like `static_assert()` and function parameters;\n* `cpp_type`: This is the base class for the C++ type hierachy. It is used in the `cpp_entity` hierachy, i.e. `cpp_type_alias` contains an `underlying_type()`. Derived classes are, for example, `cpp_builtin_type` or `cpp_pointer_type`;\n* `cpp_expression`: This is the base class for all C++ expressions. It is used in the `cpp_entity` hierarchy, i.e. `cpp_function_parameter` contains a `default_value()` as expression. Derived classes are currently only `cpp_literal_expression` and `cpp_unexposed_expression`;\n\nIn order to parse a C++ source file, you need an implementation of `parser`.\nThe library provides one, `libclang_parser`, but you could also write one yourself.\nParsing is as simple as calling the `parse()` member function passing it three things:\n\n* An object of type `cpp_entity_index`: This is only required to resolve cross-references in the AST (i.e. if you want to get the `cpp_class` referenced in the return type of a `cpp_function`); it does not own the entities;\n* The path to the file;\n* An object of a type derived from `compile_config`: It stores the compilation flags used for compiling the file, it needs to match the parser, i.e. use `libclang_compile_config` with `libclang_parser`;\n\nIt returns `nullptr` on failure and prints diagnostics using a given `diagnostic_logger` \u0026mdash; note that it will only return `nullptr` on fatal parse errors, else it will just skip the one where the error occured.\nIf everything went succesful, it returns a `std::unique_ptr\u003ccpp_file\u003e` which is the top-level AST entity of the current file.\nYou can then work with it.\n","funding_links":["https://patreon.com/foonathan","https://jonathanmueller.dev/support-me/"],"categories":["TODO scan for Android support in followings","C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstandardese%2Fcppast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstandardese%2Fcppast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstandardese%2Fcppast/lists"}