Revising the function prototype

Hi,

I want to revise the prototype of a FunctionDecl object. Is there any example in Clang that I can have a look?

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.

Cheers,
Zheng

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

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);

}