1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_idlc.hxx" 30 #include <idlc/astenum.hxx> 31 32 #include "registry/version.h" 33 #include "registry/writer.hxx" 34 35 using namespace ::rtl; 36 37 AstEnum::AstEnum(const ::rtl::OString& name, AstScope* pScope) 38 : AstType(NT_enum, name, pScope) 39 , AstScope(NT_enum) 40 , m_enumValueCount(0) 41 { 42 } 43 44 AstEnum::~AstEnum() 45 { 46 } 47 48 AstConstant* AstEnum::checkValue(AstExpression* pExpr) 49 { 50 DeclList::const_iterator iter = getIteratorBegin(); 51 DeclList::const_iterator end = getIteratorEnd(); 52 AstConstant* pConst = NULL; 53 AstDeclaration* pDecl = NULL; 54 55 while ( iter != end) 56 { 57 pDecl = *iter; 58 pConst = (AstConstant*)pDecl; 59 60 if (pConst->getConstValue()->compare(pExpr)) 61 return pConst; 62 63 ++iter; 64 } 65 66 if ( pExpr->getExprValue()->u.lval > m_enumValueCount ) 67 m_enumValueCount = pExpr->getExprValue()->u.lval + 1; 68 69 return NULL; 70 } 71 72 sal_Bool AstEnum::dump(RegistryKey& rKey) 73 { 74 RegistryKey localKey; 75 if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey)) 76 { 77 fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n", 78 idlc()->getOptions()->getProgramName().getStr(), 79 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr()); 80 return sal_False; 81 } 82 83 OUString emptyStr; 84 sal_uInt16 nConst = getNodeCount(NT_enum_val); 85 if ( nConst > 0 ) 86 { 87 typereg::Writer aBlob( 88 m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0, 89 getDocumentation(), emptyStr, RT_TYPE_ENUM, m_bPublished, 90 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0, 91 nConst, 0, 0); 92 93 DeclList::const_iterator iter = getIteratorBegin(); 94 DeclList::const_iterator end = getIteratorEnd(); 95 AstDeclaration* pDecl = NULL; 96 sal_uInt16 index = 0; 97 while ( iter != end ) 98 { 99 pDecl = *iter; 100 if ( pDecl->getNodeType() == NT_enum_val ) 101 ((AstConstant*)pDecl)->dumpBlob(aBlob, index++, false); 102 103 ++iter; 104 } 105 106 sal_uInt32 aBlobSize; 107 void const * pBlob = aBlob.getBlob(&aBlobSize); 108 109 if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY, 110 (RegValue)pBlob, aBlobSize)) 111 { 112 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n", 113 idlc()->getOptions()->getProgramName().getStr(), 114 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr()); 115 return sal_False; 116 } 117 } 118 119 return sal_True; 120 } 121 122 AstDeclaration* AstEnum::addDeclaration(AstDeclaration* pDecl) 123 { 124 return AstScope::addDeclaration(pDecl); 125 } 126