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>
26 using namespace ::rtl
;
29 const OString
& name
, std::vector
< OString
> const & typeParameters
,
30 AstStruct
const* pBaseType
, AstScope
* pScope
)
31 : AstType(NT_struct
, name
, pScope
)
33 , m_pBaseType(pBaseType
)
35 for (std::vector
< OString
>::const_iterator
i(typeParameters
.begin());
36 i
!= typeParameters
.end(); ++i
)
38 m_typeParameters
.push_back(
39 new AstType(NT_type_parameter
, *i
, 0));
43 AstStruct::AstStruct(const NodeType type
,
45 AstStruct
const* pBaseType
,
47 : AstType(type
, name
, pScope
)
49 , m_pBaseType(pBaseType
)
53 AstStruct::~AstStruct()
55 for (DeclList::iterator
i(m_typeParameters
.begin());
56 i
!= m_typeParameters
.end(); ++i
)
62 AstDeclaration
const * AstStruct::findTypeParameter(OString
const & name
)
65 for (DeclList::const_iterator
i(m_typeParameters
.begin());
66 i
!= m_typeParameters
.end(); ++i
)
68 if ((*i
)->getLocalName() == name
) {
75 bool AstStruct::isType() const {
76 return getNodeType() == NT_struct
77 ? getTypeParameterCount() == 0 : AstDeclaration::isType();
80 bool AstStruct::dump(RegistryKey
& rKey
)
83 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
))
85 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
86 idlc()->getOptions()->getProgramName().getStr(),
87 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
91 if (m_typeParameters
.size() > SAL_MAX_UINT16
) {
94 ("%s: polymorphic struct type template %s has too many type"
96 idlc()->getOptions()->getProgramName().getStr(),
97 getScopedName().getStr());
101 sal_uInt16 nMember
= getNodeCount(NT_member
);
103 RTTypeClass typeClass
= RT_TYPE_STRUCT
;
104 if ( getNodeType() == NT_exception
)
105 typeClass
= RT_TYPE_EXCEPTION
;
108 typereg::Writer
aBlob(
109 (m_typeParameters
.empty() && !m_bPublished
110 ? TYPEREG_VERSION_0
: TYPEREG_VERSION_1
),
111 getDocumentation(), emptyStr
, typeClass
, m_bPublished
,
112 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
),
113 m_pBaseType
== 0 ? 0 : 1, nMember
, 0,
114 static_cast< sal_uInt16
>(m_typeParameters
.size()));
115 if (m_pBaseType
!= 0) {
116 aBlob
.setSuperTypeName(
119 m_pBaseType
->getRelativName(), RTL_TEXTENCODING_UTF8
));
124 DeclList::const_iterator iter
= getIteratorBegin();
125 DeclList::const_iterator end
= getIteratorEnd();
126 AstDeclaration
* pDecl
= NULL
;
127 AstMember
* pMember
= NULL
;
128 sal_uInt16 index
= 0;
129 while ( iter
!= end
)
132 if ( pDecl
->getNodeType() == NT_member
)
134 pMember
= (AstMember
*)pDecl
;
135 RTFieldAccess flags
= RT_ACCESS_READWRITE
;
137 if (pMember
->getType()->getNodeType() == NT_type_parameter
) {
138 flags
|= RT_ACCESS_PARAMETERIZED_TYPE
;
139 typeName
= pMember
->getType()->getLocalName();
141 typeName
= pMember
->getType()->getRelativName();
144 index
++, pMember
->getDocumentation(), emptyStr
, flags
,
146 pMember
->getLocalName(), RTL_TEXTENCODING_UTF8
),
147 OStringToOUString(typeName
, RTL_TEXTENCODING_UTF8
),
154 sal_uInt16 index
= 0;
155 for (DeclList::iterator
i(m_typeParameters
.begin());
156 i
!= m_typeParameters
.end(); ++i
)
158 aBlob
.setReferenceData(
159 index
++, emptyStr
, RT_REF_TYPE_PARAMETER
, RT_ACCESS_INVALID
,
161 (*i
)->getLocalName(), RTL_TEXTENCODING_UTF8
));
164 sal_uInt32 aBlobSize
;
165 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
167 if (localKey
.setValue(emptyStr
, RG_VALUETYPE_BINARY
,
168 (RegValue
)pBlob
, aBlobSize
))
170 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
171 idlc()->getOptions()->getProgramName().getStr(),
172 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */