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 <astmodule.hxx>
21 #include <asttypedef.hxx>
22 #include <astservice.hxx>
23 #include <astconstant.hxx>
24 #include <astattribute.hxx>
25 #include <astinterfacemember.hxx>
26 #include <astservicemember.hxx>
27 #include <astobserves.hxx>
28 #include <astneeds.hxx>
29 #include <astsequence.hxx>
30 #include <astoperation.hxx>
32 #include <osl/diagnose.h>
34 #include <registry/version.h>
35 #include <registry/writer.hxx>
37 bool AstModule::dump(RegistryKey
& rKey
)
40 if ( getNodeType() == NT_root
)
45 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
) != RegError::NO_ERROR
)
47 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
48 idlc()->getOptions()->getProgramName().getStr(),
49 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
54 sal_uInt16 nConst
= getNodeCount(NT_const
);
58 RTTypeClass typeClass
= RT_TYPE_MODULE
;
59 if ( getNodeType() == NT_constants
)
60 typeClass
= RT_TYPE_CONSTANTS
;
62 typereg::Writer
aBlob(
63 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
64 getDocumentation(), "", typeClass
,
66 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 0,
69 DeclList::const_iterator iter
= getIteratorBegin();
70 DeclList::const_iterator end
= getIteratorEnd();
74 AstDeclaration
* pDecl
= *iter
;
75 if ( pDecl
->getNodeType() == NT_const
&&
76 pDecl
->isInMainfile() )
78 static_cast<AstConstant
*>(pDecl
)->dumpBlob(
80 getNodeType() == NT_module
&& pDecl
->isPublished());
86 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
88 if (localKey
.setValue("", RegValueType::BINARY
,
89 const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
91 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
92 idlc()->getOptions()->getProgramName().getStr(),
93 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
98 RTTypeClass typeClass
= RT_TYPE_MODULE
;
99 if ( getNodeType() == NT_constants
)
100 typeClass
= RT_TYPE_CONSTANTS
;
102 typereg::Writer
aBlob(
103 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
104 getDocumentation(), "", typeClass
, m_bPublished
,
105 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 0, 0, 0,
108 sal_uInt32 aBlobSize
;
109 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
111 if ( getNodeType() != NT_root
)
113 if (localKey
.setValue("", RegValueType::BINARY
,
114 const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
116 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
117 idlc()->getOptions()->getProgramName().getStr(),
118 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
123 if ( getNodeType() == NT_root
)
125 localKey
.releaseKey();
127 return AstDeclaration::dump(rKey
);
130 bool AstTypeDef::dump(RegistryKey
& rKey
)
132 RegistryKey localKey
;
133 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
) != RegError::NO_ERROR
)
135 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
136 idlc()->getOptions()->getProgramName().getStr(),
137 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
141 typereg::Writer
aBlob(
142 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
143 getDocumentation(), "", RT_TYPE_TYPEDEF
, m_bPublished
,
144 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 1, 0, 0, 0);
145 aBlob
.setSuperTypeName(
148 getBaseType()->getRelativName(), RTL_TEXTENCODING_UTF8
));
150 sal_uInt32 aBlobSize
;
151 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
153 if (localKey
.setValue("", RegValueType::BINARY
, const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
155 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
156 idlc()->getOptions()->getProgramName().getStr(),
157 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
164 bool AstService::dump(RegistryKey
& rKey
)
166 typereg_Version version
= m_bPublished
167 ? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
;
169 sal_uInt16 constructors
= 0;
170 sal_uInt16 properties
= 0;
171 sal_uInt16 references
= 0;
172 for (DeclList::const_iterator
i(getIteratorBegin()); i
!= getIteratorEnd();
175 switch ((*i
)->getNodeType()) {
178 version
= TYPEREG_VERSION_1
;
179 OSL_ASSERT(superName
.isEmpty());
180 superName
= (*i
)->getRelativName();
184 OSL_ASSERT(getNodeType() == NT_service
);
189 OSL_ASSERT(getNodeType() == NT_service
);
193 case NT_service_member
:
194 if (getNodeType() == NT_singleton
) {
195 OSL_ASSERT(superName
.isEmpty());
196 superName
= static_cast<AstServiceMember
*>(*i
)->
197 getRealService()->getRelativName();
201 case NT_interface_member
:
204 OSL_ASSERT(getNodeType() == NT_service
);
213 OSL_ASSERT(constructors
== 0 || !m_defaultConstructor
);
214 if (m_defaultConstructor
) {
217 RegistryKey localKey
;
219 OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
),
220 localKey
) != RegError::NO_ERROR
) {
222 stderr
, "%s: warning, could not create key '%s' in '%s'\n",
223 idlc()->getOptions()->getProgramName().getStr(),
224 getFullName().getStr(),
226 rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
229 typereg::Writer
writer(
230 version
, getDocumentation(), "",
231 getNodeType() == NT_singleton
? RT_TYPE_SINGLETON
: RT_TYPE_SERVICE
,
233 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
),
234 superName
.isEmpty() ? 0 : 1, properties
, constructors
,
236 if (!superName
.isEmpty()) {
237 writer
.setSuperTypeName(
238 0, OStringToOUString(superName
, RTL_TEXTENCODING_UTF8
));
240 sal_uInt16 constructorIndex
= 0;
241 sal_uInt16 propertyIndex
= 0;
242 sal_uInt16 referenceIndex
= 0;
243 for (DeclList::const_iterator
i(getIteratorBegin()); i
!= getIteratorEnd(); ++i
)
245 switch ((*i
)->getNodeType()) {
247 static_cast<AstOperation
*>(*i
)->dumpBlob(writer
, constructorIndex
++);
251 static_cast<AstAttribute
*>(*i
)->dumpBlob(writer
, propertyIndex
++, nullptr);
254 case NT_interface_member
:
256 AstInterfaceMember
* decl
= static_cast<AstInterfaceMember
*>(*i
);
257 writer
.setReferenceData(
258 referenceIndex
++, decl
->getDocumentation(), RTReferenceType::SUPPORTS
,
259 (decl
->isOptional() ? RTFieldAccess::OPTIONAL
: RTFieldAccess::INVALID
),
260 OStringToOUString( decl
->getRealInterface()->getRelativName(),
261 RTL_TEXTENCODING_UTF8
));
265 case NT_service_member
:
266 if (getNodeType() == NT_service
)
268 AstServiceMember
* decl
= static_cast<AstServiceMember
*>(*i
);
269 writer
.setReferenceData(referenceIndex
++, decl
->getDocumentation(), RTReferenceType::EXPORTS
,
270 (decl
->isOptional() ? RTFieldAccess::OPTIONAL
: RTFieldAccess::INVALID
),
271 OStringToOUString(decl
->getRealService()->getRelativName(),
272 RTL_TEXTENCODING_UTF8
));
278 AstObserves
* decl
= static_cast<AstObserves
*>(*i
);
279 writer
.setReferenceData(referenceIndex
++, decl
->getDocumentation(), RTReferenceType::OBSERVES
,
280 RTFieldAccess::INVALID
,
281 OStringToOUString( decl
->getRealInterface()->getRelativName(),
282 RTL_TEXTENCODING_UTF8
));
288 AstNeeds
* decl
= static_cast<AstNeeds
*>(*i
);
289 writer
.setReferenceData( referenceIndex
++, decl
->getDocumentation(), RTReferenceType::NEEDS
,
290 RTFieldAccess::INVALID
,
291 OStringToOUString( decl
->getRealService()->getRelativName(),
292 RTL_TEXTENCODING_UTF8
));
297 OSL_ASSERT( (*i
)->getNodeType() == NT_interface
|| (*i
)->getNodeType() == NT_typedef
);
301 if (m_defaultConstructor
) {
302 writer
.setMethodData(
303 constructorIndex
++, "", RTMethodMode::TWOWAY
,
308 void const * blob
= writer
.getBlob(&size
);
309 if (localKey
.setValue(
310 "", RegValueType::BINARY
, const_cast< void * >(blob
),
311 size
) != RegError::NO_ERROR
)
314 stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
315 idlc()->getOptions()->getProgramName().getStr(),
316 getFullName().getStr(),
318 localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
324 void AstAttribute::dumpBlob(
325 typereg::Writer
& rBlob
, sal_uInt16 index
, sal_uInt16
* methodIndex
) const
327 RTFieldAccess accessMode
= RTFieldAccess::INVALID
;
331 accessMode
|= RTFieldAccess::READONLY
;
334 accessMode
|= RTFieldAccess::READWRITE
;
338 accessMode
|= RTFieldAccess::OPTIONAL
;
342 accessMode
|= RTFieldAccess::BOUND
;
346 accessMode
|= RTFieldAccess::MAYBEVOID
;
350 accessMode
|= RTFieldAccess::CONSTRAINED
;
354 accessMode
|= RTFieldAccess::TRANSIENT
;
356 if (isMayBeAmbiguous())
358 accessMode
|= RTFieldAccess::MAYBEAMBIGUOUS
;
360 if (isMayBeDefault())
362 accessMode
|= RTFieldAccess::MAYBEDEFAULT
;
366 accessMode
|= RTFieldAccess::REMOVABLE
;
369 OUString
name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8
));
371 index
, getDocumentation(), OUString(), accessMode
, name
,
372 OStringToOUString(m_pType
->getRelativName(), RTL_TEXTENCODING_UTF8
),
375 rBlob
, m_getDocumentation
, m_getExceptions
, RTMethodMode::ATTRIBUTE_GET
,
378 rBlob
, m_setDocumentation
, m_setExceptions
, RTMethodMode::ATTRIBUTE_SET
,
382 void AstAttribute::dumpExceptions(
383 typereg::Writer
& writer
, OUString
const & documentation
,
384 DeclList
const & exceptions
, RTMethodMode flags
, sal_uInt16
* methodIndex
) const
386 if (!exceptions
.empty()) {
387 OSL_ASSERT(methodIndex
!= nullptr);
388 sal_uInt16 idx
= (*methodIndex
)++;
389 // exceptions.size() <= SAL_MAX_UINT16 already checked in
390 // AstInterface::dump:
391 writer
.setMethodData(
392 idx
, documentation
, flags
,
393 OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8
),
395 static_cast< sal_uInt16
>(exceptions
.size()));
396 sal_uInt16 exceptionIndex
= 0;
397 for (auto const& elem
: exceptions
)
399 writer
.setMethodExceptionTypeName(
400 idx
, exceptionIndex
++,
402 elem
->getRelativName(), RTL_TEXTENCODING_UTF8
));
407 const sal_Char
* AstSequence::getRelativName() const
409 if ( !m_xRelativName
)
411 m_xRelativName
= OString("[]");
412 AstDeclaration
const * pType
= resolveTypedefs( m_pMemberType
);
413 *m_xRelativName
+= pType
->getRelativName();
416 return m_xRelativName
->getStr();
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */