Commit cfc1069c authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

C++: Remove hard-coded configuration file name.



Change-Id: Ibe4cc69eafd14dab7707862b1068ce1e21b1d8e0
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent d37ee4d1
...@@ -30,13 +30,12 @@ ...@@ -30,13 +30,12 @@
#include "FastPreprocessor.h" #include "FastPreprocessor.h"
#include <Literals.h> #include <Literals.h>
#include <TranslationUnit.h> #include <TranslationUnit.h>
#include <QDebug>
using namespace CPlusPlus; using namespace CPlusPlus;
FastPreprocessor::FastPreprocessor(const Snapshot &snapshot) FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
: _snapshot(snapshot), : _snapshot(snapshot)
_preproc(this, &_env) , _preproc(this, &_env)
{ } { }
QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source) QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source)
...@@ -49,7 +48,7 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source) ...@@ -49,7 +48,7 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source)
if (Document::Ptr doc = _snapshot.document(fileName)) { if (Document::Ptr doc = _snapshot.document(fileName)) {
_merged.insert(fileName); _merged.insert(fileName);
mergeEnvironment(QLatin1String("<configuration>")); mergeEnvironment(Preprocessor::configurationFileName);
foreach (const Document::Include &i, doc->includes()) foreach (const Document::Include &i, doc->includes())
mergeEnvironment(i.fileName()); mergeEnvironment(i.fileName());
} }
......
...@@ -589,6 +589,8 @@ void Preprocessor::State::popTokenBuffer() ...@@ -589,6 +589,8 @@ void Preprocessor::State::popTokenBuffer()
--m_tokenBufferDepth; --m_tokenBufferDepth;
} }
const QString Preprocessor::configurationFileName = QLatin1String("<configuration>");
Preprocessor::Preprocessor(Client *client, Environment *env) Preprocessor::Preprocessor(Client *client, Environment *env)
: m_client(client) : m_client(client)
, m_env(env) , m_env(env)
...@@ -1751,7 +1753,7 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk) ...@@ -1751,7 +1753,7 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk)
// the macro is a feature constraint(e.g. QT_NO_XXX) // the macro is a feature constraint(e.g. QT_NO_XXX)
if (checkUndefined && macroName.startsWith("QT_NO_")) { if (checkUndefined && macroName.startsWith("QT_NO_")) {
if (macro->fileName() == QLatin1String("<configuration>")) { if (macro->fileName() == configurationFileName) {
// and it' defined in a pro file (e.g. DEFINES += QT_NO_QOBJECT) // and it' defined in a pro file (e.g. DEFINES += QT_NO_QOBJECT)
value = false; // take the branch value = false; // take the branch
......
...@@ -74,6 +74,9 @@ class CPLUSPLUS_EXPORT Preprocessor ...@@ -74,6 +74,9 @@ class CPLUSPLUS_EXPORT Preprocessor
typedef Internal::PPToken PPToken; typedef Internal::PPToken PPToken;
typedef Internal::Value Value; typedef Internal::Value Value;
public:
static const QString configurationFileName;
public: public:
Preprocessor(Client *client, Environment *env); Preprocessor(Client *client, Environment *env);
......
...@@ -1434,7 +1434,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor, ...@@ -1434,7 +1434,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
return link; //already on definition! return link; //already on definition!
} else { } else {
const Document::MacroUse *use = doc->findMacroUseAt(endOfToken - 1); const Document::MacroUse *use = doc->findMacroUseAt(endOfToken - 1);
if (use && use->macro().fileName() != QLatin1String("<configuration>")) { if (use && use->macro().fileName() != CppModelManagerInterface::configurationFileName()) {
const Macro &macro = use->macro(); const Macro &macro = use->macro();
link.fileName = macro.fileName(); link.fileName = macro.fileName();
link.line = macro.line(); link.line = macro.line();
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
****************************************************************************/ ****************************************************************************/
#include "ModelManagerInterface.h" #include "ModelManagerInterface.h"
#include "pp-engine.h"
#include <QtCore/QSet> #include <QtCore/QSet>
...@@ -35,6 +36,9 @@ using namespace CPlusPlus; ...@@ -35,6 +36,9 @@ using namespace CPlusPlus;
static CppModelManagerInterface *g_instance = 0; static CppModelManagerInterface *g_instance = 0;
const QString CppModelManagerInterface::configurationFileName()
{ return Preprocessor::configurationFileName; }
CppModelManagerInterface::CppModelManagerInterface(QObject *parent) CppModelManagerInterface::CppModelManagerInterface(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
......
...@@ -180,6 +180,9 @@ public: ...@@ -180,6 +180,9 @@ public:
CppSemanticsDiagnostic CppSemanticsDiagnostic
}; };
public:
static const QString configurationFileName();
public: public:
CppModelManagerInterface(QObject *parent = 0); CppModelManagerInterface(QObject *parent = 0);
virtual ~CppModelManagerInterface(); virtual ~CppModelManagerInterface();
......
...@@ -16,8 +16,7 @@ namespace { ...@@ -16,8 +16,7 @@ namespace {
static void parse(QFutureInterface<void> &future, static void parse(QFutureInterface<void> &future,
CppPreprocessor *preproc, CppPreprocessor *preproc,
QStringList files, QStringList files)
const char *pp_configuration_file)
{ {
if (files.isEmpty()) if (files.isEmpty())
return; return;
...@@ -53,8 +52,7 @@ static void parse(QFutureInterface<void> &future, ...@@ -53,8 +52,7 @@ static void parse(QFutureInterface<void> &future,
future.setProgressRange(0, files.size()); future.setProgressRange(0, files.size());
QString conf = QLatin1String(pp_configuration_file); const QString conf = CPlusPlus::CppModelManagerInterface::configurationFileName();
bool processingHeaders = false; bool processingHeaders = false;
for (int i = 0; i < files.size(); ++i) { for (int i = 0; i < files.size(); ++i) {
...@@ -163,9 +161,8 @@ private: ...@@ -163,9 +161,8 @@ private:
} // anonymous namespace } // anonymous namespace
BuiltinIndexingSupport::BuiltinIndexingSupport(const char *pp_configuration_file) BuiltinIndexingSupport::BuiltinIndexingSupport()
: m_pp_configuration_file(pp_configuration_file) : m_revision(0)
, m_revision(0)
{ {
m_synchronizer.setCancelOnWait(true); m_synchronizer.setCancelOnWait(true);
m_dumpFileNameWhileParsing = !qgetenv("QTCREATOR_DUMP_FILENAME_WHILE_PARSING").isNull(); m_dumpFileNameWhileParsing = !qgetenv("QTCREATOR_DUMP_FILENAME_WHILE_PARSING").isNull();
...@@ -186,7 +183,7 @@ QFuture<void> BuiltinIndexingSupport::refreshSourceFiles(const QStringList &sour ...@@ -186,7 +183,7 @@ QFuture<void> BuiltinIndexingSupport::refreshSourceFiles(const QStringList &sour
preproc->setFrameworkPaths(mgr->frameworkPaths()); preproc->setFrameworkPaths(mgr->frameworkPaths());
preproc->setWorkingCopy(workingCopy); preproc->setWorkingCopy(workingCopy);
QFuture<void> result = QtConcurrent::run(&parse, preproc, sourceFiles, m_pp_configuration_file); QFuture<void> result = QtConcurrent::run(&parse, preproc, sourceFiles);
if (m_synchronizer.futures().size() > 10) { if (m_synchronizer.futures().size() > 10) {
QList<QFuture<void> > futures = m_synchronizer.futures(); QList<QFuture<void> > futures = m_synchronizer.futures();
......
...@@ -14,14 +14,13 @@ public: ...@@ -14,14 +14,13 @@ public:
typedef CPlusPlus::CppModelManagerInterface::WorkingCopy WorkingCopy; typedef CPlusPlus::CppModelManagerInterface::WorkingCopy WorkingCopy;
public: public:
BuiltinIndexingSupport(const char *m_pp_configuration_file); BuiltinIndexingSupport();
~BuiltinIndexingSupport(); ~BuiltinIndexingSupport();
virtual QFuture<void> refreshSourceFiles(const QStringList &sourceFiles); virtual QFuture<void> refreshSourceFiles(const QStringList &sourceFiles);
virtual SymbolSearcher *createSymbolSearcher(SymbolSearcher::Parameters parameters, QSet<QString> fileNames); virtual SymbolSearcher *createSymbolSearcher(SymbolSearcher::Parameters parameters, QSet<QString> fileNames);
private: private:
const char *m_pp_configuration_file;
QFutureSynchronizer<void> m_synchronizer; QFutureSynchronizer<void> m_synchronizer;
unsigned m_revision; unsigned m_revision;
bool m_dumpFileNameWhileParsing; bool m_dumpFileNameWhileParsing;
......
...@@ -1418,7 +1418,7 @@ void CppCompletionAssistProcessor::globalCompletion(CPlusPlus::Scope *currentSco ...@@ -1418,7 +1418,7 @@ void CppCompletionAssistProcessor::globalCompletion(CPlusPlus::Scope *currentSco
completeNamespace(b); completeNamespace(b);
addKeywords(); addKeywords();
addMacros(QLatin1String("<configuration>"), context.snapshot()); addMacros(CppModelManagerInterface::configurationFileName(), context.snapshot());
addMacros(context.thisDocument()->fileName(), context.snapshot()); addMacros(context.thisDocument()->fileName(), context.snapshot());
addSnippets(); addSnippets();
} }
......
...@@ -164,8 +164,6 @@ protected: ...@@ -164,8 +164,6 @@ protected:
#endif // QTCREATOR_WITH_DUMP_AST #endif // QTCREATOR_WITH_DUMP_AST
static const char pp_configuration_file[] = "<configuration>";
static const char pp_configuration[] = static const char pp_configuration[] =
"# 1 \"<configuration>\"\n" "# 1 \"<configuration>\"\n"
"#define __cplusplus 1\n" "#define __cplusplus 1\n"
...@@ -396,7 +394,7 @@ static inline void appendDirSeparatorIfNeeded(QString &path) ...@@ -396,7 +394,7 @@ static inline void appendDirSeparatorIfNeeded(QString &path)
QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType type, unsigned *revision) QString CppPreprocessor::tryIncludeFile_helper(QString &fileName, IncludeType type, unsigned *revision)
{ {
QFileInfo fileInfo(fileName); QFileInfo fileInfo(fileName);
if (fileName == QLatin1String(pp_configuration_file) || fileInfo.isAbsolute()) { if (fileName == Preprocessor::configurationFileName || fileInfo.isAbsolute()) {
QString contents; QString contents;
includeFile(fileName, &contents, revision); includeFile(fileName, &contents, revision);
return contents; return contents;
...@@ -741,7 +739,7 @@ CppModelManager::CppModelManager(QObject *parent) ...@@ -741,7 +739,7 @@ CppModelManager::CppModelManager(QObject *parent)
ExtensionSystem::PluginManager::addObject(m_completionAssistProvider); ExtensionSystem::PluginManager::addObject(m_completionAssistProvider);
m_highlightingFallback = new CppHighlightingSupportInternalFactory; m_highlightingFallback = new CppHighlightingSupportInternalFactory;
m_highlightingFactory = m_highlightingFallback; m_highlightingFactory = m_highlightingFallback;
m_internalIndexingSupport = new BuiltinIndexingSupport(pp_configuration_file); m_internalIndexingSupport = new BuiltinIndexingSupport;
} }
CppModelManager::~CppModelManager() CppModelManager::~CppModelManager()
...@@ -940,7 +938,7 @@ CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList() ...@@ -940,7 +938,7 @@ CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList()
// add the project configuration file // add the project configuration file
QByteArray conf(pp_configuration); QByteArray conf(pp_configuration);
conf += definedMacros(); conf += definedMacros();
workingCopy.insert(QLatin1String(pp_configuration_file), QString::fromUtf8(conf)); workingCopy.insert(configurationFileName(), QString::fromUtf8(conf));
return workingCopy; return workingCopy;
} }
......
...@@ -273,7 +273,7 @@ void GenericProject::refresh(RefreshOptions options) ...@@ -273,7 +273,7 @@ void GenericProject::refresh(RefreshOptions options)
if (options & Configuration) { if (options & Configuration) {
filesToUpdate = part->sourceFiles; filesToUpdate = part->sourceFiles;
filesToUpdate.append(QLatin1String("<configuration>")); // XXX don't hardcode configuration file name filesToUpdate.append(CPlusPlus::CppModelManagerInterface::configurationFileName());
// Full update, if there's a code model update, cancel it // Full update, if there's a code model update, cancel it
m_codeModelFuture.cancel(); m_codeModelFuture.cancel();
} else if (options & Files) { } else if (options & Files) {
......
...@@ -528,9 +528,9 @@ bool Qt4Project::equalFileList(const QStringList &a, const QStringList &b) ...@@ -528,9 +528,9 @@ bool Qt4Project::equalFileList(const QStringList &a, const QStringList &b)
QStringList::const_iterator bend = b.constEnd(); QStringList::const_iterator bend = b.constEnd();
while (ait != aend && bit != bend) { while (ait != aend && bit != bend) {
if (*ait == QLatin1String("<configuration>")) if (*ait == CPlusPlus::CppModelManagerInterface::configurationFileName())
++ait; ++ait;
else if (*bit == QLatin1String("<configuration>")) else if (*bit == CPlusPlus::CppModelManagerInterface::configurationFileName())
++bit; ++bit;
else if (*ait == *bit) else if (*ait == *bit)
++ait, ++bit; ++ait, ++bit;
...@@ -634,7 +634,7 @@ void Qt4Project::updateCppCodeModel() ...@@ -634,7 +634,7 @@ void Qt4Project::updateCppCodeModel()
part->sourceFiles = pro->variableValue(CppSourceVar); part->sourceFiles = pro->variableValue(CppSourceVar);
part->headerFiles += pro->variableValue(CppHeaderVar); part->headerFiles += pro->variableValue(CppHeaderVar);
part->headerFiles += pro->uiFiles(); part->headerFiles += pro->uiFiles();
part->sourceFiles.prepend(QLatin1String("<configuration>")); part->sourceFiles.prepend(CPlusPlus::CppModelManagerInterface::configurationFileName());
part->objcSourceFiles = pro->variableValue(ObjCSourceVar); part->objcSourceFiles = pro->variableValue(ObjCSourceVar);
pinfo.appendProjectPart(part); pinfo.appendProjectPart(part);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment