/librfl

Library for generating code from C++ annotations

Primary LanguageC++BSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

librfl

(WIP)

Library for generating code from C++ annotations using Clang Tooling.

#include "rfl/annotations.h"

class rfl_class(name="Hello World") HelloWorld {
public:
  rfl_method(name = "Do Something")
  void DoSomething(rfl_arg(name = "A", kind = "in") int a,
                   rfl_arg(name = "B", kind = "in") int b);

private:
  rfl_property(id = "int_value",
               kind = "number",
               name = "Integer Value",
               default = 10,
               min = 0,
               max = 100,
               step = 1,
               page_step = 1,
               page_size = 1,
               precision = 0)
  int int_value_;
};

How it works

Currently annotations are supported on typedefs, enums, structures & classes, member fields and methods. Source files are fed to rfl-scan that parses the annotations into internal hierachical representation (see rfl/reflected.h):

Package
  PackageFile
    Namespace
      Class
        Method
        Property
        Class
      Enum

Resulting Package is then feed to the Generator plugin which takes care of output (more on that bellow).

Scanner needs an access to compilation flags. These can be provided either via JSON compilation database (generated by CMake) :

rfl-scan -p <cmake_build_directory> <annotated files...>

Or directly using -- :

rfl-scan <annotated files...> -- <c++ flags>
rfl-scan [options] <source0> [... <sourceN>]
  -G=<generator-name>        - Specify output generator
  -basedir=<string>          - Package basedir
  -i=<string>                - Import rfl library
  -l=<string>                - Link library
  -output=<string>           - Output file name prefix
  -p=<string>                - Build path
  -pkg-name=<string>         - Package name
  -pkg-version=<string>      - Package version

See example directory for a more real-like usage.

Installation

  • Requires Clang 3.6 libraries and CMake to be installed
  • Set environment variable LLVM_PATH to point to the Clang installation (eg. export LLVM_PATH=/opt/clang)
  • Use CMake to generate the build

TODO

  • Only single inheritance is supported
  • Support templates

Known limitations

  • Member field offsets may differ when using other compiler than Clang, if so you need to use compiler specific way to compute member offset
  • Tested on Linux and Mac OS X