Process the initializers of a C++ class properly

Hi,

I have been trying to get information from the initializers of a C++ class. For example if I have something like this:

class A { };
 class B : public A {
   float f;
 public:
   B(A& a) : A(a), f(3.14159) { }
 };

I wold like to get the initialization values for each member. In this example the values a and 3.14159 for the members A and f respectively.

What I have done so far is this:

I am using the method VisitCXXConstructorDecl and then getting the initalizers by means of iterator CXXConstructorDecl::init_iterator. I am able to get the members that are being initialized by means of getMember () method for each initializer.

However, I want to have the initialization values themselves (a and 3.14…), then I tried to get the initializer expression (getInit ()) and then cast it to CXXConstructExpr in order to try to get the arguments of the call to the constructors of A and f.

The problem is that the method getInit() is not returning the initialization expression. Any ideas what could be wrong, or other ways to get the initialization values for the members.

Thanks,

Miguel

Hi,

I have been trying to get information from the initializers of a C++ class. For example if I have something like this:

class A { };
 class B : public A {
   float f;
 public:
   B(A& a) : A(a), f(3.14159) { }
 };

I wold like to get the initialization values for each member. In this example the values a and 3.14159 for the members A and f respectively.

What I have done so far is this:

I am using the method VisitCXXConstructorDecl and then getting the initalizers by means of iterator CXXConstructorDecl::init_iterator. I am able to get the members that are being initialized by means of getMember () method for each initializer.

However, I want to have the initialization values themselves (a and 3.14…), then I tried to get the initializer expression (getInit ()) and then cast it to CXXConstructExpr in order to try to get the arguments of the call to the constructors of A and f.

The problem is that the method getInit() is not returning the initialization expression. Any ideas what could be wrong, or other ways to get the initialization values for the members.

Thanks,

Miguel

Clang has its own mailing list (see clang.llvm.org for details.) Posting
your questions there will maximize your chances of obtaining a helpful
response.

Nevermind, I manage to make it work casting the original Expr to ExprWithCleanups and then to CXXConstructExpr. Now I am able to get the Expr initializers of the members of the classes.