[cfe-dev] Can newFrontendActionFactory be allowed to take arbitrary arguments?

Manasij Mukherjee manasij7479 at gmail.com
Mon Dec 22 11:32:09 PST 2014


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

Tool.run(newFrontendActionFactory<ActionType>().get());

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.

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

  return std::unique_ptr<FrontendActionFactory>(
      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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141223/64bd8a8d/attachment.html>


More information about the cfe-dev mailing list