{"id":26400099,"url":"https://github.com/xoofx/CppAst","last_synced_at":"2025-03-17T14:01:17.218Z","repository":{"id":37879343,"uuid":"188537475","full_name":"xoofx/CppAst.NET","owner":"xoofx","description":"CppAst is a .NET library providing a C/C++ parser for header files powered by Clang/libclang with access to the full AST, comments and macros","archived":false,"fork":false,"pushed_at":"2024-05-19T13:54:27.000Z","size":3194,"stargazers_count":446,"open_issues_count":24,"forks_count":59,"subscribers_count":16,"default_branch":"main","last_synced_at":"2024-05-19T14:03:14.366Z","etag":null,"topics":["ast","clang","cplusplus","csharp","dotnet","dotnet-core","libclang","parser"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xoofx.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.txt","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":{"github":["xoofx"]}},"created_at":"2019-05-25T07:55:35.000Z","updated_at":"2024-05-22T19:57:43.956Z","dependencies_parsed_at":"2024-02-13T09:31:14.461Z","dependency_job_id":"02689b11-66f4-436b-b116-af1c94c7b179","html_url":"https://github.com/xoofx/CppAst.NET","commit_stats":null,"previous_names":["xoofx/cppast"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoofx%2FCppAst.NET","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoofx%2FCppAst.NET/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoofx%2FCppAst.NET/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoofx%2FCppAst.NET/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xoofx","download_url":"https://codeload.github.com/xoofx/CppAst.NET/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047608,"owners_count":20389205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","clang","cplusplus","csharp","dotnet","dotnet-core","libclang","parser"],"created_at":"2025-03-17T14:00:46.353Z","updated_at":"2025-03-17T14:01:17.203Z","avatar_url":"https://github.com/xoofx.png","language":"C#","readme":"# CppAst.NET [![Build Status](https://github.com/xoofx/CppAst/workflows/ci/badge.svg?branch=main)](https://github.com/xoofx/CppAst/actions) [![Coverage Status](https://coveralls.io/repos/github/xoofx/CppAst.NET/badge.svg?branch=main)](https://coveralls.io/github/xoofx/CppAst.NET?branch=main) [![NuGet](https://img.shields.io/nuget/v/CppAst.svg)](https://www.nuget.org/packages/CppAst/)\n\n\u003cimg align=\"right\" width=\"160px\" height=\"160px\" src=\"https://raw.githubusercontent.com/xoofx/CppAst.NET/main/img/cppast.png\"\u003e\n\nCppAst provides a C/C++ parser for header files with access to the full AST, comments and macros for .NET Framework and .NET Core\n\n## Purpose\n\n\u003e The target primary usage of this library is to serve as a simple foundation for domain oriented PInvoke/Interop codegen\n\n## Features\n\n- Compatible with `net8.0`\n    - For `netstandard2.0` use `0.14.0` version.\n- Using `Clang/libclang 18.1.0`\n- Allow to parse *in-memory* C/C++ text and C/C++ files from the disk\n- Simple AST model\n- Full type system\n- Provides basic access to attributes (`_declspec(...)` or `__attribute__((...))`)\n- Provides access to attached comments\n- Provides access to expressions for variable and parameter init value (e.g `const int x = (1 + 2) \u003c\u003c 1` the `(1 + 2) \u003c\u003c 1` will be retrievable as a binary expression from the AST)\n- Provides access to macro definitions, including tokens via the option `CppParserOptions.ParseMacros` (default is `false`)\n\n## Documentation\n\nCheck the [user guide](doc/readme.md) documentation from the `doc/` folder.\n\n## Usage Example\n\n### Setup\nAfter installing the NuGet package, you need to modify your csproj to select a Platform RID via the `RuntimeIdentifier` property:\n\n```xml\n  \u003cPropertyGroup\u003e\n    \u003c!-- Workaround for issue https://github.com/microsoft/ClangSharp/issues/129 --\u003e\n    \u003cRuntimeIdentifier Condition=\"'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'\"\u003e$(NETCoreSdkRuntimeIdentifier)\u003c/RuntimeIdentifier\u003e\n  \u003c/PropertyGroup\u003e\n```\n\n### Code\n\nYou can jump-start with the `CppParser.Parse` method:\n\n```C#\n// Parse a C++ files\nvar compilation = CppParser.Parse(@\"\nenum MyEnum { MyEnum_0, MyEnum_1 };\nvoid function0(int a, int b);\nstruct MyStruct { int field0; int field1;};\ntypedef MyStruct* MyStructPtr;\n\"\n);\n// Print diagnostic messages\nforeach (var message in compilation.Diagnostics.Messages)\n    Console.WriteLine(message);\n\n// Print All enums\nforeach (var cppEnum in compilation.Enums)\n    Console.WriteLine(cppEnum);\n\n// Print All functions\nforeach (var cppFunction in compilation.Functions)\n    Console.WriteLine(cppFunction);\n\n// Print All classes, structs\nforeach (var cppClass in compilation.Classes)\n    Console.WriteLine(cppClass);\n\n// Print All typedefs\nforeach (var cppTypedef in compilation.Typedefs)\n    Console.WriteLine(cppTypedef);\n```\n\nPrints the following result:\n\n```\nenum MyEnum {...}\nvoid function0(int a, int b)\nstruct MyStruct { ... }\ntypedef MyStruct* MyStructPtr\n```\n\n## Binaries\n\nThis library is distributed as a NuGet package [![NuGet](https://img.shields.io/nuget/v/CppAst.svg)](https://www.nuget.org/packages/CppAst/)\n\n## Known issues\n\nThe library libclang used by this project has some known issues and limitations:\n\n- Attributes are not fully exposed (e.g in function parameters, on typedefs...)\n- Generic instance types are not fully exposed (e.g used as parameters, or as base types...) \n\n## License\n\nThis software is released under the [BSD-Clause 2 license](https://opensource.org/licenses/BSD-2-Clause). \n\n## Credits\n\n* [ClangSharp](https://github.com/microsoft/ClangSharp): .NET managed wrapper around Clang/libclang\n\n## Related\n\nThe C++ project [cppast](https://github.com/foonathan/cppast) serves similar purpose although CppAst.NET does not share API or any implementation details.\n\n## Author\n\nAlexandre Mutel aka [xoofx](https://xoofx.github.io).\n","funding_links":["https://github.com/sponsors/xoofx"],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxoofx%2FCppAst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxoofx%2FCppAst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxoofx%2FCppAst/lists"}