Get the global variables (members) of a given C++ class


I am wondering if for a given c++ class record (CXXRecordDecl) is possible to walk through the global variables (members).

For example:

class Consumer : public Process
   Consumer(const Id& n, In<int>& i);
   const char* type() const;
   void main();

   InPort<int> in;

Here I would like to parse the member "InPort<int> in;" in order to get the type and the name of the variable.



I think you want RecordDecl's inherited field_begin and field_end.

Hi Jordan,

Thanks for the reply, RecordDecl is exactly what I wanted to use. However as I am using a type derived from a template I am getting the following output:


Is there any way to get the name of type (OutPort) and the parameter of the template (int), independently?



Hi Miguel,

I did something similar where I wanted to get the class/type names of a variable declared using templates. I had class data members that looked like:

sc_in< sc_int<32> > value;

I used RecursiveASTVisitor to visit the Type class. This code may provide some guidance:

Hope it helps.