[cfe-dev] Finding a particular constructor

Jesper Eskilson jesper.eskilson at iar.com
Fri Oct 11 05:37:05 PDT 2013


On 10/10/2013 11:38 PM, Richard Trieu wrote:
> Call getConstructor() on your CXXConstructExpr to get the
> CXXConstructorDecl that matches your function.  Then iterate over the
> parameters till you find the one called "x".  Get the index of the
> parameter and use getArg(index) on CXXConstructExpr to get the argument
> corresponding to "x".

How do I get the name of the parameter? I tried doing

       for (auto it = ctorExpr->getConstructor()->param_begin();
           it != ctorExpr->getConstructor()->param_end(); ++it)
       {
         cerr << (*it)->getDeclName().getNameAsString() << endl;
       }

but all I get are empty strings.

>
> On Wed, Oct 9, 2013 at 2:42 AM, Jesper Eskilson <jesper.eskilson at iar.com
> <mailto:jesper.eskilson at iar.com>> wrote:
>
>     Hi,
>
>     I have a class with a large number of constructors which differ only
>     slightly. I'd like to be able to distinguish these by looking at the
>     names of the arguments, but I cannot seem to find them.
>
>     class A {
>     public:
>           A(int x);
>           A(int x, float y);
>           A(double w, int x, char *z);
>           ...
>     }
>
>     I'd like to be able to (for example) look at a particular
>     CXXConstructExpr and get the value of "x", whichever position "x"
>     may have.
>
>     Where should I be looking?
>
>     --
>     *Jesper Eskilson* /Development Engineer/
>     IAR Systems AB
>     Box 23051, Strandbodgatan 1
>     SE-750 23 Uppsala, SWEDEN
>     E-mail: jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com>
>     <mailto:jesper.eskilson at iar.__com <mailto:jesper.eskilson at iar.com>>
>     Website: www.iar.com <http://www.iar.com>
>     <http://www.iar.com> Twitter: www.twitter.com/iarsystems
>     <http://www.twitter.com/iarsystems>
>     <http://www.twitter.com/__iarsystems
>     <http://www.twitter.com/iarsystems>>
>
>     _________________________________________________
>     cfe-dev mailing list
>     cfe-dev at cs.uiuc.edu <mailto:cfe-dev at cs.uiuc.edu>
>     http://lists.cs.uiuc.edu/__mailman/listinfo/cfe-dev
>     <http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev>
>
>


-- 
*Jesper Eskilson* /Development Engineer/
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
E-mail: jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com>
Website: www.iar.com
<http://www.iar.com> Twitter: www.twitter.com/iarsystems
<http://www.twitter.com/iarsystems>



More information about the cfe-dev mailing list