[cfe-dev] Finding a particular constructor

Jesper Eskilson jesper.eskilson at iar.com
Mon Oct 14 01:15:26 PDT 2013


On 10/11/2013 08:35 PM, Richard Trieu wrote:
> On Fri, Oct 11, 2013 at 5:37 AM, Jesper Eskilson
> <jesper.eskilson at iar.com <mailto: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.
>

I still only get empty strings.

I'll try to construct a minimal example to recreate this.

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