[cfe-dev] Add a parameter to FunctionDecl

Eli Friedman eli.friedman at gmail.com
Sat Nov 10 18:32:43 PST 2012


On Sat, Nov 10, 2012 at 3:27 PM, madil90 <madil90 at gmail.com> wrote:
> Hi,
>    I am using clang to create and parse an AST. I have a function in an
> ASTVisitor called "VisitFunctionDecl" which gives me a functiondecl object.
> I need to add a new parameter to this declaration in source code e.g.
>
> int foo()
> {
>
> }
>
>   should be converted to
>
> int foo(int a)
> {
> }
>
>    I need to find the location just before the ending bracket. Is there any
> way to do that?

Get a FunctionTypeLoc out of the decl; that stores the relevant locations.

> Also, can I ensure that the new parameter being added
> doesn't conflict with some variable in the function?

You can use a RecursiveASTVisitor or something like that to visit all
the declarations in the function.

-Eli



More information about the cfe-dev mailing list