~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvirc/kvs/tree/KviKvsTreeNodeExpression.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviKvsTreeNodeExpression.cpp
 
4
//   Creation date : Mon 06 Oct 2003 01.35 CEST by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2003-2010 Szymon Stefanek (pragma at kvirc dot net)
 
8
//
 
9
//   This program is FREE software. You can redistribute it and/or
 
10
//   modify it under the terms of the GNU General Public License
 
11
//   as published by the Free Software Foundation; either version 2
 
12
//   of the License, or (at your opinion) any later version.
 
13
//
 
14
//   This program is distributed in the HOPE that it will be USEFUL,
 
15
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
17
//   See the GNU General Public License for more details.
 
18
//
 
19
//   You should have received a copy of the GNU General Public License
 
20
//   along with this program. If not, write to the Free Software Foundation,
 
21
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
#include "KviKvsTreeNodeExpression.h"
 
26
#include "KviLocale.h"
 
27
 
 
28
#include <math.h>
 
29
 
 
30
KviKvsTreeNodeExpression::KviKvsTreeNodeExpression(const QChar * pLocation)
 
31
: KviKvsTreeNodeData(pLocation)
 
32
{
 
33
        m_pParentExpression = 0;
 
34
}
 
35
 
 
36
KviKvsTreeNodeExpression::~KviKvsTreeNodeExpression()
 
37
{
 
38
}
 
39
 
 
40
void KviKvsTreeNodeExpression::contextDescription(QString &szBuffer)
 
41
{
 
42
        szBuffer = "Expression Evaluation";
 
43
}
 
44
 
 
45
void KviKvsTreeNodeExpression::dump(const char * prefix)
 
46
{
 
47
        qDebug("%s Expression",prefix);
 
48
}
 
49
 
 
50
int KviKvsTreeNodeExpression::precedence()
 
51
{
 
52
        return PREC_MAXIMUM;
 
53
}
 
54
 
 
55
KviKvsTreeNodeExpression * KviKvsTreeNodeExpression::left()
 
56
{
 
57
        qDebug("KviKvsTreeNodeExpression::left() : should never end up here!");
 
58
        return 0;
 
59
}
 
60
 
 
61
KviKvsTreeNodeExpression * KviKvsTreeNodeExpression::right()
 
62
{
 
63
        qDebug("KviKvsTreeNodeExpression::right() : should never end up here!");
 
64
        return 0;
 
65
}
 
66
 
 
67
void KviKvsTreeNodeExpression::setLeft(KviKvsTreeNodeExpression *)
 
68
{
 
69
        qDebug("KviKvsTreeNodeExpression::setLeft() : should never end up here!");
 
70
}
 
71
 
 
72
void KviKvsTreeNodeExpression::setRight(KviKvsTreeNodeExpression *)
 
73
{
 
74
        qDebug("KviKvsTreeNodeExpression::setRight() : should never end up here!");
 
75
}
 
76
 
 
77
KviKvsTreeNodeExpression * KviKvsTreeNodeExpression::parentWithPrecedenceLowerThan(int iPrec)
 
78
{
 
79
        if(precedence() > iPrec)return this;
 
80
        if(!parentExpression())return 0;
 
81
        return parentExpression()->parentWithPrecedenceLowerThan(iPrec);
 
82
}
 
83
 
 
84
int KviKvsTreeNodeExpression::firstBinaryOperator()
 
85
{
 
86
        if(!left())return precedence();
 
87
        return left()->firstBinaryOperator();
 
88
}
 
89
 
 
90
///////////////////////////////////////////////////////////////////////////////
 
91
 
 
92
 
 
93
KviKvsTreeNodeExpressionVariableOperand::KviKvsTreeNodeExpressionVariableOperand(const QChar * pLocation,KviKvsTreeNodeData * pData)
 
94
: KviKvsTreeNodeExpression(pLocation)
 
95
{
 
96
        m_pData = pData;
 
97
        m_pData->setParent(this);
 
98
}
 
99
 
 
100
KviKvsTreeNodeExpressionVariableOperand::~KviKvsTreeNodeExpressionVariableOperand()
 
101
{
 
102
        delete m_pData;
 
103
}
 
104
 
 
105
void KviKvsTreeNodeExpressionVariableOperand::contextDescription(QString &szBuffer)
 
106
{
 
107
        szBuffer = "Expression Variable Operand Evaluation";
 
108
}
 
109
 
 
110
void KviKvsTreeNodeExpressionVariableOperand::dump(const char * prefix)
 
111
{
 
112
        qDebug("%s ExpressionVariableOperand",prefix);
 
113
        QString tmp = prefix;
 
114
        tmp.append("  ");
 
115
        m_pData->dump(tmp.toUtf8().data());
 
116
}
 
117
 
 
118
bool KviKvsTreeNodeExpressionVariableOperand::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
119
{
 
120
        return m_pData->evaluateReadOnly(c,pBuffer);
 
121
}
 
122
 
 
123
 
 
124
///////////////////////////////////////////////////////////////////////////////
 
125
 
 
126
KviKvsTreeNodeExpressionConstantOperand::KviKvsTreeNodeExpressionConstantOperand(const QChar * pLocation,KviKvsVariant * pConstant)
 
127
: KviKvsTreeNodeExpression(pLocation)
 
128
{
 
129
        m_pConstant = pConstant;
 
130
}
 
131
 
 
132
KviKvsTreeNodeExpressionConstantOperand::~KviKvsTreeNodeExpressionConstantOperand()
 
133
{
 
134
        delete m_pConstant;
 
135
}
 
136
 
 
137
void KviKvsTreeNodeExpressionConstantOperand::contextDescription(QString &szBuffer)
 
138
{
 
139
        szBuffer = "Expression Constant Operand Evaluation";
 
140
}
 
141
 
 
142
 
 
143
void KviKvsTreeNodeExpressionConstantOperand::dump(const char * prefix)
 
144
{
 
145
        qDebug("%s ExpressionConstantOperand",prefix);
 
146
        QString tmp = prefix;
 
147
        tmp.append("  ");
 
148
        m_pConstant->dump(tmp.toUtf8().data());
 
149
}
 
150
 
 
151
bool KviKvsTreeNodeExpressionConstantOperand::evaluateReadOnly(KviKvsRunTimeContext *,KviKvsVariant * pBuffer)
 
152
{
 
153
        pBuffer->copyFrom(m_pConstant);
 
154
        return true;
 
155
}
 
156
 
 
157
///////////////////////////////////////////////////////////////////////////////
 
158
 
 
159
 
 
160
KviKvsTreeNodeExpressionOperator::KviKvsTreeNodeExpressionOperator(const QChar * pLocation)
 
161
: KviKvsTreeNodeExpression(pLocation)
 
162
{
 
163
}
 
164
 
 
165
KviKvsTreeNodeExpressionOperator::~KviKvsTreeNodeExpressionOperator()
 
166
{
 
167
}
 
168
 
 
169
void KviKvsTreeNodeExpressionOperator::contextDescription(QString &szBuffer)
 
170
{
 
171
        szBuffer = "Expression Operator Evaluation";
 
172
}
 
173
 
 
174
 
 
175
void KviKvsTreeNodeExpressionOperator::dump(const char * prefix)
 
176
{
 
177
        qDebug("%s ExpressionOperator",prefix);
 
178
}
 
179
 
 
180
 
 
181
 
 
182
///////////////////////////////////////////////////////////////////////////////
 
183
 
 
184
 
 
185
KviKvsTreeNodeExpressionUnaryOperator::KviKvsTreeNodeExpressionUnaryOperator(const QChar * pLocation,KviKvsTreeNodeExpression * pData)
 
186
: KviKvsTreeNodeExpressionOperator(pLocation)
 
187
{
 
188
        m_pData = pData;
 
189
        m_pData->setParent(this);
 
190
        m_pData->setParentExpression(this);
 
191
}
 
192
 
 
193
KviKvsTreeNodeExpressionUnaryOperator::~KviKvsTreeNodeExpressionUnaryOperator()
 
194
{
 
195
        delete m_pData;
 
196
}
 
197
 
 
198
void KviKvsTreeNodeExpressionUnaryOperator::contextDescription(QString &szBuffer)
 
199
{
 
200
        szBuffer = "Expression Unary Operator Evaluation";
 
201
}
 
202
 
 
203
void KviKvsTreeNodeExpressionUnaryOperator::dump(const char * prefix)
 
204
{
 
205
        qDebug("%s ExpressionUnaryOperator",prefix);
 
206
        QString tmp = prefix;
 
207
        tmp.append("  ");
 
208
        m_pData->dump(tmp.toUtf8().data());
 
209
}
 
210
 
 
211
bool KviKvsTreeNodeExpressionUnaryOperator::evaluateOperand(KviKvsRunTimeContext * c)
 
212
{
 
213
        KviKvsVariant v;
 
214
        if(!m_pData->evaluateReadOnly(c,&v))return false;
 
215
 
 
216
        if(!v.asNumber(m_nData))
 
217
        {
 
218
                c->error(this,__tr2qs_ctx("Operand of unary operator didn't evaluate to a number","kvs"));
 
219
                return false;
 
220
        }
 
221
        return true;
 
222
}
 
223
 
 
224
///////////////////////////////////////////////////////////////////////////////
 
225
 
 
226
 
 
227
KviKvsTreeNodeExpressionUnaryOperatorNegate::KviKvsTreeNodeExpressionUnaryOperatorNegate(const QChar * pLocation,KviKvsTreeNodeExpression * pData)
 
228
: KviKvsTreeNodeExpressionUnaryOperator(pLocation,pData)
 
229
{
 
230
}
 
231
 
 
232
KviKvsTreeNodeExpressionUnaryOperatorNegate::~KviKvsTreeNodeExpressionUnaryOperatorNegate()
 
233
{
 
234
}
 
235
 
 
236
 
 
237
void KviKvsTreeNodeExpressionUnaryOperatorNegate::contextDescription(QString &szBuffer)
 
238
{
 
239
        szBuffer = "Expression Unary Operator Negate";
 
240
}
 
241
 
 
242
 
 
243
void KviKvsTreeNodeExpressionUnaryOperatorNegate::dump(const char * prefix)
 
244
{
 
245
        qDebug("%s ExpressionUnaryOperatorNegate",prefix);
 
246
        QString tmp = prefix;
 
247
        tmp.append("  ");
 
248
        m_pData->dump(tmp.toUtf8().data());
 
249
}
 
250
 
 
251
int KviKvsTreeNodeExpressionUnaryOperatorNegate::precedence()
 
252
{
 
253
        return PREC_OP_NEGATE;
 
254
}
 
255
 
 
256
bool KviKvsTreeNodeExpressionUnaryOperatorNegate::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
257
{
 
258
        if(!evaluateOperand(c))return false;
 
259
        if(m_nData.isReal())pBuffer->setReal(-m_nData.real());
 
260
        else pBuffer->setInteger(-m_nData.integer());
 
261
        return true;
 
262
}
 
263
 
 
264
 
 
265
///////////////////////////////////////////////////////////////////////////////
 
266
 
 
267
 
 
268
KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot::KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot(const QChar * pLocation,KviKvsTreeNodeExpression * pData)
 
269
: KviKvsTreeNodeExpressionUnaryOperator(pLocation,pData)
 
270
{
 
271
}
 
272
 
 
273
KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot::~KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot()
 
274
{
 
275
}
 
276
 
 
277
void KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot::contextDescription(QString &szBuffer)
 
278
{
 
279
        szBuffer = "Expression Unary Operator Bitwise Not";
 
280
}
 
281
 
 
282
void KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot::dump(const char * prefix)
 
283
{
 
284
        qDebug("%s ExpressionUnaryOperatorBitwiseNot",prefix);
 
285
        QString tmp = prefix;
 
286
        tmp.append("  ");
 
287
        m_pData->dump(tmp.toUtf8().data());
 
288
}
 
289
 
 
290
int KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot::precedence()
 
291
{
 
292
        return PREC_OP_BITWISENOT;
 
293
}
 
294
 
 
295
bool KviKvsTreeNodeExpressionUnaryOperatorBitwiseNot::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
296
{
 
297
        if(!evaluateOperand(c))return false;
 
298
        if(m_nData.isReal())pBuffer->setInteger(~(int)(m_nData.real()));
 
299
        else pBuffer->setInteger(~m_nData.integer());
 
300
        return true;
 
301
}
 
302
 
 
303
 
 
304
///////////////////////////////////////////////////////////////////////////////
 
305
 
 
306
 
 
307
KviKvsTreeNodeExpressionUnaryOperatorLogicalNot::KviKvsTreeNodeExpressionUnaryOperatorLogicalNot(const QChar * pLocation,KviKvsTreeNodeExpression * pData)
 
308
: KviKvsTreeNodeExpressionUnaryOperator(pLocation,pData)
 
309
{
 
310
}
 
311
 
 
312
KviKvsTreeNodeExpressionUnaryOperatorLogicalNot::~KviKvsTreeNodeExpressionUnaryOperatorLogicalNot()
 
313
{
 
314
}
 
315
 
 
316
void KviKvsTreeNodeExpressionUnaryOperatorLogicalNot::contextDescription(QString &szBuffer)
 
317
{
 
318
        szBuffer = "Expression Unary Operator Logical Not";
 
319
}
 
320
 
 
321
void KviKvsTreeNodeExpressionUnaryOperatorLogicalNot::dump(const char * prefix)
 
322
{
 
323
        qDebug("%s ExpressionUnaryOperatorLogicalNot",prefix);
 
324
        QString tmp = prefix;
 
325
        tmp.append("  ");
 
326
        m_pData->dump(tmp.toUtf8().data());
 
327
}
 
328
 
 
329
int KviKvsTreeNodeExpressionUnaryOperatorLogicalNot::precedence()
 
330
{
 
331
        return PREC_OP_LOGICALNOT;
 
332
}
 
333
 
 
334
bool KviKvsTreeNodeExpressionUnaryOperatorLogicalNot::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
335
{
 
336
        KviKvsVariant v;
 
337
        if(!m_pData->evaluateReadOnly(c,&v))return false;
 
338
//#warning "FIXME: We could use setNothing() for false and setInteger(1) for true: this would save memory allocations for false conditions"
 
339
        pBuffer->setBoolean(!v.asBoolean());
 
340
        return true;
 
341
}
 
342
 
 
343
 
 
344
 
 
345
///////////////////////////////////////////////////////////////////////////////
 
346
 
 
347
 
 
348
KviKvsTreeNodeExpressionBinaryOperator::KviKvsTreeNodeExpressionBinaryOperator(const QChar * pLocation)
 
349
: KviKvsTreeNodeExpressionOperator(pLocation)
 
350
{
 
351
        m_pLeft = 0;
 
352
        m_pRight = 0;
 
353
}
 
354
 
 
355
KviKvsTreeNodeExpressionBinaryOperator::~KviKvsTreeNodeExpressionBinaryOperator()
 
356
{
 
357
        if(m_pLeft)delete m_pLeft;
 
358
        if(m_pRight)delete m_pRight;
 
359
}
 
360
 
 
361
bool KviKvsTreeNodeExpressionBinaryOperator::evaluateOperands(KviKvsRunTimeContext * c)
 
362
{
 
363
        KviKvsVariant v1;
 
364
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
365
        if(!v1.asNumber(m_nLeft))
 
366
        {
 
367
                c->error(this,__tr2qs_ctx("Left operand didn't evaluate to a number","kvs"));
 
368
                return false;
 
369
        }
 
370
        KviKvsVariant v2;
 
371
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
372
        if(!v2.asNumber(m_nRight))
 
373
        {
 
374
                c->error(this,__tr2qs_ctx("Right operand didn't evaluate to a number","kvs"));
 
375
                return false;
 
376
        }
 
377
        return true;
 
378
}
 
379
 
 
380
KviKvsTreeNodeExpression * KviKvsTreeNodeExpressionBinaryOperator::left()
 
381
{
 
382
        return m_pLeft;
 
383
}
 
384
 
 
385
KviKvsTreeNodeExpression * KviKvsTreeNodeExpressionBinaryOperator::right()
 
386
{
 
387
        return m_pRight;
 
388
}
 
389
 
 
390
int KviKvsTreeNodeExpressionBinaryOperator::firstBinaryOperator()
 
391
{
 
392
        return precedence();
 
393
}
 
394
 
 
395
void KviKvsTreeNodeExpressionBinaryOperator::setLeft(KviKvsTreeNodeExpression * pLeft)
 
396
{
 
397
        m_pLeft = pLeft;
 
398
        m_pLeft->setParent(this);
 
399
        m_pLeft->setParentExpression(this);
 
400
}
 
