[cfe-users] using Clang for runtime compilation of a class
Georg Bartels via cfe-users
cfe-users at lists.llvm.org
Sat Oct 3 00:30:39 PDT 2015
Dear Clang Users,
I have a particular programming problem, and several discussion forums
suggested Clang as a possible solution. Being totally new to Clang and
its community, is this the right place to ask questions about how to use
Clang for a particular programming task? If not, where should I turn to?
In case this is the right forum for such questions, I continue
describing my problem. Basically, I want to compile a class which
inherits from a virtual interface class at runtime of my program. The
program should then create an instance of this new class and use it
through its interface.
Let me quickly sketch an example. The static version of my program would
look like this:
virtual int calc() const;
class Derived: public Base
virtual int calc() const
std::cout << Derived().calc() << std::endl;
The dynamic version (with two fuzzy lines of code) shall look like this:
virtual void calc() const;
std::string code = read_derived_code();
// two fuzzy lines for which I am looking for a solution
SomeCompiledObjectClass o = compile(code);
Base* d = SomeFactoryClass(o).createInstance();
std::cout << d->calc() << std::endl;
Is Clang the right tool for solving my two fuzzy lines of code? If yes,
which class should have a look at? If not, do you maybe know about
another library/compile which can achieve this task?
Thanks a lot for your help!
More information about the cfe-users