2014-08-22 08:42:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-05-16 15:51:04 -04:00
|
|
|
#ifndef CPPSOURCEPROCESSOR_H
|
|
|
|
|
#define CPPSOURCEPROCESSOR_H
|
2013-04-23 15:04:36 +02:00
|
|
|
|
|
|
|
|
#include "cppmodelmanagerinterface.h"
|
2014-07-30 16:29:02 +02:00
|
|
|
#include "cppworkingcopy.h"
|
2013-04-23 15:04:36 +02:00
|
|
|
|
|
|
|
|
#include <cplusplus/PreprocessorEnvironment.h>
|
|
|
|
|
#include <cplusplus/pp-engine.h>
|
2014-05-16 16:09:26 -04:00
|
|
|
#include <utils/qtcoverride.h>
|
2013-04-23 15:04:36 +02:00
|
|
|
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QPointer>
|
2014-05-16 16:09:26 -04:00
|
|
|
#include <QSet>
|
|
|
|
|
#include <QStringList>
|
2013-04-23 15:04:36 +02:00
|
|
|
|
2014-06-27 22:11:09 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2013-11-14 10:59:46 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QTextCodec;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2013-04-23 15:04:36 +02:00
|
|
|
namespace CppTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2013-05-26 10:57:41 +04:00
|
|
|
// Documentation inside.
|
2014-05-19 11:17:39 -04:00
|
|
|
class CppSourceProcessor: public CPlusPlus::Client
|
2013-04-23 15:04:36 +02:00
|
|
|
{
|
2014-05-16 15:51:04 -04:00
|
|
|
Q_DISABLE_COPY(CppSourceProcessor)
|
2013-04-23 15:04:36 +02:00
|
|
|
|
2014-06-06 14:41:19 +02:00
|
|
|
public:
|
|
|
|
|
typedef std::function<void (const CPlusPlus::Document::Ptr &)> DocumentCallback;
|
|
|
|
|
|
2013-04-23 15:04:36 +02:00
|
|
|
public:
|
2013-05-26 10:57:41 +04:00
|
|
|
static QString cleanPath(const QString &path);
|
|
|
|
|
|
2014-06-06 14:41:19 +02:00
|
|
|
CppSourceProcessor(const CPlusPlus::Snapshot &snapshot, DocumentCallback documentFinished);
|
2014-05-16 16:09:26 -04:00
|
|
|
~CppSourceProcessor();
|
2013-04-23 15:04:36 +02:00
|
|
|
|
2014-06-06 14:41:19 +02:00
|
|
|
void setDumpFileNameWhileParsing(bool onoff)
|
|
|
|
|
{ m_dumpFileNameWhileParsing = onoff; }
|
|
|
|
|
|
2013-04-23 15:04:36 +02:00
|
|
|
void setRevision(unsigned revision);
|
2014-07-30 16:29:02 +02:00
|
|
|
void setWorkingCopy(const CppTools::WorkingCopy &workingCopy);
|
2014-06-25 17:23:19 +02:00
|
|
|
void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths);
|
2013-04-23 15:04:36 +02:00
|
|
|
void setTodo(const QStringList &files);
|
|
|
|
|
|
2014-07-16 11:25:15 +02:00
|
|
|
void run(const QString &fileName, const QStringList &initialIncludes = QStringList());
|
2013-04-23 15:04:36 +02:00
|
|
|
void removeFromCache(const QString &fileName);
|
|
|
|
|
void resetEnvironment();
|
|
|
|
|
|
2014-05-16 16:09:26 -04:00
|
|
|
CPlusPlus::Snapshot snapshot() const { return m_snapshot; }
|
|
|
|
|
const QSet<QString> &todo() const { return m_todo; }
|
2013-04-23 15:04:36 +02:00
|
|
|
|
2013-08-19 16:05:29 +02:00
|
|
|
void setGlobalSnapshot(const CPlusPlus::Snapshot &snapshot) { m_globalSnapshot = snapshot; }
|
|
|
|
|
|
2014-05-16 16:09:26 -04:00
|
|
|
private:
|
2014-06-25 17:23:19 +02:00
|
|
|
void addFrameworkPath(const ProjectPart::HeaderPath &frameworkPath);
|
2014-05-16 16:09:26 -04:00
|
|
|
|
|
|
|
|
CPlusPlus::Document::Ptr switchCurrentDocument(CPlusPlus::Document::Ptr doc);
|
2013-04-23 15:04:36 +02:00
|
|
|
|
2014-02-19 09:11:59 -03:00
|
|
|
bool getFileContents(const QString &absoluteFilePath, QByteArray *contents,
|
|
|
|
|
unsigned *revision) const;
|
2013-04-23 15:04:36 +02:00
|
|
|
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);
|
|
|
|
|
|
2014-05-16 16:09:26 -04:00
|
|
|
// Client interface
|
|
|
|
|
void macroAdded(const CPlusPlus::Macro ¯o) QTC_OVERRIDE;
|
|
|
|
|
void passedMacroDefinitionCheck(unsigned bytesOffset, unsigned utf16charsOffset,
|
|
|
|
|
unsigned line, const CPlusPlus::Macro ¯o) 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 ¯o) QTC_OVERRIDE;
|
|
|
|
|
void startExpandingMacro(unsigned bytesOffset, unsigned utf16charOffset,
|
|
|
|
|
unsigned line, const CPlusPlus::Macro ¯o,
|
|
|
|
|
const QVector<CPlusPlus::MacroArgumentReference> &actuals) QTC_OVERRIDE;
|
|
|
|
|
void stopExpandingMacro(unsigned bytesOffset, const CPlusPlus::Macro ¯o) QTC_OVERRIDE;
|
|
|
|
|
void markAsIncludeGuard(const QByteArray ¯oName) QTC_OVERRIDE;
|
|
|
|
|
void startSkippingBlocks(unsigned utf16charsOffset) QTC_OVERRIDE;
|
|
|
|
|
void stopSkippingBlocks(unsigned utf16charsOffset) QTC_OVERRIDE;
|
2014-07-16 11:25:15 +02:00
|
|
|
void sourceNeeded(unsigned line, const QString &fileName, IncludeType type,
|
|
|
|
|
const QStringList &initialIncludes) QTC_OVERRIDE;
|
2013-04-23 15:04:36 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CPlusPlus::Snapshot m_snapshot;
|
2013-08-19 16:05:29 +02:00
|
|
|
CPlusPlus::Snapshot m_globalSnapshot;
|
2014-06-06 14:41:19 +02:00
|
|
|
DocumentCallback m_documentFinished;
|
2013-04-23 15:04:36 +02:00
|
|
|
bool m_dumpFileNameWhileParsing;
|
|
|
|
|
CPlusPlus::Environment m_env;
|
|
|
|
|
CPlusPlus::Preprocessor m_preprocess;
|
2014-06-25 17:23:19 +02:00
|
|
|
ProjectPart::HeaderPaths m_headerPaths;
|
2014-07-30 16:29:02 +02:00
|
|
|
CppTools::WorkingCopy m_workingCopy;
|
2013-04-23 15:04:36 +02:00
|
|
|
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;
|
2013-11-14 10:59:46 +01:00
|
|
|
QTextCodec *m_defaultCodec;
|
2013-04-23 15:04:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CppTools
|
|
|
|
|
|
2014-05-16 15:51:04 -04:00
|
|
|
#endif // CPPSOURCEPROCESSOR_H
|