1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <idlc/astconstant.hxx>
21 #include <idlc/astscope.hxx>
23 #include <registry/writer.hxx>
25 using namespace ::rtl
;
27 AstConstant::AstConstant(const ExprType type
,
28 const NodeType nodeType
,
32 : AstDeclaration(nodeType
, name
, pScope
)
33 , m_pConstValue(pExpr
)
34 , m_constValueType(type
)
38 AstConstant::AstConstant(const ExprType type
,
42 : AstDeclaration(NT_const
, name
, pScope
)
43 , m_pConstValue(pExpr
)
44 , m_constValueType(type
)
48 AstConstant::~AstConstant()
53 bool AstConstant::dumpBlob(
54 typereg::Writer
& rBlob
, sal_uInt16 index
, bool published
)
58 AstExprValue
*exprVal
= getConstValue()->getExprValue();
59 switch (getConstValueType())
62 aConst
.m_type
= RT_TYPE_INT16
;
63 aConst
.m_value
.aShort
= exprVal
->u
.sval
;
66 aConst
.m_type
= RT_TYPE_UINT16
;
67 aConst
.m_value
.aUShort
= exprVal
->u
.usval
;
70 aConst
.m_type
= RT_TYPE_INT32
;
71 aConst
.m_value
.aLong
= exprVal
->u
.lval
;
74 aConst
.m_type
= RT_TYPE_UINT32
;
75 aConst
.m_value
.aULong
= exprVal
->u
.ulval
;
78 aConst
.m_type
= RT_TYPE_INT64
;
79 aConst
.m_value
.aHyper
= exprVal
->u
.hval
;
82 aConst
.m_type
= RT_TYPE_UINT64
;
83 aConst
.m_value
.aUHyper
= exprVal
->u
.uhval
;
86 aConst
.m_type
= RT_TYPE_FLOAT
;
87 aConst
.m_value
.aFloat
= exprVal
->u
.fval
;
90 aConst
.m_type
= RT_TYPE_DOUBLE
;
91 aConst
.m_value
.aDouble
= exprVal
->u
.dval
;
94 aConst
.m_type
= RT_TYPE_BYTE
;
95 aConst
.m_value
.aByte
= exprVal
->u
.byval
;
98 aConst
.m_type
= RT_TYPE_BOOL
;
99 aConst
.m_value
.aBool
= exprVal
->u
.bval
;
103 fprintf(stderr
, "%s: exprtype to const type: cannot convert ExprType\n",
104 idlc()->getOptions()->getProgramName().getStr());
109 OString name
= getLocalName();
112 if ( getNodeType() != NT_enum_val
)
114 type
= OStringToOUString(exprTypeToString(getConstValueType()), RTL_TEXTENCODING_UTF8
);
118 index
, getDocumentation(), OUString(),
119 RT_ACCESS_CONST
| (published
? RT_ACCESS_PUBLISHED
: 0),
120 OStringToOUString(name
, RTL_TEXTENCODING_UTF8
), type
, aConst
);
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */