1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astconstant.cxx,v $
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
,
43 const ::rtl::OString
& name
,
45 : AstDeclaration(nodeType
, name
, pScope
)
46 , m_pConstValue(pExpr
)
47 , m_constValueType(type
)
51 AstConstant::AstConstant(const ExprType type
,
53 const ::rtl::OString
& name
,
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
)
70 sal_Unicode
* str
= NULL
;
72 AstExprValue
*exprVal
= getConstValue()->getExprValue();
73 switch (getConstValueType())
76 aConst
.m_type
= RT_TYPE_INT16
;
77 aConst
.m_value
.aShort
= exprVal
->u
.sval
;
80 aConst
.m_type
= RT_TYPE_UINT16
;
81 aConst
.m_value
.aUShort
= exprVal
->u
.usval
;
84 aConst
.m_type
= RT_TYPE_INT32
;
85 aConst
.m_value
.aLong
= exprVal
->u
.lval
;
88 aConst
.m_type
= RT_TYPE_UINT32
;
89 aConst
.m_value
.aULong
= exprVal
->u
.ulval
;
92 aConst
.m_type
= RT_TYPE_INT64
;
93 aConst
.m_value
.aHyper
= exprVal
->u
.hval
;
96 aConst
.m_type
= RT_TYPE_UINT64
;
97 aConst
.m_value
.aUHyper
= exprVal
->u
.uhval
;
100 aConst
.m_type
= RT_TYPE_FLOAT
;
101 aConst
.m_value
.aFloat
= exprVal
->u
.fval
;
104 aConst
.m_type
= RT_TYPE_DOUBLE
;
105 aConst
.m_value
.aDouble
= exprVal
->u
.dval
;
108 aConst
.m_type
= RT_TYPE_BYTE
;
109 aConst
.m_value
.aByte
= exprVal
->u
.byval
;
112 aConst
.m_type
= RT_TYPE_BOOL
;
113 aConst
.m_value
.aBool
= exprVal
->u
.bval
;
117 fprintf(stderr
, "%s: exprtype to const type: cannot convert ExprType\n",
118 idlc()->getOptions()->getProgramName().getStr());
123 OString name
= getLocalName();
126 if ( getNodeType() != NT_enum_val
)
128 type
= OStringToOUString(exprTypeToString(getConstValueType()), RTL_TEXTENCODING_UTF8
);
132 index
, getDocumentation(), OUString(),
133 RT_ACCESS_CONST
| (published
? RT_ACCESS_PUBLISHED
: 0),
134 OStringToOUString(name
, RTL_TEXTENCODING_UTF8
), type
, aConst
);