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/astenum.hxx>
22 #include <registry/version.h>
23 #include <registry/writer.hxx>
25 AstEnum::AstEnum(const OString
& name
, AstScope
* pScope
)
26 : AstType(NT_enum
, name
, pScope
)
36 AstConstant
* AstEnum::checkValue(AstExpression
* pExpr
)
38 DeclList::const_iterator iter
= getIteratorBegin();
39 DeclList::const_iterator end
= getIteratorEnd();
43 AstDeclaration
* pDecl
= *iter
;
44 AstConstant
* pConst
= static_cast<AstConstant
*>(pDecl
);
46 if (pConst
->getConstValue()->compare(pExpr
))
52 if ( pExpr
->getExprValue()->u
.lval
> m_enumValueCount
)
53 m_enumValueCount
= pExpr
->getExprValue()->u
.lval
+ 1;
58 bool AstEnum::dump(RegistryKey
& rKey
)
61 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
) != RegError::NO_ERROR
)
63 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
64 idlc()->getOptions()->getProgramName().getStr(),
65 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
70 sal_uInt16 nConst
= getNodeCount(NT_enum_val
);
73 typereg::Writer
aBlob(
74 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
75 getDocumentation(), emptyStr
, RT_TYPE_ENUM
, m_bPublished
,
76 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 0,
79 DeclList::const_iterator iter
= getIteratorBegin();
80 DeclList::const_iterator end
= getIteratorEnd();
84 AstDeclaration
* pDecl
= *iter
;
85 if ( pDecl
->getNodeType() == NT_enum_val
)
86 static_cast<AstConstant
*>(pDecl
)->dumpBlob(aBlob
, index
++, false);
92 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
94 if (localKey
.setValue(emptyStr
, RegValueType::BINARY
,
95 const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
97 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
98 idlc()->getOptions()->getProgramName().getStr(),
99 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
107 AstDeclaration
* AstEnum::addDeclaration(AstDeclaration
* pDecl
)
109 return AstScope::addDeclaration(pDecl
);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */