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