From 3f4a0d5370ae6c34afe180df96add3b8522f4af1 Mon Sep 17 00:00:00 2001 From: mattkae Date: Wed, 11 May 2022 09:23:58 -0400 Subject: initial commit --- elpa/irony-20220110.849/server/src/TUManager.h | 109 +++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 elpa/irony-20220110.849/server/src/TUManager.h (limited to 'elpa/irony-20220110.849/server/src/TUManager.h') diff --git a/elpa/irony-20220110.849/server/src/TUManager.h b/elpa/irony-20220110.849/server/src/TUManager.h new file mode 100644 index 0000000..bd7730d --- /dev/null +++ b/elpa/irony-20220110.849/server/src/TUManager.h @@ -0,0 +1,109 @@ +/**-*-C++-*- + * \file + * \author Guillaume Papin + * + * \brief Translation Unit manager. + * + * Keeps a cache of translation units, reparsing or recreating them as + * necessary. + * + * This file is distributed under the GNU General Public License. See + * COPYING for details. + */ + +#ifndef IRONY_MODE_SERVER_TUMANAGER_H_ +#define IRONY_MODE_SERVER_TUMANAGER_H_ + +#include "support/CIndex.h" +#include "support/NonCopyable.h" + +#include +#include +#include + +class TUManager : public util::NonCopyable { +public: + TUManager(); + ~TUManager(); + + /** + * \brief Parse \p filename with flag \p flags. + * + * The first time call \c clang_parseTranslationUnit() and save the TU in the + * member \c translationUnits_, The next call with the same \p filename will + * call \c clang_reparseTranslationUnit(). + * + * usage: + * \code + * std::vector flags; + * flags.push_back("-I../utils"); + * CXTranslationUnit tu = tuManager.parse("file.cpp", flags); + * + * if (! tu) + * std::cerr << "parsing translation unit failed\n"; + * \endcode + * + * \return The translation unit, if the parsing failed the translation unit + * will be \c NULL. + */ + CXTranslationUnit parse(const std::string &filename, + const std::vector &flags, + const std::vector &unsavedFiles); + + /** + * \brief Retrieve, creating it if necessary the TU associated to filename. + * + * \return The translation unit. Will be NULL if the translation unit couldn't + * be created. + */ + CXTranslationUnit getOrCreateTU(const std::string &filename, + const std::vector &flags, + const std::vector &unsavedFiles); + + /** + * \brief Invalidate a given cached TU, the next use of a TU will require + * reparsing. + * + * This can be useful for example: when the flags used to compile a file have + * changed. + * + * \param filename The filename for which the associated + * translation unit flags need to be invalidated. + * + * \sa invalidateAllCachedTUs() + */ + void invalidateCachedTU(const std::string &filename); + + /** + * \brief Invalidate all cached TU, the next use of a TU will require + * reparsing. + * + * \sa invalidateCachedTU() + */ + void invalidateAllCachedTUs(); + +private: + /** + * \brief Get a reference to the translation unit that matches \p filename + * with the given set of flags. + * + * The TU will be null if it has never been parsed or if the flags have + * changed. + * + * \todo Find a proper name. + */ + CXTranslationUnit &tuRef(const std::string &filename, + const std::vector &flags); + +private: + typedef std::map TranslationUnitsMap; + typedef std::map> FilenameFlagsMap; + +private: + CXIndex index_; + TranslationUnitsMap translationUnits_; // cache variable + FilenameFlagsMap flagsPerFileCache_; + unsigned parseTUOptions_; +}; + +#endif /* !IRONY_MODE_SERVER_TUMANAGER_H_ */ -- cgit v1.2.1