xref: /aoo41x/main/idlc/source/astconstant.cxx (revision 2fe1ca3d)
1*2fe1ca3dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2fe1ca3dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2fe1ca3dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2fe1ca3dSAndrew Rist  * distributed with this work for additional information
6*2fe1ca3dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2fe1ca3dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2fe1ca3dSAndrew Rist  * "License"); you may not use this file except in compliance
9*2fe1ca3dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2fe1ca3dSAndrew Rist  *
11*2fe1ca3dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2fe1ca3dSAndrew Rist  *
13*2fe1ca3dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2fe1ca3dSAndrew Rist  * software distributed under the License is distributed on an
15*2fe1ca3dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2fe1ca3dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2fe1ca3dSAndrew Rist  * specific language governing permissions and limitations
18*2fe1ca3dSAndrew Rist  * under the License.
19*2fe1ca3dSAndrew Rist  *
20*2fe1ca3dSAndrew Rist  *************************************************************/
21*2fe1ca3dSAndrew Rist 
22*2fe1ca3dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_idlc.hxx"
26cdf0e10cSrcweir #include <idlc/astconstant.hxx>
27cdf0e10cSrcweir #include <idlc/astscope.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "registry/writer.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace ::rtl;
32cdf0e10cSrcweir 
AstConstant(const ExprType type,const NodeType nodeType,AstExpression * pExpr,const::rtl::OString & name,AstScope * pScope)33cdf0e10cSrcweir AstConstant::AstConstant(const ExprType type,
34cdf0e10cSrcweir 						 const NodeType nodeType,
35cdf0e10cSrcweir 						 AstExpression* pExpr,
36cdf0e10cSrcweir 						 const ::rtl::OString& name,
37cdf0e10cSrcweir 						 AstScope* pScope)
38cdf0e10cSrcweir 	: AstDeclaration(nodeType, name, pScope)
39cdf0e10cSrcweir 	, m_pConstValue(pExpr)
40cdf0e10cSrcweir 	, m_constValueType(type)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
AstConstant(const ExprType type,AstExpression * pExpr,const::rtl::OString & name,AstScope * pScope)44cdf0e10cSrcweir AstConstant::AstConstant(const ExprType type,
45cdf0e10cSrcweir 						 AstExpression* pExpr,
46cdf0e10cSrcweir 						 const ::rtl::OString& name,
47cdf0e10cSrcweir 						 AstScope* pScope)
48cdf0e10cSrcweir 	: AstDeclaration(NT_const, name, pScope)
49cdf0e10cSrcweir 	, m_pConstValue(pExpr)
50cdf0e10cSrcweir 	, m_constValueType(type)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
~AstConstant()54cdf0e10cSrcweir AstConstant::~AstConstant()
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
dumpBlob(typereg::Writer & rBlob,sal_uInt16 index,bool published)59cdf0e10cSrcweir sal_Bool AstConstant::dumpBlob(
60cdf0e10cSrcweir     typereg::Writer & rBlob, sal_uInt16 index, bool published)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	RTConstValue 	aConst;
63cdf0e10cSrcweir 	sal_Unicode* 	str = NULL;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	AstExprValue *exprVal = getConstValue()->getExprValue();
66cdf0e10cSrcweir 	switch (getConstValueType())
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir 		case ET_short:
69cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_INT16;
70cdf0e10cSrcweir 			aConst.m_value.aShort = exprVal->u.sval;
71cdf0e10cSrcweir 			break;
72cdf0e10cSrcweir 		case ET_ushort:
73cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_UINT16;
74cdf0e10cSrcweir 			aConst.m_value.aUShort = exprVal->u.usval;
75cdf0e10cSrcweir 			break;
76cdf0e10cSrcweir 		case ET_long:
77cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_INT32;
78cdf0e10cSrcweir 			aConst.m_value.aLong = exprVal->u.lval;
79cdf0e10cSrcweir 			break;
80cdf0e10cSrcweir 		case ET_ulong:
81cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_UINT32;
82cdf0e10cSrcweir 			aConst.m_value.aULong = exprVal->u.ulval;
83cdf0e10cSrcweir 			break;
84cdf0e10cSrcweir 		case ET_hyper:
85cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_INT64;
86cdf0e10cSrcweir 			aConst.m_value.aHyper = exprVal->u.hval;
87cdf0e10cSrcweir 			break;
88cdf0e10cSrcweir 		case ET_uhyper:
89cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_UINT64;
90cdf0e10cSrcweir 			aConst.m_value.aUHyper = exprVal->u.uhval;
91cdf0e10cSrcweir 			break;
92cdf0e10cSrcweir 		case ET_float:
93cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_FLOAT;
94cdf0e10cSrcweir 			aConst.m_value.aFloat = exprVal->u.fval;
95cdf0e10cSrcweir 			break;
96cdf0e10cSrcweir 		case ET_double:
97cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_DOUBLE;
98cdf0e10cSrcweir 			aConst.m_value.aDouble = exprVal->u.dval;
99cdf0e10cSrcweir 			break;
100cdf0e10cSrcweir 		case ET_byte:
101cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_BYTE;
102cdf0e10cSrcweir 			aConst.m_value.aByte = exprVal->u.byval;
103cdf0e10cSrcweir 			break;
104cdf0e10cSrcweir 		case ET_boolean:
105cdf0e10cSrcweir 			aConst.m_type = RT_TYPE_BOOL;
106cdf0e10cSrcweir 			aConst.m_value.aBool = exprVal->u.bval;
107cdf0e10cSrcweir 			break;
108cdf0e10cSrcweir 		default:
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				fprintf(stderr, "%s: exprtype to const type: cannot convert ExprType\n",
111cdf0e10cSrcweir 						idlc()->getOptions()->getProgramName().getStr());
112cdf0e10cSrcweir 				return sal_False;
113cdf0e10cSrcweir 			}
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	OString name = getLocalName();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	OUString type;
119cdf0e10cSrcweir 	if ( getNodeType() != NT_enum_val )
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		type = OStringToOUString(exprTypeToString(getConstValueType()), RTL_TEXTENCODING_UTF8);
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	rBlob.setFieldData(
125cdf0e10cSrcweir         index, getDocumentation(), OUString(),
126cdf0e10cSrcweir         RT_ACCESS_CONST | (published ? RT_ACCESS_PUBLISHED : 0),
127cdf0e10cSrcweir         OStringToOUString(name, RTL_TEXTENCODING_UTF8), type, aConst);
128cdf0e10cSrcweir 	if (str)
129cdf0e10cSrcweir 		delete[] str;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	return sal_True;
132cdf0e10cSrcweir }
133