clang-metatool
A framework for reusing code in clang tools
All Classes Namespaces Files Functions Variables Typedefs Pages
meta_tool_factory.h
Go to the documentation of this file.
1 #ifndef INCLUDED_CLANGMETATOOL_META_TOOL_FACTORY_H
2 #define INCLUDED_CLANGMETATOOL_META_TOOL_FACTORY_H
3 
4 #include <string>
5 #include <map>
6 
7 #include <clang/Frontend/FrontendAction.h>
8 #include <clang/Tooling/Core/Replacement.h>
9 #include <clang/Tooling/Tooling.h>
10 
11 namespace clangmetatool {
18 template <class T>
19 class MetaToolFactory : public clang::tooling::FrontendActionFactory {
20 private:
21  // T *must* provide this
22  typename T::ArgTypes args;
23 
27  std::map<std::string, clang::tooling::Replacements> &replacements;
28 
29 public:
36  std::map<std::string, clang::tooling::Replacements> &replacements,
37  typename T::ArgTypes &args)
38  : replacements(replacements), args(args) {}
39 
41  std::map<std::string, clang::tooling::Replacements> &replacements)
42  : replacements(replacements) {}
43 
48  virtual clang::FrontendAction *create() { return new T(replacements, args); }
49 };
50 }
51 
52 #endif
53 
54 // ----------------------------------------------------------------------------
55 // Copyright 2018 Bloomberg Finance L.P.
56 //
57 // Licensed under the Apache License, Version 2.0 (the "License");
58 // you may not use this file except in compliance with the License.
59 // You may obtain a copy of the License at
60 //
61 // http://www.apache.org/licenses/LICENSE-2.0
62 //
63 // Unless required by applicable law or agreed to in writing, software
64 // distributed under the License is distributed on an "AS IS" BASIS,
65 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66 // See the License for the specific language governing permissions and
67 // limitations under the License.
68 // ----------------------------- END-OF-FILE ----------------------------------
MetaToolFactory(std::map< std::string, clang::tooling::Replacements > &replacements)
MetaToolFactory(std::map< std::string, clang::tooling::Replacements > &replacements, typename T::ArgTypes &args)
virtual clang::FrontendAction * create()