401
 
 
402
void KviKvsTreeNodeExpressionBinaryOperator::setRight(KviKvsTreeNodeExpression * pRight)
 
403
{
 
404
        m_pRight = pRight;
 
405
        m_pRight->setParent(this);
 
406
        m_pRight->setParentExpression(this);
 
407
}
 
408
 
 
409
 
 
410
void KviKvsTreeNodeExpressionBinaryOperator::dumpOperands(const char * prefix)
 
411
{
 
412
        QString tmp = prefix;
 
413
        tmp.append("  ");
 
414
        if(m_pLeft)m_pLeft->dump(tmp.toUtf8().data());
 
415
        if(m_pRight)m_pRight->dump(tmp.toUtf8().data());
 
416
}
 
417
 
 
418
void KviKvsTreeNodeExpressionBinaryOperator::contextDescription(QString &szBuffer)
 
419
{
 
420
        szBuffer = "Expression Binary Operator";
 
421
}
 
422
 
 
423
void KviKvsTreeNodeExpressionBinaryOperator::dump(const char * prefix)
 
424
{
 
425
        qDebug("%s ExpressionBinaryOperator",prefix);
 
426
        dumpOperands(prefix);
 
427
}
 
428
 
 
429
////////////////////////////////////////////////////////////////////////////////
 
430
 
 
431
 
 
432
#define PREIMPLEMENT_BINARY_OPERATOR(__name,__stringname,__contextdescription,__precedence) \
 
433
        __name::__name(const QChar * pLocation) \
 
434
        : KviKvsTreeNodeExpressionBinaryOperator(pLocation){} \
 
435
        __name::~__name(){} \
 
436
        void __name::dump(const char * prefix){ qDebug("%s " __stringname,prefix); dumpOperands(prefix); } \
 
437
        void __name::contextDescription(QString &szBuffer){ szBuffer = __contextdescription; } \
 
438
        int __name::precedence(){ return __precedence; };
 
439
 
 
440
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorSum,"ExpressionBinaryOperatorSum","Expression Binary Operator \"+\"",PREC_OP_SUM)
 
441
 
 
442
bool KviKvsTreeNodeExpressionBinaryOperatorSum::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
443
{
 
444
        if(!evaluateOperands(c))return false;
 
445
        if(m_nLeft.isInteger())
 
446
        {
 
447
                if(m_nRight.isInteger())pBuffer->setInteger(m_nLeft.integer() + m_nRight.integer());
 
448
                else pBuffer->setReal(m_nLeft.integer() + m_nRight.real());
 
449
        } else {
 
450
                if(m_nRight.isInteger())pBuffer->setReal(m_nLeft.real() + m_nRight.integer());
 
451
                else pBuffer->setReal(m_nLeft.real() + m_nRight.real());
 
452
        }
 
453
        return true;
 
454
}
 
455
 
 
456
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorSubtraction,"ExpressionBinaryOperatorSubtraction","Expression Binary Operator \"-\"",PREC_OP_SUBTRACTION)
 
457
 
 
458
bool KviKvsTreeNodeExpressionBinaryOperatorSubtraction::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
459
{
 
460
        if(!evaluateOperands(c))return false;
 
461
        if(m_nLeft.isInteger())
 
462
        {
 
463
                if(m_nRight.isInteger())pBuffer->setInteger(m_nLeft.integer() - m_nRight.integer());
 
464
                else pBuffer->setReal(((kvs_real_t)(m_nLeft.integer())) - m_nRight.real());
 
465
        } else {
 
466
                if(m_nRight.isInteger())pBuffer->setReal(m_nLeft.real() - ((kvs_real_t)(m_nRight.integer())));
 
467
                else pBuffer->setReal(m_nLeft.real() - m_nRight.real());
 
468
        }
 
469
        return true;
 
470
}
 
471
 
 
472
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorMultiplication,"ExpressionBinaryOperatorMultiplication","Expression Binary Operator \"*\"",PREC_OP_MULTIPLICATION)
 
