1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <idlc/aststruct.hxx>
21 #include <idlc/astmember.hxx>
23 #include <registry/version.h>
24 #include <registry/writer.hxx>
27 const OString
& name
, std::vector
< OString
> const & typeParameters
,
28 AstStruct
const* pBaseType
, AstScope
* pScope
)
29 : AstType(NT_struct
, name
, pScope
)
31 , m_pBaseType(pBaseType
)
33 for (std::vector
< OString
>::const_iterator
i(typeParameters
.begin());
34 i
!= typeParameters
.end(); ++i
)
36 m_typeParameters
.push_back(
37 new AstType(NT_type_parameter
, *i
, 0));
41 AstStruct::AstStruct(const NodeType type
,
43 AstStruct
const* pBaseType
,
45 : AstType(type
, name
, pScope
)
47 , m_pBaseType(pBaseType
)
51 AstStruct::~AstStruct()
53 for (DeclList::iterator
i(m_typeParameters
.begin());
54 i
!= m_typeParameters
.end(); ++i
)
60 AstDeclaration
const * AstStruct::findTypeParameter(OString
const & name
)
63 for (DeclList::const_iterator
i(m_typeParameters
.begin());
64 i
!= m_typeParameters
.end(); ++i
)
66 if ((*i
)->getLocalName() == name
) {
73 bool AstStruct::isType() const {
74 return getNodeType() == NT_struct
75 ? getTypeParameterCount() == 0 : AstDeclaration::isType();
78 bool AstStruct::dump(RegistryKey
& rKey
)
81 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
) != RegError::NO_ERROR
)
83 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
84 idlc()->getOptions()->getProgramName().getStr(),
85 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
89 if (m_typeParameters
.size() > SAL_MAX_UINT16
) {
92 ("%s: polymorphic struct type template %s has too many type"
94 idlc()->getOptions()->getProgramName().getStr(),
95 getScopedName().getStr());
99 sal_uInt16 nMember
= getNodeCount(NT_member
);
101 RTTypeClass typeClass
= RT_TYPE_STRUCT
;
102 if ( getNodeType() == NT_exception
)
103 typeClass
= RT_TYPE_EXCEPTION
;
106 typereg::Writer
aBlob(
107 (m_typeParameters
.empty() && !m_bPublished
108 ? TYPEREG_VERSION_0
: TYPEREG_VERSION_1
),
109 getDocumentation(), emptyStr
, typeClass
, m_bPublished
,
110 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
),
111 m_pBaseType
== 0 ? 0 : 1, nMember
, 0,
112 static_cast< sal_uInt16
>(m_typeParameters
.size()));
113 if (m_pBaseType
!= 0) {
114 aBlob
.setSuperTypeName(
117 m_pBaseType
->getRelativName(), RTL_TEXTENCODING_UTF8
));
122 DeclList::const_iterator iter
= getIteratorBegin();
123 DeclList::const_iterator end
= getIteratorEnd();
124 AstMember
* pMember
= NULL
;
125 sal_uInt16 index
= 0;
126 while ( iter
!= end
)
128 AstDeclaration
* pDecl
= *iter
;
129 if ( pDecl
->getNodeType() == NT_member
)
131 pMember
= static_cast<AstMember
*>(pDecl
);
132 RTFieldAccess flags
= RTFieldAccess::READWRITE
;
134 if (pMember
->getType()->getNodeType() == NT_type_parameter
) {
135 flags
|= RTFieldAccess::PARAMETERIZED_TYPE
;
136 typeName
= pMember
->getType()->getLocalName();
138 typeName
= pMember
->getType()->getRelativName();
141 index
++, pMember
->getDocumentation(), emptyStr
, flags
,
143 pMember
->getLocalName(), RTL_TEXTENCODING_UTF8
),
144 OStringToOUString(typeName
, RTL_TEXTENCODING_UTF8
),
151 sal_uInt16 index
= 0;
152 for (DeclList::iterator
i(m_typeParameters
.begin());
153 i
!= m_typeParameters
.end(); ++i
)
155 aBlob
.setReferenceData(
156 index
++, emptyStr
, RTReferenceType::TYPE_PARAMETER
, RTFieldAccess::INVALID
,
158 (*i
)->getLocalName(), RTL_TEXTENCODING_UTF8
));
161 sal_uInt32 aBlobSize
;
162 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
164 if (localKey
.setValue(emptyStr
, RegValueType::BINARY
,
165 const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
167 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
168 idlc()->getOptions()->getProgramName().getStr(),
169 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */