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