cppsourceprocessor.h 4.04 KB
Newer Older
1 2
#ifndef CPPSOURCEPROCESSOR_H
#define CPPSOURCEPROCESSOR_H
3 4 5 6 7

#include "cppmodelmanagerinterface.h"

#include <cplusplus/PreprocessorEnvironment.h>
#include <cplusplus/pp-engine.h>
8
#include <utils/qtcoverride.h>
9 10 11

#include <QHash>
#include <QPointer>
12 13
#include <QSet>
#include <QStringList>
14

15 16 17 18
QT_BEGIN_NAMESPACE
class QTextCodec;
QT_END_NAMESPACE

19 20 21 22 23
namespace CppTools {
namespace Internal {

class CppModelManager;

24
// Documentation inside.
25
class CPPTOOLS_EXPORT CppSourceProcessor: public CPlusPlus::Client
26
{
27
    Q_DISABLE_COPY(CppSourceProcessor)
28 29

public:
30 31
    static QString cleanPath(const QString &path);

32 33 34
    CppSourceProcessor(QPointer<CppModelManager> modelManager, bool dumpFileNameWhileParsing = false);
    CppSourceProcessor(QPointer<CppModelManager> modelManager, const CPlusPlus::Snapshot &snapshot,
                       bool dumpFileNameWhileParsing = false);
35
    ~CppSourceProcessor();
36 37 38 39 40 41 42 43 44 45 46

    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();

47 48 49
    CPlusPlus::Snapshot snapshot() const { return m_snapshot; }
    const QSet<QString> &todo() const { return m_todo; }
    CppModelManager *modelManager() const { return m_modelManager.data(); }
50

51 52
    void setGlobalSnapshot(const CPlusPlus::Snapshot &snapshot) { m_globalSnapshot = snapshot; }

53 54 55 56 57
private:
    CppSourceProcessor();
    void addFrameworkPath(const QString &frameworkPath);

    CPlusPlus::Document::Ptr switchCurrentDocument(CPlusPlus::Document::Ptr doc);
58

59 60
    bool getFileContents(const QString &absoluteFilePath, QByteArray *contents,
                         unsigned *revision) const;
61 62 63 64 65 66
    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);

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    // Client interface
    void macroAdded(const CPlusPlus::Macro &macro) QTC_OVERRIDE;
    void passedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charsOffset,
                                    unsigned line, const CPlusPlus::Macro &macro) QTC_OVERRIDE;
    void failedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charOffset,
                                    const CPlusPlus::ByteArrayRef &name) QTC_OVERRIDE;
    void notifyMacroReference(unsigned bytesOffset, unsigned utf16charOffset,
                              unsigned line, const CPlusPlus::Macro &macro) QTC_OVERRIDE;
    void startExpandingMacro(unsigned bytesOffset, unsigned utf16charOffset,
                             unsigned line, const CPlusPlus::Macro &macro,
                             const QVector<CPlusPlus::MacroArgumentReference> &actuals) QTC_OVERRIDE;
    void stopExpandingMacro(unsigned bytesOffset, const CPlusPlus::Macro &macro) QTC_OVERRIDE;
    void markAsIncludeGuard(const QByteArray &macroName) QTC_OVERRIDE;
    void startSkippingBlocks(unsigned utf16charsOffset) QTC_OVERRIDE;
    void stopSkippingBlocks(unsigned utf16charsOffset) QTC_OVERRIDE;
    void sourceNeeded(unsigned line, const QString &fileName, IncludeType type) QTC_OVERRIDE;
83 84 85

private:
    CPlusPlus::Snapshot m_snapshot;
86
    CPlusPlus::Snapshot m_globalSnapshot;
87 88 89 90 91 92 93 94 95 96 97 98 99
    QPointer<CppModelManager> 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<QString> m_included;
    CPlusPlus::Document::Ptr m_currentDoc;
    QSet<QString> m_todo;
    QSet<QString> m_processed;
    unsigned m_revision;
    QHash<QString, QString> m_fileNameCache;
100
    QTextCodec *m_defaultCodec;
101 102 103 104 105
};

} // namespace Internal
} // namespace CppTools

106
#endif // CPPSOURCEPROCESSOR_H