diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-06-01 15:08:39 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-06-01 19:34:28 (GMT) |
commit | f1249f94c07654f0b76e7a90fb81ed5b58cd30f7 (patch) | |
tree | f8a18a3bbc7b4b0c3bf6f11b3cb2aa39e018adbe /tools/linguist/shared/proitems.h | |
parent | 9f71cffea1d5cdac94ae7368ffa7f54183ac33a4 (diff) | |
download | Qt-f1249f94c07654f0b76e7a90fb81ed5b58cd30f7.zip Qt-f1249f94c07654f0b76e7a90fb81ed5b58cd30f7.tar.gz Qt-f1249f94c07654f0b76e7a90fb81ed5b58cd30f7.tar.bz2 |
synchronize qmake project parser with qt creator
qt creator as of ddb918f.
not feeling like replaying the whole history ...
Diffstat (limited to 'tools/linguist/shared/proitems.h')
-rw-r--r-- | tools/linguist/shared/proitems.h | 354 |
1 files changed, 164 insertions, 190 deletions
diff --git a/tools/linguist/shared/proitems.h b/tools/linguist/shared/proitems.h index f4bf183..4967b27 100644 --- a/tools/linguist/shared/proitems.h +++ b/tools/linguist/shared/proitems.h @@ -1,246 +1,220 @@ -/**************************************************************************** +/************************************************************************** ** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) ** -** This file is part of the Qt Linguist of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage +** ** 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: +** 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. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** ** 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. ** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. ** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +**************************************************************************/ #ifndef PROITEMS_H #define PROITEMS_H +#include "proparser_global.h" #include <QtCore/QString> -#include <QtCore/QList> +#include <QtCore/QVector> QT_BEGIN_NAMESPACE -struct AbstractProItemVisitor; - -class ProItem -{ +#ifdef PROPARSER_THREAD_SAFE +typedef QAtomicInt ProItemRefCount; +#else +class ProItemRefCount { public: - enum ProItemKind { - ValueKind, - FunctionKind, - ConditionKind, - OperatorKind, - BlockKind - }; - - enum ProItemReturn { - ReturnFalse, - ReturnTrue, - ReturnBreak, - ReturnNext, - ReturnLoop, - ReturnSkip, - ReturnReturn - }; - - ProItem() : m_lineNumber(0) {} - virtual ~ProItem() {} - - virtual ProItemKind kind() const = 0; - - void setComment(const QString &comment); - QString comment() const; - - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor) = 0; - int lineNumber() const { return m_lineNumber; } - void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; } - + 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: - QString m_comment; - int m_lineNumber; + int m_cnt; }; +#endif -class ProBlock : public ProItem -{ -public: - enum ProBlockKind { - NormalKind = 0x00, - ScopeKind = 0x01, - ScopeContentsKind = 0x02, - VariableKind = 0x04, - ProFileKind = 0x08, - FunctionBodyKind = 0x10, - SingleLine = 0x80 - }; - - ProBlock(ProBlock *parent); - ~ProBlock(); - - void appendItem(ProItem *proitem); - void setItems(const QList<ProItem *> &proitems); - QList<ProItem *> items() const; - - void setBlockKind(int blockKind); - int blockKind() const; - - void setParent(ProBlock *parent); - ProBlock *parent() const; - - void ref() { ++m_refCount; } - void deref() { if (!--m_refCount) delete this; } - - ProItem::ProItemKind kind() const; - - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor); -protected: - QList<ProItem *> m_proitems; -private: - ProBlock *m_parent; - int m_blockKind; - int m_refCount; -}; - -class ProVariable : public ProBlock -{ -public: - enum VariableOperator { - AddOperator = 0, - RemoveOperator = 1, - ReplaceOperator = 2, - SetOperator = 3, - UniqueAddOperator = 4 - }; - - ProVariable(const QString &name, ProBlock *parent); +namespace ProStringConstants { +enum OmitPreHashing { NoHash }; +} - void setVariableOperator(VariableOperator variableKind); - VariableOperator variableOperator() const; +class ProStringList; +class ProFile; - void setVariable(const QString &name); - QString variable() const; - - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor); -private: - VariableOperator m_variableKind; - QString m_variable; -}; - -class ProValue : public ProItem -{ +class ProString { public: - ProValue(const QString &value, ProVariable *variable); - - void setValue(const QString &value); - QString value() const; - - void setVariable(ProVariable *variable); - ProVariable *variable() const; + 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); + 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); + void setValue(const QString &str); + void setValue(const QString &str, ProStringConstants::OmitPreHashing); + ProString &setSource(const ProString &other) { m_file = other.m_file; return *this; } + ProString &setSource(const ProFile *pro) { m_file = pro; return *this; } + const ProFile *sourceFile() const { return m_file; } + QString toQString() const; + QString &toQString(QString &tmp) const; + ProString &operator+=(const ProString &other); + ProString &append(const ProString &other, bool *pending = 0); + ProString &append(const ProStringList &other, bool *pending = 0, bool skipEmpty1st = false); + 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; } + + static uint hash(const QChar *p, int n); - ProItem::ProItemKind kind() const; - - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor); private: - QString m_value; - ProVariable *m_variable; + QString m_string; + int m_offset, m_length; + const ProFile *m_file; + mutable uint m_hash; + QChar *prepareAppend(int extraLen); + 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); -class ProFunction : public ProItem -{ -public: - explicit ProFunction(const QString &text); - - void setText(const QString &text); - QString text() const; +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; } - ProItem::ProItemKind kind() const; - - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor); -private: - QString m_text; -}; - -class ProCondition : public ProItem -{ +class ProStringList : public QVector<ProString> { public: - explicit ProCondition(const QString &text); - - void setText(const QString &text); - QString text() const; - - ProItem::ProItemKind kind() const; - - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor); -private: - QString m_text; + ProStringList() {} + ProStringList(const ProString &str) { *this << str; } + QString join(const QString &sep) const; + void removeDuplicates(); }; -class ProOperator : public ProItem -{ -public: - enum OperatorKind { - OrOperator = 1, - NotOperator = 2 - }; - - explicit ProOperator(OperatorKind operatorKind); - - void setOperatorKind(OperatorKind operatorKind); - OperatorKind operatorKind() const; - - ProItem::ProItemKind kind() const; - - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor); -private: - OperatorKind m_operatorKind; +// 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 + // - 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 + // - 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 + 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) + TokMask = 0xff, + TokQuoted = 0x100, // The expression is quoted => join expanded stringlist + TokNewStr = 0x200 // Next stringlist element }; -class ProFile : public ProBlock +class PROPARSER_EXPORT ProFile { public: explicit ProFile(const QString &fileName); ~ProFile(); - QString displayFileName() const; - QString fileName() const; - QString directoryName() const; + 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(); } - void setModified(bool modified); - bool isModified() const; + void ref() { m_refCount.ref(); } + void deref() { if (!m_refCount.deref()) delete this; } - virtual ProItemReturn Accept(AbstractProItemVisitor *visitor); + bool isOk() const { return m_ok; } + void setOk(bool ok) { m_ok = ok; } private: + ProItemRefCount m_refCount; + QString m_proitems; QString m_fileName; - QString m_displayFileName; QString m_directoryName; - bool m_modified; + bool m_ok; }; QT_END_NAMESPACE |