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 <aststruct.hxx>
21 #include <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 (auto const& elem
: typeParameters
)
35 m_typeParameters
.emplace_back(
36 new AstType(NT_type_parameter
, elem
, nullptr));
40 AstStruct::AstStruct(const NodeType type
,
42 AstStruct
const* pBaseType
,
44 : AstType(type
, name
, pScope
)
46 , m_pBaseType(pBaseType
)
50 AstStruct::~AstStruct()
54 AstDeclaration
const * AstStruct::findTypeParameter(std::string_view name
)
57 for (auto const& elem
: m_typeParameters
)
59 if (elem
->getLocalName() == name
) {
66 bool AstStruct::isType() const {
67 return getNodeType() == NT_struct
68 ? getTypeParameterCount() == 0 : AstDeclaration::isType();
71 bool AstStruct::dump(RegistryKey
& rKey
)
74 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
) != RegError::NO_ERROR
)
76 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
77 idlc()->getOptions()->getProgramName().getStr(),
78 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
82 if (m_typeParameters
.size() > SAL_MAX_UINT16
) {
85 ("%s: polymorphic struct type template %s has too many type"
87 idlc()->getOptions()->getProgramName().getStr(),
88 getScopedName().getStr());
92 sal_uInt16 nMember
= getNodeCount(NT_member
);
94 RTTypeClass typeClass
= RT_TYPE_STRUCT
;
95 if ( getNodeType() == NT_exception
)
96 typeClass
= RT_TYPE_EXCEPTION
;
98 typereg::Writer
aBlob(
99 (m_typeParameters
.empty() && !m_bPublished
100 ? TYPEREG_VERSION_0
: TYPEREG_VERSION_1
),
101 getDocumentation(), "", typeClass
, m_bPublished
,
102 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
),
103 m_pBaseType
== nullptr ? 0 : 1, nMember
, 0,
104 static_cast< sal_uInt16
>(m_typeParameters
.size()));
105 if (m_pBaseType
!= nullptr) {
106 aBlob
.setSuperTypeName(
109 m_pBaseType
->getRelativName(), RTL_TEXTENCODING_UTF8
));
114 DeclList::const_iterator iter
= getIteratorBegin();
115 DeclList::const_iterator end
= getIteratorEnd();
116 AstMember
* pMember
= nullptr;
117 sal_uInt16 index
= 0;
118 while ( iter
!= end
)
120 AstDeclaration
* pDecl
= *iter
;
121 if ( pDecl
->getNodeType() == NT_member
)
123 pMember
= static_cast<AstMember
*>(pDecl
);
124 RTFieldAccess flags
= RTFieldAccess::READWRITE
;
126 if (pMember
->getType()->getNodeType() == NT_type_parameter
) {
127 flags
|= RTFieldAccess::PARAMETERIZED_TYPE
;
128 typeName
= pMember
->getType()->getLocalName();
130 typeName
= pMember
->getType()->getRelativName();
133 index
++, pMember
->getDocumentation(), "", flags
,
135 pMember
->getLocalName(), RTL_TEXTENCODING_UTF8
),
136 OStringToOUString(typeName
, RTL_TEXTENCODING_UTF8
),
143 sal_uInt16 index
= 0;
144 for (auto const& elem
: m_typeParameters
)
146 aBlob
.setReferenceData(
147 index
++, "", RTReferenceType::TYPE_PARAMETER
, RTFieldAccess::INVALID
,
149 elem
->getLocalName(), RTL_TEXTENCODING_UTF8
));
152 sal_uInt32 aBlobSize
;
153 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
155 if (localKey
.setValue("", RegValueType::BINARY
,
156 const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
158 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
159 idlc()->getOptions()->getProgramName().getStr(),
160 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */