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_idlc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <idlc/astexpression.hxx> 32*cdf0e10cSrcweir #include <idlc/astconstant.hxx> 33*cdf0e10cSrcweir #include <idlc/astscope.hxx> 34*cdf0e10cSrcweir #include <idlc/errorhandler.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <limits.h> 37*cdf0e10cSrcweir #include <float.h> 38*cdf0e10cSrcweir #include <memory> // auto_ptr<> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #undef MAXCHAR 41*cdf0e10cSrcweir #define MAXCHAR 127 42*cdf0e10cSrcweir #undef MINCHAR 43*cdf0e10cSrcweir #define MINCHAR -128 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace ::rtl; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir AstExpression::AstExpression(ExprComb c, AstExpression *pExpr1, AstExpression *pExpr2) 48*cdf0e10cSrcweir : m_combOperator(c) 49*cdf0e10cSrcweir , m_subExpr1(pExpr1) 50*cdf0e10cSrcweir , m_subExpr2(pExpr2) 51*cdf0e10cSrcweir , m_exprValue(NULL) 52*cdf0e10cSrcweir , m_pSymbolicName(NULL) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir fillDefinitionDetails(); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir AstExpression::AstExpression(sal_Int32 l) 59*cdf0e10cSrcweir : m_combOperator(EC_none) 60*cdf0e10cSrcweir , m_subExpr1(NULL) 61*cdf0e10cSrcweir , m_subExpr2(NULL) 62*cdf0e10cSrcweir , m_exprValue(NULL) 63*cdf0e10cSrcweir , m_pSymbolicName(NULL) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir fillDefinitionDetails(); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir m_exprValue = new AstExprValue(); 68*cdf0e10cSrcweir m_exprValue->et = ET_long; 69*cdf0e10cSrcweir m_exprValue->u.lval = l; 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir AstExpression::AstExpression(sal_Int32 l, ExprType et) 73*cdf0e10cSrcweir : m_combOperator(EC_none) 74*cdf0e10cSrcweir , m_subExpr1(NULL) 75*cdf0e10cSrcweir , m_subExpr2(NULL) 76*cdf0e10cSrcweir , m_exprValue(NULL) 77*cdf0e10cSrcweir , m_pSymbolicName(NULL) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir fillDefinitionDetails(); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir m_exprValue = new AstExprValue(); 82*cdf0e10cSrcweir m_exprValue->et = et; 83*cdf0e10cSrcweir m_exprValue->u.lval = l; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir AstExpression::AstExpression(sal_Int64 h) 87*cdf0e10cSrcweir : m_combOperator(EC_none) 88*cdf0e10cSrcweir , m_subExpr1(NULL) 89*cdf0e10cSrcweir , m_subExpr2(NULL) 90*cdf0e10cSrcweir , m_exprValue(NULL) 91*cdf0e10cSrcweir , m_pSymbolicName(NULL) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir fillDefinitionDetails(); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir m_exprValue = new AstExprValue(); 96*cdf0e10cSrcweir m_exprValue->et = ET_hyper; 97*cdf0e10cSrcweir m_exprValue->u.hval = h; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir AstExpression::AstExpression(sal_uInt64 uh) 101*cdf0e10cSrcweir : m_combOperator(EC_none) 102*cdf0e10cSrcweir , m_subExpr1(NULL) 103*cdf0e10cSrcweir , m_subExpr2(NULL) 104*cdf0e10cSrcweir , m_exprValue(NULL) 105*cdf0e10cSrcweir , m_pSymbolicName(NULL) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir fillDefinitionDetails(); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir m_exprValue = new AstExprValue(); 110*cdf0e10cSrcweir m_exprValue->et = ET_uhyper; 111*cdf0e10cSrcweir m_exprValue->u.uhval = uh; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir AstExpression::AstExpression(double d) 115*cdf0e10cSrcweir : m_combOperator(EC_none) 116*cdf0e10cSrcweir , m_subExpr1(NULL) 117*cdf0e10cSrcweir , m_subExpr2(NULL) 118*cdf0e10cSrcweir , m_exprValue(NULL) 119*cdf0e10cSrcweir , m_pSymbolicName(NULL) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir fillDefinitionDetails(); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir m_exprValue = new AstExprValue(); 124*cdf0e10cSrcweir m_exprValue->et = ET_double; 125*cdf0e10cSrcweir m_exprValue->u.dval = d; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir AstExpression::AstExpression(::rtl::OString* scopedName) 129*cdf0e10cSrcweir : m_combOperator(EC_symbol) 130*cdf0e10cSrcweir , m_subExpr1(NULL) 131*cdf0e10cSrcweir , m_subExpr2(NULL) 132*cdf0e10cSrcweir , m_exprValue(NULL) 133*cdf0e10cSrcweir , m_pSymbolicName(scopedName) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir fillDefinitionDetails(); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir AstExpression::~AstExpression() 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir if ( m_exprValue ) 141*cdf0e10cSrcweir delete m_exprValue; 142*cdf0e10cSrcweir if ( m_subExpr1 ) 143*cdf0e10cSrcweir delete m_subExpr1; 144*cdf0e10cSrcweir if ( m_subExpr2 ) 145*cdf0e10cSrcweir delete m_subExpr2; 146*cdf0e10cSrcweir if ( m_pSymbolicName ) 147*cdf0e10cSrcweir delete m_pSymbolicName; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir /* 151*cdf0e10cSrcweir * Perform the coercion from the given AstExprValue to the requested 152*cdf0e10cSrcweir * ExprType. Return an AstExprValue if successful, NULL if failed. 153*cdf0e10cSrcweir * must be done for hyper, uhyper 154*cdf0e10cSrcweir */ 155*cdf0e10cSrcweir static AstExprValue * 156*cdf0e10cSrcweir coerce_value(AstExprValue *ev, ExprType t) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir if (ev == NULL) 159*cdf0e10cSrcweir return NULL; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir switch (t) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir case ET_short: 164*cdf0e10cSrcweir switch (ev->et) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir case ET_short: 167*cdf0e10cSrcweir return ev; 168*cdf0e10cSrcweir case ET_ushort: 169*cdf0e10cSrcweir if (ev->u.usval > SAL_MAX_INT16) 170*cdf0e10cSrcweir return NULL; 171*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.usval; 172*cdf0e10cSrcweir ev->et = ET_short; 173*cdf0e10cSrcweir return ev; 174*cdf0e10cSrcweir case ET_long: 175*cdf0e10cSrcweir if (ev->u.lval < SAL_MIN_INT16 || ev->u.lval > SAL_MAX_INT16) 176*cdf0e10cSrcweir return NULL; 177*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.lval; 178*cdf0e10cSrcweir ev->et = ET_short; 179*cdf0e10cSrcweir return ev; 180*cdf0e10cSrcweir case ET_ulong: 181*cdf0e10cSrcweir if (ev->u.ulval > SAL_MAX_INT16) 182*cdf0e10cSrcweir return NULL; 183*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.ulval; 184*cdf0e10cSrcweir ev->et = ET_short; 185*cdf0e10cSrcweir return ev; 186*cdf0e10cSrcweir case ET_hyper: 187*cdf0e10cSrcweir if (ev->u.hval < SAL_MIN_INT16 || ev->u.hval > SAL_MAX_INT16) 188*cdf0e10cSrcweir return NULL; 189*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.hval; 190*cdf0e10cSrcweir ev->et = ET_short; 191*cdf0e10cSrcweir return ev; 192*cdf0e10cSrcweir case ET_uhyper: 193*cdf0e10cSrcweir if (ev->u.uhval > SAL_MAX_INT16) 194*cdf0e10cSrcweir return NULL; 195*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.uhval; 196*cdf0e10cSrcweir ev->et = ET_short; 197*cdf0e10cSrcweir return ev; 198*cdf0e10cSrcweir case ET_boolean: 199*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.bval; 200*cdf0e10cSrcweir ev->et = ET_short; 201*cdf0e10cSrcweir return ev; 202*cdf0e10cSrcweir case ET_float: 203*cdf0e10cSrcweir if (ev->u.fval < SAL_MIN_INT16 || ev->u.fval > SAL_MAX_INT16) 204*cdf0e10cSrcweir return NULL; 205*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.fval; 206*cdf0e10cSrcweir ev->et = ET_short; 207*cdf0e10cSrcweir return ev; 208*cdf0e10cSrcweir case ET_double: 209*cdf0e10cSrcweir if (ev->u.dval < SAL_MIN_INT16 || ev->u.dval > SAL_MAX_INT16) 210*cdf0e10cSrcweir return NULL; 211*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.dval; 212*cdf0e10cSrcweir ev->et = ET_short; 213*cdf0e10cSrcweir return ev; 214*cdf0e10cSrcweir case ET_byte: 215*cdf0e10cSrcweir ev->u.sval = (sal_Int16)ev->u.byval; 216*cdf0e10cSrcweir ev->et = ET_short; 217*cdf0e10cSrcweir return ev; 218*cdf0e10cSrcweir default: 219*cdf0e10cSrcweir OSL_ASSERT(false); 220*cdf0e10cSrcweir return NULL; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir case ET_ushort: 223*cdf0e10cSrcweir switch (ev->et) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir case ET_short: 226*cdf0e10cSrcweir if (ev->u.sval < 0) 227*cdf0e10cSrcweir return NULL; 228*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.sval; 229*cdf0e10cSrcweir ev->et = ET_ushort; 230*cdf0e10cSrcweir return ev; 231*cdf0e10cSrcweir case ET_ushort: 232*cdf0e10cSrcweir return ev; 233*cdf0e10cSrcweir case ET_long: 234*cdf0e10cSrcweir if (ev->u.lval < 0 || ev->u.lval > SAL_MAX_UINT16) 235*cdf0e10cSrcweir return NULL; 236*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.lval; 237*cdf0e10cSrcweir ev->et = ET_ushort; 238*cdf0e10cSrcweir return ev; 239*cdf0e10cSrcweir case ET_ulong: 240*cdf0e10cSrcweir if (ev->u.ulval > SAL_MAX_UINT16) 241*cdf0e10cSrcweir return NULL; 242*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.ulval; 243*cdf0e10cSrcweir ev->et = ET_ushort; 244*cdf0e10cSrcweir return ev; 245*cdf0e10cSrcweir case ET_hyper: 246*cdf0e10cSrcweir if (ev->u.hval < 0 || ev->u.hval > SAL_MAX_UINT16) 247*cdf0e10cSrcweir return NULL; 248*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.hval; 249*cdf0e10cSrcweir ev->et = ET_ushort; 250*cdf0e10cSrcweir return ev; 251*cdf0e10cSrcweir case ET_uhyper: 252*cdf0e10cSrcweir if (ev->u.uhval > SAL_MAX_UINT16) 253*cdf0e10cSrcweir return NULL; 254*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.uhval; 255*cdf0e10cSrcweir ev->et = ET_ushort; 256*cdf0e10cSrcweir return ev; 257*cdf0e10cSrcweir case ET_boolean: 258*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.bval; 259*cdf0e10cSrcweir ev->et = ET_short; 260*cdf0e10cSrcweir return ev; 261*cdf0e10cSrcweir case ET_float: 262*cdf0e10cSrcweir if (ev->u.fval < 0.0 || ev->u.fval > SAL_MAX_UINT16) 263*cdf0e10cSrcweir return NULL; 264*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.fval; 265*cdf0e10cSrcweir ev->et = ET_short; 266*cdf0e10cSrcweir return ev; 267*cdf0e10cSrcweir case ET_double: 268*cdf0e10cSrcweir if (ev->u.dval < 0.0 || ev->u.dval > SAL_MAX_UINT16) 269*cdf0e10cSrcweir return NULL; 270*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.dval; 271*cdf0e10cSrcweir ev->et = ET_short; 272*cdf0e10cSrcweir return ev; 273*cdf0e10cSrcweir case ET_byte: 274*cdf0e10cSrcweir ev->u.usval = (sal_uInt16)ev->u.byval; 275*cdf0e10cSrcweir ev->et = ET_ushort; 276*cdf0e10cSrcweir return ev; 277*cdf0e10cSrcweir default: 278*cdf0e10cSrcweir OSL_ASSERT(false); 279*cdf0e10cSrcweir return NULL; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir case ET_long: 282*cdf0e10cSrcweir switch (ev->et) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir case ET_short: 285*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.sval; 286*cdf0e10cSrcweir ev->et = ET_long; 287*cdf0e10cSrcweir return ev; 288*cdf0e10cSrcweir case ET_ushort: 289*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.usval; 290*cdf0e10cSrcweir ev->et = ET_long; 291*cdf0e10cSrcweir return ev; 292*cdf0e10cSrcweir case ET_long: 293*cdf0e10cSrcweir return ev; 294*cdf0e10cSrcweir case ET_ulong: 295*cdf0e10cSrcweir if (ev->u.ulval > SAL_MAX_INT32) 296*cdf0e10cSrcweir return NULL; 297*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.ulval; 298*cdf0e10cSrcweir ev->et = ET_long; 299*cdf0e10cSrcweir return ev; 300*cdf0e10cSrcweir case ET_hyper: 301*cdf0e10cSrcweir if (ev->u.hval < SAL_MIN_INT32 || ev->u.hval > SAL_MAX_INT32) 302*cdf0e10cSrcweir return NULL; 303*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.hval; 304*cdf0e10cSrcweir ev->et = ET_long; 305*cdf0e10cSrcweir return ev; 306*cdf0e10cSrcweir case ET_uhyper: 307*cdf0e10cSrcweir if (ev->u.uhval > SAL_MAX_INT32) 308*cdf0e10cSrcweir return NULL; 309*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.uhval; 310*cdf0e10cSrcweir ev->et = ET_long; 311*cdf0e10cSrcweir return ev; 312*cdf0e10cSrcweir case ET_boolean: 313*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.bval; 314*cdf0e10cSrcweir ev->et = ET_long; 315*cdf0e10cSrcweir return ev; 316*cdf0e10cSrcweir case ET_float: 317*cdf0e10cSrcweir if (ev->u.fval < SAL_MIN_INT32 || ev->u.fval > SAL_MAX_INT32) 318*cdf0e10cSrcweir return NULL; 319*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.fval; 320*cdf0e10cSrcweir ev->et = ET_long; 321*cdf0e10cSrcweir return ev; 322*cdf0e10cSrcweir case ET_double: 323*cdf0e10cSrcweir if (ev->u.dval < SAL_MIN_INT32 || ev->u.dval > SAL_MAX_INT32) 324*cdf0e10cSrcweir return NULL; 325*cdf0e10cSrcweir ev->u.lval = (sal_Int32)ev->u.dval; 326*cdf0e10cSrcweir ev->et = ET_long; 327*cdf0e10cSrcweir return ev; 328*cdf0e10cSrcweir case ET_byte: 329*cdf0e10cSrcweir ev->u.lval = (sal_Int32) ev->u.byval; 330*cdf0e10cSrcweir ev->et = ET_long; 331*cdf0e10cSrcweir return ev; 332*cdf0e10cSrcweir default: 333*cdf0e10cSrcweir OSL_ASSERT(false); 334*cdf0e10cSrcweir return NULL; 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir case ET_ulong: 337*cdf0e10cSrcweir switch (ev->et) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir case ET_short: 340*cdf0e10cSrcweir if (ev->u.sval < 0) 341*cdf0e10cSrcweir return NULL; 342*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.sval; 343*cdf0e10cSrcweir ev->et = ET_ulong; 344*cdf0e10cSrcweir return ev; 345*cdf0e10cSrcweir case ET_ushort: 346*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.usval; 347*cdf0e10cSrcweir ev->et = ET_ulong; 348*cdf0e10cSrcweir return ev; 349*cdf0e10cSrcweir case ET_long: 350*cdf0e10cSrcweir if (ev->u.lval < 0) 351*cdf0e10cSrcweir return NULL; 352*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.lval; 353*cdf0e10cSrcweir ev->et = ET_ulong; 354*cdf0e10cSrcweir return ev; 355*cdf0e10cSrcweir case ET_ulong: 356*cdf0e10cSrcweir return ev; 357*cdf0e10cSrcweir case ET_hyper: 358*cdf0e10cSrcweir if (ev->u.hval < 0 || ev->u.hval > SAL_MAX_UINT32) 359*cdf0e10cSrcweir return NULL; 360*cdf0e10cSrcweir ev->u.lval = (sal_uInt32)ev->u.hval; 361*cdf0e10cSrcweir ev->et = ET_ulong; 362*cdf0e10cSrcweir return ev; 363*cdf0e10cSrcweir case ET_uhyper: 364*cdf0e10cSrcweir if (ev->u.uhval > SAL_MAX_UINT32) 365*cdf0e10cSrcweir return NULL; 366*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.uhval; 367*cdf0e10cSrcweir ev->et = ET_ulong; 368*cdf0e10cSrcweir return ev; 369*cdf0e10cSrcweir case ET_boolean: 370*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.bval; 371*cdf0e10cSrcweir ev->et = ET_ulong; 372*cdf0e10cSrcweir return ev; 373*cdf0e10cSrcweir case ET_float: 374*cdf0e10cSrcweir if (ev->u.fval < 0.0 || ev->u.fval > SAL_MAX_UINT32) 375*cdf0e10cSrcweir return NULL; 376*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.fval; 377*cdf0e10cSrcweir ev->et = ET_ulong; 378*cdf0e10cSrcweir return ev; 379*cdf0e10cSrcweir case ET_double: 380*cdf0e10cSrcweir if (ev->u.dval < 0.0 || ev->u.dval > SAL_MAX_UINT32) 381*cdf0e10cSrcweir return NULL; 382*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.dval; 383*cdf0e10cSrcweir ev->et = ET_ulong; 384*cdf0e10cSrcweir return ev; 385*cdf0e10cSrcweir case ET_byte: 386*cdf0e10cSrcweir ev->u.ulval = (sal_uInt32)ev->u.byval; 387*cdf0e10cSrcweir ev->et = ET_ulong; 388*cdf0e10cSrcweir return ev; 389*cdf0e10cSrcweir default: 390*cdf0e10cSrcweir OSL_ASSERT(false); 391*cdf0e10cSrcweir return NULL; 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir case ET_hyper: 394*cdf0e10cSrcweir switch (ev->et) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir case ET_short: 397*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.sval; 398*cdf0e10cSrcweir ev->et = ET_hyper; 399*cdf0e10cSrcweir return ev; 400*cdf0e10cSrcweir case ET_ushort: 401*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.usval; 402*cdf0e10cSrcweir ev->et = ET_hyper; 403*cdf0e10cSrcweir return ev; 404*cdf0e10cSrcweir case ET_long: 405*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.lval; 406*cdf0e10cSrcweir ev->et = ET_hyper; 407*cdf0e10cSrcweir return ev; 408*cdf0e10cSrcweir case ET_ulong: 409*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.ulval; 410*cdf0e10cSrcweir ev->et = ET_hyper; 411*cdf0e10cSrcweir return ev; 412*cdf0e10cSrcweir case ET_hyper: 413*cdf0e10cSrcweir return ev; 414*cdf0e10cSrcweir case ET_uhyper: 415*cdf0e10cSrcweir if (ev->u.uhval > SAL_MAX_INT64) 416*cdf0e10cSrcweir return NULL; 417*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.uhval; 418*cdf0e10cSrcweir ev->et = ET_long; 419*cdf0e10cSrcweir return ev; 420*cdf0e10cSrcweir case ET_boolean: 421*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.bval; 422*cdf0e10cSrcweir ev->et = ET_hyper; 423*cdf0e10cSrcweir return ev; 424*cdf0e10cSrcweir case ET_float: 425*cdf0e10cSrcweir if (ev->u.fval < SAL_MIN_INT64 || ev->u.fval > SAL_MAX_INT64) 426*cdf0e10cSrcweir return NULL; 427*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.fval; 428*cdf0e10cSrcweir ev->et = ET_hyper; 429*cdf0e10cSrcweir return ev; 430*cdf0e10cSrcweir case ET_double: 431*cdf0e10cSrcweir if (ev->u.dval < SAL_MIN_INT64 || ev->u.dval > SAL_MAX_INT64) 432*cdf0e10cSrcweir return NULL; 433*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.dval; 434*cdf0e10cSrcweir ev->et = ET_hyper; 435*cdf0e10cSrcweir return ev; 436*cdf0e10cSrcweir case ET_byte: 437*cdf0e10cSrcweir ev->u.hval = (sal_Int64)ev->u.byval; 438*cdf0e10cSrcweir ev->et = ET_hyper; 439*cdf0e10cSrcweir return ev; 440*cdf0e10cSrcweir default: 441*cdf0e10cSrcweir OSL_ASSERT(false); 442*cdf0e10cSrcweir return NULL; 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir case ET_uhyper: 445*cdf0e10cSrcweir switch (ev->et) 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir case ET_short: 448*cdf0e10cSrcweir if (ev->u.sval < 0) 449*cdf0e10cSrcweir return NULL; 450*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.sval; 451*cdf0e10cSrcweir ev->et = ET_uhyper; 452*cdf0e10cSrcweir return ev; 453*cdf0e10cSrcweir case ET_ushort: 454*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.usval; 455*cdf0e10cSrcweir ev->et = ET_uhyper; 456*cdf0e10cSrcweir return ev; 457*cdf0e10cSrcweir case ET_long: 458*cdf0e10cSrcweir if (ev->u.lval < 0) 459*cdf0e10cSrcweir return NULL; 460*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.lval; 461*cdf0e10cSrcweir ev->et = ET_uhyper; 462*cdf0e10cSrcweir return ev; 463*cdf0e10cSrcweir case ET_ulong: 464*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.ulval; 465*cdf0e10cSrcweir ev->et = ET_uhyper; 466*cdf0e10cSrcweir return ev; 467*cdf0e10cSrcweir case ET_hyper: 468*cdf0e10cSrcweir if (ev->u.hval < 0) 469*cdf0e10cSrcweir return NULL; 470*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.hval; 471*cdf0e10cSrcweir ev->et = ET_uhyper; 472*cdf0e10cSrcweir return ev; 473*cdf0e10cSrcweir case ET_uhyper: 474*cdf0e10cSrcweir return ev; 475*cdf0e10cSrcweir case ET_boolean: 476*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.bval; 477*cdf0e10cSrcweir ev->et = ET_uhyper; 478*cdf0e10cSrcweir return ev; 479*cdf0e10cSrcweir case ET_float: 480*cdf0e10cSrcweir if (ev->u.fval < 0.0 || ev->u.fval > SAL_MAX_UINT64) 481*cdf0e10cSrcweir return NULL; 482*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.fval; 483*cdf0e10cSrcweir ev->et = ET_uhyper; 484*cdf0e10cSrcweir return ev; 485*cdf0e10cSrcweir case ET_double: 486*cdf0e10cSrcweir if (ev->u.dval < 0.0 || ev->u.dval > SAL_MAX_UINT64) 487*cdf0e10cSrcweir return NULL; 488*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.dval; 489*cdf0e10cSrcweir ev->et = ET_uhyper; 490*cdf0e10cSrcweir return ev; 491*cdf0e10cSrcweir case ET_byte: 492*cdf0e10cSrcweir ev->u.uhval = (sal_uInt64)ev->u.byval; 493*cdf0e10cSrcweir ev->et = ET_uhyper; 494*cdf0e10cSrcweir return ev; 495*cdf0e10cSrcweir default: 496*cdf0e10cSrcweir OSL_ASSERT(false); 497*cdf0e10cSrcweir return NULL; 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir case ET_boolean: 500*cdf0e10cSrcweir switch (ev->et) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir case ET_short: 503*cdf0e10cSrcweir ev->u.bval = (ev->u.sval == 0) ? sal_False : sal_True; 504*cdf0e10cSrcweir ev->et = ET_boolean; 505*cdf0e10cSrcweir return ev; 506*cdf0e10cSrcweir case ET_ushort: 507*cdf0e10cSrcweir ev->u.bval = (ev->u.usval == 0) ? sal_False : sal_True; 508*cdf0e10cSrcweir ev->et = ET_boolean; 509*cdf0e10cSrcweir return ev; 510*cdf0e10cSrcweir case ET_long: 511*cdf0e10cSrcweir ev->u.bval = (ev->u.lval == 0) ? sal_False : sal_True; 512*cdf0e10cSrcweir ev->et = ET_boolean; 513*cdf0e10cSrcweir return ev; 514*cdf0e10cSrcweir case ET_ulong: 515*cdf0e10cSrcweir ev->u.bval = (ev->u.ulval == 0) ? sal_False : sal_True; 516*cdf0e10cSrcweir ev->et = ET_boolean; 517*cdf0e10cSrcweir return ev; 518*cdf0e10cSrcweir case ET_hyper: 519*cdf0e10cSrcweir ev->u.bval = (ev->u.hval == 0) ? sal_False : sal_True; 520*cdf0e10cSrcweir ev->et = ET_boolean; 521*cdf0e10cSrcweir return ev; 522*cdf0e10cSrcweir case ET_uhyper: 523*cdf0e10cSrcweir ev->u.bval = (ev->u.uhval == 0) ? sal_False : sal_True; 524*cdf0e10cSrcweir ev->et = ET_boolean; 525*cdf0e10cSrcweir return ev; 526*cdf0e10cSrcweir case ET_boolean: 527*cdf0e10cSrcweir return ev; 528*cdf0e10cSrcweir case ET_float: 529*cdf0e10cSrcweir ev->u.bval = (ev->u.fval == 0.0) ? sal_False : sal_True; 530*cdf0e10cSrcweir ev->et = ET_boolean; 531*cdf0e10cSrcweir return ev; 532*cdf0e10cSrcweir case ET_double: 533*cdf0e10cSrcweir ev->u.bval = (ev->u.dval == 0.0) ? sal_False : sal_True; 534*cdf0e10cSrcweir ev->et = ET_boolean; 535*cdf0e10cSrcweir return ev; 536*cdf0e10cSrcweir case ET_byte: 537*cdf0e10cSrcweir ev->u.bval = (ev->u.byval == 0) ? sal_False : sal_True; 538*cdf0e10cSrcweir ev->et = ET_boolean; 539*cdf0e10cSrcweir return ev; 540*cdf0e10cSrcweir default: 541*cdf0e10cSrcweir OSL_ASSERT(false); 542*cdf0e10cSrcweir return NULL; 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir case ET_float: 545*cdf0e10cSrcweir switch (ev->et) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir case ET_short: 548*cdf0e10cSrcweir ev->u.fval = (float)ev->u.sval; 549*cdf0e10cSrcweir ev->et = ET_float; 550*cdf0e10cSrcweir return ev; 551*cdf0e10cSrcweir case ET_ushort: 552*cdf0e10cSrcweir ev->u.fval = (float)ev->u.usval; 553*cdf0e10cSrcweir ev->et = ET_float; 554*cdf0e10cSrcweir return ev; 555*cdf0e10cSrcweir case ET_long: 556*cdf0e10cSrcweir ev->u.fval = (float)ev->u.lval; 557*cdf0e10cSrcweir ev->et = ET_float; 558*cdf0e10cSrcweir return ev; 559*cdf0e10cSrcweir case ET_ulong: 560*cdf0e10cSrcweir ev->u.fval = (float)ev->u.ulval; 561*cdf0e10cSrcweir ev->et = ET_float; 562*cdf0e10cSrcweir return ev; 563*cdf0e10cSrcweir case ET_hyper: 564*cdf0e10cSrcweir ev->u.fval = (float)ev->u.hval; 565*cdf0e10cSrcweir ev->et = ET_float; 566*cdf0e10cSrcweir return ev; 567*cdf0e10cSrcweir case ET_uhyper: 568*cdf0e10cSrcweir if ((float)ev->u.ulval > FLT_MAX) 569*cdf0e10cSrcweir return NULL; 570*cdf0e10cSrcweir ev->u.fval = (float)ev->u.ulval; 571*cdf0e10cSrcweir ev->et = ET_float; 572*cdf0e10cSrcweir return ev; 573*cdf0e10cSrcweir case ET_boolean: 574*cdf0e10cSrcweir ev->u.fval = (ev->u.bval == sal_True) ? 1.0f : 0.0f; 575*cdf0e10cSrcweir ev->et = ET_float; 576*cdf0e10cSrcweir return ev; 577*cdf0e10cSrcweir case ET_float: 578*cdf0e10cSrcweir return ev; 579*cdf0e10cSrcweir case ET_double: 580*cdf0e10cSrcweir if ((float)ev->u.dval > FLT_MAX || (float)ev->u.dval < -FLT_MAX) 581*cdf0e10cSrcweir return NULL; 582*cdf0e10cSrcweir ev->u.fval = (float)ev->u.dval; 583*cdf0e10cSrcweir ev->et = ET_float; 584*cdf0e10cSrcweir return ev; 585*cdf0e10cSrcweir case ET_byte: 586*cdf0e10cSrcweir ev->u.fval = (float)ev->u.byval; 587*cdf0e10cSrcweir ev->et = ET_float; 588*cdf0e10cSrcweir return ev; 589*cdf0e10cSrcweir default: 590*cdf0e10cSrcweir OSL_ASSERT(false); 591*cdf0e10cSrcweir return NULL; 592*cdf0e10cSrcweir } 593*cdf0e10cSrcweir case ET_double: 594*cdf0e10cSrcweir switch (ev->et) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir case ET_short: 597*cdf0e10cSrcweir ev->u.dval = (double)ev->u.sval; 598*cdf0e10cSrcweir ev->et = ET_double; 599*cdf0e10cSrcweir return ev; 600*cdf0e10cSrcweir case ET_ushort: 601*cdf0e10cSrcweir ev->u.dval = (double)ev->u.usval; 602*cdf0e10cSrcweir ev->et = ET_double; 603*cdf0e10cSrcweir return ev; 604*cdf0e10cSrcweir case ET_long: 605*cdf0e10cSrcweir ev->u.dval = (double)ev->u.lval; 606*cdf0e10cSrcweir ev->et = ET_double; 607*cdf0e10cSrcweir return ev; 608*cdf0e10cSrcweir case ET_ulong: 609*cdf0e10cSrcweir ev->u.dval = (double)ev->u.ulval; 610*cdf0e10cSrcweir ev->et = ET_double; 611*cdf0e10cSrcweir return ev; 612*cdf0e10cSrcweir case ET_hyper: 613*cdf0e10cSrcweir ev->u.dval = (double)ev->u.hval; 614*cdf0e10cSrcweir ev->et = ET_double; 615*cdf0e10cSrcweir return ev; 616*cdf0e10cSrcweir case ET_uhyper: 617*cdf0e10cSrcweir if ((double)ev->u.dval > FLT_MAX || (double)ev->u.dval < -FLT_MAX) 618*cdf0e10cSrcweir return NULL; 619*cdf0e10cSrcweir ev->u.dval = (double)ev->u.ulval; 620*cdf0e10cSrcweir ev->et = ET_double; 621*cdf0e10cSrcweir return ev; 622*cdf0e10cSrcweir case ET_boolean: 623*cdf0e10cSrcweir ev->u.dval = (ev->u.bval == sal_True) ? 1.0 : 0.0; 624*cdf0e10cSrcweir ev->et = ET_double; 625*cdf0e10cSrcweir return ev; 626*cdf0e10cSrcweir case ET_float: 627*cdf0e10cSrcweir ev->u.dval = (double)ev->u.fval; 628*cdf0e10cSrcweir ev->et = ET_double; 629*cdf0e10cSrcweir return ev; 630*cdf0e10cSrcweir case ET_double: 631*cdf0e10cSrcweir return ev; 632*cdf0e10cSrcweir case ET_byte: 633*cdf0e10cSrcweir ev->u.dval = (double)ev->u.byval; 634*cdf0e10cSrcweir ev->et = ET_double; 635*cdf0e10cSrcweir return ev; 636*cdf0e10cSrcweir default: 637*cdf0e10cSrcweir OSL_ASSERT(false); 638*cdf0e10cSrcweir return NULL; 639*cdf0e10cSrcweir } 640*cdf0e10cSrcweir case ET_byte: 641*cdf0e10cSrcweir switch (ev->et) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir case ET_short: 644*cdf0e10cSrcweir if (ev->u.sval < SAL_MIN_INT8 || ev->u.sval > SAL_MAX_UINT8) 645*cdf0e10cSrcweir return NULL; 646*cdf0e10cSrcweir ev->u.byval = (sal_uChar)ev->u.sval; 647*cdf0e10cSrcweir ev->et = ET_byte; 648*cdf0e10cSrcweir return ev; 649*cdf0e10cSrcweir case ET_ushort: 650*cdf0e10cSrcweir if (ev->u.usval > SAL_MAX_UINT8) 651*cdf0e10cSrcweir return NULL; 652*cdf0e10cSrcweir ev->u.byval = (sal_uChar)ev->u.usval; 653*cdf0e10cSrcweir ev->et = ET_byte; 654*cdf0e10cSrcweir return ev; 655*cdf0e10cSrcweir case ET_long: 656*cdf0e10cSrcweir if (ev->u.lval < SAL_MIN_INT8 || ev->u.lval > SAL_MAX_UINT8) 657*cdf0e10cSrcweir return NULL; 658*cdf0e10cSrcweir ev->u.byval = (sal_uChar) ev->u.lval; 659*cdf0e10cSrcweir ev->et = ET_byte; 660*cdf0e10cSrcweir return ev; 661*cdf0e10cSrcweir case ET_ulong: 662*cdf0e10cSrcweir if (ev->u.ulval > SAL_MAX_UINT8) 663*cdf0e10cSrcweir return NULL; 664*cdf0e10cSrcweir ev->u.byval = (sal_uChar) ev->u.ulval; 665*cdf0e10cSrcweir ev->et = ET_byte; 666*cdf0e10cSrcweir return ev; 667*cdf0e10cSrcweir case ET_hyper: 668*cdf0e10cSrcweir if (ev->u.hval < SAL_MIN_INT8 || ev->u.hval > SAL_MAX_UINT8) 669*cdf0e10cSrcweir return NULL; 670*cdf0e10cSrcweir ev->u.byval = (sal_uChar) ev->u.hval; 671*cdf0e10cSrcweir ev->et = ET_byte; 672*cdf0e10cSrcweir return ev; 673*cdf0e10cSrcweir case ET_uhyper: 674*cdf0e10cSrcweir if (ev->u.uhval > SAL_MAX_UINT8) 675*cdf0e10cSrcweir return NULL; 676*cdf0e10cSrcweir ev->u.byval = (sal_uChar) ev->u.uhval; 677*cdf0e10cSrcweir ev->et = ET_byte; 678*cdf0e10cSrcweir return ev; 679*cdf0e10cSrcweir case ET_boolean: 680*cdf0e10cSrcweir ev->u.byval = (ev->u.bval == sal_False) ? 1 : 0; 681*cdf0e10cSrcweir ev->et = ET_byte; 682*cdf0e10cSrcweir return ev; 683*cdf0e10cSrcweir case ET_float: 684*cdf0e10cSrcweir if (ev->u.fval < SAL_MIN_INT8 || ev->u.fval > SAL_MAX_UINT8) 685*cdf0e10cSrcweir return NULL; 686*cdf0e10cSrcweir ev->u.byval = (sal_uChar) ev->u.fval; 687*cdf0e10cSrcweir ev->et = ET_byte; 688*cdf0e10cSrcweir return ev; 689*cdf0e10cSrcweir case ET_double: 690*cdf0e10cSrcweir if (ev->u.dval < SAL_MIN_INT8 || ev->u.dval > SAL_MAX_UINT8) 691*cdf0e10cSrcweir return NULL; 692*cdf0e10cSrcweir ev->u.byval = (sal_uChar) ev->u.dval; 693*cdf0e10cSrcweir ev->et = ET_byte; 694*cdf0e10cSrcweir return ev; 695*cdf0e10cSrcweir case ET_byte: 696*cdf0e10cSrcweir return ev; 697*cdf0e10cSrcweir default: 698*cdf0e10cSrcweir OSL_ASSERT(false); 699*cdf0e10cSrcweir return NULL; 700*cdf0e10cSrcweir } 701*cdf0e10cSrcweir default: 702*cdf0e10cSrcweir OSL_ASSERT(false); 703*cdf0e10cSrcweir return NULL; 704*cdf0e10cSrcweir } 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir /* 708*cdf0e10cSrcweir * Evaluate the expression with the evaluation kind requested. Supported 709*cdf0e10cSrcweir * evaluation kinds are 710*cdf0e10cSrcweir * - EK_const: The expression must evaluate to a constant 711*cdf0e10cSrcweir * - EK_positive_int: The expression must further evaluate to a 712*cdf0e10cSrcweir * positive integer 713*cdf0e10cSrcweir */ 714*cdf0e10cSrcweir static AstExprValue * 715*cdf0e10cSrcweir eval_kind(AstExprValue *ev, EvalKind ek) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir if (ek == EK_const) 718*cdf0e10cSrcweir return ev; 719*cdf0e10cSrcweir if (ek == EK_positive_int) 720*cdf0e10cSrcweir return coerce_value(ev, ET_ulong); 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir return NULL; 723*cdf0e10cSrcweir } 724*cdf0e10cSrcweir 725*cdf0e10cSrcweir AstExprValue* AstExpression::coerce(ExprType t, sal_Bool bAssign) 726*cdf0e10cSrcweir { 727*cdf0e10cSrcweir AstExprValue *copy; 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir /* 730*cdf0e10cSrcweir * Is it already of the right type? 731*cdf0e10cSrcweir */ 732*cdf0e10cSrcweir if (m_exprValue != NULL && m_exprValue->et == t) 733*cdf0e10cSrcweir return m_exprValue; 734*cdf0e10cSrcweir /* 735*cdf0e10cSrcweir * OK, must coerce 736*cdf0e10cSrcweir * 737*cdf0e10cSrcweir * First, evaluate it, then try to coerce result type 738*cdf0e10cSrcweir * If already evaluated, return the result 739*cdf0e10cSrcweir */ 740*cdf0e10cSrcweir m_exprValue = eval_internal(EK_const); 741*cdf0e10cSrcweir if (m_exprValue == NULL) 742*cdf0e10cSrcweir return NULL; 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir /* 745*cdf0e10cSrcweir * Create a copy to contain coercion result 746*cdf0e10cSrcweir */ 747*cdf0e10cSrcweir copy = new AstExprValue; 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir copy->et = m_exprValue->et; 750*cdf0e10cSrcweir switch (m_exprValue->et) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir case ET_short: 753*cdf0e10cSrcweir copy->u.sval = m_exprValue->u.sval; 754*cdf0e10cSrcweir break; 755*cdf0e10cSrcweir case ET_ushort: 756*cdf0e10cSrcweir copy->u.usval = m_exprValue->u.usval; 757*cdf0e10cSrcweir break; 758*cdf0e10cSrcweir case ET_long: 759*cdf0e10cSrcweir copy->u.lval = m_exprValue->u.lval; 760*cdf0e10cSrcweir break; 761*cdf0e10cSrcweir case ET_ulong: 762*cdf0e10cSrcweir copy->u.ulval = m_exprValue->u.ulval; 763*cdf0e10cSrcweir break; 764*cdf0e10cSrcweir case ET_hyper: 765*cdf0e10cSrcweir copy->u.hval = m_exprValue->u.hval; 766*cdf0e10cSrcweir break; 767*cdf0e10cSrcweir case ET_uhyper: 768*cdf0e10cSrcweir copy->u.uhval = m_exprValue->u.uhval; 769*cdf0e10cSrcweir break; 770*cdf0e10cSrcweir case ET_boolean: 771*cdf0e10cSrcweir copy->u.bval = m_exprValue->u.bval; 772*cdf0e10cSrcweir break; 773*cdf0e10cSrcweir case ET_float: 774*cdf0e10cSrcweir copy->u.fval = m_exprValue->u.fval; 775*cdf0e10cSrcweir break; 776*cdf0e10cSrcweir case ET_double: 777*cdf0e10cSrcweir copy->u.dval = m_exprValue->u.dval; 778*cdf0e10cSrcweir break; 779*cdf0e10cSrcweir case ET_byte: 780*cdf0e10cSrcweir copy->u.byval = m_exprValue->u.byval; 781*cdf0e10cSrcweir break; 782*cdf0e10cSrcweir default: 783*cdf0e10cSrcweir OSL_ASSERT(false); 784*cdf0e10cSrcweir break; 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir if (bAssign) 788*cdf0e10cSrcweir { 789*cdf0e10cSrcweir m_exprValue = coerce_value(copy, t); 790*cdf0e10cSrcweir return m_exprValue; 791*cdf0e10cSrcweir } 792*cdf0e10cSrcweir 793*cdf0e10cSrcweir return coerce_value(copy, t); 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir void AstExpression::evaluate(EvalKind ek) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir m_exprValue = eval_internal(ek); 799*cdf0e10cSrcweir m_exprValue = eval_kind(m_exprValue, ek); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir sal_Bool AstExpression::operator==(AstExpression *pExpr) 803*cdf0e10cSrcweir { 804*cdf0e10cSrcweir if (m_combOperator != pExpr->getCombOperator()) 805*cdf0e10cSrcweir return sal_False; 806*cdf0e10cSrcweir evaluate(EK_const); 807*cdf0e10cSrcweir pExpr->evaluate(EK_const); 808*cdf0e10cSrcweir if (m_exprValue == NULL || pExpr->getExprValue() == NULL) 809*cdf0e10cSrcweir return sal_False; 810*cdf0e10cSrcweir if (m_exprValue->et != pExpr->getExprValue()->et) 811*cdf0e10cSrcweir return sal_False; 812*cdf0e10cSrcweir switch (m_exprValue->et) 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir case ET_short: 815*cdf0e10cSrcweir return (m_exprValue->u.sval == pExpr->getExprValue()->u.sval) ? sal_True : sal_False; 816*cdf0e10cSrcweir case ET_ushort: 817*cdf0e10cSrcweir return (m_exprValue->u.usval == pExpr->getExprValue()->u.usval) ? sal_True : sal_False; 818*cdf0e10cSrcweir case ET_long: 819*cdf0e10cSrcweir return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False; 820*cdf0e10cSrcweir case ET_ulong: 821*cdf0e10cSrcweir return (m_exprValue->u.ulval == pExpr->getExprValue()->u.ulval) ? sal_True : sal_False; 822*cdf0e10cSrcweir case ET_hyper: 823*cdf0e10cSrcweir return (m_exprValue->u.hval == pExpr->getExprValue()->u.hval) ? sal_True : sal_False; 824*cdf0e10cSrcweir case ET_uhyper: 825*cdf0e10cSrcweir return (m_exprValue->u.uhval == pExpr->getExprValue()->u.uhval) ? sal_True : sal_False; 826*cdf0e10cSrcweir case ET_float: 827*cdf0e10cSrcweir return (m_exprValue->u.fval == pExpr->getExprValue()->u.fval) ? sal_True : sal_False; 828*cdf0e10cSrcweir case ET_double: 829*cdf0e10cSrcweir return (m_exprValue->u.dval == pExpr->getExprValue()->u.dval) ? sal_True : sal_False; 830*cdf0e10cSrcweir case ET_byte: 831*cdf0e10cSrcweir return (m_exprValue->u.byval == pExpr->getExprValue()->u.byval) ? sal_True : sal_False; 832*cdf0e10cSrcweir case ET_boolean: 833*cdf0e10cSrcweir return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False; 834*cdf0e10cSrcweir default: 835*cdf0e10cSrcweir OSL_ASSERT(false); 836*cdf0e10cSrcweir return sal_False; 837*cdf0e10cSrcweir } 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir return sal_False; 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir sal_Bool AstExpression::compare(AstExpression *pExpr) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir if (m_combOperator != pExpr->getCombOperator()) 845*cdf0e10cSrcweir return sal_False; 846*cdf0e10cSrcweir evaluate(EK_const); 847*cdf0e10cSrcweir pExpr->evaluate(EK_const); 848*cdf0e10cSrcweir if (m_exprValue == NULL || pExpr->getExprValue() == NULL) 849*cdf0e10cSrcweir return sal_False; 850*cdf0e10cSrcweir if (m_exprValue->et != pExpr->getExprValue()->et) 851*cdf0e10cSrcweir return sal_False; 852*cdf0e10cSrcweir switch (m_exprValue->et) 853*cdf0e10cSrcweir { 854*cdf0e10cSrcweir case ET_short: 855*cdf0e10cSrcweir return (m_exprValue->u.sval == pExpr->getExprValue()->u.sval) ? sal_True : sal_False; 856*cdf0e10cSrcweir case ET_ushort: 857*cdf0e10cSrcweir return (m_exprValue->u.usval == pExpr->getExprValue()->u.usval) ? sal_True : sal_False; 858*cdf0e10cSrcweir case ET_long: 859*cdf0e10cSrcweir return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False; 860*cdf0e10cSrcweir case ET_ulong: 861*cdf0e10cSrcweir return (m_exprValue->u.ulval == pExpr->getExprValue()->u.ulval) ? sal_True : sal_False; 862*cdf0e10cSrcweir case ET_hyper: 863*cdf0e10cSrcweir return (m_exprValue->u.hval == pExpr->getExprValue()->u.hval) ? sal_True : sal_False; 864*cdf0e10cSrcweir case ET_uhyper: 865*cdf0e10cSrcweir return (m_exprValue->u.uhval == pExpr->getExprValue()->u.uhval) ? sal_True : sal_False; 866*cdf0e10cSrcweir case ET_float: 867*cdf0e10cSrcweir return (m_exprValue->u.fval == pExpr->getExprValue()->u.fval) ? sal_True : sal_False; 868*cdf0e10cSrcweir case ET_double: 869*cdf0e10cSrcweir return (m_exprValue->u.dval == pExpr->getExprValue()->u.dval) ? sal_True : sal_False; 870*cdf0e10cSrcweir case ET_byte: 871*cdf0e10cSrcweir return (m_exprValue->u.byval == pExpr->getExprValue()->u.byval) ? sal_True : sal_False; 872*cdf0e10cSrcweir case ET_boolean: 873*cdf0e10cSrcweir return (m_exprValue->u.lval == pExpr->getExprValue()->u.lval) ? sal_True : sal_False; 874*cdf0e10cSrcweir default: 875*cdf0e10cSrcweir OSL_ASSERT(false); 876*cdf0e10cSrcweir return sal_False; 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir return sal_False; 880*cdf0e10cSrcweir } 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir void AstExpression::fillDefinitionDetails() 883*cdf0e10cSrcweir { 884*cdf0e10cSrcweir m_pScope = idlc()->scopes()->depth() > 0 ? idlc()->scopes()->top() : NULL; 885*cdf0e10cSrcweir m_lineNo = idlc()->getLineNumber(); 886*cdf0e10cSrcweir m_fileName = idlc()->getFileName(); 887*cdf0e10cSrcweir } 888*cdf0e10cSrcweir 889*cdf0e10cSrcweir AstExprValue* AstExpression::eval_internal(EvalKind ek) 890*cdf0e10cSrcweir { 891*cdf0e10cSrcweir /* 892*cdf0e10cSrcweir * Already evaluated? 893*cdf0e10cSrcweir */ 894*cdf0e10cSrcweir if ( m_exprValue != NULL ) 895*cdf0e10cSrcweir return eval_kind(m_exprValue, ek); 896*cdf0e10cSrcweir /* 897*cdf0e10cSrcweir * OK, must evaluate operator 898*cdf0e10cSrcweir */ 899*cdf0e10cSrcweir switch (m_combOperator) 900*cdf0e10cSrcweir { 901*cdf0e10cSrcweir case EC_add: 902*cdf0e10cSrcweir case EC_minus: 903*cdf0e10cSrcweir case EC_mul: 904*cdf0e10cSrcweir case EC_div: 905*cdf0e10cSrcweir case EC_mod: 906*cdf0e10cSrcweir m_exprValue = eval_bin_op(ek); 907*cdf0e10cSrcweir return eval_kind(m_exprValue, ek); 908*cdf0e10cSrcweir case EC_or: 909*cdf0e10cSrcweir case EC_xor: 910*cdf0e10cSrcweir case EC_and: 911*cdf0e10cSrcweir case EC_left: 912*cdf0e10cSrcweir case EC_right: 913*cdf0e10cSrcweir m_exprValue = eval_bit_op(ek); 914*cdf0e10cSrcweir return eval_kind(m_exprValue, ek); 915*cdf0e10cSrcweir case EC_u_plus: 916*cdf0e10cSrcweir case EC_u_minus: 917*cdf0e10cSrcweir case EC_bit_neg: 918*cdf0e10cSrcweir m_exprValue = eval_un_op(ek); 919*cdf0e10cSrcweir return eval_kind(m_exprValue, ek); 920*cdf0e10cSrcweir case EC_symbol: 921*cdf0e10cSrcweir m_exprValue = eval_symbol(ek); 922*cdf0e10cSrcweir return eval_kind(m_exprValue, ek); 923*cdf0e10cSrcweir case EC_none: 924*cdf0e10cSrcweir return NULL; 925*cdf0e10cSrcweir } 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir return NULL; 928*cdf0e10cSrcweir } 929*cdf0e10cSrcweir 930*cdf0e10cSrcweir AstExprValue* AstExpression::eval_bin_op(EvalKind ek) 931*cdf0e10cSrcweir { 932*cdf0e10cSrcweir ExprType eType = ET_double; 933*cdf0e10cSrcweir 934*cdf0e10cSrcweir if ( m_combOperator == EC_mod ) 935*cdf0e10cSrcweir eType = ET_hyper; 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir if (ek != EK_const && ek != EK_positive_int) 938*cdf0e10cSrcweir return NULL; 939*cdf0e10cSrcweir if (m_subExpr1 == NULL || m_subExpr2 == NULL) 940*cdf0e10cSrcweir return NULL; 941*cdf0e10cSrcweir m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek)); 942*cdf0e10cSrcweir if (m_subExpr1->getExprValue() == NULL) 943*cdf0e10cSrcweir return NULL; 944*cdf0e10cSrcweir m_subExpr1->setExprValue(m_subExpr1->coerce(eType)); 945*cdf0e10cSrcweir if (m_subExpr1->getExprValue() == NULL) 946*cdf0e10cSrcweir return NULL; 947*cdf0e10cSrcweir m_subExpr2->setExprValue(m_subExpr2->eval_internal(ek)); 948*cdf0e10cSrcweir if (m_subExpr2->getExprValue() == NULL) 949*cdf0e10cSrcweir return NULL; 950*cdf0e10cSrcweir m_subExpr2->setExprValue(m_subExpr2->coerce(eType)); 951*cdf0e10cSrcweir if (m_subExpr2->getExprValue() == NULL) 952*cdf0e10cSrcweir return NULL; 953*cdf0e10cSrcweir 954*cdf0e10cSrcweir std::auto_ptr< AstExprValue > retval(new AstExprValue()); 955*cdf0e10cSrcweir retval->et = eType; 956*cdf0e10cSrcweir 957*cdf0e10cSrcweir switch (m_combOperator) 958*cdf0e10cSrcweir { 959*cdf0e10cSrcweir case EC_mod: 960*cdf0e10cSrcweir if (m_subExpr2->getExprValue()->u.hval == 0) 961*cdf0e10cSrcweir return NULL; 962*cdf0e10cSrcweir retval->u.hval = m_subExpr1->getExprValue()->u.hval % m_subExpr2->getExprValue()->u.hval; 963*cdf0e10cSrcweir break; 964*cdf0e10cSrcweir case EC_add: 965*cdf0e10cSrcweir retval->u.dval = m_subExpr1->getExprValue()->u.dval + m_subExpr2->getExprValue()->u.dval; 966*cdf0e10cSrcweir break; 967*cdf0e10cSrcweir case EC_minus: 968*cdf0e10cSrcweir retval->u.dval = m_subExpr1->getExprValue()->u.dval - m_subExpr2->getExprValue()->u.dval; 969*cdf0e10cSrcweir break; 970*cdf0e10cSrcweir case EC_mul: 971*cdf0e10cSrcweir retval->u.dval = m_subExpr1->getExprValue()->u.dval * m_subExpr2->getExprValue()->u.dval; 972*cdf0e10cSrcweir break; 973*cdf0e10cSrcweir case EC_div: 974*cdf0e10cSrcweir if (m_subExpr2->getExprValue()->u.dval == 0.0) 975*cdf0e10cSrcweir return NULL; 976*cdf0e10cSrcweir retval->u.dval = m_subExpr1->getExprValue()->u.dval / m_subExpr2->getExprValue()->u.dval; 977*cdf0e10cSrcweir break; 978*cdf0e10cSrcweir default: 979*cdf0e10cSrcweir return NULL; 980*cdf0e10cSrcweir } 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir return retval.release(); 983*cdf0e10cSrcweir } 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir AstExprValue* AstExpression::eval_bit_op(EvalKind ek) 986*cdf0e10cSrcweir { 987*cdf0e10cSrcweir if (ek != EK_const && ek != EK_positive_int) 988*cdf0e10cSrcweir return NULL; 989*cdf0e10cSrcweir if (m_subExpr1 == NULL || m_subExpr2 == NULL) 990*cdf0e10cSrcweir return NULL; 991*cdf0e10cSrcweir m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek)); 992*cdf0e10cSrcweir if (m_subExpr1->getExprValue() == NULL) 993*cdf0e10cSrcweir return NULL; 994*cdf0e10cSrcweir m_subExpr1->setExprValue(m_subExpr1->coerce(ET_long)); 995*cdf0e10cSrcweir if (m_subExpr1->getExprValue() == NULL) 996*cdf0e10cSrcweir return NULL; 997*cdf0e10cSrcweir m_subExpr2->setExprValue(m_subExpr2->eval_internal(ek)); 998*cdf0e10cSrcweir if (m_subExpr2->getExprValue() == NULL) 999*cdf0e10cSrcweir return NULL; 1000*cdf0e10cSrcweir m_subExpr2->setExprValue(m_subExpr2->coerce(ET_long)); 1001*cdf0e10cSrcweir if (m_subExpr2->getExprValue() == NULL) 1002*cdf0e10cSrcweir return NULL; 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir std::auto_ptr< AstExprValue > retval(new AstExprValue()); 1005*cdf0e10cSrcweir retval->et = ET_long; 1006*cdf0e10cSrcweir 1007*cdf0e10cSrcweir switch (m_combOperator) 1008*cdf0e10cSrcweir { 1009*cdf0e10cSrcweir case EC_or: 1010*cdf0e10cSrcweir retval->u.lval = m_subExpr1->getExprValue()->u.lval | m_subExpr2->getExprValue()->u.lval; 1011*cdf0e10cSrcweir break; 1012*cdf0e10cSrcweir case EC_xor: 1013*cdf0e10cSrcweir retval->u.lval = m_subExpr1->getExprValue()->u.lval ^ m_subExpr2->getExprValue()->u.lval; 1014*cdf0e10cSrcweir break; 1015*cdf0e10cSrcweir case EC_and: 1016*cdf0e10cSrcweir retval->u.lval = m_subExpr1->getExprValue()->u.lval & m_subExpr2->getExprValue()->u.lval; 1017*cdf0e10cSrcweir break; 1018*cdf0e10cSrcweir case EC_left: 1019*cdf0e10cSrcweir retval->u.lval = m_subExpr1->getExprValue()->u.lval << m_subExpr2->getExprValue()->u.lval; 1020*cdf0e10cSrcweir break; 1021*cdf0e10cSrcweir case EC_right: 1022*cdf0e10cSrcweir retval->u.lval = m_subExpr1->getExprValue()->u.lval >> m_subExpr2->getExprValue()->u.lval; 1023*cdf0e10cSrcweir break; 1024*cdf0e10cSrcweir default: 1025*cdf0e10cSrcweir return NULL; 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir return retval.release(); 1029*cdf0e10cSrcweir } 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir AstExprValue* AstExpression::eval_un_op(EvalKind ek) 1032*cdf0e10cSrcweir { 1033*cdf0e10cSrcweir if (m_exprValue != NULL) 1034*cdf0e10cSrcweir return m_exprValue; 1035*cdf0e10cSrcweir 1036*cdf0e10cSrcweir if (ek != EK_const && ek != EK_positive_int) 1037*cdf0e10cSrcweir return NULL; 1038*cdf0e10cSrcweir if (m_subExpr1 == NULL) 1039*cdf0e10cSrcweir return NULL; 1040*cdf0e10cSrcweir m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek)); 1041*cdf0e10cSrcweir if (m_subExpr1->getExprValue() == NULL) 1042*cdf0e10cSrcweir return NULL; 1043*cdf0e10cSrcweir m_subExpr1->setExprValue(m_subExpr1->coerce(ET_double)); 1044*cdf0e10cSrcweir if (m_subExpr1->getExprValue() == NULL) 1045*cdf0e10cSrcweir return NULL; 1046*cdf0e10cSrcweir 1047*cdf0e10cSrcweir std::auto_ptr< AstExprValue > retval(new AstExprValue()); 1048*cdf0e10cSrcweir retval->et = ET_double; 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir switch (m_combOperator) 1051*cdf0e10cSrcweir { 1052*cdf0e10cSrcweir case EC_u_plus: 1053*cdf0e10cSrcweir retval->u.lval = m_subExpr1->getExprValue()->u.lval; 1054*cdf0e10cSrcweir break; 1055*cdf0e10cSrcweir case EC_u_minus: 1056*cdf0e10cSrcweir retval->u.lval = -(m_subExpr1->getExprValue()->u.lval); 1057*cdf0e10cSrcweir break; 1058*cdf0e10cSrcweir case EC_bit_neg: 1059*cdf0e10cSrcweir m_subExpr1->setExprValue(m_subExpr1->coerce(ET_long)); 1060*cdf0e10cSrcweir if (m_subExpr1->getExprValue() == NULL) 1061*cdf0e10cSrcweir return NULL; 1062*cdf0e10cSrcweir retval->u.lval = ~m_subExpr1->getExprValue()->u.lval; 1063*cdf0e10cSrcweir break; 1064*cdf0e10cSrcweir default: 1065*cdf0e10cSrcweir return NULL; 1066*cdf0e10cSrcweir } 1067*cdf0e10cSrcweir 1068*cdf0e10cSrcweir return retval.release(); 1069*cdf0e10cSrcweir } 1070*cdf0e10cSrcweir 1071*cdf0e10cSrcweir AstExprValue* AstExpression::eval_symbol(EvalKind ek) 1072*cdf0e10cSrcweir { 1073*cdf0e10cSrcweir AstScope *pScope = 0; 1074*cdf0e10cSrcweir AstDeclaration *pDecl; 1075*cdf0e10cSrcweir AstConstant *pConst; 1076*cdf0e10cSrcweir 1077*cdf0e10cSrcweir /* 1078*cdf0e10cSrcweir * Is there a symbol stored? 1079*cdf0e10cSrcweir */ 1080*cdf0e10cSrcweir if (m_pSymbolicName == NULL) 1081*cdf0e10cSrcweir { 1082*cdf0e10cSrcweir idlc()->error()->evalError(this); 1083*cdf0e10cSrcweir return NULL; 1084*cdf0e10cSrcweir } 1085*cdf0e10cSrcweir /* 1086*cdf0e10cSrcweir * Get current scope for lookup 1087*cdf0e10cSrcweir */ 1088*cdf0e10cSrcweir if (idlc()->scopes()->depth() > 0) 1089*cdf0e10cSrcweir pScope = idlc()->scopes()->topNonNull(); 1090*cdf0e10cSrcweir if ( !pScope ) 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir idlc()->error()->lookupError(*m_pSymbolicName); 1093*cdf0e10cSrcweir return NULL; 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir /* 1096*cdf0e10cSrcweir * Do lookup 1097*cdf0e10cSrcweir */ 1098*cdf0e10cSrcweir pDecl = pScope->lookupByName(*m_pSymbolicName); 1099*cdf0e10cSrcweir if (pDecl == NULL) 1100*cdf0e10cSrcweir { 1101*cdf0e10cSrcweir idlc()->error()->lookupError(*m_pSymbolicName); 1102*cdf0e10cSrcweir return NULL; 1103*cdf0e10cSrcweir } 1104*cdf0e10cSrcweir /* 1105*cdf0e10cSrcweir * Is it a constant? 1106*cdf0e10cSrcweir */ 1107*cdf0e10cSrcweir if (pDecl->getNodeType() != NT_const && 1108*cdf0e10cSrcweir pDecl->getNodeType() != NT_enum_val) 1109*cdf0e10cSrcweir { 1110*cdf0e10cSrcweir idlc()->error()->constantExpected(pDecl, *m_pSymbolicName); 1111*cdf0e10cSrcweir return NULL; 1112*cdf0e10cSrcweir } 1113*cdf0e10cSrcweir if (!idlc()->error()->checkPublished(pDecl)) 1114*cdf0e10cSrcweir { 1115*cdf0e10cSrcweir return NULL; 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir /* 1118*cdf0e10cSrcweir * OK, now evaluate the constant we just got, to produce its value 1119*cdf0e10cSrcweir */ 1120*cdf0e10cSrcweir pConst = static_cast< AstConstant* >(pDecl); 1121*cdf0e10cSrcweir if (pConst == NULL) 1122*cdf0e10cSrcweir return NULL; 1123*cdf0e10cSrcweir return pConst->getConstValue()->eval_internal(ek); 1124*cdf0e10cSrcweir } 1125*cdf0e10cSrcweir 1126*cdf0e10cSrcweir OString AstExpression::toString() 1127*cdf0e10cSrcweir { 1128*cdf0e10cSrcweir OString exprStr; 1129*cdf0e10cSrcweir if ( m_combOperator == EC_symbol ) 1130*cdf0e10cSrcweir return *m_pSymbolicName; 1131*cdf0e10cSrcweir 1132*cdf0e10cSrcweir if ( m_exprValue ) 1133*cdf0e10cSrcweir { 1134*cdf0e10cSrcweir switch (m_exprValue->et) 1135*cdf0e10cSrcweir { 1136*cdf0e10cSrcweir case ET_short: 1137*cdf0e10cSrcweir return OString::valueOf((sal_Int32)m_exprValue->u.sval); 1138*cdf0e10cSrcweir case ET_ushort: 1139*cdf0e10cSrcweir return OString::valueOf((sal_Int32)m_exprValue->u.usval); 1140*cdf0e10cSrcweir case ET_long: 1141*cdf0e10cSrcweir return OString::valueOf(m_exprValue->u.lval); 1142*cdf0e10cSrcweir case ET_ulong: 1143*cdf0e10cSrcweir return OString::valueOf((sal_Int32)m_exprValue->u.ulval); 1144*cdf0e10cSrcweir case ET_hyper: 1145*cdf0e10cSrcweir return OString::valueOf(m_exprValue->u.hval); 1146*cdf0e10cSrcweir case ET_uhyper: 1147*cdf0e10cSrcweir return OString::valueOf((sal_Int64)m_exprValue->u.uhval); 1148*cdf0e10cSrcweir case ET_float: 1149*cdf0e10cSrcweir return OString::valueOf(m_exprValue->u.fval); 1150*cdf0e10cSrcweir case ET_double: 1151*cdf0e10cSrcweir return OString::valueOf(m_exprValue->u.dval); 1152*cdf0e10cSrcweir case ET_byte: 1153*cdf0e10cSrcweir return OString::valueOf((sal_Int32)m_exprValue->u.byval); 1154*cdf0e10cSrcweir case ET_boolean: 1155*cdf0e10cSrcweir if ( m_exprValue->u.lval == 0) 1156*cdf0e10cSrcweir return OString("FALSE"); 1157*cdf0e10cSrcweir else 1158*cdf0e10cSrcweir return OString("TRUE"); 1159*cdf0e10cSrcweir default: 1160*cdf0e10cSrcweir OSL_ASSERT(false); 1161*cdf0e10cSrcweir return OString(); 1162*cdf0e10cSrcweir } 1163*cdf0e10cSrcweir } 1164*cdf0e10cSrcweir 1165*cdf0e10cSrcweir switch (m_combOperator) 1166*cdf0e10cSrcweir { 1167*cdf0e10cSrcweir case EC_u_plus: 1168*cdf0e10cSrcweir exprStr += OString("+"); 1169*cdf0e10cSrcweir break; 1170*cdf0e10cSrcweir case EC_u_minus: 1171*cdf0e10cSrcweir exprStr += OString("-"); 1172*cdf0e10cSrcweir break; 1173*cdf0e10cSrcweir case EC_bit_neg: 1174*cdf0e10cSrcweir exprStr += OString("~"); 1175*cdf0e10cSrcweir break; 1176*cdf0e10cSrcweir default: 1177*cdf0e10cSrcweir break; 1178*cdf0e10cSrcweir } 1179*cdf0e10cSrcweir if ( m_subExpr1 ) 1180*cdf0e10cSrcweir exprStr += m_subExpr1->toString(); 1181*cdf0e10cSrcweir switch (m_combOperator) 1182*cdf0e10cSrcweir { 1183*cdf0e10cSrcweir case EC_add: 1184*cdf0e10cSrcweir exprStr += OString(" + "); 1185*cdf0e10cSrcweir break; 1186*cdf0e10cSrcweir case EC_minus: 1187*cdf0e10cSrcweir exprStr += OString(" - "); 1188*cdf0e10cSrcweir break; 1189*cdf0e10cSrcweir case EC_mul: 1190*cdf0e10cSrcweir exprStr += OString(" * "); 1191*cdf0e10cSrcweir break; 1192*cdf0e10cSrcweir case EC_div: 1193*cdf0e10cSrcweir exprStr += OString(" / "); 1194*cdf0e10cSrcweir break; 1195*cdf0e10cSrcweir case EC_mod: 1196*cdf0e10cSrcweir exprStr += OString(" % "); 1197*cdf0e10cSrcweir break; 1198*cdf0e10cSrcweir case EC_or: 1199*cdf0e10cSrcweir exprStr += OString(" | "); 1200*cdf0e10cSrcweir break; 1201*cdf0e10cSrcweir case EC_xor: 1202*cdf0e10cSrcweir exprStr += OString(" ^ "); 1203*cdf0e10cSrcweir break; 1204*cdf0e10cSrcweir case EC_and: 1205*cdf0e10cSrcweir exprStr += OString(" & "); 1206*cdf0e10cSrcweir break; 1207*cdf0e10cSrcweir case EC_left: 1208*cdf0e10cSrcweir exprStr += OString(" << "); 1209*cdf0e10cSrcweir break; 1210*cdf0e10cSrcweir case EC_right: 1211*cdf0e10cSrcweir exprStr += OString(" >> "); 1212*cdf0e10cSrcweir break; 1213*cdf0e10cSrcweir default: 1214*cdf0e10cSrcweir break; 1215*cdf0e10cSrcweir } 1216*cdf0e10cSrcweir 1217*cdf0e10cSrcweir if ( m_subExpr2 ) 1218*cdf0e10cSrcweir exprStr += m_subExpr2->toString(); 1219*cdf0e10cSrcweir 1220*cdf0e10cSrcweir return exprStr; 1221*cdf0e10cSrcweir } 1222*cdf0e10cSrcweir 1223*cdf0e10cSrcweir // Convert the type of an AST_Expression to a char * 1224*cdf0e10cSrcweir const sal_Char* SAL_CALL exprTypeToString(ExprType t) 1225*cdf0e10cSrcweir { 1226*cdf0e10cSrcweir switch (t) 1227*cdf0e10cSrcweir { 1228*cdf0e10cSrcweir case ET_short: 1229*cdf0e10cSrcweir return "short"; 1230*cdf0e10cSrcweir case ET_ushort: 1231*cdf0e10cSrcweir return "unsigned short"; 1232*cdf0e10cSrcweir case ET_long: 1233*cdf0e10cSrcweir return "long"; 1234*cdf0e10cSrcweir case ET_ulong: 1235*cdf0e10cSrcweir return "unsigned long"; 1236*cdf0e10cSrcweir case ET_hyper: 1237*cdf0e10cSrcweir return "hyper"; 1238*cdf0e10cSrcweir case ET_uhyper: 1239*cdf0e10cSrcweir return "unsigned hyper"; 1240*cdf0e10cSrcweir case ET_float: 1241*cdf0e10cSrcweir return "float"; 1242*cdf0e10cSrcweir case ET_double: 1243*cdf0e10cSrcweir return "double"; 1244*cdf0e10cSrcweir case ET_char: 1245*cdf0e10cSrcweir return "char"; 1246*cdf0e10cSrcweir case ET_byte: 1247*cdf0e10cSrcweir return "byte"; 1248*cdf0e10cSrcweir case ET_boolean: 1249*cdf0e10cSrcweir return "boolean"; 1250*cdf0e10cSrcweir case ET_string: 1251*cdf0e10cSrcweir return "string"; 1252*cdf0e10cSrcweir case ET_any: 1253*cdf0e10cSrcweir return "any"; 1254*cdf0e10cSrcweir case ET_type: 1255*cdf0e10cSrcweir return "type"; 1256*cdf0e10cSrcweir case ET_void: 1257*cdf0e10cSrcweir return "void"; 1258*cdf0e10cSrcweir case ET_none: 1259*cdf0e10cSrcweir return "none"; 1260*cdf0e10cSrcweir } 1261*cdf0e10cSrcweir 1262*cdf0e10cSrcweir return ("unkown"); 1263*cdf0e10cSrcweir } 1264