update dev300-m58
[ooovba.git] / idlc / source / astconstant.cxx
blobe40e8357d3b7891853d6a85dcbb5b1f13c990aa5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astconstant.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idlc.hxx"
33 #include <idlc/astconstant.hxx>
34 #include <idlc/astscope.hxx>
36 #include "registry/writer.hxx"
38 using namespace ::rtl;
40 AstConstant::AstConstant(const ExprType type,
41 const NodeType nodeType,
42 AstExpression* pExpr,
43 const ::rtl::OString& name,
44 AstScope* pScope)
45 : AstDeclaration(nodeType, name, pScope)
46 , m_pConstValue(pExpr)
47 , m_constValueType(type)
51 AstConstant::AstConstant(const ExprType type,
52 AstExpression* pExpr,
53 const ::rtl::OString& name,
54 AstScope* pScope)
55 : AstDeclaration(NT_const, name, pScope)
56 , m_pConstValue(pExpr)
57 , m_constValueType(type)
61 AstConstant::~AstConstant()
66 sal_Bool AstConstant::dumpBlob(
67 typereg::Writer & rBlob, sal_uInt16 index, bool published)
69 RTConstValue aConst;
70 sal_Unicode* str = NULL;
72 AstExprValue *exprVal = getConstValue()->getExprValue();
73 switch (getConstValueType())
75 case ET_short:
76 aConst.m_type = RT_TYPE_INT16;
77 aConst.m_value.aShort = exprVal->u.sval;
78 break;
79 case ET_ushort:
80 aConst.m_type = RT_TYPE_UINT16;
81 aConst.m_value.aUShort = exprVal->u.usval;
82 break;
83 case ET_long:
84 aConst.m_type = RT_TYPE_INT32;
85 aConst.m_value.aLong = exprVal->u.lval;
86 break;
87 case ET_ulong:
88 aConst.m_type = RT_TYPE_UINT32;
89 aConst.m_value.aULong = exprVal->u.ulval;
90 break;
91 case ET_hyper:
92 aConst.m_type = RT_TYPE_INT64;
93 aConst.m_value.aHyper = exprVal->u.hval;
94 break;
95 case ET_uhyper:
96 aConst.m_type = RT_TYPE_UINT64;
97 aConst.m_value.aUHyper = exprVal->u.uhval;
98 break;
99 case ET_float:
100 aConst.m_type = RT_TYPE_FLOAT;
101 aConst.m_value.aFloat = exprVal->u.fval;
102 break;
103 case ET_double:
104 aConst.m_type = RT_TYPE_DOUBLE;
105 aConst.m_value.aDouble = exprVal->u.dval;
106 break;
107 case ET_byte:
108 aConst.m_type = RT_TYPE_BYTE;
109 aConst.m_value.aByte = exprVal->u.byval;
110 break;
111 case ET_boolean:
112 aConst.m_type = RT_TYPE_BOOL;
113 aConst.m_value.aBool = exprVal->u.bval;
114 break;
115 default:
117 fprintf(stderr, "%s: exprtype to const type: cannot convert ExprType\n",
118 idlc()->getOptions()->getProgramName().getStr());
119 return sal_False;
123 OString name = getLocalName();
125 OUString type;
126 if ( getNodeType() != NT_enum_val )
128 type = OStringToOUString(exprTypeToString(getConstValueType()), RTL_TEXTENCODING_UTF8);
131 rBlob.setFieldData(
132 index, getDocumentation(), OUString(),
133 RT_ACCESS_CONST | (published ? RT_ACCESS_PUBLISHED : 0),
134 OStringToOUString(name, RTL_TEXTENCODING_UTF8), type, aConst);
135 if (str)
136 delete[] str;
138 return sal_True;