473
 
 
474
bool KviKvsTreeNodeExpressionBinaryOperatorMultiplication::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
475
{
 
476
        if(!evaluateOperands(c))return false;
 
477
        if(m_nLeft.isInteger())
 
478
        {
 
479
                if(m_nRight.isInteger())pBuffer->setInteger(m_nLeft.integer() * m_nRight.integer());
 
480
                else pBuffer->setReal(((kvs_real_t)(m_nLeft.integer())) * m_nRight.real());
 
481
        } else {
 
482
                if(m_nRight.isInteger())pBuffer->setReal(m_nLeft.real() * ((kvs_real_t)(m_nRight.integer())));
 
483
                else pBuffer->setReal(m_nLeft.real() * m_nRight.real());
 
484
        }
 
485
        return true;
 
486
}
 
487
 
 
488
 
 
489
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorDivision,"ExpressionBinaryOperatorDivision","Expression Binary Operator \"/\"",PREC_OP_DIVISION)
 
490
 
 
491
bool KviKvsTreeNodeExpressionBinaryOperatorDivision::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
492
{
 
493
        if(!evaluateOperands(c))return false;
 
494
 
 
495
        if(m_nRight.isInteger())
 
496
        {
 
497
                if(m_nRight.integer() == 0)
 
498
                {
 
499
                        c->error(this,__tr2qs_ctx("Division by zero","kvs"));
 
500
                        return false;
 
501
                }
 
502
                if(m_nLeft.isInteger())pBuffer->setInteger(m_nLeft.integer() / m_nRight.integer());
 
503
                else pBuffer->setReal(m_nLeft.real() / ((kvs_real_t)(m_nRight.integer())));
 
504
        } else {
 
505
                if(m_nRight.real() == 0.0)
 
506
                {
 
507
                        c->error(this,__tr2qs_ctx("Division by zero","kvs"));
 
508
                        return false;
 
509
                }
 
510
                if(m_nLeft.isInteger())pBuffer->setReal(((kvs_real_t)(m_nLeft.integer())) / m_nRight.real());
 
511
                else pBuffer->setReal(m_nLeft.real() / m_nRight.real());
 
512
        }
 
513
        return true;
 
514
}
 
515
 
 
516
 
 
517
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorModulus,"ExpressionBinaryOperatorModulus","Expression Binary Operator \"modulus\"",PREC_OP_MODULUS)
 
518
 
 
519
bool KviKvsTreeNodeExpressionBinaryOperatorModulus::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
520
{
 
521
        if(!evaluateOperands(c))return false;
 
522
 
 
523
        if(m_nRight.isInteger())
 
524
        {
 
525
                if(m_nRight.integer() == 0)
 
526
                {
 
527
                        c->error(this,__tr2qs_ctx("Division by zero","kvs"));
 
528
                        return false;
 
529
                }
 
530
                if(m_nLeft.isInteger())pBuffer->setInteger(m_nLeft.integer() % m_nRight.integer());
 
531
                else pBuffer->setReal(fmod(m_nLeft.real(),((kvs_real_t)(m_nRight.integer()))));
 
532
        } else {
 
533
                if(m_nRight.real() == 0.0)
 
534
                {
 
535
                        c->error(this,__tr2qs_ctx("Division by zero","kvs"));
 
536
                        return false;
 
537
                }
 
538
                if(m_nLeft.isInteger())pBuffer->setReal(fmod(((kvs_real_t)(m_nLeft.integer())),m_nRight.real()));
 
539
                else pBuffer->setReal(fmod(m_nLeft.real(),m_nRight.real()));
 
540
        }
 
541
        return true;
 
542
}
 
543
 
 
544
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseAnd,"ExpressionBinaryOperatorBitwiseAnd","Expression Binary Operator \"&\"",PREC_OP_BITWISEAND)
 
545
 
 
546
bool KviKvsTreeNodeExpressionBinaryOperatorBitwiseAnd::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
547
{
 
548
        if(!evaluateOperands(c))return false;
 
549
        int iLeft = m_nLeft.isInteger() ? m_nLeft.integer() : (kvs_int_t)m_nLeft.real();
 
550
        int iRight = m_nRight.isInteger() ? m_nRight.integer() : (kvs_int_t)m_nRight.real();
 
551
        pBuffer->setInteger(iLeft & iRight);
 
552
        return true;
 
553
}
 
554
 
 
555
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseOr,"ExpressionBinaryOperatorBitwiseOr","Expression Binary Operator \"|\"",PREC_OP_BITWISEOR)
 
