[cfe-dev] What is starting point to extend clang RTTI features ?

mohsen via cfe-dev cfe-dev at lists.llvm.org
Sat Dec 30 03:00:12 PST 2017


On Fri, 29 Dec 2017 21:07:35 +0330
mohsen <mohsen.timar at gmail.com> wrote:

> On Fri, 29 Dec 2017 11:12:27 +0100
> David Wiberg <dwiberg at gmail.com> wrote:
> 
> > 2017-12-28 22:51 GMT+01:00 mohsen via cfe-dev
> > <cfe-dev at lists.llvm.org>:
> > > On Thu, 28 Dec 2017 14:17:10 +0330
> > > mohsen <mohsen.timar at gmail.com> wrote:
> > >  
> > >> Hi
> > >>
> > >> I am working on many projects that's need RTTI for
> > >> implementation; for example JSON reader, writer, Database
> > >> library, RESTFul and so on. 
> > 
> > Hello,
> > 
> > I think it would be good if you can expand the description of your
> > use-case a bit to help people understand what you are looking for
> > and why.
> > 
> > Are the projects you mention C++ projects? If so, can you explain
> > why you can't use the normal C++ RTTI support?
> > 
> > Best regards
> > David
> > 
> > >> For that cases I use another languages like pascal and sometimes
> > >> script languages like PHP.
> > >>
> > >> Now, I want to extend clang compiler RTTI to use it for that
> > >> cases but can't find starting point.
> > >>
> > >> Please help me to find best starting point.
> > >>  
> > >
> > > For first try to implement RTTI, I create a plugin to visit AST
> > > nodes and extract functions and classes methods info to generate a
> > > header file based on AST nodes, This header contain a map from a
> > > function/method signature in string to pointer of that.
> > >
> > > To complete my idea , I need help to solve two problem :
> > >
> > > 1- How to get pointer of overloaded methods and functions ?
> > >
> > > An example:
> > >
> > > template<typename T>
> > > T sum(T a,T b) {
> > >         return a + b;
> > > }
> > >
> > > int main(int argc, char const *argv[])
> > > {
> > >         sum(1,2);
> > >         sum(1.0,2.0);
> > >         return 0;
> > > }
> > >
> > > function extraction result is :
> > >
> > > main (int argc, const char ** argv )
> > > sum (int a, int b )
> > > sum (double a, double b )
> > >
> > >
> > > 2- If a project contain more than one file how to generate a
> > > header for all files ?
> > >
> > > --
> > > Regards,
> > > Mohsen Timar
> > > _______________________________________________
> > > cfe-dev mailing list
> > > cfe-dev at lists.llvm.org
> > > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev  
> 
> Hi,
> 
> To give you more information about the features of RTTI that I need, I
> can explain one of my projects.
> 
> About two weeks ago I was working on an application that read Sketch
> App (UI Design) file format and store file data to a tree of objects.
> 
> Sketch file is in JSON format,To read that file at first I should
> write interface structures then for each property at least two line of
> code should be written to set the object field. So I replace
> RTTI instead of this complex codes.
> 
> In pascal we can define some properties for classes and set
> value of those properties with RTTI. After define classes I write a
> JSON reader that reads class_type property and it searches the class
> by RTTI based on class_type property. then creates
> an instance of that class.  
> each property that reads from the JSON set to  the object instance
> that created in previous step.
> 
> Create objects, read and set properties , type checkings and type
> converting was done in one method because of RTTI.
> 
> C++ is my favorite lang, I want to improve it's RTTI.
> Features I thinking about are a tree of namespaces, classes, structs,
> methods, fields, functions and routines to search over tree , get and
> set filed values and call methods and functions.
> 

Hi again,

After many search around the web finally found many resources around
reflection and RTTI implementation in C++ and clang. 

Some links about this topic :
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0385r1.pdf
https://github.com/asutton/clang-reflect
https://github.com/AustinBrunkhorst/CPP-Reflection
https://bytemaster.github.io/boost_reflect

I think it's not a easy task to do so I will go to read more about
reflection in other languages and implementations.

-- 
Regards,
Mohsen Timar



More information about the cfe-dev mailing list