1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astenum.cxx,v $
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
)
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
;
61 pConst
= (AstConstant
*)pDecl
;
63 if (pConst
->getConstValue()->compare(pExpr
))
69 if ( pExpr
->getExprValue()->u
.lval
> m_enumValueCount
)
70 m_enumValueCount
= pExpr
->getExprValue()->u
.lval
+ 1;
75 sal_Bool
AstEnum::dump(RegistryKey
& rKey
)
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());
87 sal_uInt16 nConst
= getNodeCount(NT_enum_val
);
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,
96 DeclList::const_iterator iter
= getIteratorBegin();
97 DeclList::const_iterator end
= getIteratorEnd();
98 AstDeclaration
* pDecl
= NULL
;
100 while ( iter
!= end
)
103 if ( pDecl
->getNodeType() == NT_enum_val
)
104 ((AstConstant
*)pDecl
)->dumpBlob(aBlob
, index
++, false);
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());
125 AstDeclaration
* AstEnum::addDeclaration(AstDeclaration
* pDecl
)
127 return AstScope::addDeclaration(pDecl
);