Coder Social home page Coder Social logo

blockspacer / flex_reflect_plugin Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 1.0 10.76 MB

C++ reflection, code generation and compile-time C++ execution

Home Page: https://blockspacer.github.io/flex_docs/

CMake 60.90% Python 13.84% C++ 25.27%
conan cmake annotation-methods code-generation reflection clang cling libtooling refactoring cplusplus

flex_reflect_plugin's Introduction

About

Plugin for https://github.com/blockspacer/flextool

Provides annotation methods. See https://blockspacer.github.io/flex_docs/about/ for details

Before installation

Installation

export CXX=clang++-10
export CC=clang-10

# NOTE: change `build_type=Debug` to `build_type=Release` in production
# NOTE: use --build=missing if you got error `ERROR: Missing prebuilt package`
cmake -E time \
  conan create . conan/stable \
  -s build_type=Debug -s cling_conan:build_type=Release \
  --profile clang \
      -o flex_reflect_plugin:shared=True \
      -o flex_reflect_plugin:enable_clang_from_conan=False \
      -e flex_reflect_plugin:enable_tests=True

# clean build cache
conan remove "*" --build --force

Provided annotation methods

  • Call function (arbitrary logic) by some name
  • Execute C++ code at runtime using Cling C++ interpreter
    // evaluates arbitrary C++ code line
    // does not support newline characters or spaces
    // may use `#include` or preprocessor macros
    // example:
    //   $executeStringWithoutSpaces("#include <cling/Interpreter/Interpreter.h>")
    // if you need to execute multiline C++ code line - use "executeCode"
    /**
      EXAMPLE:
        // will be replaced with empty string
        __attribute__((annotate("{gen};{executeStringWithoutSpaces};\
        printf(\"Hello world!\");"))) \
        int SOME_UNIQUE_NAME0
        ;
        // if nothing printed, then
        // replace printf with
        // LOG(INFO)<<\"Hello!\";"))) \
    **/
    "{executeStringWithoutSpaces};"

    // exports arbitrary C++ code, code can be multiline
    // unable to use `#include` or preprocessor macros
    /**
      EXAMPLE:
        // will be replaced with empty string
        __attribute__((annotate("{gen};{executeCode};\
        printf(\"Hello me!\");"))) \
        int SOME_UNIQUE_NAME1
        ;
        // if nothing printed, then
        // replace printf with
        // LOG(INFO)<<\"Hello!\";"))) \
    **/
    "{executeCode};"

    // embeds arbitrary C++ code
    /**
      EXAMPLE:
        // will be replaced with 1234
        __attribute__((annotate("{gen};{executeCodeAndReplace};\
        new llvm::Optional<std::string>{\"1234\"};")))
        int SOME_UNIQUE_NAME2
        ;
    **/
    "{executeCodeAndReplace};"

    /**
      EXAMPLE:
        #include <string>
        #include <vector>
        struct
          __attribute__((annotate("{gen};{funccall};make_reflect;")))
        SomeStructName {
         public:
          SomeStructName() {
            // ...
          }
         private:
          const int m_bar2 = 2;

          std::vector<std::string> m_VecStr2;
        };
        // handler for make_reflect must be registered by plugin!
    **/
    "{funccall};"

For contibutors: conan editable mode

With the editable packages, you can tell Conan where to find the headers and the artifacts ready for consumption in your local working directory. There is no need to run conan create or conan export-pkg.

See for details https://docs.conan.io/en/latest/developing_packages/editable_packages.html

Build locally:

export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
export GIT_SSL_NO_VERIFY=true

cmake -E time \
  conan install . \
  --install-folder local_build \
  -s build_type=Debug -s cling_conan:build_type=Release \
  --profile clang \
    -o flex_reflect_plugin:shared=True \
    -o flex_reflect_plugin:enable_clang_from_conan=False \
    -e flex_reflect_plugin:enable_tests=True

cmake -E time \
  conan source . \
  --source-folder local_build \
  --install-folder local_build

conan build . \
  --build-folder local_build

conan package . \
  --build-folder local_build \
  --package-folder local_build/package_dir \
  --source-folder local_build \
  --install-folder local_build

cmake -E time \
  conan export-pkg . conan/stable \
  --package-folder local_build/package_dir \
  -s build_type=Debug \
  -s cling_conan:build_type=Release \
  -s llvm_tools:build_type=Release \
   --force --profile clang

cmake -E time \
  conan test test_package flex_reflect_plugin/master@conan/stable \
  -s build_type=Debug \
  -s cling_conan:build_type=Release \
  -s llvm_tools:build_type=Release \
  --profile clang

Set package to editable mode:

conan editable add local_build/package_dir \
  flex_reflect_plugin/master@conan/stable

Note that conanfile.py modified to detect local builds via self.in_local_cache

After change source in folder local_build (run commands in source package folder):

conan build . \
  --build-folder local_build

conan package . \
  --build-folder local_build \
  --package-folder local_build/package_dir \
  --source-folder local_build \
  --install-folder local_build

Build your test project

In order to revert the editable mode just remove the link using:

conan editable remove \
  flex_reflect_plugin/master@conan/stable

flex_reflect_plugin's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

linecode

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.