[cfe-dev] Revising the function prototype

Zheng Wang jason.wangz at gmail.com
Wed May 18 11:04:07 PDT 2011


Hi Douglas,

Thanks! I have found a way to do it. I posted my code here, in case someone
may have the same situation.

void revise(FunctionDecl* D)
{
...
//store all the types of parameters to ParamTypes

FunctionProtoType::ExtProtoInfo fpi;
fpi.Variadic = D->isVariadic();

 QualType newFT = D->getASTContext().getFunctionType(D->getResultType(),
ParamTypes.data(), ParamTypes.size(), fpi);
 D->setType(newFT);

}

On 18 May 2011 17:04, Douglas Gregor <dgregor at apple.com> wrote:

>
> On May 18, 2011, at 6:36 AM, Zheng Wang wrote:
>
> > Hi,
> >
> > I want to revise the prototype of a FunctionDecl object. Is there any
> example in Clang that I can have a look?
>
> No. Clang avoids mutating its ASTs in this way, since doing so is likely to
> break invariants in the AST.
>
> > For example,
> >
> > the original prototype of a FunctionDecl object is:
> >
> > (int, int, double*)
> >
> > and I want to change it to:
> >
> > (int, int, long, long, double*)
> >
> >
> > I have managed to change the parameters of the FunctionDecl and I am not
> sure how to revise the prototype.
>
> You would have to update both the function's type and the TypeSourceInfo
> that describes the type as it was written in the source.
>
>        - Doug
>
>


-- 
Best regards,

WANG Zheng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110518/d4954319/attachment.html>


More information about the cfe-dev mailing list