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 #include <idlc/astconstant.hxx> 31*cdf0e10cSrcweir #include <idlc/astscope.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "registry/writer.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir using namespace ::rtl; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir AstConstant::AstConstant(const ExprType type, 38*cdf0e10cSrcweir const NodeType nodeType, 39*cdf0e10cSrcweir AstExpression* pExpr, 40*cdf0e10cSrcweir const ::rtl::OString& name, 41*cdf0e10cSrcweir AstScope* pScope) 42*cdf0e10cSrcweir : AstDeclaration(nodeType, name, pScope) 43*cdf0e10cSrcweir , m_pConstValue(pExpr) 44*cdf0e10cSrcweir , m_constValueType(type) 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir AstConstant::AstConstant(const ExprType type, 49*cdf0e10cSrcweir AstExpression* pExpr, 50*cdf0e10cSrcweir const ::rtl::OString& name, 51*cdf0e10cSrcweir AstScope* pScope) 52*cdf0e10cSrcweir : AstDeclaration(NT_const, name, pScope) 53*cdf0e10cSrcweir , m_pConstValue(pExpr) 54*cdf0e10cSrcweir , m_constValueType(type) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir AstConstant::~AstConstant() 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir sal_Bool AstConstant::dumpBlob( 64*cdf0e10cSrcweir typereg::Writer & rBlob, sal_uInt16 index, bool published) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir RTConstValue aConst; 67*cdf0e10cSrcweir sal_Unicode* str = NULL; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir AstExprValue *exprVal = getConstValue()->getExprValue(); 70*cdf0e10cSrcweir switch (getConstValueType()) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir case ET_short: 73*cdf0e10cSrcweir aConst.m_type = RT_TYPE_INT16; 74*cdf0e10cSrcweir aConst.m_value.aShort = exprVal->u.sval; 75*cdf0e10cSrcweir break; 76*cdf0e10cSrcweir case ET_ushort: 77*cdf0e10cSrcweir aConst.m_type = RT_TYPE_UINT16; 78*cdf0e10cSrcweir aConst.m_value.aUShort = exprVal->u.usval; 79*cdf0e10cSrcweir break; 80*cdf0e10cSrcweir case ET_long: 81*cdf0e10cSrcweir aConst.m_type = RT_TYPE_INT32; 82*cdf0e10cSrcweir aConst.m_value.aLong = exprVal->u.lval; 83*cdf0e10cSrcweir break; 84*cdf0e10cSrcweir case ET_ulong: 85*cdf0e10cSrcweir aConst.m_type = RT_TYPE_UINT32; 86*cdf0e10cSrcweir aConst.m_value.aULong = exprVal->u.ulval; 87*cdf0e10cSrcweir break; 88*cdf0e10cSrcweir case ET_hyper: 89*cdf0e10cSrcweir aConst.m_type = RT_TYPE_INT64; 90*cdf0e10cSrcweir aConst.m_value.aHyper = exprVal->u.hval; 91*cdf0e10cSrcweir break; 92*cdf0e10cSrcweir case ET_uhyper: 93*cdf0e10cSrcweir aConst.m_type = RT_TYPE_UINT64; 94*cdf0e10cSrcweir aConst.m_value.aUHyper = exprVal->u.uhval; 95*cdf0e10cSrcweir break; 96*cdf0e10cSrcweir case ET_float: 97*cdf0e10cSrcweir aConst.m_type = RT_TYPE_FLOAT; 98*cdf0e10cSrcweir aConst.m_value.aFloat = exprVal->u.fval; 99*cdf0e10cSrcweir break; 100*cdf0e10cSrcweir case ET_double: 101*cdf0e10cSrcweir aConst.m_type = RT_TYPE_DOUBLE; 102*cdf0e10cSrcweir aConst.m_value.aDouble = exprVal->u.dval; 103*cdf0e10cSrcweir break; 104*cdf0e10cSrcweir case ET_byte: 105*cdf0e10cSrcweir aConst.m_type = RT_TYPE_BYTE; 106*cdf0e10cSrcweir aConst.m_value.aByte = exprVal->u.byval; 107*cdf0e10cSrcweir break; 108*cdf0e10cSrcweir case ET_boolean: 109*cdf0e10cSrcweir aConst.m_type = RT_TYPE_BOOL; 110*cdf0e10cSrcweir aConst.m_value.aBool = exprVal->u.bval; 111*cdf0e10cSrcweir break; 112*cdf0e10cSrcweir default: 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir fprintf(stderr, "%s: exprtype to const type: cannot convert ExprType\n", 115*cdf0e10cSrcweir idlc()->getOptions()->getProgramName().getStr()); 116*cdf0e10cSrcweir return sal_False; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir OString name = getLocalName(); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir OUString type; 123*cdf0e10cSrcweir if ( getNodeType() != NT_enum_val ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir type = OStringToOUString(exprTypeToString(getConstValueType()), RTL_TEXTENCODING_UTF8); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir rBlob.setFieldData( 129*cdf0e10cSrcweir index, getDocumentation(), OUString(), 130*cdf0e10cSrcweir RT_ACCESS_CONST | (published ? RT_ACCESS_PUBLISHED : 0), 131*cdf0e10cSrcweir OStringToOUString(name, RTL_TEXTENCODING_UTF8), type, aConst); 132*cdf0e10cSrcweir if (str) 133*cdf0e10cSrcweir delete[] str; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir return sal_True; 136*cdf0e10cSrcweir } 137