cppsourceprocessor.h 3.97 KB
Newer Older
1 2
#ifndef CPPSOURCEPROCESSOR_H
#define CPPSOURCEPROCESSOR_H
3 4

#include "cppmodelmanagerinterface.h"
5
#include "cppworkingcopy.h"
6 7 8

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

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

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

18 19 20 21
QT_BEGIN_NAMESPACE
class QTextCodec;
QT_END_NAMESPACE

22 23 24
namespace CppTools {
namespace Internal {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

} // namespace Internal
} // namespace CppTools

108
#endif // CPPSOURCEPROCESSOR_H