generate/create a function call dynamically in clang

Hello,

In some situations, I need to generate a function call on the fly in clang. For example, whenever I find a reference to some identifier ‘myvar’, I want to replace the reference with the call foo(myvar), where ‘foo’ is a known function name.

I investigated the code of clang and I see CallExpr represents a function call, but it requires quite a lot to be created and I’m not sure where to get that information.just be created. What would be the best way to go about this?

Thanks in advance.

Let Sema help you build a proper call expression, by looking at the callbacks the parser makes when parsing "foo(myvar)", then emulating those with your own code. For the transformation you're talking about, build the DeclRefExpr for "myvar" (with Sema::ActOnIdExpression) and for "foo" (with the same routine), then pass those to ActOnCallExpr.

  - Doug