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: aststruct.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/aststruct.hxx>
34 #ifndef _IDLC_ASTMember_HXX_
35 #include <idlc/astmember.hxx>
38 #include "registry/version.h"
39 #include "registry/writer.hxx"
41 using namespace ::rtl
;
44 const OString
& name
, std::vector
< rtl::OString
> const & typeParameters
,
45 AstStruct
* pBaseType
, AstScope
* pScope
)
46 : AstType(NT_struct
, name
, pScope
)
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
,
62 : AstType(type
, name
, pScope
)
64 , m_pBaseType(pBaseType
)
68 AstStruct::~AstStruct()
70 for (DeclList::iterator
i(m_typeParameters
.begin());
71 i
!= m_typeParameters
.end(); ++i
)
77 AstDeclaration
const * AstStruct::findTypeParameter(rtl::OString
const & name
)
80 for (DeclList::const_iterator
i(m_typeParameters
.begin());
81 i
!= m_typeParameters
.end(); ++i
)
83 if ((*i
)->getLocalName() == name
) {
90 bool AstStruct::isType() const {
91 return getNodeType() == NT_struct
92 ? getTypeParameterCount() == 0 : AstDeclaration::isType();
95 sal_Bool
AstStruct::dump(RegistryKey
& rKey
)
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());
106 if (m_typeParameters
.size() > SAL_MAX_UINT16
) {
109 ("%s: polymorphic struct type template %s has too many type"
111 idlc()->getOptions()->getProgramName().getStr(),
112 getScopedName().getStr());
116 sal_uInt16 nMember
= getNodeCount(NT_member
);
118 RTTypeClass typeClass
= RT_TYPE_STRUCT
;
119 if ( getNodeType() == NT_exception
)
120 typeClass
= RT_TYPE_EXCEPTION
;
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(
134 m_pBaseType
->getRelativName(), RTL_TEXTENCODING_UTF8
));
139 DeclList::const_iterator iter
= getIteratorBegin();
140 DeclList::const_iterator end
= getIteratorEnd();
141 AstDeclaration
* pDecl
= NULL
;
142 AstMember
* pMember
= NULL
;
144 sal_uInt16 index
= 0;
145 while ( iter
!= end
)
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();
157 typeName
= pMember
->getType()->getRelativName();
160 index
++, pMember
->getDocumentation(), emptyStr
, flags
,
162 pMember
->getLocalName(), RTL_TEXTENCODING_UTF8
),
163 OStringToOUString(typeName
, RTL_TEXTENCODING_UTF8
),
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
,
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());