Update ooo320-m1
[ooovba.git] / idlc / source / astenum.cxx
blobaf79e9950190733f8664ac122f192f0995a54adb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astenum.cxx,v $
10 * $Revision: 1.10 $
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/astenum.hxx>
35 #include "registry/version.h"
36 #include "registry/writer.hxx"
38 using namespace ::rtl;
40 AstEnum::AstEnum(const ::rtl::OString& name, AstScope* pScope)
41 : AstType(NT_enum, name, pScope)
42 , AstScope(NT_enum)
43 , m_enumValueCount(0)
47 AstEnum::~AstEnum()
51 AstConstant* AstEnum::checkValue(AstExpression* pExpr)
53 DeclList::const_iterator iter = getIteratorBegin();
54 DeclList::const_iterator end = getIteratorEnd();
55 AstConstant* pConst = NULL;
56 AstDeclaration* pDecl = NULL;
58 while ( iter != end)
60 pDecl = *iter;
61 pConst = (AstConstant*)pDecl;
63 if (pConst->getConstValue()->compare(pExpr))
64 return pConst;
66 ++iter;
69 if ( pExpr->getExprValue()->u.lval > m_enumValueCount )
70 m_enumValueCount = pExpr->getExprValue()->u.lval + 1;
72 return NULL;
75 sal_Bool AstEnum::dump(RegistryKey& rKey)
77 RegistryKey localKey;
78 if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
80 fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
81 idlc()->getOptions()->getProgramName().getStr(),
82 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
83 return sal_False;
86 OUString emptyStr;
87 sal_uInt16 nConst = getNodeCount(NT_enum_val);
88 if ( nConst > 0 )
90 typereg::Writer aBlob(
91 m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
92 getDocumentation(), emptyStr, RT_TYPE_ENUM, m_bPublished,
93 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
94 nConst, 0, 0);
96 DeclList::const_iterator iter = getIteratorBegin();
97 DeclList::const_iterator end = getIteratorEnd();
98 AstDeclaration* pDecl = NULL;
99 sal_uInt16 index = 0;
100 while ( iter != end )
102 pDecl = *iter;
103 if ( pDecl->getNodeType() == NT_enum_val )
104 ((AstConstant*)pDecl)->dumpBlob(aBlob, index++, false);
106 ++iter;
109 sal_uInt32 aBlobSize;
110 void const * pBlob = aBlob.getBlob(&aBlobSize);
112 if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
113 (RegValue)pBlob, aBlobSize))
115 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
116 idlc()->getOptions()->getProgramName().getStr(),
117 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
118 return sal_False;
122 return sal_True;
125 AstDeclaration* AstEnum::addDeclaration(AstDeclaration* pDecl)
127 return AstScope::addDeclaration(pDecl);