Can newFrontendActionFactory be allowed to take arbitrary arguments?


In a lot of the examples, a clang tool is invoked in the following way:;

The problem is that this does not allow the user to construct their object with arguments.

The solution is implementing a FrontendActionFactory and overriding create.

This is overkill in my opinion and can be easily integrated into the SimpleFrontendActionFactory class defined in the library function as follows.

std::unique_ptr newFrontendActionFactory() {
class SimpleFrontendActionFactory : public FrontendActionFactory {
clang::FrontendAction *create() override { return new T; }

return std::unique_ptr(
new SimpleFrontendActionFactory);

This can be adapted to to use variadic templates, store the arguments somehow and use them when constructing the new T.

Is that a viable idea?

Manasij Mukherjee

I have a patch somewhere that provides a couple of more generalized
utilities that accept lambdas...

(see this thread:
and the 'makeTrivialFrontendActionFactory" and
"makeLessTrivialFrontendActionFactory" - clearly some naming improvements
would be in order at least - this all got mixed up along with some other
refactoring I was doing at the time & I couldn't really settle on how to
separate it due to some unresolved underlying design issues)

Perfect forwarding is tricky here - since the values would need to be
stashed into the SimpleFrontendActionFactory, then used in the construction
of the new T object. That's why I went with something more general, the
lambda, so the state capturing was clearer/more flexible.

- David


I tried to do the perfect forwarding by storing a ‘bound’ wrapper function which calls new and got linker errors for a few tools.

Your idea seems better anyway.

I will try to use your patch locally.