CppAst.cgnx
0.8.0-alpha-013
See the version list below for details.
dotnet add package CppAst.cgnx --version 0.8.0-alpha-013
NuGet\Install-Package CppAst.cgnx -Version 0.8.0-alpha-013
<PackageReference Include="CppAst.cgnx" Version="0.8.0-alpha-013" />
paket add CppAst.cgnx --version 0.8.0-alpha-013
#r "nuget: CppAst.cgnx, 0.8.0-alpha-013"
// Install CppAst.cgnx as a Cake Addin #addin nuget:?package=CppAst.cgnx&version=0.8.0-alpha-013&prerelease // Install CppAst.cgnx as a Cake Tool #tool nuget:?package=CppAst.cgnx&version=0.8.0-alpha-013&prerelease
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
.NET Standard 2.0+
- Using
Clang/libclang 15.0.2
- 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) << 1
the(1 + 2) << 1
will 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 | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- ClangSharp (>= 15.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.13.15 | 570 | 12/11/2024 |
0.13.14 | 14,866 | 9/6/2024 |
0.13.13 | 116 | 6/11/2024 |
0.13.12 | 8,803 | 6/7/2024 |
0.13.11 | 108 | 6/6/2024 |
0.13.10 | 121 | 6/6/2024 |
0.13.9 | 116 | 6/4/2024 |
0.13.8 | 13,337 | 2/5/2024 |
0.13.7 | 2,312 | 1/9/2024 |
0.13.6 | 167 | 12/14/2023 |
0.13.5 | 147 | 12/13/2023 |
0.13.4 | 245 | 12/6/2023 |
0.13.3 | 143 | 12/5/2023 |
0.13.2 | 164 | 11/3/2023 |
0.13.1 | 151 | 10/25/2023 |
0.8.0-alpha-015 | 121 | 10/18/2023 |
0.8.0-alpha-014 | 135 | 9/29/2023 |
0.8.0-alpha-013 | 111 | 9/21/2023 |
0.8.0-alpha-011 | 149 | 9/15/2023 |
0.8.0-alpha-010 | 168 | 2/1/2023 |
0.8.0-alpha-009 | 141 | 1/30/2023 |
0.8.0-alpha-008 | 140 | 1/25/2023 |
0.8.0-alpha-007 | 172 | 10/6/2022 |
0.8.0-alpha-006 | 139 | 10/5/2022 |
0.8.0-alpha-005 | 160 | 9/8/2022 |
0.8.0-alpha-004 | 229 | 5/25/2022 |
0.8.0-alpha-003 | 170 | 4/22/2022 |