Files
qt-creator/src/shared/proparser/proitems.h

194 lines
5.2 KiB
C
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 12:01:29 +01:00
#ifndef PROITEMS_H
#define PROITEMS_H
#include <QtCore/QString>
#include <QtCore/QList>
QT_BEGIN_NAMESPACE
#ifdef PROPARSER_THREAD_SAFE
typedef QAtomicInt ProItemRefCount;
#else
class ProItemRefCount {
public:
ProItemRefCount() : m_cnt(0) {}
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
2008-12-02 12:01:29 +01:00
class ProItem
{
public:
enum ProItemKind {
ConditionKind,
OperatorKind,
VariableKind,
2008-12-02 12:01:29 +01:00
BlockKind
};
2008-12-04 20:51:30 +01:00
enum ProItemReturn {
ReturnFalse,
ReturnTrue,
ReturnBreak,
ReturnNext,
ReturnLoop,
ReturnSkip,
ReturnReturn
};
ProItem(ProItemKind kind) : m_kind(kind), m_lineNumber(0) {}
2008-12-02 12:01:29 +01:00
ProItemKind kind() const { return m_kind; }
2008-12-02 12:01:29 +01:00
int lineNumber() const { return m_lineNumber; }
void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; }
ProItem *next() const { return m_next; }
ProItem **nextRef() { return &m_next; }
2008-12-02 12:01:29 +01:00
private:
ProItem *m_next;
ProItemKind m_kind;
2008-12-02 12:01:29 +01:00
int m_lineNumber;
friend class ProBlock; // C++ is braindead ...
2008-12-02 12:01:29 +01:00
};
class ProBlock : public ProItem
{
public:
enum ProBlockKind {
NormalKind = 0x00,
ScopeKind = 0x01,
ScopeContentsKind = 0x02,
ProFileKind = 0x08,
FunctionBodyKind = 0x10,
SingleLine = 0x80
2008-12-02 12:01:29 +01:00
};
2010-02-03 10:08:45 +01:00
ProBlock();
2008-12-02 12:01:29 +01:00
~ProBlock();
2010-02-03 10:09:15 +01:00
void setBlockKind(int blockKind) { m_blockKind = blockKind; }
int blockKind() const { return m_blockKind; }
2008-12-02 12:01:29 +01:00
ProItem *items() const { return m_proitems; }
ProItem **itemsRef() { return &m_proitems; }
void ref() { m_refCount.ref(); }
void deref() { if (!m_refCount.deref()) delete this; }
2008-12-02 12:01:29 +01:00
private:
ProItem *m_proitems;
2008-12-02 12:01:29 +01:00
int m_blockKind;
friend class ProFile; // for the pseudo-virtual d'tor
ProItemRefCount m_refCount;
2008-12-02 12:01:29 +01:00
};
class ProVariable : public ProItem
2008-12-02 12:01:29 +01:00
{
public:
enum VariableOperator {
AddOperator = 0,
RemoveOperator = 1,
ReplaceOperator = 2,
SetOperator = 3,
UniqueAddOperator = 4
};
ProVariable(const QString &name) : ProItem(VariableKind), m_variableKind(SetOperator), m_variable(name) {}
2010-02-03 10:09:15 +01:00
void setVariableOperator(VariableOperator variableKind) { m_variableKind = variableKind; }
VariableOperator variableOperator() const { return m_variableKind; }
void setVariable(const QString &name) { m_variable = name; }
QString variable() const { return m_variable; }
void setValue(const QString &value) { m_value = value; }
QString value() const { return m_value; }
2008-12-02 12:01:29 +01:00
private:
VariableOperator m_variableKind;
QString m_variable;
2008-12-02 12:01:29 +01:00
QString m_value;
};
class ProCondition : public ProItem
{
public:
explicit ProCondition(const QString &text) : ProItem(ConditionKind), m_text(text) {}
2010-02-03 10:09:15 +01:00
void setText(const QString &text) { m_text = text; }
QString text() const { return m_text; }
2008-12-02 12:01:29 +01:00
private:
QString m_text;
};
class ProOperator : public ProItem
{
public:
enum OperatorKind {
OrOperator = 1,
NotOperator = 2
};
explicit ProOperator(OperatorKind operatorKind) : ProItem(ProItem::OperatorKind), m_operatorKind(operatorKind) {}
2010-02-03 10:09:15 +01:00
void setOperatorKind(OperatorKind operatorKind) { m_operatorKind = operatorKind; }
OperatorKind operatorKind() const { return m_operatorKind; }
2008-12-02 12:01:29 +01:00
private:
OperatorKind m_operatorKind;
};
class ProFile : public ProBlock
2008-12-02 12:01:29 +01:00
{
public:
explicit ProFile(const QString &fileName);
2010-02-03 10:09:15 +01:00
QString displayFileName() const { return m_displayFileName; }
QString fileName() const { return m_fileName; }
QString directoryName() const { return m_directoryName; }
2008-12-02 12:01:29 +01:00
// d'tor is not virtual
void deref() { if (!m_refCount.deref()) delete this; }
2008-12-02 12:01:29 +01:00
private:
QString m_fileName;
QString m_displayFileName;
2008-12-19 21:35:10 +01:00
QString m_directoryName;
2008-12-02 12:01:29 +01:00
};
QT_END_NAMESPACE
#endif // PROITEMS_H