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

Hi,

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
{
public:
   Consumer(const Id& n, In<int>& i);
   const char* type() const;
   void main();

private:
   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.

Thanks,

Miguel

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:

OutPort<int>

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

Thanks,

Miguel

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: https://github.com/hdpatel/systemc-clang/blob/revamp/src/FindTemplateTypes.h

Hope it helps.