cppsourceprocessor.h 3.99 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

hjk's avatar
hjk committed
15 16
#include <functional>

17 18 19 20
QT_BEGIN_NAMESPACE
class QTextCodec;
QT_END_NAMESPACE

21 22 23
namespace CppTools {
namespace Internal {

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

29 30 31
public:
    typedef std::function<void (const CPlusPlus::Document::Ptr &)> DocumentCallback;

32
public:
33 34
    static QString cleanPath(const QString &path);

35
    CppSourceProcessor(const CPlusPlus::Snapshot &snapshot, DocumentCallback documentFinished);
36
    ~CppSourceProcessor();
37

38 39 40
    void setDumpFileNameWhileParsing(bool onoff)
    { m_dumpFileNameWhileParsing = onoff; }

41 42
    void setRevision(unsigned revision);
    void setWorkingCopy(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy);
43
    void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths);
44 45
    void setTodo(const QStringList &files);

46
    void run(const QString &fileName, const QStringList &initialIncludes = QStringList());
47 48 49
    void removeFromCache(const QString &fileName);
    void resetEnvironment();

50 51
    CPlusPlus::Snapshot snapshot() const { return m_snapshot; }
    const QSet<QString> &todo() const { return m_todo; }
52

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

55
private:
56
    void addFrameworkPath(const ProjectPart::HeaderPath &frameworkPath);
57 58

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

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

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;
83 84
    void sourceNeeded(unsigned line, const QString &fileName, IncludeType type,
                      const QStringList &initialIncludes) QTC_OVERRIDE;
85 86 87

private:
    CPlusPlus::Snapshot m_snapshot;
88
    CPlusPlus::Snapshot m_globalSnapshot;
89
    DocumentCallback m_documentFinished;
90 91 92
    bool m_dumpFileNameWhileParsing;
    CPlusPlus::Environment m_env;
    CPlusPlus::Preprocessor m_preprocess;
93
    ProjectPart::HeaderPaths m_headerPaths;
94 95 96 97 98 99 100
    CppTools::CppModelManagerInterface::WorkingCopy m_workingCopy;
    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;
101
    QTextCodec *m_defaultCodec;
102 103 104 105 106
};

} // namespace Internal
} // namespace CppTools

107
#endif // CPPSOURCEPROCESSOR_H