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