1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basic.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <math.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <rtl/math.hxx> 34*cdf0e10cSrcweir #include "sbcomp.hxx" 35*cdf0e10cSrcweir #include "expr.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir SbiExprNode::SbiExprNode( void ) 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir pLeft = NULL; 42*cdf0e10cSrcweir pRight = NULL; 43*cdf0e10cSrcweir eNodeType = SbxDUMMY; 44*cdf0e10cSrcweir } 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir SbiExprNode::SbiExprNode( SbiParser* p, SbiExprNode* l, SbiToken t, SbiExprNode* r ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir BaseInit( p ); 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir pLeft = l; 51*cdf0e10cSrcweir pRight = r; 52*cdf0e10cSrcweir eTok = t; 53*cdf0e10cSrcweir nVal = 0; 54*cdf0e10cSrcweir eType = SbxVARIANT; // Nodes sind immer Variant 55*cdf0e10cSrcweir eNodeType = SbxNODE; 56*cdf0e10cSrcweir bComposite= sal_True; 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir SbiExprNode::SbiExprNode( SbiParser* p, double n, SbxDataType t ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir BaseInit( p ); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir eType = t; 64*cdf0e10cSrcweir eNodeType = SbxNUMVAL; 65*cdf0e10cSrcweir nVal = n; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir SbiExprNode::SbiExprNode( SbiParser* p, const String& rVal ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir BaseInit( p ); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir eType = SbxSTRING; 73*cdf0e10cSrcweir eNodeType = SbxSTRVAL; 74*cdf0e10cSrcweir aStrVal = rVal; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir SbiExprNode::SbiExprNode( SbiParser* p, const SbiSymDef& r, SbxDataType t, SbiExprList* l ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir BaseInit( p ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir eType = ( t == SbxVARIANT ) ? r.GetType() : t; 82*cdf0e10cSrcweir eNodeType = SbxVARVAL; 83*cdf0e10cSrcweir aVar.pDef = (SbiSymDef*) &r; 84*cdf0e10cSrcweir aVar.pPar = l; 85*cdf0e10cSrcweir aVar.pvMorePar = NULL; 86*cdf0e10cSrcweir aVar.pNext= NULL; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // Funktionsergebnisse sind nie starr 89*cdf0e10cSrcweir bComposite= sal_Bool( aVar.pDef->GetProcDef() != NULL ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // #120061 TypeOf 93*cdf0e10cSrcweir SbiExprNode::SbiExprNode( SbiParser* p, SbiExprNode* l, sal_uInt16 nId ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir BaseInit( p ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir pLeft = l; 98*cdf0e10cSrcweir eType = SbxBOOL; 99*cdf0e10cSrcweir eNodeType = SbxTYPEOF; 100*cdf0e10cSrcweir nTypeStrId = nId; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // new <type> 104*cdf0e10cSrcweir SbiExprNode::SbiExprNode( SbiParser* p, sal_uInt16 nId ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir BaseInit( p ); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir eType = SbxOBJECT; 109*cdf0e10cSrcweir eNodeType = SbxNEW; 110*cdf0e10cSrcweir nTypeStrId = nId; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // AB: 17.12.95, Hilfsfunktion fuer Ctor fuer einheitliche Initialisierung 114*cdf0e10cSrcweir void SbiExprNode::BaseInit( SbiParser* p ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir pGen = &p->aGen; 117*cdf0e10cSrcweir eTok = NIL; 118*cdf0e10cSrcweir pLeft = NULL; 119*cdf0e10cSrcweir pRight = NULL; 120*cdf0e10cSrcweir pWithParent = NULL; 121*cdf0e10cSrcweir bComposite = sal_False; 122*cdf0e10cSrcweir bError = sal_False; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir SbiExprNode::~SbiExprNode() 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir delete pLeft; 128*cdf0e10cSrcweir delete pRight; 129*cdf0e10cSrcweir if( IsVariable() ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir delete aVar.pPar; 132*cdf0e10cSrcweir delete aVar.pNext; 133*cdf0e10cSrcweir SbiExprListVector* pvMorePar = aVar.pvMorePar; 134*cdf0e10cSrcweir if( pvMorePar ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir SbiExprListVector::iterator it; 137*cdf0e10cSrcweir for( it = pvMorePar->begin() ; it != pvMorePar->end() ; ++it ) 138*cdf0e10cSrcweir delete *it; 139*cdf0e10cSrcweir delete pvMorePar; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir SbiSymDef* SbiExprNode::GetVar() 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir if( eNodeType == SbxVARVAL ) 147*cdf0e10cSrcweir return aVar.pDef; 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir return NULL; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir SbiSymDef* SbiExprNode::GetRealVar() 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir SbiExprNode* p = GetRealNode(); 155*cdf0e10cSrcweir if( p ) 156*cdf0e10cSrcweir return p->GetVar(); 157*cdf0e10cSrcweir else 158*cdf0e10cSrcweir return NULL; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // AB: 18.12.95 162*cdf0e10cSrcweir SbiExprNode* SbiExprNode::GetRealNode() 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir if( eNodeType == SbxVARVAL ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir SbiExprNode* p = this; 167*cdf0e10cSrcweir while( p->aVar.pNext ) 168*cdf0e10cSrcweir p = p->aVar.pNext; 169*cdf0e10cSrcweir return p; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir else 172*cdf0e10cSrcweir return NULL; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir // Diese Methode setzt den Typ um, falls er in den Integer-Bereich hineinpasst 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir sal_Bool SbiExprNode::IsIntConst() 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir if( eNodeType == SbxNUMVAL ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir if( eType >= SbxINTEGER && eType <= SbxDOUBLE ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir double n; 184*cdf0e10cSrcweir if( nVal >= SbxMININT && nVal <= SbxMAXINT && modf( nVal, &n ) == 0 ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir nVal = (double) (short) nVal; 187*cdf0e10cSrcweir eType = SbxINTEGER; 188*cdf0e10cSrcweir return sal_True; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir return sal_False; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir sal_Bool SbiExprNode::IsNumber() 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir return sal_Bool( eNodeType == SbxNUMVAL ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir sal_Bool SbiExprNode::IsString() 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir return sal_Bool( eNodeType == SbxSTRVAL ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir sal_Bool SbiExprNode::IsVariable() 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir return sal_Bool( eNodeType == SbxVARVAL ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir sal_Bool SbiExprNode::IsLvalue() 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir return IsVariable(); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // Ermitteln der Tiefe eines Baumes 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir short SbiExprNode::GetDepth() 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir if( IsOperand() ) return 0; 220*cdf0e10cSrcweir else 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir short d1 = pLeft->GetDepth(); 223*cdf0e10cSrcweir short d2 = pRight->GetDepth(); 224*cdf0e10cSrcweir return( (d1 < d2 ) ? d2 : d1 ) + 1; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // Abgleich eines Baumes: 230*cdf0e10cSrcweir // 1. Constant Folding 231*cdf0e10cSrcweir // 2. Typabgleich 232*cdf0e10cSrcweir // 3. Umwandlung der Operanden in Strings 233*cdf0e10cSrcweir // 4. Hochziehen der Composite- und Error-Bits 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir void SbiExprNode::Optimize() 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir FoldConstants(); 238*cdf0e10cSrcweir CollectBits(); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir // Hochziehen der Composite- und Fehlerbits 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir void SbiExprNode::CollectBits() 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir if( pLeft ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir pLeft->CollectBits(); 248*cdf0e10cSrcweir bError |= pLeft->bError; 249*cdf0e10cSrcweir bComposite |= pLeft->bComposite; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir if( pRight ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir pRight->CollectBits(); 254*cdf0e10cSrcweir bError |= pRight->bError; 255*cdf0e10cSrcweir bComposite |= pRight->bComposite; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // Kann ein Zweig umgeformt werden, wird sal_True zurueckgeliefert. In diesem 260*cdf0e10cSrcweir // Fall ist das Ergebnis im linken Zweig. 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir void SbiExprNode::FoldConstants() 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir if( IsOperand() || eTok == LIKE ) return; 265*cdf0e10cSrcweir if( pLeft ) 266*cdf0e10cSrcweir pLeft->FoldConstants(); 267*cdf0e10cSrcweir if( pRight ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir pRight->FoldConstants(); 270*cdf0e10cSrcweir if( pLeft->IsConstant() && pRight->IsConstant() 271*cdf0e10cSrcweir && pLeft->eNodeType == pRight->eNodeType ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir CollectBits(); 274*cdf0e10cSrcweir if( eTok == CAT ) 275*cdf0e10cSrcweir // CAT verbindet auch zwei Zahlen miteinander! 276*cdf0e10cSrcweir eType = SbxSTRING; 277*cdf0e10cSrcweir if( pLeft->eType == SbxSTRING ) 278*cdf0e10cSrcweir // Kein Type Mismatch! 279*cdf0e10cSrcweir eType = SbxSTRING; 280*cdf0e10cSrcweir if( eType == SbxSTRING ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir String rl( pLeft->GetString() ); 283*cdf0e10cSrcweir String rr( pRight->GetString() ); 284*cdf0e10cSrcweir delete pLeft; pLeft = NULL; 285*cdf0e10cSrcweir delete pRight; pRight = NULL; 286*cdf0e10cSrcweir bComposite = sal_False; 287*cdf0e10cSrcweir if( eTok == PLUS || eTok == CAT ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir eTok = CAT; 290*cdf0e10cSrcweir // Verkettung: 291*cdf0e10cSrcweir aStrVal = rl; 292*cdf0e10cSrcweir aStrVal += rr; 293*cdf0e10cSrcweir eType = SbxSTRING; 294*cdf0e10cSrcweir eNodeType = SbxSTRVAL; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir else 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir eType = SbxDOUBLE; 299*cdf0e10cSrcweir eNodeType = SbxNUMVAL; 300*cdf0e10cSrcweir StringCompare eRes = rr.CompareTo( rl ); 301*cdf0e10cSrcweir switch( eTok ) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir case EQ: 304*cdf0e10cSrcweir nVal = ( eRes == COMPARE_EQUAL ) ? SbxTRUE : SbxFALSE; 305*cdf0e10cSrcweir break; 306*cdf0e10cSrcweir case NE: 307*cdf0e10cSrcweir nVal = ( eRes != COMPARE_EQUAL ) ? SbxTRUE : SbxFALSE; 308*cdf0e10cSrcweir break; 309*cdf0e10cSrcweir case LT: 310*cdf0e10cSrcweir nVal = ( eRes == COMPARE_LESS ) ? SbxTRUE : SbxFALSE; 311*cdf0e10cSrcweir break; 312*cdf0e10cSrcweir case GT: 313*cdf0e10cSrcweir nVal = ( eRes == COMPARE_GREATER ) ? SbxTRUE : SbxFALSE; 314*cdf0e10cSrcweir break; 315*cdf0e10cSrcweir case LE: 316*cdf0e10cSrcweir nVal = ( eRes != COMPARE_GREATER ) ? SbxTRUE : SbxFALSE; 317*cdf0e10cSrcweir break; 318*cdf0e10cSrcweir case GE: 319*cdf0e10cSrcweir nVal = ( eRes != COMPARE_LESS ) ? SbxTRUE : SbxFALSE; 320*cdf0e10cSrcweir break; 321*cdf0e10cSrcweir default: 322*cdf0e10cSrcweir pGen->GetParser()->Error( SbERR_CONVERSION ); 323*cdf0e10cSrcweir bError = sal_True; 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir else 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir double nl = pLeft->nVal; 330*cdf0e10cSrcweir double nr = pRight->nVal; 331*cdf0e10cSrcweir long ll = 0, lr = 0; 332*cdf0e10cSrcweir long llMod = 0, lrMod = 0; 333*cdf0e10cSrcweir if( ( eTok >= AND && eTok <= IMP ) 334*cdf0e10cSrcweir || eTok == IDIV || eTok == MOD ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir // Integer-Operationen 337*cdf0e10cSrcweir sal_Bool err = sal_False; 338*cdf0e10cSrcweir if( nl > SbxMAXLNG ) err = sal_True, nl = SbxMAXLNG; 339*cdf0e10cSrcweir else 340*cdf0e10cSrcweir if( nl < SbxMINLNG ) err = sal_True, nl = SbxMINLNG; 341*cdf0e10cSrcweir if( nr > SbxMAXLNG ) err = sal_True, nr = SbxMAXLNG; 342*cdf0e10cSrcweir else 343*cdf0e10cSrcweir if( nr < SbxMINLNG ) err = sal_True, nr = SbxMINLNG; 344*cdf0e10cSrcweir ll = (long) nl; lr = (long) nr; 345*cdf0e10cSrcweir llMod = (long) (nl < 0 ? nl - 0.5 : nl + 0.5); 346*cdf0e10cSrcweir lrMod = (long) (nr < 0 ? nr - 0.5 : nr + 0.5); 347*cdf0e10cSrcweir if( err ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir pGen->GetParser()->Error( SbERR_MATH_OVERFLOW ); 350*cdf0e10cSrcweir bError = sal_True; 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir sal_Bool bBothInt = sal_Bool( pLeft->eType < SbxSINGLE 354*cdf0e10cSrcweir && pRight->eType < SbxSINGLE ); 355*cdf0e10cSrcweir delete pLeft; pLeft = NULL; 356*cdf0e10cSrcweir delete pRight; pRight = NULL; 357*cdf0e10cSrcweir nVal = 0; 358*cdf0e10cSrcweir eType = SbxDOUBLE; 359*cdf0e10cSrcweir eNodeType = SbxNUMVAL; 360*cdf0e10cSrcweir bComposite = sal_False; 361*cdf0e10cSrcweir sal_Bool bCheckType = sal_False; 362*cdf0e10cSrcweir switch( eTok ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir case EXPON: 365*cdf0e10cSrcweir nVal = pow( nl, nr ); break; 366*cdf0e10cSrcweir case MUL: 367*cdf0e10cSrcweir bCheckType = sal_True; 368*cdf0e10cSrcweir nVal = nl * nr; break; 369*cdf0e10cSrcweir case DIV: 370*cdf0e10cSrcweir if( !nr ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir pGen->GetParser()->Error( SbERR_ZERODIV ); nVal = HUGE_VAL; 373*cdf0e10cSrcweir bError = sal_True; 374*cdf0e10cSrcweir } else nVal = nl / nr; 375*cdf0e10cSrcweir break; 376*cdf0e10cSrcweir case PLUS: 377*cdf0e10cSrcweir bCheckType = sal_True; 378*cdf0e10cSrcweir nVal = nl + nr; break; 379*cdf0e10cSrcweir case MINUS: 380*cdf0e10cSrcweir bCheckType = sal_True; 381*cdf0e10cSrcweir nVal = nl - nr; break; 382*cdf0e10cSrcweir case EQ: 383*cdf0e10cSrcweir nVal = ( nl == nr ) ? SbxTRUE : SbxFALSE; 384*cdf0e10cSrcweir eType = SbxINTEGER; break; 385*cdf0e10cSrcweir case NE: 386*cdf0e10cSrcweir nVal = ( nl != nr ) ? SbxTRUE : SbxFALSE; 387*cdf0e10cSrcweir eType = SbxINTEGER; break; 388*cdf0e10cSrcweir case LT: 389*cdf0e10cSrcweir nVal = ( nl < nr ) ? SbxTRUE : SbxFALSE; 390*cdf0e10cSrcweir eType = SbxINTEGER; break; 391*cdf0e10cSrcweir case GT: 392*cdf0e10cSrcweir nVal = ( nl > nr ) ? SbxTRUE : SbxFALSE; 393*cdf0e10cSrcweir eType = SbxINTEGER; break; 394*cdf0e10cSrcweir case LE: 395*cdf0e10cSrcweir nVal = ( nl <= nr ) ? SbxTRUE : SbxFALSE; 396*cdf0e10cSrcweir eType = SbxINTEGER; break; 397*cdf0e10cSrcweir case GE: 398*cdf0e10cSrcweir nVal = ( nl >= nr ) ? SbxTRUE : SbxFALSE; 399*cdf0e10cSrcweir eType = SbxINTEGER; break; 400*cdf0e10cSrcweir case IDIV: 401*cdf0e10cSrcweir if( !lr ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir pGen->GetParser()->Error( SbERR_ZERODIV ); nVal = HUGE_VAL; 404*cdf0e10cSrcweir bError = sal_True; 405*cdf0e10cSrcweir } else nVal = ll / lr; 406*cdf0e10cSrcweir eType = SbxLONG; break; 407*cdf0e10cSrcweir case MOD: 408*cdf0e10cSrcweir if( !lr ) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir pGen->GetParser()->Error( SbERR_ZERODIV ); nVal = HUGE_VAL; 411*cdf0e10cSrcweir bError = sal_True; 412*cdf0e10cSrcweir } else nVal = llMod % lrMod; 413*cdf0e10cSrcweir eType = SbxLONG; break; 414*cdf0e10cSrcweir case AND: 415*cdf0e10cSrcweir nVal = (double) ( ll & lr ); eType = SbxLONG; break; 416*cdf0e10cSrcweir case OR: 417*cdf0e10cSrcweir nVal = (double) ( ll | lr ); eType = SbxLONG; break; 418*cdf0e10cSrcweir case XOR: 419*cdf0e10cSrcweir nVal = (double) ( ll ^ lr ); eType = SbxLONG; break; 420*cdf0e10cSrcweir case EQV: 421*cdf0e10cSrcweir nVal = (double) ( ~ll ^ lr ); eType = SbxLONG; break; 422*cdf0e10cSrcweir case IMP: 423*cdf0e10cSrcweir nVal = (double) ( ~ll | lr ); eType = SbxLONG; break; 424*cdf0e10cSrcweir default: break; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir if( !::rtl::math::isFinite( nVal ) ) 428*cdf0e10cSrcweir pGen->GetParser()->Error( SbERR_MATH_OVERFLOW ); 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir // Den Datentyp wiederherstellen, um Rundungsfehler 431*cdf0e10cSrcweir // zu killen 432*cdf0e10cSrcweir if( bCheckType && bBothInt 433*cdf0e10cSrcweir && nVal >= SbxMINLNG && nVal <= SbxMAXLNG ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir // NK-Stellen weg 436*cdf0e10cSrcweir long n = (long) nVal; 437*cdf0e10cSrcweir nVal = n; 438*cdf0e10cSrcweir eType = ( n >= SbxMININT && n <= SbxMAXINT ) 439*cdf0e10cSrcweir ? SbxINTEGER : SbxLONG; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir else if( pLeft && pLeft->IsNumber() ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir nVal = pLeft->nVal; 447*cdf0e10cSrcweir delete pLeft; 448*cdf0e10cSrcweir pLeft = NULL; 449*cdf0e10cSrcweir eType = SbxDOUBLE; 450*cdf0e10cSrcweir eNodeType = SbxNUMVAL; 451*cdf0e10cSrcweir bComposite = sal_False; 452*cdf0e10cSrcweir switch( eTok ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir case NEG: 455*cdf0e10cSrcweir nVal = -nVal; break; 456*cdf0e10cSrcweir case NOT: { 457*cdf0e10cSrcweir // Integer-Operation! 458*cdf0e10cSrcweir sal_Bool err = sal_False; 459*cdf0e10cSrcweir if( nVal > SbxMAXLNG ) err = sal_True, nVal = SbxMAXLNG; 460*cdf0e10cSrcweir else 461*cdf0e10cSrcweir if( nVal < SbxMINLNG ) err = sal_True, nVal = SbxMINLNG; 462*cdf0e10cSrcweir if( err ) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir pGen->GetParser()->Error( SbERR_MATH_OVERFLOW ); 465*cdf0e10cSrcweir bError = sal_True; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir nVal = (double) ~((long) nVal); 468*cdf0e10cSrcweir eType = SbxLONG; 469*cdf0e10cSrcweir } break; 470*cdf0e10cSrcweir default: break; 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir if( eNodeType == SbxNUMVAL ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir // Evtl auf INTEGER falten (wg. besserem Opcode)? 476*cdf0e10cSrcweir if( eType == SbxSINGLE || eType == SbxDOUBLE ) 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir double x; 479*cdf0e10cSrcweir if( nVal >= SbxMINLNG && nVal <= SbxMAXLNG 480*cdf0e10cSrcweir && !modf( nVal, &x ) ) 481*cdf0e10cSrcweir eType = SbxLONG; 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir if( eType == SbxLONG && nVal >= SbxMININT && nVal <= SbxMAXINT ) 484*cdf0e10cSrcweir eType = SbxINTEGER; 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir 489