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

Miguel Aguilar miguel.aguilar at ice.rwth-aachen.de
Fri Feb 8 05:36:30 PST 2013

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.

On 02/06/2013 06:10 PM, Miguel Aguilar wrote:
> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

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

More information about the cfe-dev mailing list