From ec97d967e63e4c66e0147625b09a658a3f99896c Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 16 May 2014 15:51:04 -0400 Subject: CppTools: Rename CppPreprocessor to CppSourceProcessor ...since it does quite a bit more than only preprocessing, as the name suggests. We use that class to process source files in general. The output is not a preprocessed source, but a set of CPlusPlus::Documents with symbols. Change-Id: I787d0f22f9f042ddf0c99e8c2f0bdb9aa7001735 Reviewed-by: Erik Verbruggen --- src/plugins/cpptools/cppsourceprocessor.h | 109 ++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/plugins/cpptools/cppsourceprocessor.h (limited to 'src/plugins/cpptools/cppsourceprocessor.h') diff --git a/src/plugins/cpptools/cppsourceprocessor.h b/src/plugins/cpptools/cppsourceprocessor.h new file mode 100644 index 0000000000..c748632500 --- /dev/null +++ b/src/plugins/cpptools/cppsourceprocessor.h @@ -0,0 +1,109 @@ +#ifndef CPPSOURCEPROCESSOR_H +#define CPPSOURCEPROCESSOR_H + +#include "cppmodelmanagerinterface.h" + +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE +class QTextCodec; +QT_END_NAMESPACE + +namespace CppTools { +namespace Internal { + +class CppModelManager; + +// Documentation inside. +class CPPTOOLS_EXPORT CppSourceProcessor: public CPlusPlus::Client +{ + Q_DISABLE_COPY(CppSourceProcessor) + +public: + static QString cleanPath(const QString &path); + + CppSourceProcessor(QPointer modelManager, bool dumpFileNameWhileParsing = false); + CppSourceProcessor(QPointer modelManager, const CPlusPlus::Snapshot &snapshot, + bool dumpFileNameWhileParsing = false); + virtual ~CppSourceProcessor(); + + void setRevision(unsigned revision); + void setWorkingCopy(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy); + void setIncludePaths(const QStringList &includePaths); + void setFrameworkPaths(const QStringList &frameworkPaths); + void setTodo(const QStringList &files); + + void run(const QString &fileName); + void removeFromCache(const QString &fileName); + void resetEnvironment(); + + CPlusPlus::Snapshot snapshot() const + { return m_snapshot; } + + const QSet &todo() const + { return m_todo; } + + CppModelManager *modelManager() const + { return m_modelManager.data(); } + + void setGlobalSnapshot(const CPlusPlus::Snapshot &snapshot) { m_globalSnapshot = snapshot; } + +protected: + CPlusPlus::Document::Ptr switchDocument(CPlusPlus::Document::Ptr doc); + + bool getFileContents(const QString &absoluteFilePath, QByteArray *contents, + unsigned *revision) const; + bool checkFile(const QString &absoluteFilePath) const; + QString resolveFile(const QString &fileName, IncludeType type); + QString resolveFile_helper(const QString &fileName, IncludeType type); + + void mergeEnvironment(CPlusPlus::Document::Ptr doc); + + virtual void macroAdded(const CPlusPlus::Macro ¯o); + virtual void passedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charsOffset, + unsigned line, const CPlusPlus::Macro ¯o); + virtual void failedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charOffset, + const CPlusPlus::ByteArrayRef &name); + virtual void notifyMacroReference(unsigned bytesOffset, unsigned utf16charOffset, + unsigned line, const CPlusPlus::Macro ¯o); + virtual void startExpandingMacro(unsigned bytesOffset, + unsigned utf16charOffset, + unsigned line, + const CPlusPlus::Macro ¯o, + const QVector &actuals); + virtual void stopExpandingMacro(unsigned bytesOffset, const CPlusPlus::Macro ¯o); + virtual void markAsIncludeGuard(const QByteArray ¯oName); + virtual void startSkippingBlocks(unsigned utf16charsOffset); + virtual void stopSkippingBlocks(unsigned utf16charsOffset); + virtual void sourceNeeded(unsigned line, const QString &fileName, IncludeType type); + +private: + CppSourceProcessor(); + void addFrameworkPath(const QString &frameworkPath); + + CPlusPlus::Snapshot m_snapshot; + CPlusPlus::Snapshot m_globalSnapshot; + QPointer m_modelManager; + bool m_dumpFileNameWhileParsing; + CPlusPlus::Environment m_env; + CPlusPlus::Preprocessor m_preprocess; + QStringList m_includePaths; + CppTools::CppModelManagerInterface::WorkingCopy m_workingCopy; + QStringList m_frameworkPaths; + QSet m_included; + CPlusPlus::Document::Ptr m_currentDoc; + QSet m_todo; + QSet m_processed; + unsigned m_revision; + QHash m_fileNameCache; + QTextCodec *m_defaultCodec; +}; + +} // namespace Internal +} // namespace CppTools + +#endif // CPPSOURCEPROCESSOR_H -- cgit v1.2.1