1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astdump.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idlc.hxx"
33 #include <idlc/astmodule.hxx>
34 #include <idlc/asttypedef.hxx>
35 #include <idlc/astservice.hxx>
36 #include <idlc/astconstant.hxx>
37 #include <idlc/astattribute.hxx>
38 #include <idlc/astinterfacemember.hxx>
39 #ifndef _IDLC_ASTSERVICEEMEMBER_HXX_
40 #include <idlc/astservicemember.hxx>
42 #include <idlc/astobserves.hxx>
43 #include <idlc/astneeds.hxx>
44 #include <idlc/astsequence.hxx>
45 #include "idlc/astoperation.hxx"
47 #include "registry/version.h"
48 #include "registry/writer.hxx"
50 using namespace ::rtl
;
52 sal_Bool
AstModule::dump(RegistryKey
& rKey
)
56 if ( getNodeType() == NT_root
)
61 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
))
63 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
64 idlc()->getOptions()->getProgramName().getStr(),
65 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
70 sal_uInt16 nConst
= getNodeCount(NT_const
);
74 RTTypeClass typeClass
= RT_TYPE_MODULE
;
75 if ( getNodeType() == NT_constants
)
76 typeClass
= RT_TYPE_CONSTANTS
;
78 typereg::Writer
aBlob(
79 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
80 getDocumentation(), emptyStr
, typeClass
,
82 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 0,
85 DeclList::const_iterator iter
= getIteratorBegin();
86 DeclList::const_iterator end
= getIteratorEnd();
87 AstDeclaration
* pDecl
= NULL
;
92 if ( pDecl
->getNodeType() == NT_const
&&
93 pDecl
->isInMainfile() )
95 ((AstConstant
*)pDecl
)->dumpBlob(
97 getNodeType() == NT_module
&& pDecl
->isPublished());
102 sal_uInt32 aBlobSize
;
103 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
105 if (localKey
.setValue(emptyStr
, RG_VALUETYPE_BINARY
,
106 (RegValue
)pBlob
, aBlobSize
))
108 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
109 idlc()->getOptions()->getProgramName().getStr(),
110 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
115 RTTypeClass typeClass
= RT_TYPE_MODULE
;
116 if ( getNodeType() == NT_constants
)
117 typeClass
= RT_TYPE_CONSTANTS
;
119 typereg::Writer
aBlob(
120 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
121 getDocumentation(), emptyStr
, typeClass
, m_bPublished
,
122 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 0, 0, 0,
125 sal_uInt32 aBlobSize
;
126 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
128 if ( getNodeType() != NT_root
)
130 if (localKey
.setValue(emptyStr
, RG_VALUETYPE_BINARY
,
131 (RegValue
)pBlob
, aBlobSize
))
133 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
134 idlc()->getOptions()->getProgramName().getStr(),
135 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
140 return AstDeclaration::dump(rKey
);
143 sal_Bool
AstTypeDef::dump(RegistryKey
& rKey
)
146 RegistryKey localKey
;
147 if (rKey
.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
), localKey
))
149 fprintf(stderr
, "%s: warning, could not create key '%s' in '%s'\n",
150 idlc()->getOptions()->getProgramName().getStr(),
151 getFullName().getStr(), OUStringToOString(rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
155 typereg::Writer
aBlob(
156 m_bPublished
? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
,
157 getDocumentation(), emptyStr
, RT_TYPE_TYPEDEF
, m_bPublished
,
158 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
), 1, 0, 0, 0);
159 aBlob
.setSuperTypeName(
162 getBaseType()->getRelativName(), RTL_TEXTENCODING_UTF8
));
164 sal_uInt32 aBlobSize
;
165 void const * pBlob
= aBlob
.getBlob(&aBlobSize
);
167 if (localKey
.setValue(emptyStr
, RG_VALUETYPE_BINARY
, (RegValue
)pBlob
, aBlobSize
))
169 fprintf(stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
170 idlc()->getOptions()->getProgramName().getStr(),
171 getFullName().getStr(), OUStringToOString(localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
178 sal_Bool
AstService::dump(RegistryKey
& rKey
)
181 typereg_Version version
= m_bPublished
182 ? TYPEREG_VERSION_1
: TYPEREG_VERSION_0
;
184 sal_uInt16 constructors
= 0;
185 sal_uInt16 properties
= 0;
186 sal_uInt16 references
= 0;
187 {for (DeclList::const_iterator
i(getIteratorBegin()); i
!= getIteratorEnd();
190 switch ((*i
)->getNodeType()) {
193 version
= TYPEREG_VERSION_1
;
194 OSL_ASSERT(superName
.getLength() == 0);
195 superName
= (*i
)->getRelativName();
199 OSL_ASSERT(getNodeType() == NT_service
);
204 OSL_ASSERT(getNodeType() == NT_service
);
208 case NT_service_member
:
209 if (getNodeType() == NT_singleton
) {
210 OSL_ASSERT(superName
.getLength() == 0);
211 superName
= ((AstServiceMember
*)(*i
))->
212 getRealService()->getRelativName();
215 case NT_interface_member
:
218 OSL_ASSERT(getNodeType() == NT_service
);
227 OSL_ASSERT(constructors
== 0 || !m_defaultConstructor
);
228 if (m_defaultConstructor
) {
231 RegistryKey localKey
;
233 rtl::OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8
),
236 stderr
, "%s: warning, could not create key '%s' in '%s'\n",
237 idlc()->getOptions()->getProgramName().getStr(),
238 getFullName().getStr(),
239 rtl::OUStringToOString(
240 rKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
243 typereg::Writer
writer(
244 version
, getDocumentation(), emptyStr
,
245 getNodeType() == NT_singleton
? RT_TYPE_SINGLETON
: RT_TYPE_SERVICE
,
247 rtl::OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8
),
248 superName
.getLength() == 0 ? 0 : 1, properties
, constructors
,
250 if (superName
.getLength() != 0) {
251 writer
.setSuperTypeName(
252 0, rtl::OStringToOUString(superName
, RTL_TEXTENCODING_UTF8
));
254 sal_uInt16 constructorIndex
= 0;
255 sal_uInt16 propertyIndex
= 0;
256 sal_uInt16 referenceIndex
= 0;
257 {for (DeclList::const_iterator
i(getIteratorBegin()); i
!= getIteratorEnd();
260 switch ((*i
)->getNodeType()) {
262 // static_cast< AstOperation * >(*i)->dumpBlob(
263 ((AstOperation
*)(*i
))->dumpBlob(
264 writer
, constructorIndex
++);
268 // static_cast< AstAttribute * >(*i)->dumpBlob(
269 ((AstAttribute
*)(*i
))->dumpBlob(
270 writer
, propertyIndex
++, 0);
273 case NT_interface_member
:
275 // AstInterfaceMember * decl = static_cast< AstInterfaceMember *>(*i);
276 AstInterfaceMember
* decl
= (AstInterfaceMember
*)(*i
);
277 writer
.setReferenceData(
278 referenceIndex
++, decl
->getDocumentation(), RT_REF_SUPPORTS
,
280 ? RT_ACCESS_OPTIONAL
: RT_ACCESS_INVALID
),
281 rtl::OStringToOUString(
282 decl
->getRealInterface()->getRelativName(),
283 RTL_TEXTENCODING_UTF8
));
287 case NT_service_member
:
288 if (getNodeType() == NT_service
) {
289 // AstServiceMember * decl = static_cast< AstServiceMember * >(*i);
290 AstServiceMember
* decl
= (AstServiceMember
*)(*i
);
291 writer
.setReferenceData(
292 referenceIndex
++, decl
->getDocumentation(), RT_REF_EXPORTS
,
294 ? RT_ACCESS_OPTIONAL
: RT_ACCESS_INVALID
),
295 rtl::OStringToOUString(
296 decl
->getRealService()->getRelativName(),
297 RTL_TEXTENCODING_UTF8
));
303 // AstObserves * decl = static_cast< AstObserves * >(*i);
304 AstObserves
* decl
= (AstObserves
*)(*i
);
305 writer
.setReferenceData(
306 referenceIndex
++, decl
->getDocumentation(), RT_REF_OBSERVES
,
308 rtl::OStringToOUString(
309 decl
->getRealInterface()->getRelativName(),
310 RTL_TEXTENCODING_UTF8
));
316 // AstNeeds * decl = static_cast< AstNeeds * >(*i);
317 AstNeeds
* decl
= (AstNeeds
*)(*i
);
318 writer
.setReferenceData(
319 referenceIndex
++, decl
->getDocumentation(), RT_REF_NEEDS
,
321 rtl::OStringToOUString(
322 decl
->getRealService()->getRelativName(),
323 RTL_TEXTENCODING_UTF8
));
329 (*i
)->getNodeType() == NT_interface
330 || (*i
)->getNodeType() == NT_typedef
);
334 if (m_defaultConstructor
) {
335 writer
.setMethodData(
336 constructorIndex
++, emptyStr
, RT_MODE_TWOWAY
,
337 emptyStr
, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")),
341 void const * blob
= writer
.getBlob(&size
);
342 if (localKey
.setValue(
343 emptyStr
, RG_VALUETYPE_BINARY
, const_cast< void * >(blob
),
347 stderr
, "%s: warning, could not set value of key \"%s\" in %s\n",
348 idlc()->getOptions()->getProgramName().getStr(),
349 getFullName().getStr(),
350 rtl::OUStringToOString(
351 localKey
.getRegistryName(), RTL_TEXTENCODING_UTF8
).getStr());
357 sal_Bool
AstAttribute::dumpBlob(
358 typereg::Writer
& rBlob
, sal_uInt16 index
, sal_uInt16
* methodIndex
)
360 RTFieldAccess accessMode
= RT_ACCESS_INVALID
;
364 accessMode
|= RT_ACCESS_READONLY
;
367 accessMode
|= RT_ACCESS_READWRITE
;
371 accessMode
|= RT_ACCESS_OPTIONAL
;
375 accessMode
|= RT_ACCESS_BOUND
;
379 accessMode
|= RT_ACCESS_MAYBEVOID
;
383 accessMode
|= RT_ACCESS_CONSTRAINED
;
387 accessMode
|= RT_ACCESS_TRANSIENT
;
389 if (isMayBeAmbiguous())
391 accessMode
|= RT_ACCESS_MAYBEAMBIGUOUS
;
393 if (isMayBeDefault())
395 accessMode
|= RT_ACCESS_MAYBEDEFAULT
;
399 accessMode
|= RT_ACCESS_REMOVEABLE
;
402 OUString
name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8
));
404 index
, getDocumentation(), OUString(), accessMode
, name
,
405 OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8
),
408 rBlob
, m_getDocumentation
, m_getExceptions
, RT_MODE_ATTRIBUTE_GET
,
411 rBlob
, m_setDocumentation
, m_setExceptions
, RT_MODE_ATTRIBUTE_SET
,
417 void AstAttribute::dumpExceptions(
418 typereg::Writer
& writer
, rtl::OUString
const & documentation
,
419 DeclList
const & exceptions
, RTMethodMode flags
, sal_uInt16
* methodIndex
)
421 if (!exceptions
.empty()) {
422 OSL_ASSERT(methodIndex
!= 0);
423 sal_uInt16 idx
= (*methodIndex
)++;
424 // exceptions.size() <= SAL_MAX_UINT16 already checked in
425 // AstInterface::dump:
426 writer
.setMethodData(
427 idx
, documentation
, flags
,
428 OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8
),
429 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")), 0,
430 static_cast< sal_uInt16
>(exceptions
.size()));
431 sal_uInt16 exceptionIndex
= 0;
432 for (DeclList::const_iterator
i(exceptions
.begin());
433 i
!= exceptions
.end(); ++i
)
435 writer
.setMethodExceptionTypeName(
436 idx
, exceptionIndex
++,
437 rtl::OStringToOUString(
438 (*i
)->getRelativName(), RTL_TEXTENCODING_UTF8
));
443 const sal_Char
* AstSequence::getRelativName() const
445 if ( !m_pRelativName
)
447 m_pRelativName
= new OString("[]");
448 AstDeclaration
const * pType
= resolveTypedefs( m_pMemberType
);
449 *m_pRelativName
+= pType
->getRelativName();
452 return m_pRelativName
->getStr();