556
 
 
557
bool KviKvsTreeNodeExpressionBinaryOperatorBitwiseOr::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
558
{
 
559
        if(!evaluateOperands(c))return false;
 
560
        int iLeft = m_nLeft.isInteger() ? m_nLeft.integer() : (kvs_int_t)m_nLeft.real();
 
561
        int iRight = m_nRight.isInteger() ? m_nRight.integer() : (kvs_int_t)m_nRight.real();
 
562
        pBuffer->setInteger(iLeft | iRight);
 
563
        return true;
 
564
}
 
565
 
 
566
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorBitwiseXor,"ExpressionBinaryOperatorBitwiseXor","Expression Binary Operator \"^\"",PREC_OP_BITWISEXOR)
 
567
 
 
568
bool KviKvsTreeNodeExpressionBinaryOperatorBitwiseXor::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
569
{
 
570
        if(!evaluateOperands(c))return false;
 
571
        int iLeft = m_nLeft.isInteger() ? m_nLeft.integer() : (kvs_int_t)m_nLeft.real();
 
572
        int iRight = m_nRight.isInteger() ? m_nRight.integer() : (kvs_int_t)m_nRight.real();
 
573
        pBuffer->setInteger(iLeft ^ iRight);
 
574
        return true;
 
575
}
 
576
 
 
577
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorShiftLeft,"ExpressionBinaryOperatorShiftLeft","Expression Binary Operator \"<<\"",PREC_OP_SHIFTLEFT)
 
578
 
 
579
bool KviKvsTreeNodeExpressionBinaryOperatorShiftLeft::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
580
{
 
581
        if(!evaluateOperands(c))return false;
 
582
        int iLeft = m_nLeft.isInteger() ? m_nLeft.integer() : (kvs_int_t)(m_nLeft.real());
 
583
        int iRight = m_nRight.isInteger() ? m_nRight.integer() : (kvs_int_t)(m_nRight.real());
 
584
        pBuffer->setInteger(iLeft << iRight);
 
585
        return true;
 
586
}
 
587
 
 
588
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorShiftRight,"ExpressionBinaryOperatorShiftRight","Expression Binary Operator \">>\"",PREC_OP_SHIFTRIGHT)
 
589
 
 
590
bool KviKvsTreeNodeExpressionBinaryOperatorShiftRight::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
591
{
 
592
        if(!evaluateOperands(c))return false;
 
593
        int iLeft = m_nLeft.isInteger() ? m_nLeft.integer() : (kvs_int_t)(m_nLeft.real());
 
594
        int iRight = m_nRight.isInteger() ? m_nRight.integer() : (kvs_int_t)(m_nRight.real());
 
595
        pBuffer->setInteger(iLeft >> iRight);
 
596
        return true;
 
597
}
 
598
 
 
599
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorAnd,"ExpressionBinaryOperatorAnd","Expression Binary Operator \"&&\"",PREC_OP_AND)
 
600
 
 
601
bool KviKvsTreeNodeExpressionBinaryOperatorAnd::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
602
{
 
603
        KviKvsVariant v1;
 
604
        KviKvsVariant v2;
 
605
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
606
        //#warning "FIXME: We could use setNothing() as false: this would save memory allocations (and thus time)"
 
607
        if(!v1.asBoolean())
 
608
        {
 
609
                pBuffer->setBoolean(false);
 
610
                return true;
 
611
        }
 
612
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
613
        pBuffer->setBoolean(v2.asBoolean());
 
614
        return true;
 
615
}
 
616
 
 
617
 
 
618
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorOr,"ExpressionBinaryOperatorOr","Expression Binary Operator \"||\"",PREC_OP_OR)
 
619
 
 
620
bool KviKvsTreeNodeExpressionBinaryOperatorOr::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
621
{
 
622
        KviKvsVariant v1;
 
623
        KviKvsVariant v2;
 
624
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
625
        //#warning "FIXME: We could use setNothing() as false: this would save memory allocations (and thus time)"
 
626
        if(v1.asBoolean())
 
627
        {
 
628
                pBuffer->setBoolean(true);
 
629
                return true;
 
630
        }
 
631
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
632
        pBuffer->setBoolean(v2.asBoolean());
 
633
        return true;
 
634
}
 
635
 
 
636
 
 
637
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorXor,"ExpressionBinaryOperatorXor","Expression Binary Operator \"^^\"",PREC_OP_XOR)
 
