Git Product home page Git Product logo

cppast's Introduction

CppAst Build status NuGet

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 Framework 4.6+ and .NET Standard 2.0
  • Using Clang/libclang 8.0.0
  • 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 macro definitions, including tokens via the option CppParserOptions.ParseMacros (default is false)

Documentation

Check the user guide documentation from the doc/ folder.

Usage Example

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 NuGet

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

    CppAst is using internally the code of this PInvoke layer to access Clang/libclang

Author

Alexandre Mutel aka xoofx.

cppast's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.