forked from qt-creator/qt-creator
Some cleanup in CppPreprocessor.
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
**
|
||||
***************************************************************************/
|
||||
|
||||
#define _SCL_SECURE_NO_WARNINGS 1
|
||||
#include "pp.h"
|
||||
|
||||
#include "cppmodelmanager.h"
|
||||
@@ -70,11 +69,10 @@
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
using namespace CPlusPlus;
|
||||
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
|
||||
static const char pp_configuration_file[] = "<configuration>";
|
||||
|
||||
static const char pp_configuration[] =
|
||||
@@ -106,38 +104,86 @@ static const char pp_configuration[] =
|
||||
"#define __declspec(a)\n"
|
||||
"#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method\n";
|
||||
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
|
||||
class CppPreprocessor: public rpp::Client
|
||||
{
|
||||
public:
|
||||
CppPreprocessor(QPointer<CppModelManager> modelManager)
|
||||
CppPreprocessor(QPointer<CppModelManager> modelManager);
|
||||
|
||||
void setWorkingCopy(const QMap<QString, QByteArray> &workingCopy);
|
||||
void setIncludePaths(const QStringList &includePaths);
|
||||
void setFrameworkPaths(const QStringList &frameworkPaths);
|
||||
void addIncludePath(const QString &path);
|
||||
void setProjectFiles(const QStringList &files);
|
||||
void run(QString &fileName);
|
||||
void operator()(QString &fileName);
|
||||
|
||||
protected:
|
||||
CPlusPlus::Document::Ptr switchDocument(CPlusPlus::Document::Ptr doc);
|
||||
|
||||
bool includeFile(const QString &absoluteFilePath, QByteArray *result);
|
||||
QByteArray tryIncludeFile(QString &fileName, IncludeType type);
|
||||
|
||||
void mergeEnvironment(CPlusPlus::Document::Ptr doc);
|
||||
void mergeEnvironment(CPlusPlus::Document::Ptr doc, QSet<QString> *processed);
|
||||
|
||||
virtual void macroAdded(const QByteArray ¯oName,
|
||||
const QByteArray ¯oText);
|
||||
virtual void startExpandingMacro(unsigned offset,
|
||||
const rpp::Macro ¯o,
|
||||
const QByteArray &originalText);
|
||||
virtual void stopExpandingMacro(unsigned offset, const rpp::Macro ¯o);
|
||||
virtual void startSkippingBlocks(unsigned offset);
|
||||
virtual void stopSkippingBlocks(unsigned offset);
|
||||
virtual void sourceNeeded(QString &fileName, IncludeType type);
|
||||
|
||||
private:
|
||||
QPointer<CppModelManager> m_modelManager;
|
||||
CppModelManager::DocumentTable m_documents;
|
||||
rpp::Environment env;
|
||||
rpp::pp m_proc;
|
||||
QStringList m_includePaths;
|
||||
QStringList m_systemIncludePaths;
|
||||
QMap<QString, QByteArray> m_workingCopy;
|
||||
QStringList m_projectFiles;
|
||||
QStringList m_frameworkPaths;
|
||||
QSet<QString> m_included;
|
||||
CPlusPlus::Document::Ptr m_currentDoc;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CppTools
|
||||
|
||||
CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager)
|
||||
: m_modelManager(modelManager),
|
||||
m_documents(modelManager->documents()),
|
||||
m_proc(this, env)
|
||||
{ }
|
||||
|
||||
void setWorkingCopy(const QMap<QString, QByteArray> &workingCopy)
|
||||
void CppPreprocessor::setWorkingCopy(const QMap<QString, QByteArray> &workingCopy)
|
||||
{ m_workingCopy = workingCopy; }
|
||||
|
||||
void setIncludePaths(const QStringList &includePaths)
|
||||
void CppPreprocessor::setIncludePaths(const QStringList &includePaths)
|
||||
{ m_includePaths = includePaths; }
|
||||
|
||||
void setFrameworkPaths(const QStringList &frameworkPaths)
|
||||
void CppPreprocessor::setFrameworkPaths(const QStringList &frameworkPaths)
|
||||
{ m_frameworkPaths = frameworkPaths; }
|
||||
|
||||
void addIncludePath(const QString &path)
|
||||
void CppPreprocessor::addIncludePath(const QString &path)
|
||||
{ m_includePaths.append(path); }
|
||||
|
||||
void setProjectFiles(const QStringList &files)
|
||||
void CppPreprocessor::setProjectFiles(const QStringList &files)
|
||||
{ m_projectFiles = files; }
|
||||
|
||||
void run(QString &fileName)
|
||||
void CppPreprocessor::run(QString &fileName)
|
||||
{ sourceNeeded(fileName, IncludeGlobal); }
|
||||
|
||||
void operator()(QString &fileName)
|
||||
void CppPreprocessor::operator()(QString &fileName)
|
||||
{ run(fileName); }
|
||||
|
||||
protected:
|
||||
bool includeFile(const QString &absoluteFilePath, QByteArray *result)
|
||||
bool CppPreprocessor::includeFile(const QString &absoluteFilePath, QByteArray *result)
|
||||
{
|
||||
if (absoluteFilePath.isEmpty() || m_included.contains(absoluteFilePath)) {
|
||||
return true;
|
||||
@@ -166,7 +212,7 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray tryIncludeFile(QString &fileName, IncludeType type)
|
||||
QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
|
||||
{
|
||||
QFileInfo fileInfo(fileName);
|
||||
if (fileName == QLatin1String(pp_configuration_file) || fileInfo.isAbsolute()) {
|
||||
@@ -249,7 +295,7 @@ protected:
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
virtual void macroAdded(const QByteArray ¯oName, const QByteArray ¯oText)
|
||||
void CppPreprocessor::macroAdded(const QByteArray ¯oName, const QByteArray ¯oText)
|
||||
{
|
||||
if (! m_currentDoc)
|
||||
return;
|
||||
@@ -257,7 +303,7 @@ protected:
|
||||
m_currentDoc->appendMacro(macroName, macroText);
|
||||
}
|
||||
|
||||
virtual void startExpandingMacro(unsigned offset,
|
||||
void CppPreprocessor::startExpandingMacro(unsigned offset,
|
||||
const rpp::Macro &,
|
||||
const QByteArray &originalText)
|
||||
{
|
||||
@@ -268,7 +314,7 @@ protected:
|
||||
m_currentDoc->addMacroUse(offset, originalText.length());
|
||||
}
|
||||
|
||||
virtual void stopExpandingMacro(unsigned, const rpp::Macro &)
|
||||
void CppPreprocessor::stopExpandingMacro(unsigned, const rpp::Macro &)
|
||||
{
|
||||
if (! m_currentDoc)
|
||||
return;
|
||||
@@ -276,13 +322,13 @@ protected:
|
||||
//qDebug() << "stop expanding:" << macro.name;
|
||||
}
|
||||
|
||||
void mergeEnvironment(Document::Ptr doc)
|
||||
void CppPreprocessor::mergeEnvironment(Document::Ptr doc)
|
||||
{
|
||||
QSet<QString> processed;
|
||||
mergeEnvironment(doc, &processed);
|
||||
}
|
||||
|
||||
void mergeEnvironment(Document::Ptr doc, QSet<QString> *processed)
|
||||
void CppPreprocessor::mergeEnvironment(Document::Ptr doc, QSet<QString> *processed)
|
||||
{
|
||||
if (! doc)
|
||||
return;
|
||||
@@ -304,21 +350,21 @@ protected:
|
||||
m_proc(localFileName, macros, &dummy);
|
||||
}
|
||||
|
||||
virtual void startSkippingBlocks(unsigned offset)
|
||||
void CppPreprocessor::startSkippingBlocks(unsigned offset)
|
||||
{
|
||||
//qDebug() << "start skipping blocks:" << offset;
|
||||
if (m_currentDoc)
|
||||
m_currentDoc->startSkippingBlocks(offset);
|
||||
}
|
||||
|
||||
virtual void stopSkippingBlocks(unsigned offset)
|
||||
void CppPreprocessor::stopSkippingBlocks(unsigned offset)
|
||||
{
|
||||
//qDebug() << "stop skipping blocks:" << offset;
|
||||
if (m_currentDoc)
|
||||
m_currentDoc->stopSkippingBlocks(offset);
|
||||
}
|
||||
|
||||
virtual void sourceNeeded(QString &fileName, IncludeType type)
|
||||
void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
@@ -372,33 +418,14 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
Document::Ptr switchDocument(Document::Ptr doc)
|
||||
Document::Ptr CppPreprocessor::switchDocument(Document::Ptr doc)
|
||||
{
|
||||
Document::Ptr previousDoc = m_currentDoc;
|
||||
m_currentDoc = doc;
|
||||
return previousDoc;
|
||||
}
|
||||
|
||||
private:
|
||||
QPointer<CppModelManager> m_modelManager;
|
||||
CppModelManager::DocumentTable m_documents;
|
||||
rpp::Environment env;
|
||||
rpp::pp m_proc;
|
||||
QStringList m_includePaths;
|
||||
QStringList m_systemIncludePaths;
|
||||
QMap<QString, QByteArray> m_workingCopy;
|
||||
QStringList m_projectFiles;
|
||||
QStringList m_frameworkPaths;
|
||||
QSet<QString> m_included;
|
||||
Document::Ptr m_currentDoc;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CppTools
|
||||
|
||||
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
|
||||
/*!
|
||||
\class CppTools::CppModelManager
|
||||
|
||||
Reference in New Issue
Block a user