KVIrc  4.9.2
DeveloperAPIs
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
70 public:
71  KviKvsTreeNodeExpression(const QChar * pLocation);
73 
74 protected:
76 
77 public:
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 {
93 public:
94  KviKvsTreeNodeExpressionVariableOperand(const QChar * pLocation, KviKvsTreeNodeData * pData);
96 
97 protected:
98  KviKvsTreeNodeData * m_pData; // can't be null
99 public:
100  virtual void contextDescription(QString & szBuffer);
101  virtual void dump(const char * prefix);
102  virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult);
103 };
104 
106 {
107 public:
108  KviKvsTreeNodeExpressionConstantOperand(const QChar * pLocation, KviKvsVariant * pConstant);
110 
111 public:
113 
114 public:
115  virtual void contextDescription(QString & szBuffer);
116  virtual void dump(const char * prefix);
117  virtual bool evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pResult);
118 };
119 
121 {
122 public:
123  KviKvsTreeNodeExpressionOperator(const QChar * pLocation);
125 
126 public:
127  virtual void contextDescription(QString & szBuffer);
128  virtual void dump(const char * prefix);
129 };
130 
132 {
133 public:
134  KviKvsTreeNodeExpressionUnaryOperator(const QChar * pLocation, KviKvsTreeNodeExpression * pData);
136 
137 protected:
138  KviKvsTreeNodeExpression * m_pData; // can't be null!
139  KviKvsNumber m_nData; // result of the number evaluation
140 public:
141  virtual void contextDescription(QString & szBuffer);
142  virtual void dump(const char * prefix);
143  bool evaluateOperand(KviKvsRunTimeContext * c);
144 };
145 
147 {
148 public:
151 
152 public:
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 {
161 public:
164 
165 public:
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 {
174 public:
177 
178 public:
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 {
187 public:
188  KviKvsTreeNodeExpressionBinaryOperator(const QChar * pLocation);
190 
191 protected:
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
196 public:
197  virtual KviKvsTreeNodeExpression * left();
198  virtual KviKvsTreeNodeExpression * right();
199  void setLeft(KviKvsTreeNodeExpression * pLeft);
200  void setRight(KviKvsTreeNodeExpression * pRight);
201  virtual int firstBinaryOperator();
202 
203 public:
204  void dumpOperands(const char * prefix);
205  virtual void contextDescription(QString & szBuffer);
206  virtual void dump(const char * prefix);
207 
208 protected:
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 
226 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorSum);
227 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorMultiplication);
228 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorSubtraction);
229 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorDivision);
230 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorModulus);
231 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseAnd);
232 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseOr);
233 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseXor);
234 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorShiftLeft);
235 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorShiftRight);
236 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorAnd);
237 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorOr);
238 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorXor);
239 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorGreaterThan);
240 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorLowerThan);
241 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorGreaterOrEqualTo);
242 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorLowerOrEqualTo);
243 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorEqualTo);
244 DECLARE_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorNotEqualTo);
245 
246 #endif
virtual bool evaluateReadOnly(KviKvsRunTimeContext *c, KviKvsVariant *pBuffer)
Definition: KviKvsTreeNodeData.cpp:78
KviKvsVariant * m_pConstant
Definition: KviKvsTreeNodeExpression.h:112
This class defines a new data type which contains variant data.
Definition: KviKvsVariant.h:351
virtual void contextDescription(QString &szBuffer)
Sets the buffer.
Definition: KviKvsTreeNodeExpression.cpp:39
#define KVIRC_API
Definition: kvi_settings.h:128
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
virtual void contextDescription(QString &szBuffer)
Sets the buffer.
Definition: KviKvsTreeNodeExpression.cpp:160
KviKvsNumber m_nLeft
Definition: KviKvsTreeNodeExpression.h:194
virtual int precedence()
Definition: KviKvsTreeNodeExpression.cpp:49
#define DECLARE_BINARY_OPERATOR(__name)
Definition: KviKvsTreeNodeExpression.h:212
KviKvsNumber m_nData
Definition: KviKvsTreeNodeExpression.h:139
virtual KviKvsTreeNodeExpression * left()
Definition: KviKvsTreeNodeExpression.cpp:54
Definition: KviKvsTreeNodeExpression.h:185
KviKvsTreeNodeExpression * m_pParentExpression
Definition: KviKvsTreeNodeExpression.h:75
Definition: KviKvsTreeNodeExpression.h:131
Definition: KviKvsTreeNodeExpression.h:105
virtual void dump(const char *prefix)
Dumps the tree.
Definition: KviKvsTreeNodeExpression.cpp:165
KviKvsTreeNodeExpression * m_pData
Definition: KviKvsTreeNodeExpression.h:138
virtual void dump(const char *prefix)
Dumps the tree.
Definition: KviKvsTreeNodeExpression.cpp:188
Definition: KviKvsTreeNodeExpression.h:67
virtual void setLeft(KviKvsTreeNodeExpression *pLeft)
Definition: KviKvsTreeNodeExpression.cpp:66
virtual void contextDescription(QString &szBuffer)
Sets the buffer.
Definition: KviKvsTreeNodeExpression.cpp:183
KviKvsNumber m_nRight
Definition: KviKvsTreeNodeExpression.h:195
KviKvsTreeNodeExpression * m_pRight
Definition: KviKvsTreeNodeExpression.h:193
Definition: KviKvsTreeNodeExpression.h:91
Definition: KviKvsTreeNodeExpression.h:159
virtual void contextDescription(QString &szBuffer)
Sets the buffer.
Definition: KviKvsTreeNodeData.cpp:36
KviKvsTreeNodeExpression * m_pLeft
Definition: KviKvsTreeNodeExpression.h:192
virtual void setRight(KviKvsTreeNodeExpression *pRight)
Definition: KviKvsTreeNodeExpression.cpp:71
virtual KviKvsTreeNodeExpression * right()
Definition: KviKvsTreeNodeExpression.cpp:60
Definition: KviKvsRunTimeContext.h:103
virtual int firstBinaryOperator()
Definition: KviKvsTreeNodeExpression.cpp:85
virtual void dump(const char *prefix)
Dumps the tree.
Definition: KviKvsTreeNodeData.cpp:41
A class which maps every number.
Definition: KviKvsVariant.h:49
virtual void dump(const char *prefix)
Dumps the tree.
Definition: KviKvsTreeNodeExpression.cpp:44
Handling of variant data type in KVS.
KviKvsTreeNodeExpression * parentExpression()
Definition: KviKvsTreeNodeExpression.h:86
Definition: KviKvsTreeNodeData.h:34
char szBuffer[4096]
Definition: winamp.cpp:77
Definition: KviKvsTreeNodeExpression.h:172
Definition: KviKvsTreeNodeExpression.h:120
KviKvsTreeNodeData * m_pData
Definition: KviKvsTreeNodeExpression.h:98
Definition: KviKvsTreeNodeExpression.h:146
Helper functions for the QString class.
void setParentExpression(KviKvsTreeNodeExpression *pParent)
Definition: KviKvsTreeNodeExpression.h:87