HexaGen.CppAst
1.0.2
Prefix Reserved
dotnet add package HexaGen.CppAst --version 1.0.2
NuGet\Install-Package HexaGen.CppAst -Version 1.0.2
<PackageReference Include="HexaGen.CppAst" Version="1.0.2" />
<PackageVersion Include="HexaGen.CppAst" Version="1.0.2" />
<PackageReference Include="HexaGen.CppAst" />
paket add HexaGen.CppAst --version 1.0.2
#r "nuget: HexaGen.CppAst, 1.0.2"
#:package HexaGen.CppAst@1.0.2
#addin nuget:?package=HexaGen.CppAst&version=1.0.2
#tool nuget:?package=HexaGen.CppAst&version=1.0.2
This is a fork of CppAst.NET, specifically tailored to HexaGen.
CppAst.NET

<img align="right" width="160px" height="160px" src="https://raw.githubusercontent.com/xoofx/CppAst.NET/main/img/cppast.png">
CppAst provides a C/C++ parser for header files with access to the full AST, comments and macros for .NET Framework and .NET Core
Purpose
The target primary usage of this library is to serve as a simple foundation for domain oriented PInvoke/Interop codegen
Features
- Compatible with
net8.0- For
netstandard2.0use0.14.0version.
- For
- Using
Clang/libclang 18.1.0.4 - Allow to parse in-memory C/C++ text and C/C++ files from the disk
- Simple AST model
- Full type system
- Provides basic access to attributes (
_declspec(...)or__attribute__((...))) - Provides access to attached comments
- Provides access to expressions for variable and parameter init value (e.g
const int x = (1 + 2) << 1the(1 + 2) << 1will be retrievable as a binary expression from the AST) - Provides access to macro definitions, including tokens via the option
CppParserOptions.ParseMacros(default isfalse)
Documentation
Check the user guide documentation from the doc/ folder.
Usage Example
Setup
After installing the NuGet package, you need to modify your csproj to select a Platform RID via the RuntimeIdentifier property:
<PropertyGroup>
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>
Code
You can jump-start with the CppParser.Parse method:
// Parse a C++ files
var compilation = CppParser.Parse(@"
enum MyEnum { MyEnum_0, MyEnum_1 };
void function0(int a, int b);
struct MyStruct { int field0; int field1;};
typedef MyStruct* MyStructPtr;
"
);
// Print diagnostic messages
foreach (var message in compilation.Diagnostics.Messages)
Console.WriteLine(message);
// Print All enums
foreach (var cppEnum in compilation.Enums)
Console.WriteLine(cppEnum);
// Print All functions
foreach (var cppFunction in compilation.Functions)
Console.WriteLine(cppFunction);
// Print All classes, structs
foreach (var cppClass in compilation.Classes)
Console.WriteLine(cppClass);
// Print All typedefs
foreach (var cppTypedef in compilation.Typedefs)
Console.WriteLine(cppTypedef);
Prints the following result:
enum MyEnum {...}
void function0(int a, int b)
struct MyStruct { ... }
typedef MyStruct* MyStructPtr
Binaries
This library is distributed as a NuGet package
Known issues
The library libclang used by this project has some known issues and limitations:
- Attributes are not fully exposed (e.g in function parameters, on typedefs...)
- Generic instance types are not fully exposed (e.g used as parameters, or as base types...)
License
This software is released under the BSD-Clause 2 license.
Credits
- ClangSharp: .NET managed wrapper around Clang/libclang
Related
The C++ project cppast serves similar purpose although CppAst.NET does not share API or any implementation details.
Author
Alexandre Mutel aka xoofx.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- ClangSharp (>= 18.1.0.4)
- Hexa.NET.Utilities (>= 2.2.3)
- Irony (>= 1.5.3)
- libclang.runtime.win-x64 (>= 18.1.3.2)
- libClangSharp.runtime.win-x64 (>= 18.1.3.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on HexaGen.CppAst:
| Package | Downloads |
|---|---|
|
HexaGen.Core
HexaGen.Core provides core functionality for the HexaGen code generation toolkit, supporting C++ and C# projects. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.2 | 245 | 10/21/2025 |