cppsourceprocessor.h 4.03 KB
Newer Older
1 2
#ifndef CPPSOURCEPROCESSOR_H
#define CPPSOURCEPROCESSOR_H
3 4 5 6 7 8 9 10 11

#include "cppmodelmanagerinterface.h"

#include <cplusplus/PreprocessorEnvironment.h>
#include <cplusplus/pp-engine.h>

#include <QHash>
#include <QPointer>

12 13 14 15
QT_BEGIN_NAMESPACE
class QTextCodec;
QT_END_NAMESPACE

16 17 18 19 20
namespace CppTools {
namespace Internal {

class CppModelManager;

21
// Documentation inside.
22
class CPPTOOLS_EXPORT CppSourceProcessor: public CPlusPlus::Client
23
{
24
    Q_DISABLE_COPY(CppSourceProcessor)
25 26

public:
27 28
    static QString cleanPath(const QString &path);

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

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

44 45 46
    CPlusPlus::Snapshot snapshot() const
    { return m_snapshot; }

47 48 49 50 51 52
    const QSet<QString> &todo() const
    { return m_todo; }

    CppModelManager *modelManager() const
    { return m_modelManager.data(); }

53 54
    void setGlobalSnapshot(const CPlusPlus::Snapshot &snapshot) { m_globalSnapshot = snapshot; }

55 56 57
protected:
    CPlusPlus::Document::Ptr switchDocument(CPlusPlus::Document::Ptr doc);

58 59
    bool getFileContents(const QString &absoluteFilePath, QByteArray *contents,
                         unsigned *revision) const;
60 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);

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

private:
85
    CppSourceProcessor();
86 87
    void addFrameworkPath(const QString &frameworkPath);

88
    CPlusPlus::Snapshot m_snapshot;
89
    CPlusPlus::Snapshot m_globalSnapshot;
90 91 92 93 94 95 96 97 98 99 100 101 102
    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;
103
    QTextCodec *m_defaultCodec;
104 105 106 107 108
};

} // namespace Internal
} // namespace CppTools

109
#endif // CPPSOURCEPROCESSOR_H