forked from qt-creator/qt-creator
CppTools: Fix QStringRef and QSharedPointer related issues with Qt6
Task-number: QTCREATORBUG-24098 Change-Id: I97347ac3fb397fea8eee655e3cc4ee252c511885 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -113,10 +113,12 @@ QString BackwardsScanner::text(int index) const
|
|||||||
return _text.mid(firstToken.utf16charsBegin(), firstToken.utf16chars());
|
return _text.mid(firstToken.utf16charsBegin(), firstToken.utf16chars());
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringRef BackwardsScanner::textRef(int index) const
|
QStringView BackwardsScanner::textRef(int index) const
|
||||||
{
|
{
|
||||||
const Token &firstToken = _tokens.at(index + _offset);
|
const Token &firstToken = _tokens.at(index + _offset);
|
||||||
return _text.midRef(firstToken.utf16charsBegin(), firstToken.utf16chars());
|
if (firstToken.utf16charsEnd() > _text.size())
|
||||||
|
return QStringView(_text).mid(firstToken.utf16charsBegin());
|
||||||
|
return QStringView(_text).mid(firstToken.utf16charsBegin(), firstToken.utf16chars());
|
||||||
}
|
}
|
||||||
|
|
||||||
int BackwardsScanner::size() const
|
int BackwardsScanner::size() const
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "SimpleLexer.h"
|
#include "SimpleLexer.h"
|
||||||
|
|
||||||
|
#include <QStringView>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QTextCursor)
|
QT_FORWARD_DECLARE_CLASS(QTextCursor)
|
||||||
@@ -52,7 +53,7 @@ public:
|
|||||||
QString mid(int index) const;
|
QString mid(int index) const;
|
||||||
|
|
||||||
QString text(int index) const;
|
QString text(int index) const;
|
||||||
QStringRef textRef(int index) const;
|
QStringView textRef(int index) const;
|
||||||
// 1-based
|
// 1-based
|
||||||
Token LA(int index) const;
|
Token LA(int index) const;
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ static bool shouldOverrideChar(QChar ch)
|
|||||||
|
|
||||||
static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index)
|
static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index)
|
||||||
{
|
{
|
||||||
const QStringRef text = tk.textRef(index);
|
const QStringView text = tk.textRef(index);
|
||||||
|
|
||||||
if (text.length() < 2)
|
if (text.length() < 2)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -87,7 +87,9 @@ Tokens SimpleLexer::operator()(const QString &text, int state)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringRef spell = text.midRef(tk.bytesBegin(), tk.bytes());
|
const QStringView spell = tk.bytesBegin() + tk.bytes() > text.size()
|
||||||
|
? QStringView(text).mid(tk.bytesBegin())
|
||||||
|
: QStringView(text).mid(tk.bytesBegin(), tk.bytes());
|
||||||
lex.setScanAngleStringLiteralTokens(false);
|
lex.setScanAngleStringLiteralTokens(false);
|
||||||
|
|
||||||
if (tk.newline() && tk.is(T_POUND))
|
if (tk.newline() && tk.is(T_POUND))
|
||||||
|
|||||||
@@ -528,7 +528,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringRef tokenText = currentTokenText();
|
QStringView tokenText = currentTokenText();
|
||||||
if (tokenText == QLatin1String("ifdef")
|
if (tokenText == QLatin1String("ifdef")
|
||||||
|| tokenText == QLatin1String("if")
|
|| tokenText == QLatin1String("if")
|
||||||
|| tokenText == QLatin1String("ifndef")) {
|
|| tokenText == QLatin1String("ifndef")) {
|
||||||
@@ -854,7 +854,7 @@ bool CodeFormatter::tryDeclaration()
|
|||||||
return true;
|
return true;
|
||||||
case T_IDENTIFIER:
|
case T_IDENTIFIER:
|
||||||
if (m_tokenIndex == 0) {
|
if (m_tokenIndex == 0) {
|
||||||
const QStringRef tokenText = currentTokenText();
|
const QStringView tokenText = currentTokenText();
|
||||||
if (tokenText.startsWith(QLatin1String("Q_"))
|
if (tokenText.startsWith(QLatin1String("Q_"))
|
||||||
|| tokenText.startsWith(QLatin1String("QT_"))
|
|| tokenText.startsWith(QLatin1String("QT_"))
|
||||||
|| tokenText.startsWith(QLatin1String("QML_"))
|
|| tokenText.startsWith(QLatin1String("QML_"))
|
||||||
@@ -1009,9 +1009,11 @@ int CodeFormatter::column(int index) const
|
|||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringRef CodeFormatter::currentTokenText() const
|
QStringView CodeFormatter::currentTokenText() const
|
||||||
{
|
{
|
||||||
return m_currentLine.midRef(m_currentToken.utf16charsBegin(), m_currentToken.utf16chars());
|
if (m_currentToken.utf16charsEnd() > m_currentLine.size())
|
||||||
|
return QStringView(m_currentLine).mid(m_currentToken.utf16charsBegin());
|
||||||
|
return QStringView(m_currentLine).mid(m_currentToken.utf16charsBegin(), m_currentToken.utf16chars());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeFormatter::turnInto(int newState)
|
void CodeFormatter::turnInto(int newState)
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ private:
|
|||||||
void saveCurrentState(const QTextBlock &block);
|
void saveCurrentState(const QTextBlock &block);
|
||||||
void restoreCurrentState(const QTextBlock &block);
|
void restoreCurrentState(const QTextBlock &block);
|
||||||
|
|
||||||
QStringRef currentTokenText() const;
|
QStringView currentTokenText() const;
|
||||||
|
|
||||||
int tokenizeBlock(const QTextBlock &block, bool *endedJoined = nullptr);
|
int tokenizeBlock(const QTextBlock &block, bool *endedJoined = nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -880,9 +880,12 @@ bool InternalCppCompletionAssistProcessor::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 = idToken.utf16charsEnd() > line.size()
|
||||||
line.midRef(idToken.utf16charsBegin(),
|
? QStringView(line).mid(
|
||||||
idToken.utf16charsEnd() - idToken.utf16charsBegin());
|
idToken.utf16charsBegin())
|
||||||
|
: QStringView(line)
|
||||||
|
.mid(idToken.utf16charsBegin(),
|
||||||
|
idToken.utf16chars());
|
||||||
if (identifier == QLatin1String("include")
|
if (identifier == QLatin1String("include")
|
||||||
|| identifier == QLatin1String("include_next")
|
|| identifier == QLatin1String("include_next")
|
||||||
|| (m_interface->languageFeatures().objCEnabled && identifier == QLatin1String("import"))) {
|
|| (m_interface->languageFeatures().objCEnabled && identifier == QLatin1String("import"))) {
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
|||||||
|
|
||||||
// Highlight the matched characters, therefore it may be necessary
|
// Highlight the matched characters, therefore it may be necessary
|
||||||
// to update the match if the displayName is different from matchString
|
// to update the match if the displayName is different from matchString
|
||||||
if (matchString.midRef(matchOffset) != filterEntry.displayName) {
|
if (QStringView(matchString).mid(matchOffset) != filterEntry.displayName) {
|
||||||
match = shortRegexp.match(filterEntry.displayName);
|
match = shortRegexp.match(filterEntry.displayName);
|
||||||
matchOffset = 0;
|
matchOffset = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ QVariant SymbolItem::data(int /*column*/, int role) const
|
|||||||
|
|
||||||
bool OverviewModel::hasDocument() const
|
bool OverviewModel::hasDocument() const
|
||||||
{
|
{
|
||||||
return _cppDocument;
|
return !_cppDocument.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
int OverviewModel::globalSymbolCount() const
|
int OverviewModel::globalSymbolCount() const
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath)
|
|||||||
bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart)
|
bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart)
|
||||||
{
|
{
|
||||||
if (projectPart)
|
if (projectPart)
|
||||||
return CppTools::CppModelManager::instance()->projectPartForId(projectPart->id());
|
return !CppTools::CppModelManager::instance()->projectPartForId(projectPart->id()).isNull();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user