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/astmodule.hxx>
21 #include <idlc/asttypedef.hxx>
22 #include <idlc/astservice.hxx>
23 #include <idlc/astconstant.hxx>
24 #include <idlc/astattribute.hxx>
25 #include <idlc/astinterfacemember.hxx>
26 #include <idlc/astservicemember.hxx>
27 #include <idlc/astobserves.hxx>
28 #include <idlc/astneeds.hxx>
29 #include <idlc/astsequence.hxx>
30 #include "idlc/astoperation.hxx"
32 #include <osl/diagnose.h>
34 #include <registry/version.h>
35 #include <registry/writer.hxx>
37 bool AstModule::dump(RegistryKey
& rKey
)
41 if ( getNodeType() == NT_root
)
46 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
) != RegError::NO_ERROR
)
48 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
49 idlc()->getOptions()->getProgramName().getStr(),
50 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
55 sal_uInt16 nConst
= getNodeCount(NT_const
);
59 RTTypeClass typeClass
= RT_TYPE_MODULE
;
60 if ( getNodeType() == NT_constants
)
61 typeClass
= RT_TYPE_CONSTANTS
;
63 typereg::Writer
aBlob(
64 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
65 getDocumentation(), emptyStr
, typeClass
,
67 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 0,
70 DeclList::const_iterator iter
= getIteratorBegin();
71 DeclList::const_iterator end
= getIteratorEnd();
75 AstDeclaration
* pDecl
= *iter
;
76 if ( pDecl
->getNodeType() == NT_const
&&
77 pDecl
->isInMainfile() )
79 static_cast<AstConstant
*>(pDecl
)->dumpBlob(
81 getNodeType() == NT_module
&& pDecl
->isPublished());
87 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
89 if (localKey
.setValue(emptyStr
, RegValueType::BINARY
,
90 const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
92 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
93 idlc()->getOptions()->getProgramName().getStr(),
94 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
99 RTTypeClass typeClass
= RT_TYPE_MODULE
;
100 if ( getNodeType() == NT_constants
)
101 typeClass
= RT_TYPE_CONSTANTS
;
103 typereg::Writer
aBlob(
104 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
105 getDocumentation(), emptyStr
, typeClass
, m_bPublished
,
106 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 0, 0, 0,
109 sal_uInt32 aBlobSize
;
110 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
112 if ( getNodeType() != NT_root
)
114 if (localKey
.setValue(emptyStr
, RegValueType::BINARY
,
115 const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
117 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
118 idlc()->getOptions()->getProgramName().getStr(),
119 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
124 if ( getNodeType() == NT_root
)
126 localKey
.releaseKey();
128 return AstDeclaration::dump(rKey
);
131 bool AstTypeDef::dump(RegistryKey
& rKey
)
134 RegistryKey localKey
;
135 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
) != RegError::NO_ERROR
)
137 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
138 idlc()->getOptions()->getProgramName().getStr(),
139 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
143 typereg::Writer
aBlob(
144 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
145 getDocumentation(), emptyStr
, RT_TYPE_TYPEDEF
, m_bPublished
,
146 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 1, 0, 0, 0);
147 aBlob
.setSuperTypeName(
150 getBaseType()->getRelativName(), RTL_TEXTENCODING_UTF8
));
152 sal_uInt32 aBlobSize
;
153 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
155 if (localKey
.setValue(emptyStr
, RegValueType::BINARY
, const_cast<RegValue
>(pBlob
), aBlobSize
) != RegError::NO_ERROR
)
157 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
158 idlc()->getOptions()->getProgramName().getStr(),
159 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
166 bool AstService::dump(RegistryKey
& rKey
)
169 typereg_Version version
= m_bPublished
170 ? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
;
172 sal_uInt16 constructors
= 0;
173 sal_uInt16 properties
= 0;
174 sal_uInt16 references
= 0;
175 for (DeclList::const_iterator
i(getIteratorBegin()); i
!= getIteratorEnd();
178 switch ((*i
)->getNodeType()) {
181 version
= TYPEREG_VERSION_1
;
182 OSL_ASSERT(superName
.isEmpty());
183 superName
= (*i
)->getRelativName();
187 OSL_ASSERT(getNodeType() == NT_service
);
192 OSL_ASSERT(getNodeType() == NT_service
);
196 case NT_service_member
:
197 if (getNodeType() == NT_singleton
) {
198 OSL_ASSERT(superName
.isEmpty());
199 superName
= (static_cast<AstServiceMember
*>(*i
))->
200 getRealService()->getRelativName();
203 case NT_interface_member
:
206 OSL_ASSERT(getNodeType() == NT_service
);
215 OSL_ASSERT(constructors
== 0 || !m_defaultConstructor
);
216 if (m_defaultConstructor
) {
219 RegistryKey localKey
;
221 OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
),
222 localKey
) != RegError::NO_ERROR
) {
224 stderr
, "%s: warning, could not create key '%s' in '%s'\n",
225 idlc()->getOptions()->getProgramName().getStr(),
226 getFullName().getStr(),
228 rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
231 typereg::Writer
writer(
232 version
, getDocumentation(), emptyStr
,
233 getNodeType() == NT_singleton
? RT_TYPE_SINGLETON
: RT_TYPE_SERVICE
,
235 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
),
236 superName
.isEmpty() ? 0 : 1, properties
, constructors
,
238 if (!superName
.isEmpty()) {
239 writer
.setSuperTypeName(
240 0, OStringToOUString(superName
, RTL_TEXTENCODING_UTF8
));
242 sal_uInt16 constructorIndex
= 0;
243 sal_uInt16 propertyIndex
= 0;
244 sal_uInt16 referenceIndex
= 0;
245 for (DeclList::const_iterator
i(getIteratorBegin()); i
!= getIteratorEnd(); ++i
)
247 switch ((*i
)->getNodeType()) {
249 static_cast<AstOperation
*>(*i
)->dumpBlob(writer
, constructorIndex
++);
253 static_cast<AstAttribute
*>(*i
)->dumpBlob(writer
, propertyIndex
++, 0);
256 case NT_interface_member
:
258 AstInterfaceMember
* decl
= static_cast<AstInterfaceMember
*>(*i
);
259 writer
.setReferenceData(
260 referenceIndex
++, decl
->getDocumentation(), RTReferenceType::SUPPORTS
,
261 (decl
->isOptional() ? RTFieldAccess::OPTIONAL
: RTFieldAccess::INVALID
),
262 OStringToOUString( decl
->getRealInterface()->getRelativName(),
263 RTL_TEXTENCODING_UTF8
));
267 case NT_service_member
:
268 if (getNodeType() == NT_service
)
270 AstServiceMember
* decl
= static_cast<AstServiceMember
*>(*i
);
271 writer
.setReferenceData(referenceIndex
++, decl
->getDocumentation(), RTReferenceType::EXPORTS
,
272 (decl
->isOptional() ? RTFieldAccess::OPTIONAL
: RTFieldAccess::INVALID
),
273 OStringToOUString(decl
->getRealService()->getRelativName(),
274 RTL_TEXTENCODING_UTF8
));
280 AstObserves
* decl
= static_cast<AstObserves
*>(*i
);
281 writer
.setReferenceData(referenceIndex
++, decl
->getDocumentation(), RTReferenceType::OBSERVES
,
282 RTFieldAccess::INVALID
,
283 OStringToOUString( decl
->getRealInterface()->getRelativName(),
284 RTL_TEXTENCODING_UTF8
));
290 AstNeeds
* decl
= static_cast<AstNeeds
*>(*i
);
291 writer
.setReferenceData( referenceIndex
++, decl
->getDocumentation(), RTReferenceType::NEEDS
,
292 RTFieldAccess::INVALID
,
293 OStringToOUString( decl
->getRealService()->getRelativName(),
294 RTL_TEXTENCODING_UTF8
));
299 OSL_ASSERT( (*i
)->getNodeType() == NT_interface
|| (*i
)->getNodeType() == NT_typedef
);
303 if (m_defaultConstructor
) {
304 writer
.setMethodData(
305 constructorIndex
++, emptyStr
, RTMethodMode::TWOWAY
,
306 emptyStr
, OUString("void"),
310 void const * blob
= writer
.getBlob(&size
);
311 if (localKey
.setValue(
312 emptyStr
, RegValueType::BINARY
, const_cast< void * >(blob
),
313 size
) != RegError::NO_ERROR
)
316 stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
317 idlc()->getOptions()->getProgramName().getStr(),
318 getFullName().getStr(),
320 localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
326 bool AstAttribute::dumpBlob(
327 typereg::Writer
& rBlob
, sal_uInt16 index
, sal_uInt16
* methodIndex
)
329 RTFieldAccess accessMode
= RTFieldAccess::INVALID
;
333 accessMode
|= RTFieldAccess::READONLY
;
336 accessMode
|= RTFieldAccess::READWRITE
;
340 accessMode
|= RTFieldAccess::OPTIONAL
;
344 accessMode
|= RTFieldAccess::BOUND
;
348 accessMode
|= RTFieldAccess::MAYBEVOID
;
352 accessMode
|= RTFieldAccess::CONSTRAINED
;
356 accessMode
|= RTFieldAccess::TRANSIENT
;
358 if (isMayBeAmbiguous())
360 accessMode
|= RTFieldAccess::MAYBEAMBIGUOUS
;
362 if (isMayBeDefault())
364 accessMode
|= RTFieldAccess::MAYBEDEFAULT
;
368 accessMode
|= RTFieldAccess::REMOVABLE
;
371 OUString
name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8
));
373 index
, getDocumentation(), OUString(), accessMode
, name
,
374 OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8
),
377 rBlob
, m_getDocumentation
, m_getExceptions
, RTMethodMode::ATTRIBUTE_GET
,
380 rBlob
, m_setDocumentation
, m_setExceptions
, RTMethodMode::ATTRIBUTE_SET
,
386 void AstAttribute::dumpExceptions(
387 typereg::Writer
& writer
, OUString
const & documentation
,
388 DeclList
const & exceptions
, RTMethodMode flags
, sal_uInt16
* methodIndex
)
390 if (!exceptions
.empty()) {
391 OSL_ASSERT(methodIndex
!= 0);
392 sal_uInt16 idx
= (*methodIndex
)++;
393 // exceptions.size() <= SAL_MAX_UINT16 already checked in
394 // AstInterface::dump:
395 writer
.setMethodData(
396 idx
, documentation
, flags
,
397 OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8
),
399 static_cast< sal_uInt16
>(exceptions
.size()));
400 sal_uInt16 exceptionIndex
= 0;
401 for (DeclList::const_iterator
i(exceptions
.begin());
402 i
!= exceptions
.end(); ++i
)
404 writer
.setMethodExceptionTypeName(
405 idx
, exceptionIndex
++,
407 (*i
)->getRelativName(), RTL_TEXTENCODING_UTF8
));
412 const sal_Char
* AstSequence::getRelativName() const
414 if ( !m_pRelativName
)
416 m_pRelativName
= new OString("[]");
417 AstDeclaration
const * pType
= resolveTypedefs( m_pMemberType
);
418 *m_pRelativName
+= pType
->getRelativName();
421 return m_pRelativName
->getStr();
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */