[cfe-dev] Process the initializers of a C++ class properly

Miguel Aguilar miguel.aguilar at ice.rwth-aachen.de
Wed Feb 6 09:10:41 PST 2013


Hi,

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

classA { };
  classB :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 
<http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html#a877f0bab49ff048f7e0faddf3f528977> 
() 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 
<http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html#a6a232de857e5b703d4d21fc86588f77b> 
()) 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130206/4bf4dcde/attachment.html>


More information about the cfe-dev mailing list