Bump version to 4.3-4
[LibreOffice.git] / idlc / source / astenum.cxx
blob13bd8774f651166928dd9b19bb15ecc3bc079d97
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 <idlc/astenum.hxx>
22 #include <registry/version.h>
23 #include <registry/writer.hxx>
25 using namespace ::rtl;
27 AstEnum::AstEnum(const OString& name, AstScope* pScope)
28 : AstType(NT_enum, name, pScope)
29 , AstScope(NT_enum)
30 , m_enumValueCount(0)
34 AstEnum::~AstEnum()
38 AstConstant* AstEnum::checkValue(AstExpression* pExpr)
40 DeclList::const_iterator iter = getIteratorBegin();
41 DeclList::const_iterator end = getIteratorEnd();
42 AstConstant* pConst = NULL;
43 AstDeclaration* pDecl = NULL;
45 while ( iter != end)
47 pDecl = *iter;
48 pConst = (AstConstant*)pDecl;
50 if (pConst->getConstValue()->compare(pExpr))
51 return pConst;
53 ++iter;
56 if ( pExpr->getExprValue()->u.lval > m_enumValueCount )
57 m_enumValueCount = pExpr->getExprValue()->u.lval + 1;
59 return NULL;
62 bool AstEnum::dump(RegistryKey& rKey)
64 RegistryKey localKey;
65 if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
67 fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
68 idlc()->getOptions()->getProgramName().getStr(),
69 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
70 return false;
73 OUString emptyStr;
74 sal_uInt16 nConst = getNodeCount(NT_enum_val);
75 if ( nConst > 0 )
77 typereg::Writer aBlob(
78 m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
79 getDocumentation(), emptyStr, RT_TYPE_ENUM, m_bPublished,
80 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
81 nConst, 0, 0);
83 DeclList::const_iterator iter = getIteratorBegin();
84 DeclList::const_iterator end = getIteratorEnd();
85 AstDeclaration* pDecl = NULL;
86 sal_uInt16 index = 0;
87 while ( iter != end )
89 pDecl = *iter;
90 if ( pDecl->getNodeType() == NT_enum_val )
91 ((AstConstant*)pDecl)->dumpBlob(aBlob, index++, false);
93 ++iter;
96 sal_uInt32 aBlobSize;
97 void const * pBlob = aBlob.getBlob(&aBlobSize);
99 if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
100 (RegValue)pBlob, aBlobSize))
102 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
103 idlc()->getOptions()->getProgramName().getStr(),
104 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
105 return false;
109 return true;
112 AstDeclaration* AstEnum::addDeclaration(AstDeclaration* pDecl)
114 return AstScope::addDeclaration(pDecl);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */