2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 12:57:59 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#ifndef PROITEMS_H
|
|
|
|
|
#define PROITEMS_H
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QString>
|
2010-04-27 18:39:10 +02:00
|
|
|
#include <QtCore/QVector>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
2010-02-26 12:53:30 +01:00
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
|
typedef QAtomicInt ProItemRefCount;
|
|
|
|
|
#else
|
|
|
|
|
class ProItemRefCount {
|
|
|
|
|
public:
|
2010-04-19 22:35:58 +02:00
|
|
|
ProItemRefCount(int cnt = 0) : m_cnt(cnt) {}
|
2010-02-26 12:53:30 +01:00
|
|
|
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
|
|
|
|
|
|
2010-04-27 18:39:10 +02:00
|
|
|
namespace ProStringConstants {
|
|
|
|
|
enum OmitPreHashing { NoHash };
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-01 18:43:11 +02:00
|
|
|
class ProStringList;
|
2011-04-20 18:19:33 +02:00
|
|
|
class ProFile;
|
2010-06-01 18:43:11 +02:00
|
|
|
|
2010-04-27 18:39:10 +02:00
|
|
|
class ProString {
|
|
|
|
|
public:
|
|
|
|
|
ProString();
|
|
|
|
|
ProString(const ProString &other);
|
|
|
|
|
ProString(const ProString &other, ProStringConstants::OmitPreHashing);
|
|
|
|
|
explicit ProString(const QString &str);
|
|
|
|
|
ProString(const QString &str, ProStringConstants::OmitPreHashing);
|
|
|
|
|
explicit ProString(const char *str);
|
|
|
|
|
ProString(const char *str, ProStringConstants::OmitPreHashing);
|
2010-05-11 12:24:05 +02:00
|
|
|
ProString(const QString &str, int offset, int length);
|
|
|
|
|
ProString(const QString &str, int offset, int length, uint hash);
|
|
|
|
|
ProString(const QString &str, int offset, int length, ProStringConstants::OmitPreHashing);
|
2011-04-20 18:19:33 +02:00
|
|
|
void setSource(const ProFile *pro) { m_file = pro; }
|
|
|
|
|
const ProFile *sourceFile() const { return m_file; }
|
2010-04-27 18:39:10 +02:00
|
|
|
QString toQString() const;
|
|
|
|
|
QString &toQString(QString &tmp) const;
|
2010-06-01 18:43:11 +02:00
|
|
|
ProString &operator+=(const ProString &other);
|
|
|
|
|
ProString &append(const ProString &other, bool *pending = 0);
|
|
|
|
|
ProString &append(const ProStringList &other, bool *pending = 0, bool skipEmpty1st = false);
|
2010-04-27 18:39:10 +02:00
|
|
|
bool operator==(const ProString &other) const;
|
|
|
|
|
bool operator==(const QString &other) const;
|
|
|
|
|
bool operator==(const QLatin1String &other) const;
|
|
|
|
|
bool operator!=(const ProString &other) const { return !(*this == other); }
|
|
|
|
|
bool operator!=(const QString &other) const { return !(*this == other); }
|
|
|
|
|
bool operator!=(const QLatin1String &other) const { return !(*this == other); }
|
|
|
|
|
bool isEmpty() const { return !m_length; }
|
|
|
|
|
int size() const { return m_length; }
|
|
|
|
|
const QChar *constData() const { return m_string.constData() + m_offset; }
|
|
|
|
|
ProString mid(int off, int len = -1) const;
|
|
|
|
|
ProString left(int len) const { return mid(0, len); }
|
|
|
|
|
ProString right(int len) const { return mid(qMax(0, size() - len)); }
|
|
|
|
|
ProString trimmed() const;
|
|
|
|
|
void clear() { m_string.clear(); m_length = 0; }
|
|
|
|
|
|
2010-05-11 12:24:05 +02:00
|
|
|
static uint hash(const QChar *p, int n);
|
|
|
|
|
|
2010-04-27 18:39:10 +02:00
|
|
|
private:
|
|
|
|
|
QString m_string;
|
|
|
|
|
int m_offset, m_length;
|
2011-04-20 18:19:33 +02:00
|
|
|
const ProFile *m_file;
|
2010-04-27 18:39:10 +02:00
|
|
|
mutable uint m_hash;
|
2010-06-01 18:43:11 +02:00
|
|
|
QChar *prepareAppend(int extraLen);
|
2010-04-27 18:39:10 +02:00
|
|
|
uint updatedHash() const;
|
|
|
|
|
friend uint qHash(const ProString &str);
|
|
|
|
|
friend QString operator+(const ProString &one, const ProString &two);
|
|
|
|
|
};
|
|
|
|
|
Q_DECLARE_TYPEINFO(ProString, Q_MOVABLE_TYPE);
|
|
|
|
|
|
|
|
|
|
uint qHash(const ProString &str);
|
|
|
|
|
QString operator+(const ProString &one, const ProString &two);
|
|
|
|
|
inline QString operator+(const ProString &one, const QString &two)
|
|
|
|
|
{ return one + ProString(two, ProStringConstants::NoHash); }
|
|
|
|
|
inline QString operator+(const QString &one, const ProString &two)
|
|
|
|
|
{ return ProString(one, ProStringConstants::NoHash) + two; }
|
|
|
|
|
|
|
|
|
|
class ProStringList : public QVector<ProString> {
|
|
|
|
|
public:
|
|
|
|
|
ProStringList() {}
|
|
|
|
|
ProStringList(const ProString &str) { *this << str; }
|
|
|
|
|
QString join(const QString &sep) const;
|
|
|
|
|
void removeDuplicates();
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-11 12:24:05 +02:00
|
|
|
// These token definitions affect both ProFileEvaluator and ProWriter
|
|
|
|
|
enum ProToken {
|
|
|
|
|
TokTerminator = 0, // end of stream (possibly not included in length; must be zero)
|
2010-06-14 14:43:00 +02:00
|
|
|
TokLine, // line marker:
|
2010-05-11 12:24:05 +02:00
|
|
|
// - line (1)
|
2010-06-14 14:43:00 +02:00
|
|
|
TokAssign, // variable =
|
|
|
|
|
TokAppend, // variable +=
|
2010-06-01 18:43:11 +02:00
|
|
|
TokAppendUnique, // variable *=
|
|
|
|
|
TokRemove, // variable -=
|
|
|
|
|
TokReplace, // variable ~=
|
|
|
|
|
// previous literal/expansion is a variable manipulation
|
|
|
|
|
// - value expression + TokValueTerminator
|
2010-06-14 14:43:00 +02:00
|
|
|
TokValueTerminator, // assignment value terminator
|
|
|
|
|
TokLiteral, // literal string (fully dequoted)
|
2010-06-01 18:43:11 +02:00
|
|
|
// - length (1)
|
|
|
|
|
// - string data (length; unterminated)
|
2010-06-14 14:43:00 +02:00
|
|
|
TokHashLiteral, // literal string with hash (fully dequoted)
|
2010-06-01 18:43:11 +02:00
|
|
|
// - hash (2)
|
|
|
|
|
// - length (1)
|
|
|
|
|
// - string data (length; unterminated)
|
|
|
|
|
TokVariable, // qmake variable expansion
|
|
|
|
|
// - hash (2)
|
|
|
|
|
// - name length (1)
|
|
|
|
|
// - name (name length; unterminated)
|
2010-06-14 14:43:00 +02:00
|
|
|
TokProperty, // qmake property expansion
|
2010-06-01 18:43:11 +02:00
|
|
|
// - name length (1)
|
|
|
|
|
// - name (name length; unterminated)
|
|
|
|
|
TokEnvVar, // environment variable expansion
|
|
|
|
|
// - name length (1)
|
|
|
|
|
// - name (name length; unterminated)
|
2010-06-14 14:43:00 +02:00
|
|
|
TokFuncName, // replace function expansion
|
2010-06-01 18:43:11 +02:00
|
|
|
// - hash (2)
|
|
|
|
|
// - name length (1)
|
|
|
|
|
// - name (name length; unterminated)
|
|
|
|
|
// - ((nested expansion + TokArgSeparator)* + nested expansion)?
|
|
|
|
|
// - TokFuncTerminator
|
2010-06-14 14:43:00 +02:00
|
|
|
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
|
2010-06-01 18:43:11 +02:00
|
|
|
// - ((nested expansion + TokArgSeparator)* + nested expansion)?
|
|
|
|
|
// - TokFuncTerminator
|
2010-06-14 14:43:00 +02:00
|
|
|
TokNot, // '!' operator
|
2010-05-11 12:24:05 +02:00
|
|
|
TokAnd, // ':' operator
|
|
|
|
|
TokOr, // '|' operator
|
2010-06-14 14:43:00 +02:00
|
|
|
TokBranch, // branch point:
|
2010-05-11 12:24:05 +02:00
|
|
|
// - then block length (2)
|
|
|
|
|
// - then block + TokTerminator (then block length)
|
|
|
|
|
// - else block length (2)
|
|
|
|
|
// - else block + TokTerminator (else block length)
|
2010-06-01 18:43:11 +02:00
|
|
|
TokForLoop, // for loop:
|
2010-05-11 12:24:05 +02:00
|
|
|
// - variable name: hash (2), length (1), chars (length)
|
2010-06-01 18:43:11 +02:00
|
|
|
// - expression: length (2), bytes + TokValueTerminator (length)
|
2010-05-11 12:24:05 +02:00
|
|
|
// - body length (2)
|
|
|
|
|
// - body + TokTerminator (body length)
|
2010-06-14 14:43:00 +02:00
|
|
|
TokTestDef, // test function definition:
|
2010-06-01 18:43:11 +02:00
|
|
|
TokReplaceDef, // replace function definition:
|
2010-05-11 12:24:05 +02:00
|
|
|
// - function name: hash (2), length (1), chars (length)
|
|
|
|
|
// - body length (2)
|
|
|
|
|
// - body + TokTerminator (body length)
|
2010-06-01 18:43:11 +02:00
|
|
|
TokMask = 0xff,
|
|
|
|
|
TokQuoted = 0x100, // The expression is quoted => join expanded stringlist
|
|
|
|
|
TokNewStr = 0x200 // Next stringlist element
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2010-04-19 22:35:58 +02:00
|
|
|
class ProFile
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit ProFile(const QString &fileName);
|
2010-04-19 22:35:58 +02:00
|
|
|
~ProFile();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-02-03 10:09:15 +01:00
|
|
|
QString fileName() const { return m_fileName; }
|
|
|
|
|
QString directoryName() const { return m_directoryName; }
|
2010-05-11 12:24:05 +02:00
|
|
|
const QString &items() const { return m_proitems; }
|
|
|
|
|
QString *itemsRef() { return &m_proitems; }
|
2010-06-23 14:51:43 +02:00
|
|
|
const ushort *tokPtr() const { return (const ushort *)m_proitems.constData(); }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-19 22:35:58 +02:00
|
|
|
void ref() { m_refCount.ref(); }
|
2010-04-01 15:58:00 +02:00
|
|
|
void deref() { if (!m_refCount.deref()) delete this; }
|
|
|
|
|
|
2011-02-09 20:00:44 +01:00
|
|
|
bool isOk() const { return m_ok; }
|
|
|
|
|
void setOk(bool ok) { m_ok = ok; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
2010-04-19 22:35:58 +02:00
|
|
|
ProItemRefCount m_refCount;
|
2010-05-11 12:24:05 +02:00
|
|
|
QString m_proitems;
|
2008-12-02 12:01:29 +01:00
|
|
|
QString m_fileName;
|
2008-12-19 21:35:10 +01:00
|
|
|
QString m_directoryName;
|
2011-02-09 20:00:44 +01:00
|
|
|
bool m_ok;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
#endif // PROITEMS_H
|