cppsourceprocessor.h 3.95 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/function.h>
9
#include <utils/qtcoverride.h>
10 11 12

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

16 17 18 19
QT_BEGIN_NAMESPACE
class QTextCodec;
QT_END_NAMESPACE

20 21 22
namespace CppTools {
namespace Internal {

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

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

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

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

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

40 41 42 43 44 45 46 47 48 49
    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();

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 56 57 58
private:
    void addFrameworkPath(const QString &frameworkPath);

    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 83
    // 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;
84 85 86

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

} // namespace Internal
} // namespace CppTools

107
#endif // CPPSOURCEPROCESSOR_H