merge the formfield patch from ooo-build
[ooovba.git] / idlc / source / aststruct.cxx
blob61c98334edb965a072ec1937f6ccc2891b6d3115
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: aststruct.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/aststruct.hxx>
34 #ifndef _IDLC_ASTMember_HXX_
35 #include <idlc/astmember.hxx>
36 #endif
38 #include "registry/version.h"
39 #include "registry/writer.hxx"
41 using namespace ::rtl;
43 AstStruct::AstStruct(
44 const OString& name, std::vector< rtl::OString > const & typeParameters,
45 AstStruct* pBaseType, AstScope* pScope)
46 : AstType(NT_struct, name, pScope)
47 , AstScope(NT_struct)
48 , m_pBaseType(pBaseType)
50 for (std::vector< rtl::OString >::const_iterator i(typeParameters.begin());
51 i != typeParameters.end(); ++i)
53 m_typeParameters.push_back(
54 new AstDeclaration(NT_type_parameter, *i, 0));
58 AstStruct::AstStruct(const NodeType type,
59 const OString& name,
60 AstStruct* pBaseType,
61 AstScope* pScope)
62 : AstType(type, name, pScope)
63 , AstScope(type)
64 , m_pBaseType(pBaseType)
68 AstStruct::~AstStruct()
70 for (DeclList::iterator i(m_typeParameters.begin());
71 i != m_typeParameters.end(); ++i)
73 delete *i;
77 AstDeclaration const * AstStruct::findTypeParameter(rtl::OString const & name)
78 const
80 for (DeclList::const_iterator i(m_typeParameters.begin());
81 i != m_typeParameters.end(); ++i)
83 if ((*i)->getLocalName() == name) {
84 return *i;
87 return 0;
90 bool AstStruct::isType() const {
91 return getNodeType() == NT_struct
92 ? getTypeParameterCount() == 0 : AstDeclaration::isType();
95 sal_Bool AstStruct::dump(RegistryKey& rKey)
97 RegistryKey localKey;
98 if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
100 fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
101 idlc()->getOptions()->getProgramName().getStr(),
102 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
103 return sal_False;
106 if (m_typeParameters.size() > SAL_MAX_UINT16) {
107 fprintf(
108 stderr,
109 ("%s: polymorphic struct type template %s has too many type"
110 " parameters\n"),
111 idlc()->getOptions()->getProgramName().getStr(),
112 getScopedName().getStr());
113 return false;
116 sal_uInt16 nMember = getNodeCount(NT_member);
118 RTTypeClass typeClass = RT_TYPE_STRUCT;
119 if ( getNodeType() == NT_exception )
120 typeClass = RT_TYPE_EXCEPTION;
122 OUString emptyStr;
123 typereg::Writer aBlob(
124 (m_typeParameters.empty() && !m_bPublished
125 ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1),
126 getDocumentation(), emptyStr, typeClass, m_bPublished,
127 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
128 m_pBaseType == 0 ? 0 : 1, nMember, 0,
129 static_cast< sal_uInt16 >(m_typeParameters.size()));
130 if (m_pBaseType != 0) {
131 aBlob.setSuperTypeName(
133 OStringToOUString(
134 m_pBaseType->getRelativName(), RTL_TEXTENCODING_UTF8));
137 if ( nMember > 0 )
139 DeclList::const_iterator iter = getIteratorBegin();
140 DeclList::const_iterator end = getIteratorEnd();
141 AstDeclaration* pDecl = NULL;
142 AstMember* pMember = NULL;
143 OUString docu;
144 sal_uInt16 index = 0;
145 while ( iter != end )
147 pDecl = *iter;
148 if ( pDecl->getNodeType() == NT_member )
150 pMember = (AstMember*)pDecl;
151 RTFieldAccess flags = RT_ACCESS_READWRITE;
152 rtl::OString typeName;
153 if (pMember->getType()->getNodeType() == NT_type_parameter) {
154 flags |= RT_ACCESS_PARAMETERIZED_TYPE;
155 typeName = pMember->getType()->getLocalName();
156 } else {
157 typeName = pMember->getType()->getRelativName();
159 aBlob.setFieldData(
160 index++, pMember->getDocumentation(), emptyStr, flags,
161 OStringToOUString(
162 pMember->getLocalName(), RTL_TEXTENCODING_UTF8),
163 OStringToOUString(typeName, RTL_TEXTENCODING_UTF8),
164 RTConstValue());
166 ++iter;
170 sal_uInt16 index = 0;
171 for (DeclList::iterator i(m_typeParameters.begin());
172 i != m_typeParameters.end(); ++i)
174 aBlob.setReferenceData(
175 index++, emptyStr, RT_REF_TYPE_PARAMETER, RT_ACCESS_INVALID,
176 OStringToOUString(
177 (*i)->getLocalName(), RTL_TEXTENCODING_UTF8));
180 sal_uInt32 aBlobSize;
181 void const * pBlob = aBlob.getBlob(&aBlobSize);
183 if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
184 (RegValue)pBlob, aBlobSize))
186 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
187 idlc()->getOptions()->getProgramName().getStr(),
188 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
189 return sal_False;
192 return sal_True;