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 "pp.h"
|
||||||
|
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
@@ -70,11 +69,10 @@
|
|||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
using namespace CppTools;
|
||||||
|
using namespace CppTools::Internal;
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
namespace CppTools {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
static const char pp_configuration_file[] = "<configuration>";
|
static const char pp_configuration_file[] = "<configuration>";
|
||||||
|
|
||||||
static const char pp_configuration[] =
|
static const char pp_configuration[] =
|
||||||
@@ -106,39 +104,87 @@ static const char pp_configuration[] =
|
|||||||
"#define __declspec(a)\n"
|
"#define __declspec(a)\n"
|
||||||
"#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method\n";
|
"#define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method\n";
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
class CppPreprocessor: public rpp::Client
|
class CppPreprocessor: public rpp::Client
|
||||||
{
|
{
|
||||||
public:
|
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_modelManager(modelManager),
|
||||||
m_documents(modelManager->documents()),
|
m_documents(modelManager->documents()),
|
||||||
m_proc(this, env)
|
m_proc(this, env)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void setWorkingCopy(const QMap<QString, QByteArray> &workingCopy)
|
void CppPreprocessor::setWorkingCopy(const QMap<QString, QByteArray> &workingCopy)
|
||||||
{ m_workingCopy = workingCopy; }
|
{ m_workingCopy = workingCopy; }
|
||||||
|
|
||||||
void setIncludePaths(const QStringList &includePaths)
|
void CppPreprocessor::setIncludePaths(const QStringList &includePaths)
|
||||||
{ m_includePaths = includePaths; }
|
{ m_includePaths = includePaths; }
|
||||||
|
|
||||||
void setFrameworkPaths(const QStringList &frameworkPaths)
|
void CppPreprocessor::setFrameworkPaths(const QStringList &frameworkPaths)
|
||||||
{ m_frameworkPaths = frameworkPaths; }
|
{ m_frameworkPaths = frameworkPaths; }
|
||||||
|
|
||||||
void addIncludePath(const QString &path)
|
void CppPreprocessor::addIncludePath(const QString &path)
|
||||||
{ m_includePaths.append(path); }
|
{ m_includePaths.append(path); }
|
||||||
|
|
||||||
void setProjectFiles(const QStringList &files)
|
void CppPreprocessor::setProjectFiles(const QStringList &files)
|
||||||
{ m_projectFiles = files; }
|
{ m_projectFiles = files; }
|
||||||
|
|
||||||
void run(QString &fileName)
|
void CppPreprocessor::run(QString &fileName)
|
||||||
{ sourceNeeded(fileName, IncludeGlobal); }
|
{ sourceNeeded(fileName, IncludeGlobal); }
|
||||||
|
|
||||||
void operator()(QString &fileName)
|
void CppPreprocessor::operator()(QString &fileName)
|
||||||
{ run(fileName); }
|
{ run(fileName); }
|
||||||
|
|
||||||
protected:
|
bool CppPreprocessor::includeFile(const QString &absoluteFilePath, QByteArray *result)
|
||||||
bool includeFile(const QString &absoluteFilePath, QByteArray *result)
|
{
|
||||||
{
|
|
||||||
if (absoluteFilePath.isEmpty() || m_included.contains(absoluteFilePath)) {
|
if (absoluteFilePath.isEmpty() || m_included.contains(absoluteFilePath)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -164,10 +210,10 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray tryIncludeFile(QString &fileName, IncludeType type)
|
QByteArray CppPreprocessor::tryIncludeFile(QString &fileName, IncludeType type)
|
||||||
{
|
{
|
||||||
QFileInfo fileInfo(fileName);
|
QFileInfo fileInfo(fileName);
|
||||||
if (fileName == QLatin1String(pp_configuration_file) || fileInfo.isAbsolute()) {
|
if (fileName == QLatin1String(pp_configuration_file) || fileInfo.isAbsolute()) {
|
||||||
QByteArray contents;
|
QByteArray contents;
|
||||||
@@ -247,43 +293,43 @@ protected:
|
|||||||
|
|
||||||
//qDebug() << "**** file" << fileName << "not found!";
|
//qDebug() << "**** file" << fileName << "not found!";
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void macroAdded(const QByteArray ¯oName, const QByteArray ¯oText)
|
void CppPreprocessor::macroAdded(const QByteArray ¯oName, const QByteArray ¯oText)
|
||||||
{
|
{
|
||||||
if (! m_currentDoc)
|
if (! m_currentDoc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_currentDoc->appendMacro(macroName, macroText);
|
m_currentDoc->appendMacro(macroName, macroText);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void startExpandingMacro(unsigned offset,
|
void CppPreprocessor::startExpandingMacro(unsigned offset,
|
||||||
const rpp::Macro &,
|
const rpp::Macro &,
|
||||||
const QByteArray &originalText)
|
const QByteArray &originalText)
|
||||||
{
|
{
|
||||||
if (! m_currentDoc)
|
if (! m_currentDoc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//qDebug() << "start expanding:" << macro.name << "text:" << originalText;
|
//qDebug() << "start expanding:" << macro.name << "text:" << originalText;
|
||||||
m_currentDoc->addMacroUse(offset, originalText.length());
|
m_currentDoc->addMacroUse(offset, originalText.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void stopExpandingMacro(unsigned, const rpp::Macro &)
|
void CppPreprocessor::stopExpandingMacro(unsigned, const rpp::Macro &)
|
||||||
{
|
{
|
||||||
if (! m_currentDoc)
|
if (! m_currentDoc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//qDebug() << "stop expanding:" << macro.name;
|
//qDebug() << "stop expanding:" << macro.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mergeEnvironment(Document::Ptr doc)
|
void CppPreprocessor::mergeEnvironment(Document::Ptr doc)
|
||||||
{
|
{
|
||||||
QSet<QString> processed;
|
QSet<QString> processed;
|
||||||
mergeEnvironment(doc, &processed);
|
mergeEnvironment(doc, &processed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mergeEnvironment(Document::Ptr doc, QSet<QString> *processed)
|
void CppPreprocessor::mergeEnvironment(Document::Ptr doc, QSet<QString> *processed)
|
||||||
{
|
{
|
||||||
if (! doc)
|
if (! doc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -302,24 +348,24 @@ protected:
|
|||||||
|
|
||||||
QByteArray dummy;
|
QByteArray dummy;
|
||||||
m_proc(localFileName, macros, &dummy);
|
m_proc(localFileName, macros, &dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void startSkippingBlocks(unsigned offset)
|
void CppPreprocessor::startSkippingBlocks(unsigned offset)
|
||||||
{
|
{
|
||||||
//qDebug() << "start skipping blocks:" << offset;
|
//qDebug() << "start skipping blocks:" << offset;
|
||||||
if (m_currentDoc)
|
if (m_currentDoc)
|
||||||
m_currentDoc->startSkippingBlocks(offset);
|
m_currentDoc->startSkippingBlocks(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void stopSkippingBlocks(unsigned offset)
|
void CppPreprocessor::stopSkippingBlocks(unsigned offset)
|
||||||
{
|
{
|
||||||
//qDebug() << "stop skipping blocks:" << offset;
|
//qDebug() << "stop skipping blocks:" << offset;
|
||||||
if (m_currentDoc)
|
if (m_currentDoc)
|
||||||
m_currentDoc->stopSkippingBlocks(offset);
|
m_currentDoc->stopSkippingBlocks(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void sourceNeeded(QString &fileName, IncludeType type)
|
void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type)
|
||||||
{
|
{
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -370,35 +416,16 @@ protected:
|
|||||||
(void) switchDocument(previousDoc);
|
(void) switchDocument(previousDoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Document::Ptr switchDocument(Document::Ptr doc)
|
Document::Ptr CppPreprocessor::switchDocument(Document::Ptr doc)
|
||||||
{
|
{
|
||||||
Document::Ptr previousDoc = m_currentDoc;
|
Document::Ptr previousDoc = m_currentDoc;
|
||||||
m_currentDoc = doc;
|
m_currentDoc = doc;
|
||||||
return previousDoc;
|
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
|
\class CppTools::CppModelManager
|
||||||
|
|||||||
Reference in New Issue
Block a user