2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
#ifndef PROITEMS_H
|
|
|
|
#define PROITEMS_H
|
|
|
|
|
|
|
|
#include "qmake_global.h"
|
|
|
|
|
2019-06-24 15:36:41 +00:00
|
|
|
#include <qdebug.h>
|
2012-09-05 16:29:19 +00:00
|
|
|
#include <qhash.h>
|
2020-07-06 09:11:44 +00:00
|
|
|
#include <qlist.h>
|
2020-01-28 11:48:53 +00:00
|
|
|
#include <qmap.h>
|
2020-07-06 09:11:44 +00:00
|
|
|
#include <qstring.h>
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
class QTextStream;
|
|
|
|
|
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
typedef QAtomicInt ProItemRefCount;
|
|
|
|
#else
|
|
|
|
class ProItemRefCount {
|
|
|
|
public:
|
|
|
|
ProItemRefCount(int cnt = 0) : m_cnt(cnt) {}
|
|
|
|
bool ref() { return ++m_cnt != 0; }
|
|
|
|
bool deref() { return --m_cnt != 0; }
|
|
|
|
ProItemRefCount &operator=(int value) { m_cnt = value; return *this; }
|
|
|
|
private:
|
|
|
|
int m_cnt;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef QT_BUILD_QMAKE
|
2012-09-06 10:21:38 +00:00
|
|
|
# define PROITEM_EXPLICIT explicit
|
|
|
|
#else
|
|
|
|
# define PROITEM_EXPLICIT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class ProKey;
|
|
|
|
class ProStringList;
|
2012-09-05 16:29:19 +00:00
|
|
|
class ProFile;
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
class ProString {
|
|
|
|
public:
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString();
|
|
|
|
ProString(const ProString &other);
|
2019-07-11 14:59:03 +00:00
|
|
|
ProString &operator=(const ProString &) = default;
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
ProString &operator=(const QStringBuilder<A, B> &str)
|
|
|
|
{ return *this = QString(str); }
|
|
|
|
ProString(const QString &str);
|
2020-05-30 21:29:21 +00:00
|
|
|
PROITEM_EXPLICIT ProString(QStringView str);
|
2012-09-05 16:29:19 +00:00
|
|
|
PROITEM_EXPLICIT ProString(const char *str);
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
ProString(const QStringBuilder<A, B> &str)
|
|
|
|
: ProString(QString(str))
|
|
|
|
{}
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString(const QString &str, int offset, int length);
|
|
|
|
void setValue(const QString &str);
|
|
|
|
void clear() { m_string.clear(); m_length = 0; }
|
|
|
|
ProString &setSource(const ProString &other) { m_file = other.m_file; return *this; }
|
2017-08-14 16:30:29 +00:00
|
|
|
ProString &setSource(int id) { m_file = id; return *this; }
|
|
|
|
int sourceFile() const { return m_file; }
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
ProString &prepend(const ProString &other);
|
2018-08-02 22:22:24 +00:00
|
|
|
ProString &append(const ProString &other, bool *pending = nullptr);
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString &append(const QString &other) { return append(ProString(other)); }
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
ProString &append(const QStringBuilder<A, B> &other) { return append(QString(other)); }
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString &append(const QLatin1String other);
|
|
|
|
ProString &append(const char *other) { return append(QLatin1String(other)); }
|
|
|
|
ProString &append(QChar other);
|
2018-08-02 22:22:24 +00:00
|
|
|
ProString &append(const ProStringList &other, bool *pending = nullptr, bool skipEmpty1st = false);
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString &operator+=(const ProString &other) { return append(other); }
|
|
|
|
ProString &operator+=(const QString &other) { return append(other); }
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
ProString &operator+=(const QStringBuilder<A, B> &other) { return append(QString(other)); }
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString &operator+=(const QLatin1String other) { return append(other); }
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString &operator+=(const char *other) { return append(other); }
|
|
|
|
ProString &operator+=(QChar other) { return append(other); }
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
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; }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2020-05-30 21:29:21 +00:00
|
|
|
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); }
|
2012-09-06 10:21:38 +00:00
|
|
|
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); }
|
2020-05-30 21:29:21 +00:00
|
|
|
bool operator<(const ProString &other) const { return toQStringView() < other.toQStringView(); }
|
2012-09-06 10:21:38 +00:00
|
|
|
bool isNull() const { return m_string.isNull(); }
|
2012-09-05 16:29:19 +00:00
|
|
|
bool isEmpty() const { return !m_length; }
|
|
|
|
int length() const { return m_length; }
|
|
|
|
int size() const { return m_length; }
|
|
|
|
QChar at(int i) const { Q_ASSERT((uint)i < (uint)m_length); return constData()[i]; }
|
|
|
|
const QChar *constData() const { return m_string.constData() + m_offset; }
|
|
|
|
ProString mid(int off, int len = -1) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString left(int len) const { return mid(0, len); }
|
|
|
|
ProString right(int len) const { return mid(qMax(0, size() - len)); }
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString trimmed() const;
|
2020-05-30 21:29:21 +00:00
|
|
|
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); }
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
bool startsWith(const QStringBuilder<A, B> &str) { return startsWith(QString(str)); }
|
2020-05-30 21:29:21 +00:00
|
|
|
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); }
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
bool endsWith(const QStringBuilder<A, B> &str) { return endsWith(QString(str)); }
|
2020-05-30 21:29:21 +00:00
|
|
|
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); }
|
2012-09-06 10:21:38 +00:00
|
|
|
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; }
|
2020-05-30 21:29:21 +00:00
|
|
|
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); }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2020-10-02 11:19:48 +00:00
|
|
|
size_t hash() const { return m_hash; }
|
|
|
|
static size_t hash(const QChar *p, int n);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
2017-04-07 15:10:37 +00:00
|
|
|
ALWAYS_INLINE QStringView toQStringView() const { return QStringView(m_string).mid(m_offset, m_length); }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
ALWAYS_INLINE ProKey &toKey() { return *(ProKey *)this; }
|
|
|
|
ALWAYS_INLINE const ProKey &toKey() const { return *(const ProKey *)this; }
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QString toQString() const;
|
|
|
|
QString &toQString(QString &tmp) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2020-05-30 21:29:21 +00:00
|
|
|
QByteArray toLatin1() const { return toQStringView().toLatin1(); }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ProString(const ProKey &other);
|
|
|
|
ProString &operator=(const ProKey &other);
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
enum OmitPreHashing { NoHash };
|
|
|
|
ProString(const ProString &other, OmitPreHashing);
|
|
|
|
|
|
|
|
enum DoPreHashing { DoHash };
|
|
|
|
ALWAYS_INLINE ProString(const QString &str, DoPreHashing);
|
|
|
|
ALWAYS_INLINE ProString(const char *str, DoPreHashing);
|
|
|
|
ALWAYS_INLINE ProString(const QString &str, int offset, int length, DoPreHashing);
|
|
|
|
ALWAYS_INLINE ProString(const QString &str, int offset, int length, uint hash);
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
QString m_string;
|
2012-09-05 16:29:19 +00:00
|
|
|
int m_offset, m_length;
|
2017-08-14 16:30:29 +00:00
|
|
|
int m_file;
|
2020-10-02 11:19:48 +00:00
|
|
|
mutable size_t m_hash;
|
|
|
|
size_t updatedHash() const;
|
2020-01-31 11:11:54 +00:00
|
|
|
friend size_t qHash(const ProString &str);
|
2012-09-06 10:21:38 +00:00
|
|
|
friend QString operator+(const ProString &one, const ProString &two);
|
|
|
|
friend class ProKey;
|
|
|
|
};
|
2020-11-27 10:18:00 +00:00
|
|
|
Q_DECLARE_TYPEINFO(ProString, Q_RELOCATABLE_TYPE);
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2020-04-03 09:49:27 +00:00
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
class ProKey : public ProString {
|
|
|
|
public:
|
|
|
|
ALWAYS_INLINE ProKey() : ProString() {}
|
2012-09-05 16:29:19 +00:00
|
|
|
explicit ProKey(const QString &str);
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
ProKey(const QStringBuilder<A, B> &str)
|
|
|
|
: ProString(str)
|
|
|
|
{}
|
2012-09-05 16:29:19 +00:00
|
|
|
PROITEM_EXPLICIT ProKey(const char *str);
|
|
|
|
ProKey(const QString &str, int off, int len);
|
|
|
|
ProKey(const QString &str, int off, int len, uint hash);
|
|
|
|
void setValue(const QString &str);
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
#ifdef Q_CC_MSVC
|
|
|
|
// Workaround strange MSVC behaviour when exporting classes with ProKey members.
|
|
|
|
ALWAYS_INLINE ProKey(const ProKey &other) : ProString(other.toString()) {}
|
|
|
|
ALWAYS_INLINE ProKey &operator=(const ProKey &other)
|
|
|
|
{
|
|
|
|
toString() = other.toString();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ALWAYS_INLINE ProString &toString() { return *(ProString *)this; }
|
|
|
|
ALWAYS_INLINE const ProString &toString() const { return *(const ProString *)this; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProKey(const ProString &other);
|
|
|
|
};
|
2020-11-27 10:18:00 +00:00
|
|
|
Q_DECLARE_TYPEINFO(ProKey, Q_RELOCATABLE_TYPE);
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2020-04-03 09:49:27 +00:00
|
|
|
template <> struct QConcatenable<ProString> : private QAbstractConcatenable
|
|
|
|
{
|
|
|
|
typedef ProString type;
|
|
|
|
typedef QString ConvertTo;
|
|
|
|
enum { ExactSize = true };
|
|
|
|
static int size(const ProString &a) { return a.length(); }
|
|
|
|
static inline void appendTo(const ProString &a, QChar *&out)
|
|
|
|
{
|
|
|
|
const auto n = a.size();
|
2020-12-01 15:30:54 +00:00
|
|
|
if (!n)
|
|
|
|
return;
|
2020-04-03 09:49:27 +00:00
|
|
|
memcpy(out, a.toQStringView().data(), sizeof(QChar) * n);
|
|
|
|
out += n;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct QConcatenable<ProKey> : private QAbstractConcatenable
|
|
|
|
{
|
|
|
|
typedef ProKey type;
|
|
|
|
typedef QString ConvertTo;
|
|
|
|
enum { ExactSize = true };
|
|
|
|
static int size(const ProKey &a) { return a.length(); }
|
|
|
|
static inline void appendTo(const ProKey &a, QChar *&out)
|
|
|
|
{
|
|
|
|
const auto n = a.size();
|
2020-12-01 15:30:54 +00:00
|
|
|
if (!n)
|
|
|
|
return;
|
2020-04-03 09:49:27 +00:00
|
|
|
memcpy(out, a.toQStringView().data(), sizeof(QChar) * n);
|
|
|
|
out += n;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-01-31 11:11:54 +00:00
|
|
|
size_t qHash(const ProString &str);
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
inline QString &operator+=(QString &that, const ProString &other)
|
2020-05-30 21:29:21 +00:00
|
|
|
{ return that += other.toQStringView(); }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QTextStream &operator<<(QTextStream &t, const ProString &str);
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
QTextStream &operator<<(QTextStream &t, const QStringBuilder<A, B> &str) { return t << QString(str); }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2017-08-14 10:06:35 +00:00
|
|
|
// This class manages read-only access to a ProString via a raw data QString
|
|
|
|
// temporary, ensuring that the latter is accessed exclusively.
|
|
|
|
class ProStringRoUser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProStringRoUser(QString &rs)
|
|
|
|
{
|
|
|
|
m_rs = &rs;
|
|
|
|
}
|
|
|
|
ProStringRoUser(const ProString &ps, QString &rs)
|
|
|
|
: ProStringRoUser(rs)
|
|
|
|
{
|
|
|
|
ps.toQString(rs);
|
|
|
|
}
|
|
|
|
// No destructor, as a RAII pattern cannot be used: references to the
|
|
|
|
// temporary string can legitimately outlive instances of this class
|
|
|
|
// (if they are held by Qt, e.g. in QRegExp).
|
|
|
|
QString &set(const ProString &ps) { return ps.toQString(*m_rs); }
|
|
|
|
QString &str() { return *m_rs; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QString *m_rs;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class manages read-write access to a ProString via a raw data QString
|
|
|
|
// temporary, ensuring that the latter is accessed exclusively, and that raw
|
|
|
|
// data does not leak outside its source's refcounting.
|
|
|
|
class ProStringRwUser : public ProStringRoUser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProStringRwUser(QString &rs)
|
2018-08-02 22:22:24 +00:00
|
|
|
: ProStringRoUser(rs), m_ps(nullptr) {}
|
2017-08-14 10:06:35 +00:00
|
|
|
ProStringRwUser(const ProString &ps, QString &rs)
|
|
|
|
: ProStringRoUser(ps, rs), m_ps(&ps) {}
|
|
|
|
QString &set(const ProString &ps) { m_ps = &ps; return ProStringRoUser::set(ps); }
|
|
|
|
ProString extract(const QString &s) const
|
|
|
|
{ return s.isSharedWith(*m_rs) ? *m_ps : ProString(s).setSource(*m_ps); }
|
|
|
|
ProString extract(const QString &s, const ProStringRwUser &other) const
|
|
|
|
{
|
|
|
|
if (other.m_ps && s.isSharedWith(*other.m_rs))
|
|
|
|
return *other.m_ps;
|
|
|
|
return extract(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ProString *m_ps;
|
|
|
|
};
|
|
|
|
|
2020-07-06 09:11:44 +00:00
|
|
|
class ProStringList : public QList<ProString> {
|
2012-09-06 10:21:38 +00:00
|
|
|
public:
|
|
|
|
ProStringList() {}
|
|
|
|
ProStringList(const ProString &str) { *this << str; }
|
2012-09-05 16:29:19 +00:00
|
|
|
explicit ProStringList(const QStringList &list);
|
|
|
|
QStringList toQStringList() const;
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
ProStringList &operator<<(const ProString &str)
|
2020-07-06 09:11:44 +00:00
|
|
|
{ QList<ProString>::operator<<(str); return *this; }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
int length() const { return size(); }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2016-05-13 13:21:05 +00:00
|
|
|
QString join(const ProString &sep) const;
|
2012-09-05 16:29:19 +00:00
|
|
|
QString join(const QString &sep) const;
|
2012-09-19 15:50:42 +00:00
|
|
|
QString join(QChar sep) const;
|
2020-04-03 09:49:27 +00:00
|
|
|
template<typename A, typename B>
|
|
|
|
QString join(const QStringBuilder<A, B> &str) { return join(QString(str)); }
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2015-01-30 18:18:54 +00:00
|
|
|
void insertUnique(const ProStringList &value);
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
void removeAll(const ProString &str);
|
|
|
|
void removeAll(const char *str);
|
2015-01-30 18:18:54 +00:00
|
|
|
void removeEach(const ProStringList &value);
|
2012-09-05 16:29:19 +00:00
|
|
|
void removeAt(int idx) { remove(idx); }
|
2015-01-30 18:18:54 +00:00
|
|
|
void removeEmpty();
|
2012-09-05 16:29:19 +00:00
|
|
|
void removeDuplicates();
|
|
|
|
|
|
|
|
bool contains(const ProString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
2020-05-30 21:29:21 +00:00
|
|
|
bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
|
2012-09-05 16:29:19 +00:00
|
|
|
{ return contains(ProString(str), cs); }
|
|
|
|
bool contains(const char *str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
2012-09-06 10:21:38 +00:00
|
|
|
};
|
2020-11-27 10:18:00 +00:00
|
|
|
Q_DECLARE_TYPEINFO(ProStringList, Q_RELOCATABLE_TYPE);
|
2012-09-06 10:21:38 +00:00
|
|
|
|
|
|
|
inline ProStringList operator+(const ProStringList &one, const ProStringList &two)
|
|
|
|
{ ProStringList ret = one; ret += two; return ret; }
|
|
|
|
|
2020-01-28 11:48:53 +00:00
|
|
|
typedef QMap<ProKey, ProStringList> ProValueMap;
|
2012-09-06 10:21:38 +00:00
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
// These token definitions affect both ProFileEvaluator and ProWriter
|
|
|
|
enum ProToken {
|
|
|
|
TokTerminator = 0, // end of stream (possibly not included in length; must be zero)
|
|
|
|
TokLine, // line marker:
|
|
|
|
// - line (1)
|
|
|
|
TokAssign, // variable =
|
|
|
|
TokAppend, // variable +=
|
|
|
|
TokAppendUnique, // variable *=
|
|
|
|
TokRemove, // variable -=
|
|
|
|
TokReplace, // variable ~=
|
|
|
|
// previous literal/expansion is a variable manipulation
|
2012-09-05 19:26:28 +00:00
|
|
|
// - lower bound for expected output length (1)
|
2012-09-05 16:29:19 +00:00
|
|
|
// - value expression + TokValueTerminator
|
|
|
|
TokValueTerminator, // assignment value terminator
|
|
|
|
TokLiteral, // literal string (fully dequoted)
|
|
|
|
// - length (1)
|
|
|
|
// - string data (length; unterminated)
|
|
|
|
TokHashLiteral, // literal string with hash (fully dequoted)
|
|
|
|
// - hash (2)
|
|
|
|
// - length (1)
|
|
|
|
// - string data (length; unterminated)
|
|
|
|
TokVariable, // qmake variable expansion
|
|
|
|
// - hash (2)
|
|
|
|
// - name length (1)
|
|
|
|
// - name (name length; unterminated)
|
|
|
|
TokProperty, // qmake property expansion
|
|
|
|
// - hash (2)
|
|
|
|
// - name length (1)
|
|
|
|
// - name (name length; unterminated)
|
|
|
|
TokEnvVar, // environment variable expansion
|
|
|
|
// - name length (1)
|
|
|
|
// - name (name length; unterminated)
|
|
|
|
TokFuncName, // replace function expansion
|
|
|
|
// - hash (2)
|
|
|
|
// - name length (1)
|
|
|
|
// - name (name length; unterminated)
|
|
|
|
// - ((nested expansion + TokArgSeparator)* + nested expansion)?
|
|
|
|
// - TokFuncTerminator
|
|
|
|
TokArgSeparator, // function argument separator
|
|
|
|
TokFuncTerminator, // function argument list terminator
|
|
|
|
TokCondition, // previous literal/expansion is a conditional
|
|
|
|
TokTestCall, // previous literal/expansion is a test function call
|
|
|
|
// - ((nested expansion + TokArgSeparator)* + nested expansion)?
|
|
|
|
// - TokFuncTerminator
|
2012-09-11 17:30:29 +00:00
|
|
|
TokReturn, // previous literal/expansion is a return value
|
|
|
|
TokBreak, // break loop
|
|
|
|
TokNext, // shortcut to next loop iteration
|
2012-09-05 16:29:19 +00:00
|
|
|
TokNot, // '!' operator
|
|
|
|
TokAnd, // ':' operator
|
|
|
|
TokOr, // '|' operator
|
|
|
|
TokBranch, // branch point:
|
|
|
|
// - then block length (2)
|
|
|
|
// - then block + TokTerminator (then block length)
|
|
|
|
// - else block length (2)
|
|
|
|
// - else block + TokTerminator (else block length)
|
|
|
|
TokForLoop, // for loop:
|
|
|
|
// - variable name: hash (2), length (1), chars (length)
|
|
|
|
// - expression: length (2), bytes + TokValueTerminator (length)
|
|
|
|
// - body length (2)
|
|
|
|
// - body + TokTerminator (body length)
|
|
|
|
TokTestDef, // test function definition:
|
|
|
|
TokReplaceDef, // replace function definition:
|
|
|
|
// - function name: hash (2), length (1), chars (length)
|
|
|
|
// - body length (2)
|
|
|
|
// - body + TokTerminator (body length)
|
2016-11-11 10:40:24 +00:00
|
|
|
TokBypassNesting, // escape from function local variable scopes:
|
|
|
|
// - block length (2)
|
|
|
|
// - block + TokTerminator (block length)
|
2012-09-05 16:29:19 +00:00
|
|
|
TokMask = 0xff,
|
|
|
|
TokQuoted = 0x100, // The expression is quoted => join expanded stringlist
|
|
|
|
TokNewStr = 0x200 // Next stringlist element
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMAKE_EXPORT ProFile
|
|
|
|
{
|
|
|
|
public:
|
2017-08-14 16:30:29 +00:00
|
|
|
ProFile(int id, const QString &fileName);
|
2012-09-05 16:29:19 +00:00
|
|
|
~ProFile();
|
|
|
|
|
2017-08-14 16:30:29 +00:00
|
|
|
int id() const { return m_id; }
|
2012-09-05 16:29:19 +00:00
|
|
|
QString fileName() const { return m_fileName; }
|
|
|
|
QString directoryName() const { return m_directoryName; }
|
|
|
|
const QString &items() const { return m_proitems; }
|
|
|
|
QString *itemsRef() { return &m_proitems; }
|
|
|
|
const ushort *tokPtr() const { return (const ushort *)m_proitems.constData(); }
|
2014-03-07 11:56:59 +00:00
|
|
|
const ushort *tokPtrEnd() const { return (const ushort *)m_proitems.constData() + m_proitems.size(); }
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
void ref() { m_refCount.ref(); }
|
|
|
|
void deref() { if (!m_refCount.deref()) delete this; }
|
|
|
|
|
|
|
|
bool isOk() const { return m_ok; }
|
|
|
|
void setOk(bool ok) { m_ok = ok; }
|
|
|
|
|
|
|
|
bool isHostBuild() const { return m_hostBuild; }
|
|
|
|
void setHostBuild(bool host_build) { m_hostBuild = host_build; }
|
|
|
|
|
2015-03-04 20:38:31 +00:00
|
|
|
ProString getStr(const ushort *&tPtr);
|
|
|
|
ProKey getHashStr(const ushort *&tPtr);
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
private:
|
|
|
|
ProItemRefCount m_refCount;
|
|
|
|
QString m_proitems;
|
|
|
|
QString m_fileName;
|
|
|
|
QString m_directoryName;
|
2017-08-14 16:30:29 +00:00
|
|
|
int m_id;
|
2012-09-05 16:29:19 +00:00
|
|
|
bool m_ok;
|
|
|
|
bool m_hostBuild;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProFunctionDef {
|
|
|
|
public:
|
|
|
|
ProFunctionDef(ProFile *pro, int offset) : m_pro(pro), m_offset(offset) { m_pro->ref(); }
|
|
|
|
ProFunctionDef(const ProFunctionDef &o) : m_pro(o.m_pro), m_offset(o.m_offset) { m_pro->ref(); }
|
2019-04-09 11:33:15 +00:00
|
|
|
ProFunctionDef(ProFunctionDef &&other) noexcept
|
2016-02-10 14:43:15 +00:00
|
|
|
: m_pro(other.m_pro), m_offset(other.m_offset) { other.m_pro = nullptr; }
|
2019-07-17 16:03:19 +00:00
|
|
|
~ProFunctionDef() { if (m_pro) m_pro->deref(); }
|
2012-09-05 16:29:19 +00:00
|
|
|
ProFunctionDef &operator=(const ProFunctionDef &o)
|
|
|
|
{
|
|
|
|
if (this != &o) {
|
2019-07-17 16:03:19 +00:00
|
|
|
if (m_pro)
|
|
|
|
m_pro->deref();
|
2012-09-05 16:29:19 +00:00
|
|
|
m_pro = o.m_pro;
|
|
|
|
m_pro->ref();
|
|
|
|
m_offset = o.m_offset;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2019-04-09 11:33:15 +00:00
|
|
|
ProFunctionDef &operator=(ProFunctionDef &&other) noexcept
|
2016-02-10 14:43:15 +00:00
|
|
|
{
|
|
|
|
ProFunctionDef moved(std::move(other));
|
|
|
|
swap(moved);
|
|
|
|
return *this;
|
|
|
|
}
|
2019-04-09 11:33:15 +00:00
|
|
|
void swap(ProFunctionDef &other) noexcept
|
2016-02-10 14:43:15 +00:00
|
|
|
{
|
|
|
|
qSwap(m_pro, other.m_pro);
|
|
|
|
qSwap(m_offset, other.m_offset);
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
ProFile *pro() const { return m_pro; }
|
|
|
|
const ushort *tokPtr() const { return m_pro->tokPtr() + m_offset; }
|
|
|
|
private:
|
|
|
|
ProFile *m_pro;
|
|
|
|
int m_offset;
|
|
|
|
};
|
|
|
|
|
2020-11-27 10:18:00 +00:00
|
|
|
Q_DECLARE_TYPEINFO(ProFunctionDef, Q_RELOCATABLE_TYPE);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
struct ProFunctionDefs {
|
|
|
|
QHash<ProKey, ProFunctionDef> testFunctions;
|
|
|
|
QHash<ProKey, ProFunctionDef> replaceFunctions;
|
|
|
|
};
|
|
|
|
|
2019-06-24 15:36:41 +00:00
|
|
|
QDebug operator<<(QDebug debug, const ProString &str);
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // PROITEMS_H
|