KVIrc 5.2.4
Developer APIs
KviKvsTreeNodeExpression.h
Go to the documentation of this file.
1#ifndef _KVI_KVS_TREENODE_EXPRESSION_H_
2#define _KVI_KVS_TREENODE_EXPRESSION_H_
3//=============================================================================
4//
5// File : KviKvsTreeNodeExpression.h
6// Creation date : Mon 06 Oct 2003 01.33 CEST by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2003-2010 Szymon Stefanek (pragma at kvirc dot net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
27#include "KviQString.h"
28#include "KviKvsVariant.h"
29#include "KviKvsTreeNodeData.h"
30
31// absolute precedence (~operand part)
32#define PREC_MAXIMUM -10
33
34#define PREC_OP_LOGICALNOT -3 /* ! */
35#define PREC_OP_BITWISENOT -2 /* ~ */
36#define PREC_OP_NEGATE -1 /* - */
37// high precedence
38#define PREC_OP_BITWISEAND 0 /* & */
39#define PREC_OP_BITWISEOR 1 /* | */
40#define PREC_OP_BITWISEXOR 2 /* ^ */
41
42#define PREC_OP_SHIFTRIGHT 3 /* >> */
43#define PREC_OP_SHIFTLEFT 3 /* << */
44
45#define PREC_OP_MULTIPLICATION 5 /* * */
46#define PREC_OP_DIVISION 5 /* / */
47#define PREC_OP_MODULUS 5 /* % */
48
49#define PREC_OP_SUM 8 /* + */
50#define PREC_OP_SUBTRACTION 8 /* - */
51
52#define PREC_OP_GREATERTHAN 11 /* > */ /* Case sensitive (normal for numbers) */
53#define PREC_OP_LOWERTHAN 11 /* < */ /* Case sensitive (normal for numbers) */
54
55#define PREC_OP_EQUALTO 12 /* == */ /* Case sensitive comparison for strings or normal comp.fr numbers */
56
57#define PREC_OP_GREATEROREQUALTO 14 /* >= */ /* Case sensitive (normal for numbers) */
58#define PREC_OP_LOWEROREQUALTO 14 /* <= */ /* Case sensitive (normal for numbers) */
59
60#define PREC_OP_NOTEQUALTO 15 /* != */ /* Case sensitive (normal for numbers) */
61
62#define PREC_OP_AND 16 /* && */
63#define PREC_OP_OR 17 /* || */
64#define PREC_OP_XOR 18 /* ^^ */
65// low precedence
66
68{
69 // this class is never instantiated
70public:
71 KviKvsTreeNodeExpression(const QChar * pLocation);
73
74protected:
76
77public:
78 virtual void contextDescription(QString & szBuffer);
79 virtual void dump(const char * prefix);
80 virtual int precedence();
81 virtual KviKvsTreeNodeExpression * left();
82 virtual KviKvsTreeNodeExpression * right();
83 virtual void setLeft(KviKvsTreeNodeExpression * pLeft);
84 virtual void setRight(KviKvsTreeNodeExpression * pRight);
85 virtual int firstBinaryOperator();
86 KviKvsTreeNodeExpression * parentExpression() { return m_pParentExpression; };
87 void setParentExpression(KviKvsTreeNodeExpression * pParent) { m_pParentExpression = pParent; };
88 virtual KviKvsTreeNodeExpression * parentWithPrecedenceLowerThan(int iPrec);
89};
90
92{
93public:
94 KviKvsTreeNodeExpressionVariableOperand(const QChar * pLocation, KviKvsTreeNodeData * pData);
96
97protected:
98 KviKvsTreeNodeData * m_pData; // can't be null
99public:
100 virtual void contextDescription(QString & szBuffer);
101 virtual void dump(const char * prefix);
102 virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult);
103};
104
106{
107public:
108 KviKvsTreeNodeExpressionConstantOperand(const QChar * pLocation, KviKvsVariant * pConstant);
110
111public:
113
114public:
115 virtual void contextDescription(QString & szBuffer);
116 virtual void dump(const char * prefix);
117 virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult);
118};
119
121{
122public:
123 KviKvsTreeNodeExpressionOperator(const QChar * pLocation);
125
126public:
127 virtual void contextDescription(QString & szBuffer);
128 virtual void dump(const char * prefix);
129};
130
132{
133public:
134 KviKvsTreeNodeExpressionUnaryOperator(const QChar * pLocation, KviKvsTreeNodeExpression * pData);
136
137protected:
139 KviKvsNumber m_nData; // result of the number evaluation
140public:
141 virtual void contextDescription(QString & szBuffer);
142 virtual void dump(const char * prefix);
143 bool evaluateOperand(KviKvsRunTimeContext * c);
144};
145
147{
148public:
151
152public:
153 virtual int precedence();
154 virtual void contextDescription(QString & szBuffer);
155 virtual void dump(const char * prefix);
156 virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult);
157};
158
160{
161public:
164
165public:
166 virtual int precedence();
167 virtual void contextDescription(QString & szBuffer);
168 virtual void dump(const char * prefix);
169 virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult);
170};
171
173{
174public:
177
178public:
179 virtual int precedence();
180 virtual void contextDescription(QString & szBuffer);
181 virtual void dump(const char * prefix);
182 virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult);
183};
184
186{
187public:
188 KviKvsTreeNodeExpressionBinaryOperator(const QChar * pLocation);
190
191protected:
192 KviKvsTreeNodeExpression * m_pLeft; // can be zero only during parsing (and thus when deleting)
193 KviKvsTreeNodeExpression * m_pRight; // can be zero only during parsing (and thus when deleting)
194 KviKvsNumber m_nLeft; // buffer used to evaluate numeric operands
195 KviKvsNumber m_nRight; // buffer used to evaluate numeric operands
196public:
197 virtual KviKvsTreeNodeExpression * left();
198 virtual KviKvsTreeNodeExpression * right();
199 void setLeft(KviKvsTreeNodeExpression * pLeft);
200 void setRight(KviKvsTreeNodeExpression * pRight);
201 virtual int firstBinaryOperator();
202
203public:
204 void dumpOperands(const char * prefix);
205 virtual void contextDescription(QString & szBuffer);
206 virtual void dump(const char * prefix);
207
208protected:
209 bool evaluateOperands(KviKvsRunTimeContext * c);
210};
211
212#define DECLARE_BINARY_OPERATOR(__name) \
213 class KVIRC_API __name : public KviKvsTreeNodeExpressionBinaryOperator \
214 { \
215 public: \
216 __name(const QChar * pLocation); \
217 ~__name(); \
218 \
219 public: \
220 virtual void contextDescription(QString & szBuffer); \
221 virtual void dump(const char * prefix); \
222 virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult); \
223 virtual int precedence(); \
224 }
225
226DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorSum);
227DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorMultiplication);
228DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorSubtraction);
229DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorDivision);
230DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorModulus);
231DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseAnd);
232DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseOr);
233DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseXor);
234DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorShiftLeft);
235DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorShiftRight);
236DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorAnd);
237DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorOr);
238DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorXor);
239DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorGreaterThan);
240DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorLowerThan);
241DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorGreaterOrEqualTo);
242DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorLowerOrEqualTo);
243DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorEqualTo);
244DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorNotEqualTo);
245
246#endif
#define DECLARE_BINARY_OPERATOR(__name)
Definition KviKvsTreeNodeExpression.h:212
Handling of variant data type in KVS.
Helper functions for the QString class.
A class which maps every number.
Definition KviKvsVariant.h:50
Definition KviKvsRunTimeContext.h:104
Definition KviKvsTreeNodeData.h:35
virtual void contextDescription(QString &szBuffer)
Sets the buffer.
Definition KviKvsTreeNodeData.cpp:36
virtual bool evaluateReadOnly(KviKvsRunTimeContext *c, KviKvsVariant *pBuffer)
Definition KviKvsTreeNodeData.cpp:78
virtual void dump(const char *prefix)
Dumps the tree.
Definition KviKvsTreeNodeData.cpp:41
Definition KviKvsTreeNodeExpression.h:186
KviKvsNumber m_nRight
Definition KviKvsTreeNodeExpression.h:195
KviKvsNumber m_nLeft
Definition KviKvsTreeNodeExpression.h:194
KviKvsTreeNodeExpression * m_pLeft
Definition KviKvsTreeNodeExpression.h:192
KviKvsTreeNodeExpression * m_pRight
Definition KviKvsTreeNodeExpression.h:193
Definition KviKvsTreeNodeExpression.h:106
KviKvsVariant * m_pConstant
Definition KviKvsTreeNodeExpression.h:112
Definition KviKvsTreeNodeExpression.h:121
Definition KviKvsTreeNodeExpression.h:160
Definition KviKvsTreeNodeExpression.h:173
Definition KviKvsTreeNodeExpression.h:147
Definition KviKvsTreeNodeExpression.h:132
KviKvsNumber m_nData
Definition KviKvsTreeNodeExpression.h:139
KviKvsTreeNodeExpression * m_pData
Definition KviKvsTreeNodeExpression.h:138
Definition KviKvsTreeNodeExpression.h:92
KviKvsTreeNodeData * m_pData
Definition KviKvsTreeNodeExpression.h:98
Definition KviKvsTreeNodeExpression.h:68
KviKvsTreeNodeExpression * parentExpression()
Definition KviKvsTreeNodeExpression.h:86
void setParentExpression(KviKvsTreeNodeExpression *pParent)
Definition KviKvsTreeNodeExpression.h:87
KviKvsTreeNodeExpression * m_pParentExpression
Definition KviKvsTreeNodeExpression.h:75
This class defines a new data type which contains variant data.
Definition KviKvsVariant.h:352
#define KVIRC_API
Definition kvi_settings.h:127
char szBuffer[4096]
Definition winamp.cpp:77