Fix build of Clang code model and CppEditor with Qt 6

QStringRef gone.
QSharedPointer is no longer auto-converted to bool.
Small things.

Task-number: QTCREATORBUG-24098
Change-Id: I3a2a55459b905118d1ca81ec015d741ab273471d
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-09-18 12:39:32 +02:00
parent f8ae051816
commit 830a829b2e
10 changed files with 29 additions and 21 deletions

View File

@@ -50,7 +50,7 @@ QByteArray LinePrefixer::prefix(const QByteArray &text)
m_previousIsEndingWithNewLine = false; m_previousIsEndingWithNewLine = false;
} }
output.replace("\n", "\n" + m_prefix); output.replace("\n", QByteArray("\n" + m_prefix));
if (m_previousIsEndingWithNewLine) if (m_previousIsEndingWithNewLine)
output.append('\n'); output.append('\n');

View File

@@ -30,6 +30,7 @@
#include <QByteArray> #include <QByteArray>
#include <QDataStream> #include <QDataStream>
#include <QDebug> #include <QDebug>
#include <QIODevice>
namespace ClangBackEnd { namespace ClangBackEnd {

View File

@@ -55,8 +55,9 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/mimetypes/mimedatabase.h> #include <utils/mimetypes/mimedatabase.h>
#include <utils/optional.h> #include <utils/optional.h>
#include <utils/textutils.h> #include <utils/porting.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/textutils.h>
#include <QDirIterator> #include <QDirIterator>
#include <QTextDocument> #include <QTextDocument>
@@ -450,9 +451,9 @@ bool ClangCompletionAssistProcessor::accepts() const
&& tokens.at(1).kind() == T_IDENTIFIER) { && tokens.at(1).kind() == T_IDENTIFIER) {
const QString &line = tc.block().text(); const QString &line = tc.block().text();
const Token &idToken = tokens.at(1); const Token &idToken = tokens.at(1);
const QStringRef &identifier = const QStringView &identifier = Utils::midView(line,
line.midRef(idToken.bytesBegin(), idToken.utf16charsBegin(),
idToken.bytesEnd() - idToken.bytesBegin()); idToken.utf16chars());
if (identifier == QLatin1String("include") if (identifier == QLatin1String("include")
|| identifier == QLatin1String("include_next") || identifier == QLatin1String("include_next")
|| (m_interface->objcEnabled() && identifier == QLatin1String("import"))) { || (m_interface->objcEnabled() && identifier == QLatin1String("import"))) {

View File

@@ -29,6 +29,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QLayout; class QLayout;
class QWidget;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace ClangCodeModel { namespace ClangCodeModel {

View File

@@ -172,7 +172,7 @@ bool ClangEditorDocumentProcessor::isParserRunning() const
bool ClangEditorDocumentProcessor::hasProjectPart() const bool ClangEditorDocumentProcessor::hasProjectPart() const
{ {
return m_projectPart; return !m_projectPart.isNull();
} }
CppTools::ProjectPart::Ptr ClangEditorDocumentProcessor::projectPart() const CppTools::ProjectPart::Ptr ClangEditorDocumentProcessor::projectPart() const

View File

@@ -129,7 +129,7 @@ ProjectPart::Ptr projectPartForFileBasedOnProcessor(const QString &filePath)
bool isProjectPartLoaded(const ProjectPart::Ptr projectPart) bool isProjectPartLoaded(const ProjectPart::Ptr projectPart)
{ {
if (projectPart) if (projectPart)
return CppModelManager::instance()->projectPartForId(projectPart->id()); return !CppModelManager::instance()->projectPartForId(projectPart->id()).isNull();
return false; return false;
} }

View File

@@ -162,13 +162,15 @@ bool handleDoxygenCppStyleContinuation(QTextCursor &cursor)
// If the line does not start with the comment we don't // If the line does not start with the comment we don't
// consider it as a continuation. Handles situations like: // consider it as a continuation. Handles situations like:
// void d(); ///<enter> // void d(); ///<enter>
const QStringRef commentMarker = text.midRef(offset, 3); if (offset + 3 > text.size())
return false;
const QStringView commentMarker = QStringView(text).mid(offset, 3);
if (commentMarker != QLatin1String("///") && commentMarker != QLatin1String("//!")) if (commentMarker != QLatin1String("///") && commentMarker != QLatin1String("//!"))
return false; return false;
QString newLine(QLatin1Char('\n')); QString newLine(QLatin1Char('\n'));
newLine.append(text.leftRef(offset)); // indent correctly newLine.append(text.left(offset)); // indent correctly
newLine.append(commentMarker); newLine.append(commentMarker.toString());
newLine.append(QLatin1Char(' ')); newLine.append(QLatin1Char(' '));
cursor.insertText(newLine); cursor.insertText(newLine);

View File

@@ -33,6 +33,8 @@
#include <cplusplus/SimpleLexer.h> #include <cplusplus/SimpleLexer.h>
#include <cplusplus/Lexer.h> #include <cplusplus/Lexer.h>
#include <utils/porting.h>
#include <QTextDocument> #include <QTextDocument>
using namespace CppEditor; using namespace CppEditor;
@@ -150,11 +152,10 @@ void CppHighlighter::highlightBlock(const QString &text)
setFormatWithSpaces(text, tk.utf16charsBegin(), tk.utf16chars(), setFormatWithSpaces(text, tk.utf16charsBegin(), tk.utf16chars(),
formatForCategory(C_PREPROCESSOR)); formatForCategory(C_PREPROCESSOR));
expectPreprocessorKeyword = true; expectPreprocessorKeyword = true;
} else if (highlightCurrentWordAsPreprocessor } else if (highlightCurrentWordAsPreprocessor && (tk.isKeyword() || tk.is(T_IDENTIFIER))
&& (tk.isKeyword() || tk.is(T_IDENTIFIER)) && isPPKeyword(Utils::midView(text, tk.utf16charsBegin(), tk.utf16chars()))) {
&& isPPKeyword(text.midRef(tk.utf16charsBegin(), tk.utf16chars()))) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_PREPROCESSOR)); setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_PREPROCESSOR));
const QStringRef ppKeyword = text.midRef(tk.utf16charsBegin(), tk.utf16chars()); const QStringView ppKeyword = Utils::midView(text, tk.utf16charsBegin(), tk.utf16chars());
if (ppKeyword == QLatin1String("error") if (ppKeyword == QLatin1String("error")
|| ppKeyword == QLatin1String("warning") || ppKeyword == QLatin1String("warning")
|| ppKeyword == QLatin1String("pragma")) { || ppKeyword == QLatin1String("pragma")) {
@@ -198,7 +199,8 @@ void CppHighlighter::highlightBlock(const QString &text)
} else if (tk.isKeyword() } else if (tk.isKeyword()
|| (m_languageFeatures.qtKeywordsEnabled || (m_languageFeatures.qtKeywordsEnabled
&& CppTools::isQtKeyword(QStringView{text}.mid(tk.utf16charsBegin(), tk.utf16chars()))) && CppTools::isQtKeyword(
QStringView{text}.mid(tk.utf16charsBegin(), tk.utf16chars())))
|| (m_languageFeatures.objCEnabled && tk.isObjCAtKeyword())) { || (m_languageFeatures.objCEnabled && tk.isObjCAtKeyword())) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_KEYWORD)); setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_KEYWORD));
} else if (tk.isPrimitiveType()) { } else if (tk.isPrimitiveType()) {
@@ -211,7 +213,8 @@ void CppHighlighter::highlightBlock(const QString &text)
} else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) { } else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_LABEL)); setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_LABEL));
} else if (tk.is(T_IDENTIFIER)) { } else if (tk.is(T_IDENTIFIER)) {
highlightWord(text.midRef(tk.utf16charsBegin(), tk.utf16chars()), tk.utf16charsBegin(), highlightWord(Utils::midView(text, tk.utf16charsBegin(), tk.utf16chars()),
tk.utf16charsBegin(),
tk.utf16chars()); tk.utf16chars());
} }
} }
@@ -274,7 +277,7 @@ void CppHighlighter::setLanguageFeatures(const LanguageFeatures &languageFeature
} }
} }
bool CppHighlighter::isPPKeyword(const QStringRef &text) const bool CppHighlighter::isPPKeyword(const QStringView &text) const
{ {
switch (text.length()) switch (text.length())
{ {
@@ -348,7 +351,7 @@ bool CppHighlighter::isPPKeyword(const QStringRef &text) const
return false; return false;
} }
void CppHighlighter::highlightWord(QStringRef word, int position, int length) void CppHighlighter::highlightWord(QStringView word, int position, int length)
{ {
// try to highlight Qt 'identifiers' like QObject and Q_PROPERTY // try to highlight Qt 'identifiers' like QObject and Q_PROPERTY

View File

@@ -46,13 +46,13 @@ public:
void highlightBlock(const QString &text) override; void highlightBlock(const QString &text) override;
private: private:
void highlightWord(QStringRef word, int position, int length); void highlightWord(QStringView word, int position, int length);
bool highlightRawStringLiteral(const QStringView &text, const CPlusPlus::Token &tk); bool highlightRawStringLiteral(const QStringView &text, const CPlusPlus::Token &tk);
void highlightDoxygenComment(const QString &text, int position, void highlightDoxygenComment(const QString &text, int position,
int length); int length);
bool isPPKeyword(const QStringRef &text) const; bool isPPKeyword(const QStringView &text) const;
private: private:
CPlusPlus::LanguageFeatures m_languageFeatures = CPlusPlus::LanguageFeatures::defaultFeatures(); CPlusPlus::LanguageFeatures m_languageFeatures = CPlusPlus::LanguageFeatures::defaultFeatures();

View File

@@ -1807,7 +1807,7 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
ulong value = 0; ulong value = 0;
const QString x = QString::fromUtf8(spell).left(numberLength); const QString x = QString::fromUtf8(spell).left(numberLength);
if (x.startsWith("0b", Qt::CaseInsensitive)) if (x.startsWith("0b", Qt::CaseInsensitive))
value = x.midRef(2).toULong(&valid, 2); value = x.mid(2).toULong(&valid, 2);
else else
value = x.toULong(&valid, 0); value = x.toULong(&valid, 0);