{"id":16693196,"url":"https://github.com/biojppm/regen","last_synced_at":"2025-07-10T16:35:39.217Z","repository":{"id":57460864,"uuid":"91028652","full_name":"biojppm/regen","owner":"biojppm","description":"Easy C++ reflection and code generation ","archived":false,"fork":false,"pushed_at":"2018-02-17T03:10:12.000Z","size":138,"stargazers_count":37,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T23:41:16.873Z","etag":null,"topics":["c","c-plus-plus","code-generation","code-generator","cplusplus","libclang","python3","reflection"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/biojppm.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-11T22:28:30.000Z","updated_at":"2024-12-31T12:49:05.000Z","dependencies_parsed_at":"2022-09-17T04:30:50.277Z","dependency_job_id":null,"html_url":"https://github.com/biojppm/regen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/biojppm/regen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biojppm%2Fregen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biojppm%2Fregen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biojppm%2Fregen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biojppm%2Fregen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/biojppm","download_url":"https://codeload.github.com/biojppm/regen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/biojppm%2Fregen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264608256,"owners_count":23636691,"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":["c","c-plus-plus","code-generation","code-generator","cplusplus","libclang","python3","reflection"],"created_at":"2024-10-12T16:29:31.217Z","updated_at":"2025-07-10T16:35:39.194Z","avatar_url":"https://github.com/biojppm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n===========  ===========\n |pypi|       |license|\n===========  ===========\n\nregen\n=====\n\n``regen`` is a python3 package providing C/C++ reflection and source-code\ngeneration. You provide `your own code generation templates\n\u003chttp://jinja.pocoo.org/docs/2.9/templates/\u003e`_ , and have full control over\nwhere the generated code goes. A flexible system of annotations is used, so\nthat you can pass meta-values to your code generation templates.\n\n``regen`` is ideal to be used as a pre-build step for your C/C++ project, but\nit can also be used separately on a file by file basis. Examples of\napplication are object-tree iteration utilities, or property systems with\narbitrary per-property annotations, or maintenance-free enum strings.\n\nThis is a very fresh pre-alpha project. It is buggy and its interface will\nchange.\n\nHow it works\n------------\n\n``regen`` receives two inputs: your C/C++ source code and the code generation\ntemplates. The code generation templates are written for Python's `jinja2\ntemplate engine \u003chttp://jinja.pocoo.org/docs/2.9/templates/\u003e`_. ``regen`` uses\n`libclang \u003chttp://clang.llvm.org/\u003e`_ to parse your C/C++ code and produce an\nAbstract Syntax Tree (AST). This tree is processed to extract the\nfeatures, which are then passed to each generator.\n\nYou can see ``regen`` being used in the project's `examples folder`_.\n\n\nQuick examples\n--------------\n\nEnum stringification\n^^^^^^^^^^^^^^^^^^^^\n\nConsider a C++ header, let's name it `myenum.h`:\n\n.. code:: c++\n\n    #pragma once\n\n    C4_ENUM()\n    typedef enum {\n        FOO,\n        BAR,\n        BAZ\n    } MyEnum;\n\nNow use the following python code for parsing and generating, saved as\n`regen.py`:\n\n.. code:: python\n\n    import c4.regen as regen\n\n    egen = regen.EnumGenerator(\n        # extract enums tagged with this macro\n        tag=\"C4_ENUM\",\n        # header preamble\n        hdrp=\"\"\"\\\n    #include \"enum_pairs.h\"\n    \"\"\"\n        # template for code in header files\n        hdr=\"\"\"\\\n    template\u003c\u003e const EnumPairs\u003c {{enum.type}} \u003e enum_pairs();\n    \"\"\",\n        # template for code in source files\n        src=\"\"\"\\\n    template\u003c\u003e const EnumPairs\u003c {{enum.type}} \u003e enum_pairs()\n    {\n        static const EnumAndName\u003c {{enum.type}} \u003e vals[] = {\n            {% for e in enum.symbols %}\n            { {{e.name}}, \"{{e.name}}\"},\n            {% endfor %}\n        };\n        EnumPairs\u003c {{enum.type}} \u003e r(vals);\n        return r;\n    }\n    \"\"\"\n    )\n    writer = regen.ChunkWriterGenFile()\n\n    #------------------------------------------------------------------------------\n    if __name__ == \"__main__\":\n        regen.run(writer, egen, [])\n\nNow run ``regen`` to parse the source code and generate your code:\n\n.. code:: bash\n\n    python regen.py myenum.h\n\nThe command above generates `myenum.gen.h`:\n\n.. code:: c++\n\n    #ifndef _MYENUM_GEN_H_\n    #define _MYENUM_GEN_H_\n\n    #include \"enum_pairs.h\"\n    #include \"myenum.h\"\n\n    template\u003c\u003e const EnumPairs\u003c MyEnum \u003e enum_pairs();\n    #endif // _MYENUM_GEN_H_\n\nand also `myenum.gen.cpp`:\n\n.. code:: c++\n\n    #include \"myenum.gen.h\"\n\n    template\u003c\u003e const EnumPairs\u003c MyEnum \u003e enum_pairs()\n    {\n        static const EnumAndName\u003c MyEnum \u003e vals[] = {\n            { FOO, \"FOO\"},\n            { BAR, \"BAR\"},\n            { BAZ, \"BAZ\"},\n        };\n        EnumPairs\u003c MyEnum \u003e r(vals);\n        return r;\n    }\n\n\nRunning\n-------\n\nFinding libclang\n^^^^^^^^^^^^^^^^\n``regen`` uses `libclang-py3 \u003chttps://pypi.python.org/pypi/libclang-py3\u003e`_,\nwhich is a python wrapper for the libclang library. The current version of\nlibclang-py3 requires libclang 3.8. regen tries to find libclang 3.8 by\nquerying ``llvm-config --libdir`` (if ``llvm-config --version`` reports 3.8)\nor ``llvm-config-3.8 --libdir`` if the first fails. If this also fails, then\nyou can still use the option ``--clang-libdir``.\n\n(This version dependency needs to be fixed; this will probably be done by\nusing different branches).\n\nlibclang on windows\n^^^^^^^^^^^^^^^^^^^\n\n`libclang is hard to use on windows\n\u003chttps://www.reddit.com/r/cpp/comments/50x2ee/how_to_get_clang_to_work/\u003e`_,\nbut it is useable.\nWhile its rough edges are rounded out by the clang developers, we need to\ndeal with its windows problems:\n\n* The official installer for version 3.8.1 on the LLVM site `is broken with\n  VS2015 Update 3\n  \u003chttp://lists.llvm.org/pipermail/cfe-dev/2016-June/049748.html\u003e`_, so it\n  won't work out of the box when the C++ library is used. It needs to be\n  compiled from source and patched (AFAIK there's no 3.8.2 release).\n* clang 3.9.1 needs to be run with the Visual Studio developer environment,\n  or it will cause a linker error (no kernel32).\n* Use of the flag ``-fms-compatibility-version=19`` is required (even after\n  compiling).\n\nFor this and other reasons it is sometimes good to compile clang from source.\nTo make this task easier, ``regen`` has a `clang build project`_, which\ndownloads the source code from llvm, clang and extra tools, patches it as\nneeded, compiles and installs. You can use it like this:\n\n.. code:: bash\n\n    cd regen/tools/clang-build\n    mkdir build\n    cd build\n    cmake -DCLANG_VERSION=3.8.1 ..\n    cmake --build --config Release .\n\nYou can compile several versions at once. For example, to compile versions\n3.8.1, 3.9.1 and 4.0.0 in a single swoop, you can configure with this command\ninstead:\n\n.. code:: bash\n\n    cmake -DCLANG_VERSION=\"3.8.1;3.9.1;4.0.0\" ..\n\nInstalling\n----------\n\nFrom PyPi\n^^^^^^^^^\n\n``regen`` installation is easy with the Python package repository. This will\ninstall regen along with its dependencies::\n\n    pip install regen\n\nFrom source\n^^^^^^^^^^^\n.. code:: bash\n\n    git clone https://github.com/biojppm/regen.git\n    cd regen\n    pip install .\n\nFor development\n^^^^^^^^^^^^^^^\n\nSetting up ``regen`` for development is easy:\n\n.. code:: bash\n\n    git clone https://github.com/biojppm/regen.git\n    cd regen\n    pip install -r requirements_dev.txt\n    pip install -e .\n\n***Windows notes***. The examples rely extensively on symbolic link\nfiles. This works as expected in Unix and Mac, but symbolic links were only\nrecently introduced in Windows. Git already allows you to use symbolic links\nin Windows, but the process is convoluted. Before cloning the repo, you must\nfirst `enable symlinks in windows\n\u003chttps://github.com/git-for-windows/git/wiki/Symbolic-Links\u003e`_. Then you need\nto pass an option to ``git clone`` to ensure that the files are really\nsymbolic links. The clone command thus needs to be:\n\n.. code:: bash\n\n    git clone -c core.symlinks=true https://github.com/biojppm/regen.git\n\n\nLicense\n-------\ncmany is permissively licensed under the `MIT license`_.\n\n.. _MIT license: LICENSE.txt\n\n.. |pypi| image:: https://img.shields.io/pypi/v/regen.svg\n      :alt: Version\n      :target: https://pypi.python.org/pypi/regen/\n\n.. |license| image:: https://img.shields.io/badge/License-MIT-yellow.svg\n   :alt: License: MIT\n   :target: https://github.com/biojppm/regen/blob/master/LICENSE.txt\n\n.. _examples folder: examples\n.. _clang build project: tools/clang-build/CMakeLists.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiojppm%2Fregen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbiojppm%2Fregen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiojppm%2Fregen/lists"}