bump product version to 7.2.5.1
[LibreOffice.git] / idlc / source / astenum.cxx
blob54324337de6d743647df3209d8cfbb704129656f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sal/config.h>
22 #include <algorithm>
24 #include <astenum.hxx>
26 #include <registry/version.h>
27 #include <registry/writer.hxx>
29 AstEnum::AstEnum(const OString& name, AstScope* pScope)
30 : AstType(NT_enum, name, pScope)
31 , AstScope(NT_enum)
32 , m_enumValueCount(0)
36 AstEnum::~AstEnum()
40 AstConstant* AstEnum::checkValue(AstExpression* pExpr)
42 DeclList::const_iterator iter = getIteratorBegin();
43 DeclList::const_iterator end = getIteratorEnd();
45 iter = std::find_if(iter, end, [&pExpr](AstDeclaration* pDecl) {
46 return static_cast<AstConstant*>(pDecl)->getConstValue()->compareLong(pExpr); });
48 if (iter != end)
49 return static_cast<AstConstant*>(*iter);
51 if ( pExpr->getExprValue()->u.lval > m_enumValueCount )
52 m_enumValueCount = pExpr->getExprValue()->u.lval + 1;
54 return nullptr;
57 bool AstEnum::dump(RegistryKey& rKey)
59 RegistryKey localKey;
60 if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey) != RegError::NO_ERROR)
62 fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
63 idlc()->getOptions()->getProgramName().getStr(),
64 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
65 return false;
68 sal_uInt16 nConst = getNodeCount(NT_enum_val);
69 if ( nConst > 0 )
71 typereg::Writer aBlob(
72 m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
73 getDocumentation(), "", RT_TYPE_ENUM, m_bPublished,
74 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
75 nConst, 0, 0);
77 DeclList::const_iterator iter = getIteratorBegin();
78 DeclList::const_iterator end = getIteratorEnd();
79 sal_uInt16 index = 0;
80 while ( iter != end )
82 AstDeclaration* pDecl = *iter;
83 if ( pDecl->getNodeType() == NT_enum_val )
84 static_cast<AstConstant*>(pDecl)->dumpBlob(aBlob, index++, false);
86 ++iter;
89 sal_uInt32 aBlobSize;
90 void const * pBlob = aBlob.getBlob(&aBlobSize);
92 if (localKey.setValue("", RegValueType::BINARY,
93 const_cast<RegValue>(pBlob), aBlobSize) != RegError::NO_ERROR)
95 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
96 idlc()->getOptions()->getProgramName().getStr(),
97 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
98 return false;
102 return true;
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */