forked from qt-creator/qt-creator
CppEditor: Remove WorkingCopy::get(QString) overload
... and fix fallout. Change-Id: I8fe67616f8f327428b1c166ae69ec34c2924ee9f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -87,7 +87,7 @@ void FastPreprocessor::macroAdded(const Macro ¯o)
|
|||||||
|
|
||||||
static const Macro revision(const Snapshot &s, const Macro &m)
|
static const Macro revision(const Snapshot &s, const Macro &m)
|
||||||
{
|
{
|
||||||
if (Document::Ptr d = s.document(m.fileName())) {
|
if (Document::Ptr d = s.document(m.filePath())) {
|
||||||
Macro newMacro(m);
|
Macro newMacro(m);
|
||||||
newMacro.setFileRevision(d->revision());
|
newMacro.setFileRevision(d->revision());
|
||||||
return newMacro;
|
return newMacro;
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <cplusplus/CPlusPlusForwardDeclarations.h>
|
#include <cplusplus/CPlusPlusForwardDeclarations.h>
|
||||||
|
|
||||||
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -69,6 +71,9 @@ public:
|
|||||||
const QString &fileName() const
|
const QString &fileName() const
|
||||||
{ return _fileName; }
|
{ return _fileName; }
|
||||||
|
|
||||||
|
Utils::FilePath filePath() const
|
||||||
|
{ return Utils::FilePath::fromString(_fileName); }
|
||||||
|
|
||||||
void setFileName(const QString &fileName)
|
void setFileName(const QString &fileName)
|
||||||
{ _fileName = fileName; }
|
{ _fileName = fileName; }
|
||||||
|
|
||||||
|
@@ -2014,7 +2014,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() == configurationFileName().pathView()) {
|
if (macro->filePath() == 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
|
||||||
|
@@ -270,7 +270,7 @@ bool handleMacroCase(const Document::Ptr document,
|
|||||||
const int length = macro->nameToQString().size();
|
const int length = macro->nameToQString().size();
|
||||||
|
|
||||||
// Macro definition
|
// Macro definition
|
||||||
if (macro->fileName() == document->filePath().pathView())
|
if (macro->filePath() == document->filePath())
|
||||||
ranges->append(toRange(textCursor, macro->utf16CharOffset(), length));
|
ranges->append(toRange(textCursor, macro->utf16CharOffset(), length));
|
||||||
|
|
||||||
// Other macro uses
|
// Other macro uses
|
||||||
|
@@ -86,7 +86,7 @@ public:
|
|||||||
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
||||||
helpIdCandidates = QStringList(macroName);
|
helpIdCandidates = QStringList(macroName);
|
||||||
helpMark = macroName;
|
helpMark = macroName;
|
||||||
link = Utils::Link(Utils::FilePath::fromString(macro.fileName()), macro.line());
|
link = Utils::Link(macro.filePath(), macro.line());
|
||||||
tooltip = macro.toStringWithLineBreaks();
|
tooltip = macro.toStringWithLineBreaks();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -706,8 +706,8 @@ static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
|||||||
const CPlusPlus::Snapshot snapshot,
|
const CPlusPlus::Snapshot snapshot,
|
||||||
const CPlusPlus::Macro macro)
|
const CPlusPlus::Macro macro)
|
||||||
{
|
{
|
||||||
const Utils::FilePath sourceFile = Utils::FilePath::fromString(macro.fileName());
|
const FilePath sourceFile = macro.filePath();
|
||||||
Utils::FilePaths files{sourceFile};
|
FilePaths files{sourceFile};
|
||||||
files = Utils::filteredUnique(files + snapshot.filesDependingOn(sourceFile));
|
files = Utils::filteredUnique(files + snapshot.filesDependingOn(sourceFile));
|
||||||
|
|
||||||
future.setProgressRange(0, files.size());
|
future.setProgressRange(0, files.size());
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
using Message = Document::DiagnosticMessage;
|
using Message = Document::DiagnosticMessage;
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ inline const CPlusPlus::Macro revision(const WorkingCopy &workingCopy,
|
|||||||
const CPlusPlus::Macro ¯o)
|
const CPlusPlus::Macro ¯o)
|
||||||
{
|
{
|
||||||
CPlusPlus::Macro newMacro(macro);
|
CPlusPlus::Macro newMacro(macro);
|
||||||
newMacro.setFileRevision(workingCopy.get(macro.fileName()).second);
|
newMacro.setFileRevision(workingCopy.get(macro.filePath()).second);
|
||||||
return newMacro;
|
return newMacro;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +182,7 @@ void CppSourceProcessor::resetEnvironment()
|
|||||||
m_included.clear();
|
m_included.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppSourceProcessor::getFileContents(const QString &absoluteFilePath,
|
bool CppSourceProcessor::getFileContents(const FilePath &absoluteFilePath,
|
||||||
QByteArray *contents,
|
QByteArray *contents,
|
||||||
unsigned *revision) const
|
unsigned *revision) const
|
||||||
{
|
{
|
||||||
@@ -199,12 +200,12 @@ bool CppSourceProcessor::getFileContents(const QString &absoluteFilePath,
|
|||||||
// Get from file
|
// Get from file
|
||||||
*revision = 0;
|
*revision = 0;
|
||||||
QString error;
|
QString error;
|
||||||
if (Utils::TextFileFormat::readFileUTF8(Utils::FilePath::fromString(absoluteFilePath),
|
if (Utils::TextFileFormat::readFileUTF8(absoluteFilePath,
|
||||||
m_defaultCodec,
|
m_defaultCodec,
|
||||||
contents,
|
contents,
|
||||||
&error)
|
&error)
|
||||||
!= Utils::TextFileFormat::ReadSuccess) {
|
!= Utils::TextFileFormat::ReadSuccess) {
|
||||||
qWarning("Error reading file \"%s\": \"%s\".", qPrintable(absoluteFilePath),
|
qWarning("Error reading file \"%s\": \"%s\".", qPrintable(absoluteFilePath.toString()),
|
||||||
qPrintable(error));
|
qPrintable(error));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -410,8 +411,9 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
|
|||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString absoluteFileName = resolveFile(fileName, type);
|
const QString absoluteFileName = QDir::cleanPath(resolveFile(fileName, type));
|
||||||
absoluteFileName = QDir::cleanPath(absoluteFileName);
|
const FilePath absoluteFilePath = FilePath::fromString(absoluteFileName);
|
||||||
|
|
||||||
if (m_currentDoc) {
|
if (m_currentDoc) {
|
||||||
m_currentDoc->addIncludeFile(Document::Include(fileName, absoluteFileName, line, type));
|
m_currentDoc->addIncludeFile(Document::Include(fileName, absoluteFileName, line, type));
|
||||||
if (absoluteFileName.isEmpty()) {
|
if (absoluteFileName.isEmpty()) {
|
||||||
@@ -437,15 +439,15 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
|
|||||||
// Otherwise get file contents
|
// Otherwise get file contents
|
||||||
unsigned editorRevision = 0;
|
unsigned editorRevision = 0;
|
||||||
QByteArray contents;
|
QByteArray contents;
|
||||||
const bool gotFileContents = getFileContents(absoluteFileName, &contents, &editorRevision);
|
const bool gotFileContents = getFileContents(absoluteFilePath, &contents, &editorRevision);
|
||||||
if (m_currentDoc && !gotFileContents) {
|
if (m_currentDoc && !gotFileContents) {
|
||||||
m_currentDoc->addDiagnosticMessage(messageNoFileContents(m_currentDoc, fileName, line));
|
m_currentDoc->addDiagnosticMessage(messageNoFileContents(m_currentDoc, fileName, line));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(log) << "Parsing:" << absoluteFileName << "contents:" << contents.size() << "bytes";
|
qCDebug(log) << "Parsing:" << absoluteFilePath.toString() << "contents:" << contents.size() << "bytes";
|
||||||
|
|
||||||
Document::Ptr document = Document::create(Utils::FilePath::fromString(absoluteFileName));
|
Document::Ptr document = Document::create(absoluteFilePath);
|
||||||
document->setEditorRevision(editorRevision);
|
document->setEditorRevision(editorRevision);
|
||||||
document->setLanguageFeatures(m_languageFeatures);
|
document->setLanguageFeatures(m_languageFeatures);
|
||||||
for (const QString &include : initialIncludes) {
|
for (const QString &include : initialIncludes) {
|
||||||
@@ -457,8 +459,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
|
|||||||
document->setLastModified(info.lastModified());
|
document->setLastModified(info.lastModified());
|
||||||
|
|
||||||
const Document::Ptr previousDocument = switchCurrentDocument(document);
|
const Document::Ptr previousDocument = switchCurrentDocument(document);
|
||||||
const QByteArray preprocessedCode =
|
const QByteArray preprocessedCode = m_preprocess.run(absoluteFilePath, contents);
|
||||||
m_preprocess.run(Utils::FilePath::fromString(absoluteFileName), contents);
|
|
||||||
// {
|
// {
|
||||||
// QByteArray b(preprocessedCode); b.replace("\n", "<<<\n");
|
// QByteArray b(preprocessedCode); b.replace("\n", "<<<\n");
|
||||||
// qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData());
|
// qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData());
|
||||||
@@ -466,7 +467,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
|
|||||||
document->setFingerprint(generateFingerPrint(document->definedMacros(), preprocessedCode));
|
document->setFingerprint(generateFingerPrint(document->definedMacros(), preprocessedCode));
|
||||||
|
|
||||||
// Re-use document from global snapshot if possible
|
// Re-use document from global snapshot if possible
|
||||||
Document::Ptr globalDocument = m_globalSnapshot.document(absoluteFileName);
|
Document::Ptr globalDocument = m_globalSnapshot.document(absoluteFilePath);
|
||||||
if (globalDocument && globalDocument->fingerprint() == document->fingerprint()) {
|
if (globalDocument && globalDocument->fingerprint() == document->fingerprint()) {
|
||||||
switchCurrentDocument(previousDocument);
|
switchCurrentDocument(previousDocument);
|
||||||
mergeEnvironment(globalDocument);
|
mergeEnvironment(globalDocument);
|
||||||
|
@@ -59,7 +59,7 @@ private:
|
|||||||
|
|
||||||
CPlusPlus::Document::Ptr switchCurrentDocument(CPlusPlus::Document::Ptr doc);
|
CPlusPlus::Document::Ptr switchCurrentDocument(CPlusPlus::Document::Ptr doc);
|
||||||
|
|
||||||
bool getFileContents(const QString &absoluteFilePath, QByteArray *contents,
|
bool getFileContents(const Utils::FilePath &absoluteFilePath, QByteArray *contents,
|
||||||
unsigned *revision) const;
|
unsigned *revision) const;
|
||||||
bool checkFile(const QString &absoluteFilePath) const;
|
bool checkFile(const QString &absoluteFilePath) const;
|
||||||
QString resolveFile(const QString &fileName, IncludeType type);
|
QString resolveFile(const QString &fileName, IncludeType type);
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "cppeditor_global.h"
|
#include "cppeditor_global.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -36,9 +36,6 @@ public:
|
|||||||
unsigned revision(const Utils::FilePath &fileName) const
|
unsigned revision(const Utils::FilePath &fileName) const
|
||||||
{ return _elements.value(fileName).second; }
|
{ return _elements.value(fileName).second; }
|
||||||
|
|
||||||
QPair<QByteArray, unsigned> get(const QString &fileName) const
|
|
||||||
{ return get(Utils::FilePath::fromString(fileName)); }
|
|
||||||
|
|
||||||
QPair<QByteArray, unsigned> get(const Utils::FilePath &fileName) const
|
QPair<QByteArray, unsigned> get(const Utils::FilePath &fileName) const
|
||||||
{ return _elements.value(fileName); }
|
{ return _elements.value(fileName); }
|
||||||
|
|
||||||
@@ -53,4 +50,4 @@ private:
|
|||||||
Table _elements;
|
Table _elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // CppEditor
|
||||||
|
Reference in New Issue
Block a user