diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
| commit | 13cc256e404620c1de0cbcc4e43ce1e2dbbc4898 (patch) | |
| tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /include/clang/Tooling | |
| parent | 657bc3d9848e3be92029b2416031340988cd0111 (diff) | |
Notes
Diffstat (limited to 'include/clang/Tooling')
| -rw-r--r-- | include/clang/Tooling/CommandLineClangTool.h | 80 | ||||
| -rw-r--r-- | include/clang/Tooling/CommonOptionsParser.h | 89 | ||||
| -rw-r--r-- | include/clang/Tooling/CompilationDatabase.h | 95 | ||||
| -rw-r--r-- | include/clang/Tooling/CompilationDatabasePluginRegistry.h | 27 | ||||
| -rw-r--r-- | include/clang/Tooling/FileMatchTrie.h | 90 | ||||
| -rw-r--r-- | include/clang/Tooling/JSONCompilationDatabase.h | 107 | ||||
| -rw-r--r-- | include/clang/Tooling/Refactoring.h | 1 | ||||
| -rw-r--r-- | include/clang/Tooling/Tooling.h | 48 |
8 files changed, 376 insertions, 161 deletions
diff --git a/include/clang/Tooling/CommandLineClangTool.h b/include/clang/Tooling/CommandLineClangTool.h deleted file mode 100644 index c29c30236416..000000000000 --- a/include/clang/Tooling/CommandLineClangTool.h +++ /dev/null @@ -1,80 +0,0 @@ -//===- CommandLineClangTool.h - command-line clang tools driver -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the CommandLineClangTool class used to run clang -// tools as separate command-line applications with a consistent common -// interface for handling compilation database and input files. -// -// It provides a common subset of command-line options, common algorithm -// for locating a compilation database and source files, and help messages -// for the basic command-line interface. -// -// It creates a CompilationDatabase, initializes a ClangTool and runs a -// user-specified FrontendAction over all TUs in which the given files are -// compiled. -// -// This class uses the Clang Tooling infrastructure, see -// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -// for details on setting it up with LLVM source tree. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H -#define LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H - -#include "llvm/Support/CommandLine.h" -#include "clang/Tooling/CompilationDatabase.h" - -namespace clang { - -namespace tooling { - -class CompilationDatabase; -class FrontendActionFactory; - -/// \brief A common driver for command-line Clang tools. -/// -/// Parses a common subset of command-line arguments, locates and loads a -/// compilation commands database, runs a tool with user-specified action. It -/// also contains a help message for the common command-line options. -/// An example of usage: -/// @code -/// int main(int argc, const char **argv) { -/// CommandLineClangTool Tool; -/// cl::extrahelp MoreHelp("\nMore help text..."); -/// Tool.initialize(argc, argv); -/// return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>()); -/// } -/// @endcode -/// -class CommandLineClangTool { -public: - /// Sets up command-line options and help messages. - /// Add your own help messages after constructing this tool. - CommandLineClangTool(); - - /// Parses command-line, initializes a compilation database. - /// This method exits program in case of error. - void initialize(int argc, const char **argv); - - /// Runs a clang tool with an action created by \c ActionFactory. - int run(FrontendActionFactory *ActionFactory); - -private: - llvm::OwningPtr<CompilationDatabase> Compilations; - llvm::cl::opt<std::string> BuildPath; - llvm::cl::list<std::string> SourcePaths; - llvm::cl::extrahelp MoreHelp; -}; - -} // namespace tooling - -} // namespace clang - -#endif // LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H diff --git a/include/clang/Tooling/CommonOptionsParser.h b/include/clang/Tooling/CommonOptionsParser.h new file mode 100644 index 000000000000..a1bad1269d80 --- /dev/null +++ b/include/clang/Tooling/CommonOptionsParser.h @@ -0,0 +1,89 @@ +//===- CommonOptionsParser.h - common options for clang tools -*- C++ -*-=====// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the CommonOptionsParser class used to parse common +// command-line options for clang tools, so that they can be run as separate +// command-line applications with a consistent common interface for handling +// compilation database and input files. +// +// It provides a common subset of command-line options, common algorithm +// for locating a compilation database and source files, and help messages +// for the basic command-line interface. +// +// It creates a CompilationDatabase and reads common command-line options. +// +// This class uses the Clang Tooling infrastructure, see +// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html +// for details on setting it up with LLVM source tree. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMONOPTIONSPARSER_H +#define LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMONOPTIONSPARSER_H + +#include "clang/Tooling/CompilationDatabase.h" + +namespace clang { +namespace tooling { +/// \brief A parser for options common to all command-line Clang tools. +/// +/// Parses a common subset of command-line arguments, locates and loads a +/// compilation commands database and runs a tool with user-specified action. It +/// also contains a help message for the common command-line options. +/// +/// An example of usage: +/// \code +/// #include "clang/Frontend/FrontendActions.h" +/// #include "clang/Tooling/CommonOptionsParser.h" +/// #include "llvm/Support/CommandLine.h" +/// +/// using namespace clang::tooling; +/// using namespace llvm; +/// +/// static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); +/// static cl::extrahelp MoreHelp("\nMore help text..."); +/// static cl:opt<bool> YourOwnOption(...); +/// ... +/// +/// int main(int argc, const char **argv) { +/// CommonOptionsParser OptionsParser(argc, argv); +/// ClangTool Tool(OptionsParser.GetCompilations(), +/// OptionsParser.GetSourcePathListi()); +/// return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>()); +/// } +/// \endcode +class CommonOptionsParser { +public: + /// \brief Parses command-line, initializes a compilation database. + /// This constructor can change argc and argv contents, e.g. consume + /// command-line options used for creating FixedCompilationDatabase. + /// This constructor exits program in case of error. + CommonOptionsParser(int &argc, const char **argv); + + /// Returns a reference to the loaded compilations database. + CompilationDatabase &GetCompilations() { + return *Compilations; + } + + /// Returns a list of source file paths to process. + std::vector<std::string> GetSourcePathList() { + return SourcePathList; + } + + static const char *const HelpMessage; + +private: + llvm::OwningPtr<CompilationDatabase> Compilations; + std::vector<std::string> SourcePathList; +}; + +} // namespace tooling +} // namespace clang + +#endif // LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMONOPTIONSPARSER_H diff --git a/include/clang/Tooling/CompilationDatabase.h b/include/clang/Tooling/CompilationDatabase.h index f78ffaed284c..a40bffec78ba 100644 --- a/include/clang/Tooling/CompilationDatabase.h +++ b/include/clang/Tooling/CompilationDatabase.h @@ -31,12 +31,9 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/YAMLParser.h" + #include <string> #include <vector> @@ -111,6 +108,27 @@ public: virtual std::vector<std::string> getAllFiles() const = 0; }; +/// \brief Interface for compilation database plugins. +/// +/// A compilation database plugin allows the user to register custom compilation +/// databases that are picked up as compilation database if the corresponding +/// library is linked in. To register a plugin, declare a static variable like: +/// +/// \code +/// static CompilationDatabasePluginRegistry::Add<MyDatabasePlugin> +/// X("my-compilation-database", "Reads my own compilation database"); +/// \endcode +class CompilationDatabasePlugin { +public: + virtual ~CompilationDatabasePlugin(); + + /// \brief Loads a compilation database from a build directory. + /// + /// \see CompilationDatabase::loadFromDirectory(). + virtual CompilationDatabase *loadFromDirectory(StringRef Directory, + std::string &ErrorMessage) = 0; +}; + /// \brief A compilation database that returns a single compile command line. /// /// Useful when we want a tool to behave more like a compiler invocation. @@ -169,75 +187,6 @@ private: std::vector<CompileCommand> CompileCommands; }; -/// \brief A JSON based compilation database. -/// -/// JSON compilation database files must contain a list of JSON objects which -/// provide the command lines in the attributes 'directory', 'command' and -/// 'file': -/// [ -/// { "directory": "<working directory of the compile>", -/// "command": "<compile command line>", -/// "file": "<path to source file>" -/// }, -/// ... -/// ] -/// Each object entry defines one compile action. The specified file is -/// considered to be the main source file for the translation unit. -/// -/// JSON compilation databases can for example be generated in CMake projects -/// by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS. -class JSONCompilationDatabase : public CompilationDatabase { -public: - /// \brief Loads a JSON compilation database from the specified file. - /// - /// Returns NULL and sets ErrorMessage if the database could not be - /// loaded from the given file. - static JSONCompilationDatabase *loadFromFile(StringRef FilePath, - std::string &ErrorMessage); - - /// \brief Loads a JSON compilation database from a data buffer. - /// - /// Returns NULL and sets ErrorMessage if the database could not be loaded. - static JSONCompilationDatabase *loadFromBuffer(StringRef DatabaseString, - std::string &ErrorMessage); - - /// \brief Returns all compile comamnds in which the specified file was - /// compiled. - /// - /// FIXME: Currently FilePath must be an absolute path inside the - /// source directory which does not have symlinks resolved. - virtual std::vector<CompileCommand> getCompileCommands( - StringRef FilePath) const; - - /// \brief Returns the list of all files available in the compilation database. - /// - /// These are the 'file' entries of the JSON objects. - virtual std::vector<std::string> getAllFiles() const; - -private: - /// \brief Constructs a JSON compilation database on a memory buffer. - JSONCompilationDatabase(llvm::MemoryBuffer *Database) - : Database(Database), YAMLStream(Database->getBuffer(), SM) {} - - /// \brief Parses the database file and creates the index. - /// - /// Returns whether parsing succeeded. Sets ErrorMessage if parsing - /// failed. - bool parse(std::string &ErrorMessage); - - // Tuple (directory, commandline) where 'commandline' pointing to the - // corresponding nodes in the YAML stream. - typedef std::pair<llvm::yaml::ScalarNode*, - llvm::yaml::ScalarNode*> CompileCommandRef; - - // Maps file paths to the compile command lines for that file. - llvm::StringMap< std::vector<CompileCommandRef> > IndexByFile; - - llvm::OwningPtr<llvm::MemoryBuffer> Database; - llvm::SourceMgr SM; - llvm::yaml::Stream YAMLStream; -}; - } // end namespace tooling } // end namespace clang diff --git a/include/clang/Tooling/CompilationDatabasePluginRegistry.h b/include/clang/Tooling/CompilationDatabasePluginRegistry.h new file mode 100644 index 000000000000..84fcd24b4a12 --- /dev/null +++ b/include/clang/Tooling/CompilationDatabasePluginRegistry.h @@ -0,0 +1,27 @@ +//===--- CompilationDatabasePluginRegistry.h - ------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLING_COMPILATION_DATABASE_PLUGIN_REGISTRY_H +#define LLVM_CLANG_TOOLING_COMPILATION_DATABASE_PLUGIN_REGISTRY_H + +#include "clang/Tooling/CompilationDatabase.h" +#include "llvm/Support/Registry.h" + +namespace clang { +namespace tooling { + +class CompilationDatabasePlugin; + +typedef llvm::Registry<CompilationDatabasePlugin> + CompilationDatabasePluginRegistry; + +} // end namespace tooling +} // end namespace clang + +#endif // LLVM_CLANG_TOOLING_COMPILATION_DATABASE_PLUGIN_REGISTRY_H diff --git a/include/clang/Tooling/FileMatchTrie.h b/include/clang/Tooling/FileMatchTrie.h new file mode 100644 index 000000000000..ff988bebf2ca --- /dev/null +++ b/include/clang/Tooling/FileMatchTrie.h @@ -0,0 +1,90 @@ +//===--- FileMatchTrie.h - --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements a match trie to find the matching file in a compilation +// database based on a given path in the presence of symlinks. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLING_FILE_MATCH_TRIE_H +#define LLVM_CLANG_TOOLING_FILE_MATCH_TRIE_H + +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/StringRef.h" + +#include <string> +#include <vector> + +namespace clang { +namespace tooling { + +struct PathComparator { + virtual ~PathComparator() {} + virtual bool equivalent(StringRef FileA, StringRef FileB) const = 0; +}; +class FileMatchTrieNode; + +/// \brief A trie to efficiently match against the entries of the compilation +/// database in order of matching suffix length. +/// +/// When a clang tool is supposed to operate on a specific file, we have to +/// find the corresponding file in the compilation database. Although entries +/// in the compilation database are keyed by filename, a simple string match +/// is insufficient because of symlinks. Commonly, a project hierarchy looks +/// like this: +/// /<project-root>/src/<path>/<somefile>.cc (used as input for the tool) +/// /<project-root>/build/<symlink-to-src>/<path>/<somefile>.cc (stored in DB) +/// +/// Furthermore, there might be symlinks inside the source folder or inside the +/// database, so that the same source file is translated with different build +/// options. +/// +/// For a given input file, the \c FileMatchTrie finds its entries in order +/// of matching suffix length. For each suffix length, there might be one or +/// more entries in the database. For each of those entries, it calls +/// \c llvm::sys::fs::equivalent() (injected as \c PathComparator). There might +/// be zero or more entries with the same matching suffix length that are +/// equivalent to the input file. Three cases are distinguished: +/// 0 equivalent files: Continue with the next suffix length. +/// 1 equivalent file: Best match found, return it. +/// >1 equivalent files: Match is ambiguous, return error. +class FileMatchTrie { +public: + FileMatchTrie(); + + /// \brief Construct a new \c FileMatchTrie with the given \c PathComparator. + /// + /// The \c FileMatchTrie takes ownership of 'Comparator'. Used for testing. + FileMatchTrie(PathComparator* Comparator); + + ~FileMatchTrie(); + + /// \brief Insert a new absolute path. Relative paths are ignored. + void insert(StringRef NewPath); + + /// \brief Finds the corresponding file in this trie. + /// + /// Returns file name stored in this trie that is equivalent to 'FileName' + /// according to 'Comparator', if it can be uniquely identified. If there + /// are no matches an empty \c StringRef is returned. If there are ambigious + /// matches, an empty \c StringRef is returned and a corresponding message + /// written to 'Error'. + StringRef findEquivalent(StringRef FileName, + llvm::raw_ostream &Error) const; +private: + FileMatchTrieNode *Root; + OwningPtr<PathComparator> Comparator; +}; + + +} // end namespace tooling +} // end namespace clang + +#endif // LLVM_CLANG_TOOLING_FILE_MATCH_TRIE_H diff --git a/include/clang/Tooling/JSONCompilationDatabase.h b/include/clang/Tooling/JSONCompilationDatabase.h new file mode 100644 index 000000000000..d62ab5c5036e --- /dev/null +++ b/include/clang/Tooling/JSONCompilationDatabase.h @@ -0,0 +1,107 @@ +//===--- JSONCompilationDatabase.h - ----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// The JSONCompilationDatabase finds compilation databases supplied as a file +// 'compile_commands.json'. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLING_JSON_COMPILATION_DATABASE_H +#define LLVM_CLANG_TOOLING_JSON_COMPILATION_DATABASE_H + +#include "clang/Basic/LLVM.h" +#include "clang/Tooling/CompilationDatabase.h" +#include "clang/Tooling/FileMatchTrie.h" +#include "llvm/ADT/OwningPtr.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/YAMLParser.h" +#include <string> +#include <vector> + +namespace clang { +namespace tooling { + +/// \brief A JSON based compilation database. +/// +/// JSON compilation database files must contain a list of JSON objects which +/// provide the command lines in the attributes 'directory', 'command' and +/// 'file': +/// [ +/// { "directory": "<working directory of the compile>", +/// "command": "<compile command line>", +/// "file": "<path to source file>" +/// }, +/// ... +/// ] +/// Each object entry defines one compile action. The specified file is +/// considered to be the main source file for the translation unit. +/// +/// JSON compilation databases can for example be generated in CMake projects +/// by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS. +class JSONCompilationDatabase : public CompilationDatabase { +public: + /// \brief Loads a JSON compilation database from the specified file. + /// + /// Returns NULL and sets ErrorMessage if the database could not be + /// loaded from the given file. + static JSONCompilationDatabase *loadFromFile(StringRef FilePath, + std::string &ErrorMessage); + + /// \brief Loads a JSON compilation database from a data buffer. + /// + /// Returns NULL and sets ErrorMessage if the database could not be loaded. + static JSONCompilationDatabase *loadFromBuffer(StringRef DatabaseString, + std::string &ErrorMessage); + + /// \brief Returns all compile comamnds in which the specified file was + /// compiled. + /// + /// FIXME: Currently FilePath must be an absolute path inside the + /// source directory which does not have symlinks resolved. + virtual std::vector<CompileCommand> getCompileCommands( + StringRef FilePath) const; + + /// \brief Returns the list of all files available in the compilation database. + /// + /// These are the 'file' entries of the JSON objects. + virtual std::vector<std::string> getAllFiles() const; + +private: + /// \brief Constructs a JSON compilation database on a memory buffer. + JSONCompilationDatabase(llvm::MemoryBuffer *Database) + : Database(Database), YAMLStream(Database->getBuffer(), SM) {} + + /// \brief Parses the database file and creates the index. + /// + /// Returns whether parsing succeeded. Sets ErrorMessage if parsing + /// failed. + bool parse(std::string &ErrorMessage); + + // Tuple (directory, commandline) where 'commandline' pointing to the + // corresponding nodes in the YAML stream. + typedef std::pair<llvm::yaml::ScalarNode*, + llvm::yaml::ScalarNode*> CompileCommandRef; + + // Maps file paths to the compile command lines for that file. + llvm::StringMap< std::vector<CompileCommandRef> > IndexByFile; + + FileMatchTrie MatchTrie; + + llvm::OwningPtr<llvm::MemoryBuffer> Database; + llvm::SourceMgr SM; + llvm::yaml::Stream YAMLStream; +}; + +} // end namespace tooling +} // end namespace clang + +#endif // LLVM_CLANG_TOOLING_JSON_COMPILATION_DATABASE_H diff --git a/include/clang/Tooling/Refactoring.h b/include/clang/Tooling/Refactoring.h index 0e42a0ec64fc..aaffc1a29e06 100644 --- a/include/clang/Tooling/Refactoring.h +++ b/include/clang/Tooling/Refactoring.h @@ -74,6 +74,7 @@ public: StringRef getFilePath() const { return FilePath; } unsigned getOffset() const { return Offset; } unsigned getLength() const { return Length; } + StringRef getReplacementText() const { return ReplacementText; } /// @} /// \brief Applies the replacement on the Rewriter. diff --git a/include/clang/Tooling/Tooling.h b/include/clang/Tooling/Tooling.h index e06705f0279b..a03bcb1bbb84 100644 --- a/include/clang/Tooling/Tooling.h +++ b/include/clang/Tooling/Tooling.h @@ -74,6 +74,14 @@ public: template <typename T> FrontendActionFactory *newFrontendActionFactory(); +/// \brief Called at the end of each source file when used with +/// \c newFrontendActionFactory. +class EndOfSourceFileCallback { +public: + virtual ~EndOfSourceFileCallback() {} + virtual void run() = 0; +}; + /// \brief Returns a new FrontendActionFactory for any type that provides an /// implementation of newASTConsumer(). /// @@ -87,7 +95,7 @@ FrontendActionFactory *newFrontendActionFactory(); /// newFrontendActionFactory(&Factory); template <typename FactoryT> inline FrontendActionFactory *newFrontendActionFactory( - FactoryT *ConsumerFactory); + FactoryT *ConsumerFactory, EndOfSourceFileCallback *EndCallback = NULL); /// \brief Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag. /// @@ -99,6 +107,19 @@ inline FrontendActionFactory *newFrontendActionFactory( bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, const Twine &FileName = "input.cc"); +/// \brief Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag and +/// with additional other flags. +/// +/// \param ToolAction The action to run over the code. +/// \param Code C++ code. +/// \param Args Additional flags to pass on. +/// \param FileName The file name which 'Code' will be mapped as. +/// +/// \return - True if 'ToolAction' was successfully executed. +bool runToolOnCodeWithArgs(clang::FrontendAction *ToolAction, const Twine &Code, + const std::vector<std::string> &Args, + const Twine &FileName = "input.cc"); + /// \brief Utility to run a FrontendAction in a single clang invocation. class ToolInvocation { public: @@ -204,34 +225,45 @@ FrontendActionFactory *newFrontendActionFactory() { template <typename FactoryT> inline FrontendActionFactory *newFrontendActionFactory( - FactoryT *ConsumerFactory) { + FactoryT *ConsumerFactory, EndOfSourceFileCallback *EndCallback) { class FrontendActionFactoryAdapter : public FrontendActionFactory { public: - explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory) - : ConsumerFactory(ConsumerFactory) {} + explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory, + EndOfSourceFileCallback *EndCallback) + : ConsumerFactory(ConsumerFactory), EndCallback(EndCallback) {} virtual clang::FrontendAction *create() { - return new ConsumerFactoryAdaptor(ConsumerFactory); + return new ConsumerFactoryAdaptor(ConsumerFactory, EndCallback); } private: class ConsumerFactoryAdaptor : public clang::ASTFrontendAction { public: - ConsumerFactoryAdaptor(FactoryT *ConsumerFactory) - : ConsumerFactory(ConsumerFactory) {} + ConsumerFactoryAdaptor(FactoryT *ConsumerFactory, + EndOfSourceFileCallback *EndCallback) + : ConsumerFactory(ConsumerFactory), EndCallback(EndCallback) {} clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &, llvm::StringRef) { return ConsumerFactory->newASTConsumer(); } + protected: + virtual void EndSourceFileAction() { + if (EndCallback != NULL) + EndCallback->run(); + clang::ASTFrontendAction::EndSourceFileAction(); + } + private: FactoryT *ConsumerFactory; + EndOfSourceFileCallback *EndCallback; }; FactoryT *ConsumerFactory; + EndOfSourceFileCallback *EndCallback; }; - return new FrontendActionFactoryAdapter(ConsumerFactory); + return new FrontendActionFactoryAdapter(ConsumerFactory, EndCallback); } /// \brief Returns the absolute path of \c File, by prepending it with |
