lokdialog: convert the show sheet dialog to async exec
[LibreOffice.git] / idlc / source / astdump.cxx
blobfbdd7232d89368e9ecc2a7cade457c7cb6f5ed65
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
39 RegistryKey localKey;
40 if ( getNodeType() == NT_root )
42 localKey = rKey;
43 }else
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());
50 return false;
54 sal_uInt16 nConst = getNodeCount(NT_const);
56 if ( nConst > 0 )
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,
65 m_bPublished,
66 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
67 nConst, 0, 0);
69 DeclList::const_iterator iter = getIteratorBegin();
70 DeclList::const_iterator end = getIteratorEnd();
71 sal_uInt16 index = 0;
72 while ( iter != end )
74 AstDeclaration* pDecl = *iter;
75 if ( pDecl->getNodeType() == NT_const &&
76 pDecl->isInMainfile() )
78 static_cast<AstConstant*>(pDecl)->dumpBlob(
79 aBlob, index++,
80 getNodeType() == NT_module && pDecl->isPublished());
82 ++iter;
85 sal_uInt32 aBlobSize;
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());
94 return false;
96 } else
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());
119 return false;
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());
138 return false;
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(
147 OStringToOUString(
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());
158 return false;
161 return true;
164 bool AstService::dump(RegistryKey& rKey)
166 typereg_Version version = m_bPublished
167 ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0;
168 OString superName;
169 sal_uInt16 constructors = 0;
170 sal_uInt16 properties = 0;
171 sal_uInt16 references = 0;
172 for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
173 ++i)
175 switch ((*i)->getNodeType()) {
176 case NT_interface:
177 case NT_typedef:
178 version = TYPEREG_VERSION_1;
179 OSL_ASSERT(superName.isEmpty());
180 superName = (*i)->getRelativName();
181 break;
183 case NT_operation:
184 OSL_ASSERT(getNodeType() == NT_service);
185 ++constructors;
186 break;
188 case NT_property:
189 OSL_ASSERT(getNodeType() == NT_service);
190 ++properties;
191 break;
193 case NT_service_member:
194 if (getNodeType() == NT_singleton) {
195 OSL_ASSERT(superName.isEmpty());
196 superName = static_cast<AstServiceMember *>(*i)->
197 getRealService()->getRelativName();
198 break;
200 SAL_FALLTHROUGH;
201 case NT_interface_member:
202 case NT_observes:
203 case NT_needs:
204 OSL_ASSERT(getNodeType() == NT_service);
205 ++references;
206 break;
208 default:
209 OSL_ASSERT(false);
210 break;
213 OSL_ASSERT(constructors == 0 || !m_defaultConstructor);
214 if (m_defaultConstructor) {
215 constructors = 1;
217 RegistryKey localKey;
218 if (rKey.createKey(
219 OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8),
220 localKey) != RegError::NO_ERROR) {
221 fprintf(
222 stderr, "%s: warning, could not create key '%s' in '%s'\n",
223 idlc()->getOptions()->getProgramName().getStr(),
224 getFullName().getStr(),
225 OUStringToOString(
226 rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
227 return false;
229 typereg::Writer writer(
230 version, getDocumentation(), "",
231 getNodeType() == NT_singleton ? RT_TYPE_SINGLETON : RT_TYPE_SERVICE,
232 m_bPublished,
233 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
234 superName.isEmpty() ? 0 : 1, properties, constructors,
235 references);
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()) {
246 case NT_operation:
247 static_cast<AstOperation *>(*i)->dumpBlob(writer, constructorIndex++);
248 break;
250 case NT_property:
251 static_cast<AstAttribute *>(*i)->dumpBlob(writer, propertyIndex++, nullptr);
252 break;
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));
262 break;
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));
274 break;
276 case NT_observes:
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));
283 break;
286 case NT_needs:
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));
293 break;
296 default:
297 OSL_ASSERT( (*i)->getNodeType() == NT_interface || (*i)->getNodeType() == NT_typedef);
298 break;
301 if (m_defaultConstructor) {
302 writer.setMethodData(
303 constructorIndex++, "", RTMethodMode::TWOWAY,
304 "", "void",
305 0, 0);
307 sal_uInt32 size;
308 void const * blob = writer.getBlob(&size);
309 if (localKey.setValue(
310 "", RegValueType::BINARY, const_cast< void * >(blob),
311 size) != RegError::NO_ERROR)
313 fprintf(
314 stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
315 idlc()->getOptions()->getProgramName().getStr(),
316 getFullName().getStr(),
317 OUStringToOString(
318 localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
319 return false;
321 return true;
324 void AstAttribute::dumpBlob(
325 typereg::Writer & rBlob, sal_uInt16 index, sal_uInt16 * methodIndex) const
327 RTFieldAccess accessMode = RTFieldAccess::INVALID;
329 if (isReadonly())
331 accessMode |= RTFieldAccess::READONLY;
332 } else
334 accessMode |= RTFieldAccess::READWRITE;
336 if (isOptional())
338 accessMode |= RTFieldAccess::OPTIONAL;
340 if (isBound())
342 accessMode |= RTFieldAccess::BOUND;
344 if (isMayBeVoid())
346 accessMode |= RTFieldAccess::MAYBEVOID;
348 if (isConstrained())
350 accessMode |= RTFieldAccess::CONSTRAINED;
352 if (isTransient())
354 accessMode |= RTFieldAccess::TRANSIENT;
356 if (isMayBeAmbiguous())
358 accessMode |= RTFieldAccess::MAYBEAMBIGUOUS;
360 if (isMayBeDefault())
362 accessMode |= RTFieldAccess::MAYBEDEFAULT;
364 if (isRemoveable())
366 accessMode |= RTFieldAccess::REMOVABLE;
369 OUString name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8));
370 rBlob.setFieldData(
371 index, getDocumentation(), OUString(), accessMode, name,
372 OStringToOUString(m_pType->getRelativName(), RTL_TEXTENCODING_UTF8),
373 RTConstValue());
374 dumpExceptions(
375 rBlob, m_getDocumentation, m_getExceptions, RTMethodMode::ATTRIBUTE_GET,
376 methodIndex);
377 dumpExceptions(
378 rBlob, m_setDocumentation, m_setExceptions, RTMethodMode::ATTRIBUTE_SET,
379 methodIndex);
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),
394 "void", 0,
395 static_cast< sal_uInt16 >(exceptions.size()));
396 sal_uInt16 exceptionIndex = 0;
397 for (DeclList::const_iterator i(exceptions.begin());
398 i != exceptions.end(); ++i)
400 writer.setMethodExceptionTypeName(
401 idx, exceptionIndex++,
402 OStringToOUString(
403 (*i)->getRelativName(), RTL_TEXTENCODING_UTF8));
408 const sal_Char* AstSequence::getRelativName() const
410 if ( !m_pRelativName )
412 m_pRelativName.reset( new OString("[]") );
413 AstDeclaration const * pType = resolveTypedefs( m_pMemberType );
414 *m_pRelativName += pType->getRelativName();
417 return m_pRelativName->getStr();
420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */