[cfe-dev] Finding a particular constructor

Richard Trieu rtrieu at google.com
Fri Oct 11 11:35:40 PDT 2013


On Fri, Oct 11, 2013 at 5:37 AM, Jesper Eskilson <jesper.eskilson at iar.com>wrote:

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

That code doesn't compile for me.  getDeclName() returns a DeclarationName
which doesn't have a getNameAsString() function.  I think either:

(*it)->getDeclName().**getAsString()

or:

(*it)->getNameAsString()

should work better.


>
>
>> On Wed, Oct 9, 2013 at 2:42 AM, Jesper Eskilson <jesper.eskilson at iar.com
>> <mailto:jesper.eskilson at iar.**com <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<jesper.eskilson at iar.com>
>> >
>>     <mailto:jesper.eskilson at iar.__**com <mailto:jesper.eskilson at iar.**com<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<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>
>>     <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<jesper.eskilson at iar.com>
> >
> Website: www.iar.com
> <http://www.iar.com> Twitter: www.twitter.com/iarsystems
> <http://www.twitter.com/**iarsystems <http://www.twitter.com/iarsystems>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131011/3bfc426d/attachment.html>


More information about the cfe-dev mailing list