Coder Social home page Coder Social logo

alpynedreams / rain Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 63 KB

Autogenerated reflection and RTTI for C++ using libclang. No macros, no templates, just reflection.

C++ 34.67% Meson 0.78% Python 64.55%
reflection serialization cpp deserialization rtti cpp20

rain's Introduction

Rain: Automatic Reflection for C++

Requirements

You will need Python 3.10 and the libclang pip package.

Examples

Setup: Meson

This process will likely change.

Add rain as a subproject. Assume you have all your .cpp files in proj_src. You want to generate a .meta.json file for each, and then combine them into an rtti.cpp file that you can link normally.

rain     = subproject('rain')
rain_dep = rain.get_variable('rain_dep')

...

python = import('python').find_installation('python3')

# Build meta files
proj_meta = []
foreach file : proj_src
    fs = import('fs')
    proj_meta += custom_target(
        fs.name(file) + '.meta.json',
        output: fs.name(file) + '.meta.json',
        input: [rain.get_variable('rain_update_py'), file],
        command: [python, '@INPUT@', '@OUTPUT@'],
        console: true
    )
endforeach

# Build rtti.cpp
proj_rtti = custom_target(
    'rtti.cpp',
    output: 'rtti.cpp',
    input: [rain.get_variable('rain_rtti_py'), proj_meta],
    command: [python, '@INPUT@', '@OUTPUT@', '@CURRENT_SOURCE_DIR@],
    console: true
)

...

proj_exe = executable(files(proj_src), proj_rtti, 
    ...
    link_with: [rain_dep, ...]
)

Structure

The Python scripts are as follows:

  • update.py - simply marks a given meta file as stale
  • rtti.py - generates a rtti.cpp file from a list of meta files
    • parse.py - actual libclang parsing logic - regenerates stale meta files
      • traverse.py - traverses the AST to produce type info

rain's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.