From c49728eb27be0f3f2eaaa77b0ed573f5d8705af1 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 30 May 2020 23:29:21 +0200 Subject: Port qmake from QStringRef to QStringView Change-Id: Ie07a976cd3c634e04c8b9b1e0a6cacd4c2d94939 Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- qmake/generators/makefile.cpp | 20 +++++----- qmake/generators/makefile.h | 6 +-- qmake/generators/win32/mingw_make.cpp | 8 ++-- qmake/generators/win32/mingw_make.h | 4 +- qmake/generators/win32/winmakefile.cpp | 4 +- qmake/generators/win32/winmakefile.h | 4 +- qmake/library/ioutils.cpp | 8 ++-- qmake/library/ioutils.h | 4 +- qmake/library/proitems.cpp | 10 ++--- qmake/library/proitems.h | 61 +++++++++++++++--------------- qmake/library/qmakebuiltins.cpp | 36 +++++++++--------- qmake/library/qmakeevaluator.cpp | 18 ++++----- qmake/library/qmakeevaluator.h | 6 +-- qmake/library/qmakeevaluator_p.h | 2 +- qmake/library/qmakeparser.cpp | 12 +++--- qmake/library/qmakeparser.h | 6 +-- qmake/project.cpp | 2 +- qmake/project.h | 4 +- tests/auto/tools/qmakelib/parsertest.cpp | 4 +- tests/auto/tools/qmakelib/tst_qmakelib.cpp | 3 -- 20 files changed, 109 insertions(+), 113 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index f27bb242a2..0fbfd0c9ef 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -857,29 +857,29 @@ MakefileGenerator::processPrlFile(QString &file, bool baseOnly) QString f = fileFixify(file, FileFixifyBackwards); // Explicitly given full .prl name if (!baseOnly && f.endsWith(Option::prl_ext)) - return processPrlFileCore(file, QStringRef(), f); + return processPrlFileCore(file, QStringView(), f); // Explicitly given or derived (from -l) base name - if (processPrlFileCore(file, QStringRef(), f + Option::prl_ext)) + if (processPrlFileCore(file, QStringView(), f + Option::prl_ext)) return true; if (!baseOnly) { // Explicitly given full library name int off = qMax(f.lastIndexOf('/'), f.lastIndexOf('\\')) + 1; - int ext = f.midRef(off).lastIndexOf('.'); + int ext = QStringView(f).mid(off).lastIndexOf('.'); if (ext != -1) - return processPrlFileBase(file, f.midRef(off), f.leftRef(off + ext), off); + return processPrlFileBase(file, QStringView(f).mid(off), QStringView{f}.left(off + ext), off); } return false; } bool -MakefileGenerator::processPrlFileBase(QString &origFile, const QStringRef &origName, - const QStringRef &fixedBase, int /*slashOff*/) +MakefileGenerator::processPrlFileBase(QString &origFile, QStringView origName, + QStringView fixedBase, int /*slashOff*/) { return processPrlFileCore(origFile, origName, fixedBase + Option::prl_ext); } bool -MakefileGenerator::processPrlFileCore(QString &origFile, const QStringRef &origName, +MakefileGenerator::processPrlFileCore(QString &origFile, QStringView origName, const QString &fixedFile) { const QString meta_file = QMakeMetaInfo::checkLib(fixedFile); @@ -1516,7 +1516,7 @@ MakefileGenerator::createObjectList(const ProStringList &sources) int lastDirSepPosition = sourceRelativePath.lastIndexOf(Option::dir_sep); if (lastDirSepPosition != -1) - dir += sourceRelativePath.leftRef(lastDirSepPosition + 1); + dir += QStringView{sourceRelativePath}.left(lastDirSepPosition + 1); if (!noIO()) { // Ensure that the final output directory of each object exists @@ -1840,8 +1840,8 @@ QString MakefileGenerator::resolveDependency(const QDir &outDir, const QString & int cut = file.indexOf('/'); if (cut < 0 || cut + 1 >= file.size()) continue; - QStringRef framework = file.leftRef(cut); - QStringRef include = file.midRef(cut + 1); + QStringView framework = QStringView{file}.left(cut); + QStringView include = QStringView(file).mid(cut + 1); if (local.endsWith('/' + framework + ".framework/Headers")) { lf = outDir.absoluteFilePath(local + '/' + include); if (exists(lf)) diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h index b80b6e3e08..131da4943f 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -260,9 +260,9 @@ protected: QString installMetaFile(const ProKey &replace_rule, const QString &src, const QString &dst); - virtual bool processPrlFileBase(QString &origFile, const QStringRef &origName, - const QStringRef &fixedBase, int slashOff); - bool processPrlFileCore(QString &origFile, const QStringRef &origName, + virtual bool processPrlFileBase(QString &origFile, QStringView origName, + QStringView fixedBase, int slashOff); + bool processPrlFileCore(QString &origFile, QStringView origName, const QString &fixedFile); void createResponseFile(const QString &fileName, const ProStringList &objList); diff --git a/qmake/generators/win32/mingw_make.cpp b/qmake/generators/win32/mingw_make.cpp index e79e804266..432525ffba 100644 --- a/qmake/generators/win32/mingw_make.cpp +++ b/qmake/generators/win32/mingw_make.cpp @@ -64,13 +64,13 @@ MingwMakefileGenerator::parseLibFlag(const ProString &flag, ProString *arg) return MakefileGenerator::parseLibFlag(flag, arg); } -bool MingwMakefileGenerator::processPrlFileBase(QString &origFile, const QStringRef &origName, - const QStringRef &fixedBase, int slashOff) +bool MingwMakefileGenerator::processPrlFileBase(QString &origFile, QStringView origName, + QStringView fixedBase, int slashOff) { - if (origName.startsWith("lib")) { + if (origName.startsWith(u"lib")) { QString newFixedBase = fixedBase.left(slashOff) + fixedBase.mid(slashOff + 3); if (Win32MakefileGenerator::processPrlFileBase(origFile, origName, - QStringRef(&newFixedBase), slashOff)) { + QStringView(newFixedBase), slashOff)) { return true; } } diff --git a/qmake/generators/win32/mingw_make.h b/qmake/generators/win32/mingw_make.h index 6ab1c95a94..6c1f0086cc 100644 --- a/qmake/generators/win32/mingw_make.h +++ b/qmake/generators/win32/mingw_make.h @@ -39,8 +39,8 @@ protected: using MakefileGenerator::escapeDependencyPath; QString escapeDependencyPath(const QString &path) const override; ProString fixLibFlag(const ProString &lib) override; - bool processPrlFileBase(QString &origFile, const QStringRef &origName, - const QStringRef &fixedBase, int slashOff) override; + bool processPrlFileBase(QString &origFile, QStringView origName, + QStringView fixedBase, int slashOff) override; bool writeMakefile(QTextStream &) override; void init() override; QString installRoot() const override; diff --git a/qmake/generators/win32/winmakefile.cpp b/qmake/generators/win32/winmakefile.cpp index a5d96483a8..0c32be8ef6 100644 --- a/qmake/generators/win32/winmakefile.cpp +++ b/qmake/generators/win32/winmakefile.cpp @@ -194,8 +194,8 @@ Win32MakefileGenerator::findLibraries(bool linkPrl, bool mergeLflags) return true; } -bool Win32MakefileGenerator::processPrlFileBase(QString &origFile, const QStringRef &origName, - const QStringRef &fixedBase, int slashOff) +bool Win32MakefileGenerator::processPrlFileBase(QString &origFile, QStringView origName, + QStringView fixedBase, int slashOff) { if (MakefileGenerator::processPrlFileBase(origFile, origName, fixedBase, slashOff)) return true; diff --git a/qmake/generators/win32/winmakefile.h b/qmake/generators/win32/winmakefile.h index 265e54204e..180bd0fde8 100644 --- a/qmake/generators/win32/winmakefile.h +++ b/qmake/generators/win32/winmakefile.h @@ -56,8 +56,8 @@ protected: LibFlagType parseLibFlag(const ProString &flag, ProString *arg) override; ProString fixLibFlag(const ProString &lib) override; - bool processPrlFileBase(QString &origFile, const QStringRef &origName, - const QStringRef &fixedBase, int slashOff) override; + bool processPrlFileBase(QString &origFile, QStringView origName, + QStringView fixedBase, int slashOff) override; void processVars(); void fixTargetExt(); diff --git a/qmake/library/ioutils.cpp b/qmake/library/ioutils.cpp index fac0541779..3a93298ffa 100644 --- a/qmake/library/ioutils.cpp +++ b/qmake/library/ioutils.cpp @@ -91,14 +91,14 @@ bool IoUtils::isRelativePath(const QString &path) return true; } -QStringRef IoUtils::pathName(const QString &fileName) +QStringView IoUtils::pathName(const QString &fileName) { - return fileName.leftRef(fileName.lastIndexOf(QLatin1Char('/')) + 1); + return QStringView{fileName}.left(fileName.lastIndexOf(QLatin1Char('/')) + 1); } -QStringRef IoUtils::fileName(const QString &fileName) +QStringView IoUtils::fileName(const QString &fileName) { - return fileName.midRef(fileName.lastIndexOf(QLatin1Char('/')) + 1); + return QStringView(fileName).mid(fileName.lastIndexOf(QLatin1Char('/')) + 1); } QString IoUtils::resolvePath(const QString &baseDir, const QString &fileName) diff --git a/qmake/library/ioutils.h b/qmake/library/ioutils.h index 32bf675f62..f4555e8eeb 100644 --- a/qmake/library/ioutils.h +++ b/qmake/library/ioutils.h @@ -53,8 +53,8 @@ public: static bool exists(const QString &fileName) { return fileType(fileName) != FileNotFound; } static bool isRelativePath(const QString &fileName); static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); } - static QStringRef pathName(const QString &fileName); // Requires normalized path - static QStringRef fileName(const QString &fileName); // Requires normalized path + static QStringView pathName(const QString &fileName); // Requires normalized path + static QStringView fileName(const QString &fileName); // Requires normalized path static QString resolvePath(const QString &baseDir, const QString &fileName); static QString shellQuoteUnix(const QString &arg); static QString shellQuoteWin(const QString &arg); diff --git a/qmake/library/proitems.cpp b/qmake/library/proitems.cpp index 6bef098874..85569ecd82 100644 --- a/qmake/library/proitems.cpp +++ b/qmake/library/proitems.cpp @@ -74,8 +74,8 @@ ProString::ProString(const QString &str) : { } -ProString::ProString(const QStringRef &str) : - m_string(*str.string()), m_offset(str.position()), m_length(str.size()), m_file(0), m_hash(0x80000000) +ProString::ProString(QStringView str) : + m_string(str.toString()), m_offset(0), m_length(str.size()), m_file(0), m_hash(0x80000000) { } @@ -341,7 +341,7 @@ ProString ProString::trimmed() const QTextStream &operator<<(QTextStream &t, const ProString &str) { - t << str.toQStringRef(); + t << str.toQStringView(); return t; } @@ -466,10 +466,10 @@ bool ProStringList::contains(const ProString &str, Qt::CaseSensitivity cs) const return false; } -bool ProStringList::contains(const QStringRef &str, Qt::CaseSensitivity cs) const +bool ProStringList::contains(QStringView str, Qt::CaseSensitivity cs) const { for (int i = 0; i < size(); i++) - if (!at(i).toQStringRef().compare(str, cs)) + if (!at(i).toQStringView().compare(str, cs)) return true; return false; } diff --git a/qmake/library/proitems.h b/qmake/library/proitems.h index 09c5504fdf..6e091354e4 100644 --- a/qmake/library/proitems.h +++ b/qmake/library/proitems.h @@ -74,7 +74,7 @@ public: ProString &operator=(const QStringBuilder &str) { return *this = QString(str); } ProString(const QString &str); - PROITEM_EXPLICIT ProString(const QStringRef &str); + PROITEM_EXPLICIT ProString(QStringView str); PROITEM_EXPLICIT ProString(const char *str); template ProString(const QStringBuilder &str) @@ -107,16 +107,16 @@ public: void chop(int n) { Q_ASSERT(n <= m_length); m_length -= n; } void chopFront(int n) { Q_ASSERT(n <= m_length); m_offset += n; m_length -= n; } - bool operator==(const ProString &other) const { return toQStringRef() == other.toQStringRef(); } - bool operator==(const QString &other) const { return toQStringRef() == other; } - bool operator==(const QStringRef &other) const { return toQStringRef() == other; } - bool operator==(QLatin1String other) const { return toQStringRef() == other; } - bool operator==(const char *other) const { return toQStringRef() == QLatin1String(other); } + bool operator==(const ProString &other) const { return toQStringView() == other.toQStringView(); } + bool operator==(const QString &other) const { return toQStringView() == other; } + bool operator==(QStringView other) const { return toQStringView() == other; } + bool operator==(QLatin1String other) const { return toQStringView() == other; } + bool operator==(const char *other) const { return toQStringView() == QLatin1String(other); } bool operator!=(const ProString &other) const { return !(*this == other); } bool operator!=(const QString &other) const { return !(*this == other); } bool operator!=(QLatin1String other) const { return !(*this == other); } bool operator!=(const char *other) const { return !(*this == other); } - bool operator<(const ProString &other) const { return toQStringRef() < other.toQStringRef(); } + bool operator<(const ProString &other) const { return toQStringView() < other.toQStringView(); } bool isNull() const { return m_string.isNull(); } bool isEmpty() const { return !m_length; } int length() const { return m_length; } @@ -127,38 +127,37 @@ public: ProString left(int len) const { return mid(0, len); } ProString right(int len) const { return mid(qMax(0, size() - len)); } ProString trimmed() const; - int compare(const ProString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().compare(sub.toQStringRef(), cs); } - int compare(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().compare(sub, cs); } - int compare(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().compare(QLatin1String(sub), cs); } - bool startsWith(const ProString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().startsWith(sub.toQStringRef(), cs); } - bool startsWith(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().startsWith(sub, cs); } - bool startsWith(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().startsWith(QLatin1String(sub), cs); } - bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().startsWith(c, cs); } + int compare(const ProString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().compare(sub.toQStringView(), cs); } + int compare(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().compare(sub, cs); } + int compare(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().compare(QLatin1String(sub), cs); } + bool startsWith(const ProString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().startsWith(sub.toQStringView(), cs); } + bool startsWith(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().startsWith(sub, cs); } + bool startsWith(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().startsWith(QLatin1String(sub), cs); } + bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().startsWith(c, cs); } template bool startsWith(const QStringBuilder &str) { return startsWith(QString(str)); } - bool endsWith(const ProString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(sub.toQStringRef(), cs); } - bool endsWith(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(sub, cs); } - bool endsWith(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(QLatin1String(sub), cs); } + bool endsWith(const ProString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().endsWith(sub.toQStringView(), cs); } + bool endsWith(const QString &sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().endsWith(sub, cs); } + bool endsWith(const char *sub, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().endsWith(QLatin1String(sub), cs); } template bool endsWith(const QStringBuilder &str) { return endsWith(QString(str)); } - bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().endsWith(c, cs); } - int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().indexOf(s, from, cs); } - int indexOf(const char *s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().indexOf(QLatin1String(s), from, cs); } - int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().indexOf(c, from, cs); } - int lastIndexOf(const QString &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().lastIndexOf(s, from, cs); } - int lastIndexOf(const char *s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().lastIndexOf(QLatin1String(s), from, cs); } - int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringRef().lastIndexOf(c, from, cs); } + bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().endsWith(c, cs); } + int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().indexOf(s, from, cs); } + int indexOf(const char *s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().indexOf(QLatin1String(s), from, cs); } + int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().indexOf(c, from, cs); } + int lastIndexOf(const QString &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().lastIndexOf(s, from, cs); } + int lastIndexOf(const char *s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().lastIndexOf(QLatin1String(s), from, cs); } + int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return toQStringView().lastIndexOf(c, from, cs); } bool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return indexOf(s, 0, cs) >= 0; } bool contains(const char *s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return indexOf(QLatin1String(s), 0, cs) >= 0; } bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return indexOf(c, 0, cs) >= 0; } - qlonglong toLongLong(bool *ok = nullptr, int base = 10) const { return toQStringRef().toLongLong(ok, base); } - int toInt(bool *ok = nullptr, int base = 10) const { return toQStringRef().toInt(ok, base); } - short toShort(bool *ok = nullptr, int base = 10) const { return toQStringRef().toShort(ok, base); } + qlonglong toLongLong(bool *ok = nullptr, int base = 10) const { return toQStringView().toLongLong(ok, base); } + int toInt(bool *ok = nullptr, int base = 10) const { return toQStringView().toInt(ok, base); } + short toShort(bool *ok = nullptr, int base = 10) const { return toQStringView().toShort(ok, base); } uint hash() const { return m_hash; } static uint hash(const QChar *p, int n); - ALWAYS_INLINE QStringRef toQStringRef() const { return QStringRef(&m_string, m_offset, m_length); } ALWAYS_INLINE QStringView toQStringView() const { return QStringView(m_string).mid(m_offset, m_length); } ALWAYS_INLINE ProKey &toKey() { return *(ProKey *)this; } @@ -167,7 +166,7 @@ public: QString toQString() const; QString &toQString(QString &tmp) const; - QByteArray toLatin1() const { return toQStringRef().toLatin1(); } + QByteArray toLatin1() const { return toQStringView().toLatin1(); } private: ProString(const ProKey &other); @@ -258,7 +257,7 @@ template <> struct QConcatenable : private QAbstractConcatenable size_t qHash(const ProString &str); inline QString &operator+=(QString &that, const ProString &other) - { return that += other.toQStringRef(); } + { return that += other.toQStringView(); } QTextStream &operator<<(QTextStream &t, const ProString &str); template @@ -341,7 +340,7 @@ public: void removeDuplicates(); bool contains(const ProString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - bool contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return contains(ProString(str), cs); } bool contains(const char *str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; diff --git a/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp index 96583e5e76..969c2e4539 100644 --- a/qmake/library/qmakebuiltins.cpp +++ b/qmake/library/qmakebuiltins.cpp @@ -673,7 +673,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( bool leftalign = false; enum { DefaultSign, PadSign, AlwaysSign } sign = DefaultSign; if (args.count() >= 2) { - const auto opts = split_value_list(args.at(1).toQStringRef()); + const auto opts = split_value_list(args.at(1).toQStringView()); for (const ProString &opt : opts) { if (opt.startsWith(QLatin1String("ibase="))) { ibase = opt.mid(6).toInt(); @@ -776,7 +776,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( const auto vars = values(map(args.at(0))); for (const ProString &var : vars) { // FIXME: this is inconsistent with the "there are no empty strings" dogma. - const auto splits = var.toQStringRef().split(sep, Qt::KeepEmptyParts); + const auto splits = var.toQStringView().split(sep, Qt::KeepEmptyParts); for (const auto &splt : splits) ret << ProString(splt).setSource(var); } @@ -866,7 +866,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( ret += ProString(stream.readLine()); } else { const QString &line = stream.readLine(); - ret += split_value_list(QStringRef(&line).trimmed()); + ret += split_value_list(QStringView(line).trimmed()); if (!singleLine) ret += ProString("\n"); } @@ -890,7 +890,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( ret = ProStringList(ProString(tmp)); ProStringList lst; for (const ProString &arg : args) - lst += split_value_list(arg.toQStringRef(), arg.sourceFile()); // Relies on deep copy + lst += split_value_list(arg.toQStringView(), arg.sourceFile()); // Relies on deep copy m_valuemapStack.top()[ret.at(0).toKey()] = lst; break; } case E_FIND: { @@ -939,7 +939,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( output.replace(QLatin1Char('\t'), QLatin1Char(' ')); if (singleLine) output.replace(QLatin1Char('\n'), QLatin1Char(' ')); - ret += split_value_list(QStringRef(&output)); + ret += split_value_list(QStringView(output)); } } break; @@ -1092,7 +1092,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( evalError(fL1S("Unexpected EOF.")); return ReturnError; } - ret = split_value_list(QStringRef(&line)); + ret = split_value_list(QStringView(line)); } break; } @@ -1125,7 +1125,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( ProString priosfx = args.count() < 4 ? ProString(".priority") : args.at(3); populateDeps(orgList, prefix, args.count() < 3 ? ProStringList(ProString(".depends")) - : split_value_list(args.at(2).toQStringRef()), + : split_value_list(args.at(2).toQStringView()), priosfx, dependencies, dependees, rootSet); while (!rootSet.isEmpty()) { QMultiMap::iterator it = rootSet.begin(); @@ -1283,7 +1283,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::testFunc_cache(const ProStringList & enum { CacheSet, CacheAdd, CacheSub } mode = CacheSet; ProKey srcvar; if (args.count() >= 2) { - const auto opts = split_value_list(args.at(1).toQStringRef()); + const auto opts = split_value_list(args.at(1).toQStringView()); for (const ProString &opt : opts) { if (opt == QLatin1String("transient")) { persist = false; @@ -1576,7 +1576,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional( case T_EVAL: { VisitReturn ret = ReturnFalse; QString contents = args.join(statics.field_sep); - ProFile *pro = m_parser->parsedProBlock(QStringRef(&contents), + ProFile *pro = m_parser->parsedProBlock(QStringView(contents), 0, m_current.pro->fileName(), m_current.line); if (m_cumulative || pro->isOk()) { m_locationStack.push(m_current); @@ -1588,19 +1588,19 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional( return ret; } case T_IF: { - return evaluateConditional(args.at(0).toQStringRef(), + return evaluateConditional(args.at(0).toQStringView(), m_current.pro->fileName(), m_current.line); } case T_CONFIG: { if (args.count() == 1) - return returnBool(isActiveConfig(args.at(0).toQStringRef())); - const auto mutuals = args.at(1).toQStringRef().split(QLatin1Char('|'), + return returnBool(isActiveConfig(args.at(0).toQStringView())); + const auto mutuals = args.at(1).toQStringView().split(QLatin1Char('|'), Qt::SkipEmptyParts); const ProStringList &configs = values(statics.strCONFIG); for (int i = configs.size() - 1; i >= 0; i--) { for (int mut = 0; mut < mutuals.count(); mut++) { - if (configs[i].toQStringRef() == mutuals[mut].trimmed()) + if (configs[i].toQStringView() == mutuals[mut].trimmed()) return returnBool(configs[i] == args[0]); } } @@ -1631,12 +1631,12 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional( } } } else { - const auto mutuals = args.at(2).toQStringRef().split(QLatin1Char('|'), + const auto mutuals = args.at(2).toQStringView().split(QLatin1Char('|'), Qt::SkipEmptyParts); for (int i = l.size() - 1; i >= 0; i--) { const ProString &val = l[i]; for (int mut = 0; mut < mutuals.count(); mut++) { - if (val.toQStringRef() == mutuals[mut].trimmed()) { + if (val.toQStringView() == mutuals[mut].trimmed()) { if (val == qry) return ReturnTrue; if (!regx.pattern().isEmpty()) { @@ -1689,8 +1689,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional( } } if (func_t == T_GREATERTHAN) - return returnBool(lhs > rhs.toQStringRef()); - return returnBool(lhs < rhs.toQStringRef()); + return returnBool(lhs > rhs.toQStringView()); + return returnBool(lhs < rhs.toQStringView()); } case T_EQUALS: return returnBool(values(map(args.at(0))).join(statics.field_sep) @@ -1881,7 +1881,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional( if (!vals.isEmpty()) contents = vals.join(QLatin1Char('\n')) + QLatin1Char('\n'); if (args.count() >= 3) { - const auto opts = split_value_list(args.at(2).toQStringRef()); + const auto opts = split_value_list(args.at(2).toQStringView()); for (const ProString &opt : opts) { if (opt == QLatin1String("append")) { mode = QIODevice::Append; diff --git a/qmake/library/qmakeevaluator.cpp b/qmake/library/qmakeevaluator.cpp index 51e26f343b..e3b20771d4 100644 --- a/qmake/library/qmakeevaluator.cpp +++ b/qmake/library/qmakeevaluator.cpp @@ -272,7 +272,7 @@ void QMakeEvaluator::skipHashStr(const ushort *&tokPtr) // FIXME: this should not build new strings for direct sections. // Note that the E_SPRINTF and E_LIST implementations rely on the deep copy. -ProStringList QMakeEvaluator::split_value_list(const QStringRef &vals, int source) +ProStringList QMakeEvaluator::split_value_list(QStringView vals, int source) { QString build; ProStringList ret; @@ -653,7 +653,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProBlock( evalError(fL1S("Conditional must expand to exactly one word.")); okey = false; } else { - okey = isActiveConfig(curr.at(0).toQStringRef(), true); + okey = isActiveConfig(curr.at(0).toQStringView(), true); traceMsg("condition %s is %s", dbgStr(curr.at(0)), dbgBool(okey)); okey ^= invert; } @@ -780,7 +780,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProLoop( } infinite = true; } else { - const QStringRef &itl = it_list.toQStringRef(); + QStringView itl = it_list.toQStringView(); int dotdot = itl.indexOf(statics.strDotDot); if (dotdot != -1) { bool ok; @@ -877,7 +877,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProVariable( ProStringList varVal; if (expandVariableReferences(tokPtr, sizeHint, &varVal, true) == ReturnError) return ReturnError; - const QStringRef &val = varVal.at(0).toQStringRef(); + QStringView val = varVal.at(0).toQStringView(); if (val.length() < 4 || val.at(0) != QLatin1Char('s')) { evalError(fL1S("The ~= operator can handle only the s/// function.")); return ReturnTrue; @@ -1315,7 +1315,7 @@ void QMakeEvaluator::setupProject() void QMakeEvaluator::evaluateCommand(const QString &cmds, const QString &where) { if (!cmds.isEmpty()) { - ProFile *pro = m_parser->parsedProBlock(QStringRef(&cmds), 0, where, -1); + ProFile *pro = m_parser->parsedProBlock(QStringView(cmds), 0, where, -1); if (pro->isOk()) { m_locationStack.push(m_current); visitProBlock(pro, pro->tokPtr()); @@ -1624,7 +1624,7 @@ QString QMakeEvaluator::currentDirectory() const return QString(); } -bool QMakeEvaluator::isActiveConfig(const QStringRef &config, bool regex) +bool QMakeEvaluator::isActiveConfig(QStringView config, bool regex) { // magic types for easy flipping if (config == statics.strtrue) @@ -1820,7 +1820,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateExpandFunction( } QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditional( - const QStringRef &cond, const QString &where, int line) + QStringView cond, const QString &where, int line) { VisitReturn ret = ReturnFalse; ProFile *pro = m_parser->parsedProBlock(cond, 0, where, line, QMakeParser::TestGrammar); @@ -1838,7 +1838,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::checkRequirements(const ProStringLis { ProStringList &failed = valuesRef(ProKey("QMAKE_FAILED_REQUIREMENTS")); for (const ProString &dep : deps) { - VisitReturn vr = evaluateConditional(dep.toQStringRef(), m_current.pro->fileName(), m_current.line); + VisitReturn vr = evaluateConditional(dep.toQStringView(), m_current.pro->fileName(), m_current.line); if (vr == ReturnError) return ReturnError; if (vr != ReturnTrue) @@ -2004,7 +2004,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFeatureFile( int start_root = 0; const QStringList &paths = m_featureRoots->paths; if (!currFn.isEmpty()) { - QStringRef currPath = IoUtils::pathName(currFn); + QStringView currPath = IoUtils::pathName(currFn); for (int root = 0; root < paths.size(); ++root) if (currPath == paths.at(root)) { start_root = root + 1; diff --git a/qmake/library/qmakeevaluator.h b/qmake/library/qmakeevaluator.h index 9f702b9182..ef60649f5c 100644 --- a/qmake/library/qmakeevaluator.h +++ b/qmake/library/qmakeevaluator.h @@ -180,7 +180,7 @@ public: void setTemplate(); - ProStringList split_value_list(const QStringRef &vals, int source = 0); + ProStringList split_value_list(QStringView vals, int source = 0); VisitReturn expandVariableReferences(const ushort *&tokPtr, int sizeHint, ProStringList *ret, bool joined); QString currentFileName() const; @@ -224,7 +224,7 @@ public: VisitReturn evaluateBuiltinConditional(const QMakeInternal::QMakeBuiltin &adef, const ProKey &function, const ProStringList &args); - VisitReturn evaluateConditional(const QStringRef &cond, const QString &where, int line = -1); + VisitReturn evaluateConditional(QStringView cond, const QString &where, int line = -1); #ifdef PROEVALUATOR_FULL VisitReturn checkRequirements(const ProStringList &deps); #endif @@ -232,7 +232,7 @@ public: void updateMkspecPaths(); void updateFeaturePaths(); - bool isActiveConfig(const QStringRef &config, bool regex = false); + bool isActiveConfig(QStringView config, bool regex = false); void populateDeps( const ProStringList &deps, const ProString &prefix, const ProStringList &suffixes, diff --git a/qmake/library/qmakeevaluator_p.h b/qmake/library/qmakeevaluator_p.h index da83ff0de2..78ae07e2f1 100644 --- a/qmake/library/qmakeevaluator_p.h +++ b/qmake/library/qmakeevaluator_p.h @@ -41,7 +41,7 @@ r == ReturnNext ? "next" : \ r == ReturnReturn ? "return" : \ "") -# define dbgKey(s) s.toString().toQStringRef().toLocal8Bit().constData() +# define dbgKey(s) s.toString().toQStringView().toLocal8Bit().constData() # define dbgStr(s) qPrintable(formatValue(s, true)) # define dbgStrList(s) qPrintable(formatValueList(s)) # define dbgSepStrList(s) qPrintable(formatValueList(s, true)) diff --git a/qmake/library/qmakeparser.cpp b/qmake/library/qmakeparser.cpp index c9d5b4fa0d..684879d195 100644 --- a/qmake/library/qmakeparser.cpp +++ b/qmake/library/qmakeparser.cpp @@ -217,7 +217,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags) #endif QString contents; if (readFile(id, flags, &contents)) { - pro = parsedProBlock(QStringRef(&contents), id, fileName, 1, FullGrammar); + pro = parsedProBlock(QStringView(contents), id, fileName, 1, FullGrammar); pro->itemsRef()->squeeze(); pro->ref(); } else { @@ -238,7 +238,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags) } else { QString contents; if (readFile(id, flags, &contents)) - pro = parsedProBlock(QStringRef(&contents), id, fileName, 1, FullGrammar); + pro = parsedProBlock(QStringView(contents), id, fileName, 1, FullGrammar); else pro = nullptr; } @@ -246,7 +246,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags) } ProFile *QMakeParser::parsedProBlock( - const QStringRef &contents, int id, const QString &name, int line, SubGrammar grammar) + QStringView contents, int id, const QString &name, int line, SubGrammar grammar) { ProFile *pro = new ProFile(id, name); read(pro, contents, line, grammar); @@ -310,7 +310,7 @@ void QMakeParser::finalizeHashStr(ushort *buf, uint len) buf[-2] = (ushort)(hash >> 16); } -void QMakeParser::read(ProFile *pro, const QStringRef &in, int line, SubGrammar grammar) +void QMakeParser::read(ProFile *pro, QStringView in, int line, SubGrammar grammar) { m_proFile = pro; m_lineNo = line; @@ -358,7 +358,7 @@ void QMakeParser::read(ProFile *pro, const QStringRef &in, int line, SubGrammar QStack xprStack; xprStack.reserve(10); - const ushort *cur = (const ushort *)in.unicode(); + const ushort *cur = (const ushort *)in.data(); const ushort *inend = cur + in.length(); m_canElse = false; freshLine: @@ -1260,7 +1260,7 @@ void QMakeParser::finalizeCall(ushort *&tokPtr, ushort *uc, ushort *ptr, int arg bool QMakeParser::resolveVariable(ushort *xprPtr, int tlen, int needSep, ushort **ptr, ushort **buf, QString *xprBuff, ushort **tokPtr, QString *tokBuff, - const ushort *cur, const QStringRef &in) + const ushort *cur, QStringView in) { QString out; m_tmp.setRawData((const QChar *)xprPtr, tlen); diff --git a/qmake/library/qmakeparser.h b/qmake/library/qmakeparser.h index c8c5c7718e..db2df43f5a 100644 --- a/qmake/library/qmakeparser.h +++ b/qmake/library/qmakeparser.h @@ -93,7 +93,7 @@ public: enum SubGrammar { FullGrammar, TestGrammar, ValueGrammar }; // fileName is expected to be absolute and cleanPath()ed. ProFile *parsedProFile(const QString &fileName, ParseFlags flags = ParseDefault); - ProFile *parsedProBlock(const QStringRef &contents, int id, const QString &name, int line = 0, + ProFile *parsedProBlock(QStringView contents, int id, const QString &name, int line = 0, SubGrammar grammar = FullGrammar); void discardFileFromCache(int id); @@ -135,7 +135,7 @@ private: }; bool readFile(int id, QMakeParser::ParseFlags flags, QString *contents); - void read(ProFile *pro, const QStringRef &content, int line, SubGrammar grammar); + void read(ProFile *pro, QStringView content, int line, SubGrammar grammar); ALWAYS_INLINE void putTok(ushort *&tokPtr, ushort tok); ALWAYS_INLINE void putBlockLen(ushort *&tokPtr, uint len); @@ -146,7 +146,7 @@ private: ALWAYS_INLINE bool resolveVariable(ushort *xprPtr, int tlen, int needSep, ushort **ptr, ushort **buf, QString *xprBuff, ushort **tokPtr, QString *tokBuff, - const ushort *cur, const QStringRef &in); + const ushort *cur, QStringView in); void finalizeCond(ushort *&tokPtr, ushort *uc, ushort *ptr, int wordCount); void finalizeCall(ushort *&tokPtr, ushort *uc, ushort *ptr, int argc); void warnOperator(const char *msg); diff --git a/qmake/project.cpp b/qmake/project.cpp index 931a337b71..15870395ae 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -125,7 +125,7 @@ QStringList QMakeProject::expand(const ProKey &func, const QList ProString QMakeProject::expand(const QString &expr, const QString &where, int line) { ProString ret; - ProFile *pro = m_parser->parsedProBlock(QStringRef(&expr), 0, where, line, + ProFile *pro = m_parser->parsedProBlock(QStringView(expr), 0, where, line, QMakeParser::ValueGrammar); if (pro->isOk()) { m_current.pro = pro; diff --git a/qmake/project.h b/qmake/project.h index 071b62424f..da08e86f44 100644 --- a/qmake/project.h +++ b/qmake/project.h @@ -55,7 +55,7 @@ public: ProString expand(const QString &v, const QString &file, int line); QStringList expand(const ProKey &func, const QList &args); bool test(const QString &v, const QString &file, int line) - { m_current.clear(); return evaluateConditional(QStringRef(&v), file, line) == ReturnTrue; } + { m_current.clear(); return evaluateConditional(QStringView(v), file, line) == ReturnTrue; } bool test(const ProKey &func, const QList &args); bool isSet(const ProKey &v) const { return m_valuemapStack.front().contains(v); } @@ -65,7 +65,7 @@ public: const ProValueMap &variables() const { return m_valuemapStack.front(); } ProValueMap &variables() { return m_valuemapStack.front(); } bool isActiveConfig(const QString &config, bool regex = false) - { return QMakeEvaluator::isActiveConfig(QStringRef(&config), regex); } + { return QMakeEvaluator::isActiveConfig(QStringView(config), regex); } void dump() const; diff --git a/tests/auto/tools/qmakelib/parsertest.cpp b/tests/auto/tools/qmakelib/parsertest.cpp index b57ea75c34..3b0e47a5ac 100644 --- a/tests/auto/tools/qmakelib/parsertest.cpp +++ b/tests/auto/tools/qmakelib/parsertest.cpp @@ -40,8 +40,8 @@ public: TokenStream &operator<<(ushort n) { ts += QChar(n); return *this; } TokenStream &operator<<(uint n) { ts += QChar(n & 0xffff); ts += QChar(n >> 16); return *this; } - TokenStream &operator<<(const QStringRef &s) { ts += s; return *this; } - TokenStream &operator<<(const ProString &s) { return *this << ushort(s.length()) << s.toQStringRef(); } + TokenStream &operator<<(QStringView s) { ts += s; return *this; } + TokenStream &operator<<(const ProString &s) { return *this << ushort(s.length()) << s.toQStringView(); } TokenStream &operator<<(const ProKey &s) { return *this << s.hash() << s.toString(); } private: diff --git a/tests/auto/tools/qmakelib/tst_qmakelib.cpp b/tests/auto/tools/qmakelib/tst_qmakelib.cpp index 4a4b20fe50..3d66f940ff 100644 --- a/tests/auto/tools/qmakelib/tst_qmakelib.cpp +++ b/tests/auto/tools/qmakelib/tst_qmakelib.cpp @@ -76,10 +76,8 @@ void tst_qmakelib::proString() QCOMPARE(ProString(qs2, 3, 13).trimmed().toQString(), QStringLiteral("spacy string")); QCOMPARE(ProString(qs2, 1, 17).trimmed().toQString(), QStringLiteral("spacy string")); - QVERIFY(s2.toQStringRef().string()->isSharedWith(qs1)); s2.prepend(ProString("there ")); QCOMPARE(s2.toQString(), QStringLiteral("there is a str")); - QVERIFY(!s2.toQStringRef().string()->isSharedWith(qs1)); ProString s3("this is a longish string with bells and whistles"); s3 = s3.mid(18, 17); @@ -129,7 +127,6 @@ void tst_qmakelib::proString() ProString s5; s5.append(sl2); QCOMPARE(s5.toQString(), QStringLiteral("foo")); - QVERIFY(s5.toQStringRef().string()->isSharedWith(*sl2.first().toQStringRef().string())); QCOMPARE(ProString("one") + ProString(" more"), QStringLiteral("one more")); } -- cgit v1.2.3