638
 
 
639
bool KviKvsTreeNodeExpressionBinaryOperatorXor::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
640
{
 
641
        KviKvsVariant v1;
 
642
        KviKvsVariant v2;
 
643
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
644
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
645
        //#warning "FIXME: We could use setNothing() as false: this would save memory allocations (and thus time)"
 
646
        if(v1.asBoolean())
 
647
                pBuffer->setBoolean(!v2.asBoolean());
 
648
        else {
 
649
                if(v2.asBoolean())
 
650
                        pBuffer->setBoolean(!v1.asBoolean());
 
651
                else
 
652
                        pBuffer->setBoolean(false);
 
653
        }
 
654
        return true;
 
655
}
 
656
 
 
657
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorLowerThan,"ExpressionBinaryOperatorLowerThan","Expression Binary Operator \"<\"",PREC_OP_LOWERTHAN)
 
658
 
 
659
bool KviKvsTreeNodeExpressionBinaryOperatorLowerThan::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
660
{
 
661
        KviKvsVariant v1;
 
662
        KviKvsVariant v2;
 
663
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
664
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
665
        pBuffer->setBoolean(v1.compare(&v2,true) > 0);
 
666
        return true;
 
667
}
 
668
 
 
669
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorGreaterThan,"ExpressionBinaryOperatorGreaterThan","Expression Binary Operator \">\"",PREC_OP_GREATERTHAN)
 
670
 
 
671
bool KviKvsTreeNodeExpressionBinaryOperatorGreaterThan::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
672
{
 
673
        KviKvsVariant v1;
 
674
        KviKvsVariant v2;
 
675
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
676
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
677
        pBuffer->setBoolean(v1.compare(&v2,true) < 0);
 
678
        return true;
 
679
}
 
680
 
 
681
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorLowerOrEqualTo,"ExpressionBinaryOperatorLowerOrEqualTo","Expression Binary Operator \"<=\"",PREC_OP_LOWEROREQUALTO)
 
682
 
 
683
bool KviKvsTreeNodeExpressionBinaryOperatorLowerOrEqualTo::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
684
{
 
685
        KviKvsVariant v1;
 
686
        KviKvsVariant v2;
 
687
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
688
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
689
        pBuffer->setBoolean(v1.compare(&v2,true) >= 0);
 
690
        return true;
 
691
}
 
692
 
 
693
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorGreaterOrEqualTo,"ExpressionBinaryOperatorGreaterOrEqualTo","Expression Binary Operator \">=\"",PREC_OP_GREATEROREQUALTO)
 
694
 
 
695
bool KviKvsTreeNodeExpressionBinaryOperatorGreaterOrEqualTo::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
696
{
 
697
        KviKvsVariant v1;
 
698
        KviKvsVariant v2;
 
699
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
700
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
701
        pBuffer->setBoolean(v1.compare(&v2,true) <= 0);
 
702
        return true;
 
703
}
 
704
 
 
705
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorEqualTo,"ExpressionBinaryOperatorEqualTo","Expression Binary Operator \"==\"",PREC_OP_EQUALTO)
 
706
 
 
707
bool KviKvsTreeNodeExpressionBinaryOperatorEqualTo::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
708
{
 
709
        KviKvsVariant v1;
 
710
        KviKvsVariant v2;
 
711
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
712
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
713
        pBuffer->setBoolean(v1.compare(&v2,true) == 0);
 
714
        return true;
 
715
}
 
716
 
 
717
 
 
718
PREIMPLEMENT_BINARY_OPERATOR(KviKvsTreeNodeExpressionBinaryOperatorNotEqualTo,"ExpressionBinaryOperatorNotEqualTo","Expression Binary Operator \"!=\"",PREC_OP_NOTEQUALTO)
 
719
 
 
720
bool KviKvsTreeNodeExpressionBinaryOperatorNotEqualTo::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
 
721
{
 
722
        KviKvsVariant v1;
 
723
        KviKvsVariant v2;
 
724
        if(!m_pLeft->evaluateReadOnly(c,&v1))return false;
 
725
        if(!m_pRight->evaluateReadOnly(c,&v2))return false;
 
726
        pBuffer->setBoolean(v1.compare(&v2,true) != 0);
 
727
        return true;
 
728
}