update dev300-m58
[ooovba.git] / idlc / source / astdump.cxx
blobae7206381947914182a3b559799f23d9be69e88b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astdump.cxx,v $
10 * $Revision: 1.15 $
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>
41 #endif
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)
54 OUString emptyStr;
55 RegistryKey localKey;
56 if ( getNodeType() == NT_root )
58 localKey = rKey;
59 }else
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());
66 return sal_False;
70 sal_uInt16 nConst = getNodeCount(NT_const);
72 if ( nConst > 0 )
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,
81 m_bPublished,
82 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
83 nConst, 0, 0);
85 DeclList::const_iterator iter = getIteratorBegin();
86 DeclList::const_iterator end = getIteratorEnd();
87 AstDeclaration* pDecl = NULL;
88 sal_uInt16 index = 0;
89 while ( iter != end )
91 pDecl = *iter;
92 if ( pDecl->getNodeType() == NT_const &&
93 pDecl->isInMainfile() )
95 ((AstConstant*)pDecl)->dumpBlob(
96 aBlob, index++,
97 getNodeType() == NT_module && pDecl->isPublished());
99 ++iter;
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());
111 return sal_False;
113 } else
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());
136 return sal_False;
140 return AstDeclaration::dump(rKey);
143 sal_Bool AstTypeDef::dump(RegistryKey& rKey)
145 OUString emptyStr;
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());
152 return sal_False;
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(
161 OStringToOUString(
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());
172 return sal_False;
175 return sal_True;
178 sal_Bool AstService::dump(RegistryKey& rKey)
180 OUString emptyStr;
181 typereg_Version version = m_bPublished
182 ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0;
183 OString superName;
184 sal_uInt16 constructors = 0;
185 sal_uInt16 properties = 0;
186 sal_uInt16 references = 0;
187 {for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
188 ++i)
190 switch ((*i)->getNodeType()) {
191 case NT_interface:
192 case NT_typedef:
193 version = TYPEREG_VERSION_1;
194 OSL_ASSERT(superName.getLength() == 0);
195 superName = (*i)->getRelativName();
196 break;
198 case NT_operation:
199 OSL_ASSERT(getNodeType() == NT_service);
200 ++constructors;
201 break;
203 case NT_property:
204 OSL_ASSERT(getNodeType() == NT_service);
205 ++properties;
206 break;
208 case NT_service_member:
209 if (getNodeType() == NT_singleton) {
210 OSL_ASSERT(superName.getLength() == 0);
211 superName = ((AstServiceMember *)(*i))->
212 getRealService()->getRelativName();
213 break;
215 case NT_interface_member:
216 case NT_observes:
217 case NT_needs:
218 OSL_ASSERT(getNodeType() == NT_service);
219 ++references;
220 break;
222 default:
223 OSL_ASSERT(false);
224 break;
227 OSL_ASSERT(constructors == 0 || !m_defaultConstructor);
228 if (m_defaultConstructor) {
229 constructors = 1;
231 RegistryKey localKey;
232 if (rKey.createKey(
233 rtl::OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8),
234 localKey)) {
235 fprintf(
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());
241 return false;
243 typereg::Writer writer(
244 version, getDocumentation(), emptyStr,
245 getNodeType() == NT_singleton ? RT_TYPE_SINGLETON : RT_TYPE_SERVICE,
246 m_bPublished,
247 rtl::OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
248 superName.getLength() == 0 ? 0 : 1, properties, constructors,
249 references);
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();
258 ++i)
260 switch ((*i)->getNodeType()) {
261 case NT_operation:
262 // static_cast< AstOperation * >(*i)->dumpBlob(
263 ((AstOperation *)(*i))->dumpBlob(
264 writer, constructorIndex++);
265 break;
267 case NT_property:
268 // static_cast< AstAttribute * >(*i)->dumpBlob(
269 ((AstAttribute *)(*i))->dumpBlob(
270 writer, propertyIndex++, 0);
271 break;
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,
279 (decl->isOptional()
280 ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID),
281 rtl::OStringToOUString(
282 decl->getRealInterface()->getRelativName(),
283 RTL_TEXTENCODING_UTF8));
284 break;
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,
293 (decl->isOptional()
294 ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID),
295 rtl::OStringToOUString(
296 decl->getRealService()->getRelativName(),
297 RTL_TEXTENCODING_UTF8));
299 break;
301 case NT_observes:
303 // AstObserves * decl = static_cast< AstObserves * >(*i);
304 AstObserves * decl = (AstObserves *)(*i);
305 writer.setReferenceData(
306 referenceIndex++, decl->getDocumentation(), RT_REF_OBSERVES,
307 RT_ACCESS_INVALID,
308 rtl::OStringToOUString(
309 decl->getRealInterface()->getRelativName(),
310 RTL_TEXTENCODING_UTF8));
311 break;
314 case NT_needs:
316 // AstNeeds * decl = static_cast< AstNeeds * >(*i);
317 AstNeeds * decl = (AstNeeds *)(*i);
318 writer.setReferenceData(
319 referenceIndex++, decl->getDocumentation(), RT_REF_NEEDS,
320 RT_ACCESS_INVALID,
321 rtl::OStringToOUString(
322 decl->getRealService()->getRelativName(),
323 RTL_TEXTENCODING_UTF8));
324 break;
327 default:
328 OSL_ASSERT(
329 (*i)->getNodeType() == NT_interface
330 || (*i)->getNodeType() == NT_typedef);
331 break;
334 if (m_defaultConstructor) {
335 writer.setMethodData(
336 constructorIndex++, emptyStr, RT_MODE_TWOWAY,
337 emptyStr, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")),
338 0, 0);
340 sal_uInt32 size;
341 void const * blob = writer.getBlob(&size);
342 if (localKey.setValue(
343 emptyStr, RG_VALUETYPE_BINARY, const_cast< void * >(blob),
344 size))
346 fprintf(
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());
352 return false;
354 return true;
357 sal_Bool AstAttribute::dumpBlob(
358 typereg::Writer & rBlob, sal_uInt16 index, sal_uInt16 * methodIndex)
360 RTFieldAccess accessMode = RT_ACCESS_INVALID;
362 if (isReadonly())
364 accessMode |= RT_ACCESS_READONLY;
365 } else
367 accessMode |= RT_ACCESS_READWRITE;
369 if (isOptional())
371 accessMode |= RT_ACCESS_OPTIONAL;
373 if (isBound())
375 accessMode |= RT_ACCESS_BOUND;
377 if (isMayBeVoid())
379 accessMode |= RT_ACCESS_MAYBEVOID;
381 if (isConstrained())
383 accessMode |= RT_ACCESS_CONSTRAINED;
385 if (isTransient())
387 accessMode |= RT_ACCESS_TRANSIENT;
389 if (isMayBeAmbiguous())
391 accessMode |= RT_ACCESS_MAYBEAMBIGUOUS;
393 if (isMayBeDefault())
395 accessMode |= RT_ACCESS_MAYBEDEFAULT;
397 if (isRemoveable())
399 accessMode |= RT_ACCESS_REMOVEABLE;
402 OUString name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8));
403 rBlob.setFieldData(
404 index, getDocumentation(), OUString(), accessMode, name,
405 OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
406 RTConstValue());
407 dumpExceptions(
408 rBlob, m_getDocumentation, m_getExceptions, RT_MODE_ATTRIBUTE_GET,
409 methodIndex);
410 dumpExceptions(
411 rBlob, m_setDocumentation, m_setExceptions, RT_MODE_ATTRIBUTE_SET,
412 methodIndex);
414 return sal_True;
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();