1*2fe1ca3dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2fe1ca3dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2fe1ca3dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2fe1ca3dSAndrew Rist * distributed with this work for additional information
6*2fe1ca3dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2fe1ca3dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2fe1ca3dSAndrew Rist * "License"); you may not use this file except in compliance
9*2fe1ca3dSAndrew Rist * with the License. You may obtain a copy of the License at
10*2fe1ca3dSAndrew Rist *
11*2fe1ca3dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2fe1ca3dSAndrew Rist *
13*2fe1ca3dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2fe1ca3dSAndrew Rist * software distributed under the License is distributed on an
15*2fe1ca3dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2fe1ca3dSAndrew Rist * KIND, either express or implied. See the License for the
17*2fe1ca3dSAndrew Rist * specific language governing permissions and limitations
18*2fe1ca3dSAndrew Rist * under the License.
19*2fe1ca3dSAndrew Rist *
20*2fe1ca3dSAndrew Rist *************************************************************/
21*2fe1ca3dSAndrew Rist
22*2fe1ca3dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_idlc.hxx"
26cdf0e10cSrcweir #include <idlc/astenum.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "registry/version.h"
29cdf0e10cSrcweir #include "registry/writer.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace ::rtl;
32cdf0e10cSrcweir
AstEnum(const::rtl::OString & name,AstScope * pScope)33cdf0e10cSrcweir AstEnum::AstEnum(const ::rtl::OString& name, AstScope* pScope)
34cdf0e10cSrcweir : AstType(NT_enum, name, pScope)
35cdf0e10cSrcweir , AstScope(NT_enum)
36cdf0e10cSrcweir , m_enumValueCount(0)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir }
39cdf0e10cSrcweir
~AstEnum()40cdf0e10cSrcweir AstEnum::~AstEnum()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir
checkValue(AstExpression * pExpr)44cdf0e10cSrcweir AstConstant* AstEnum::checkValue(AstExpression* pExpr)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir DeclList::const_iterator iter = getIteratorBegin();
47cdf0e10cSrcweir DeclList::const_iterator end = getIteratorEnd();
48cdf0e10cSrcweir AstConstant* pConst = NULL;
49cdf0e10cSrcweir AstDeclaration* pDecl = NULL;
50cdf0e10cSrcweir
51cdf0e10cSrcweir while ( iter != end)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir pDecl = *iter;
54cdf0e10cSrcweir pConst = (AstConstant*)pDecl;
55cdf0e10cSrcweir
56cdf0e10cSrcweir if (pConst->getConstValue()->compare(pExpr))
57cdf0e10cSrcweir return pConst;
58cdf0e10cSrcweir
59cdf0e10cSrcweir ++iter;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
62cdf0e10cSrcweir if ( pExpr->getExprValue()->u.lval > m_enumValueCount )
63cdf0e10cSrcweir m_enumValueCount = pExpr->getExprValue()->u.lval + 1;
64cdf0e10cSrcweir
65cdf0e10cSrcweir return NULL;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
dump(RegistryKey & rKey)68cdf0e10cSrcweir sal_Bool AstEnum::dump(RegistryKey& rKey)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir RegistryKey localKey;
71cdf0e10cSrcweir if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
72cdf0e10cSrcweir {
73cdf0e10cSrcweir fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
74cdf0e10cSrcweir idlc()->getOptions()->getProgramName().getStr(),
75cdf0e10cSrcweir getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
76cdf0e10cSrcweir return sal_False;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir
79cdf0e10cSrcweir OUString emptyStr;
80cdf0e10cSrcweir sal_uInt16 nConst = getNodeCount(NT_enum_val);
81cdf0e10cSrcweir if ( nConst > 0 )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir typereg::Writer aBlob(
84cdf0e10cSrcweir m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
85cdf0e10cSrcweir getDocumentation(), emptyStr, RT_TYPE_ENUM, m_bPublished,
86cdf0e10cSrcweir OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
87cdf0e10cSrcweir nConst, 0, 0);
88cdf0e10cSrcweir
89cdf0e10cSrcweir DeclList::const_iterator iter = getIteratorBegin();
90cdf0e10cSrcweir DeclList::const_iterator end = getIteratorEnd();
91cdf0e10cSrcweir AstDeclaration* pDecl = NULL;
92cdf0e10cSrcweir sal_uInt16 index = 0;
93cdf0e10cSrcweir while ( iter != end )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir pDecl = *iter;
96cdf0e10cSrcweir if ( pDecl->getNodeType() == NT_enum_val )
97cdf0e10cSrcweir ((AstConstant*)pDecl)->dumpBlob(aBlob, index++, false);
98cdf0e10cSrcweir
99cdf0e10cSrcweir ++iter;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir sal_uInt32 aBlobSize;
103cdf0e10cSrcweir void const * pBlob = aBlob.getBlob(&aBlobSize);
104cdf0e10cSrcweir
105cdf0e10cSrcweir if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
106cdf0e10cSrcweir (RegValue)pBlob, aBlobSize))
107cdf0e10cSrcweir {
108cdf0e10cSrcweir fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
109cdf0e10cSrcweir idlc()->getOptions()->getProgramName().getStr(),
110cdf0e10cSrcweir getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
111cdf0e10cSrcweir return sal_False;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
115cdf0e10cSrcweir return sal_True;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
addDeclaration(AstDeclaration * pDecl)118cdf0e10cSrcweir AstDeclaration* AstEnum::addDeclaration(AstDeclaration* pDecl)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir return AstScope::addDeclaration(pDecl);
121cdf0e10cSrcweir }
122