GithubHelp home page GithubHelp logo

1aam2am1 / archimedes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jdah/archimedes

0.0 0.0 0.0 1.9 MB

C++20 reflection via code generation

License: MIT License

C++ 99.12% Makefile 0.88%

archimedes's Introduction

archimedes - C++ reflection via code generation

WARNING: this is ALPHA software. the code is highly unstable hot garbage. use at your own risk!

Features

  • templates are supported - though only those which are naturally instantiated (used) by the program itself
  • Reflected class/struct types have:
    • template parameter names, types, and values
    • typedef and using values (i.e. struct Foo { using F = int; /* ... */})
    • base classes
    • class memory layout including virtual bases, vtable pointers, etc.
    • fields and get/set values on live objects
    • static fields and their values
    • functions, member and static, which can be invoked on live objects
    • constructors (and destructors) which can be invoked on raw memory to (de)initialize objects
    • various type traits (is_abstract/is_polymorphic/is_pod/...)
    • inspect private members
  • Reflected enum types have:
    • std::string to value conversion
    • value to std::string conversion
    • underlying type information
  • Reflected functions:
    • can be invoke(...)'d with arbitrary arguments
    • list parameters; with types, names, and qualifiers

Example

The shortest demo which covers the most features (see test/example.test.{cpp, hpp})

TODO (just look through the tests for now!)

How does it work?

archimedes works via a clang plugin which runs on already compiled/template-instantiated ASTs. It traverses ASTs and gathers type information, serializing it and emitting it in an object file emitted alongside the actual compiler output. These object files can then be linked into any normal executable (or library) and their data loaded via archimedes::load() on program startup. In order to not bloat compile times, the majority of information (that which doesn't rely on function pointers, constexpr values, etc.) is serialized and embedded into the program via simple byte arrays which are deserialized at runtime.

Usage

Include include/archimedes.hpp for full access, and include/archimedes/*.hpp for submodules (any, type_id, etc.) See Makefile for complex usage.

$ clang++
	-o main.o
	-fplugin=<path_to_argimedes>
	-fplugin-arg-archimedes-header-include/archimedes.hpp 	# path to archimedes header
	-fplugin-arg-archimedes-exclude-ns-std 			# use "exclude-ns-<regex>" to exclude namespaces from reflection
	-fplugin-arg-archimedes-file-main.cpp 			# list files in which types should be reflected
	-fplugin-arg-archimedes-file-main.hpp
	-fplugin-arg-archimedes-out-main.types.o 		# reflection output object file
	-c
	main.cpp
$ clang++ -o main main.o main.types.o 				# link *.o and *.types.o to include reflection information

Building

$ make plugin static shared

TODO: Developing

archimedes's People

Contributors

jdah 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.