fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / idlc / source / astdump.cxx
blobb4dfa84df65ae4ca429abb8e278cbf6eb14644fa
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 <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)
39 OUString emptyStr;
40 RegistryKey localKey;
41 if ( getNodeType() == NT_root )
43 localKey = rKey;
44 }else
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());
51 return false;
55 sal_uInt16 nConst = getNodeCount(NT_const);
57 if ( nConst > 0 )
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,
66 m_bPublished,
67 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
68 nConst, 0, 0);
70 DeclList::const_iterator iter = getIteratorBegin();
71 DeclList::const_iterator end = getIteratorEnd();
72 sal_uInt16 index = 0;
73 while ( iter != end )
75 AstDeclaration* pDecl = *iter;
76 if ( pDecl->getNodeType() == NT_const &&
77 pDecl->isInMainfile() )
79 static_cast<AstConstant*>(pDecl)->dumpBlob(
80 aBlob, index++,
81 getNodeType() == NT_module && pDecl->isPublished());
83 ++iter;
86 sal_uInt32 aBlobSize;
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());
95 return false;
97 } else
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());
120 return false;
124 if ( getNodeType() == NT_root )
126 localKey.releaseKey();
128 return AstDeclaration::dump(rKey);
131 bool AstTypeDef::dump(RegistryKey& rKey)
133 OUString emptyStr;
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());
140 return false;
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(
149 OStringToOUString(
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());
160 return false;
163 return true;
166 bool AstService::dump(RegistryKey& rKey)
168 OUString emptyStr;
169 typereg_Version version = m_bPublished
170 ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0;
171 OString superName;
172 sal_uInt16 constructors = 0;
173 sal_uInt16 properties = 0;
174 sal_uInt16 references = 0;
175 for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
176 ++i)
178 switch ((*i)->getNodeType()) {
179 case NT_interface:
180 case NT_typedef:
181 version = TYPEREG_VERSION_1;
182 OSL_ASSERT(superName.isEmpty());
183 superName = (*i)->getRelativName();
184 break;
186 case NT_operation:
187 OSL_ASSERT(getNodeType() == NT_service);
188 ++constructors;
189 break;
191 case NT_property:
192 OSL_ASSERT(getNodeType() == NT_service);
193 ++properties;
194 break;
196 case NT_service_member:
197 if (getNodeType() == NT_singleton) {
198 OSL_ASSERT(superName.isEmpty());
199 superName = (static_cast<AstServiceMember *>(*i))->
200 getRealService()->getRelativName();
201 break;
203 case NT_interface_member:
204 case NT_observes:
205 case NT_needs:
206 OSL_ASSERT(getNodeType() == NT_service);
207 ++references;
208 break;
210 default:
211 OSL_ASSERT(false);
212 break;
215 OSL_ASSERT(constructors == 0 || !m_defaultConstructor);
216 if (m_defaultConstructor) {
217 constructors = 1;
219 RegistryKey localKey;
220 if (rKey.createKey(
221 OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8),
222 localKey) != RegError::NO_ERROR) {
223 fprintf(
224 stderr, "%s: warning, could not create key '%s' in '%s'\n",
225 idlc()->getOptions()->getProgramName().getStr(),
226 getFullName().getStr(),
227 OUStringToOString(
228 rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
229 return false;
231 typereg::Writer writer(
232 version, getDocumentation(), emptyStr,
233 getNodeType() == NT_singleton ? RT_TYPE_SINGLETON : RT_TYPE_SERVICE,
234 m_bPublished,
235 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
236 superName.isEmpty() ? 0 : 1, properties, constructors,
237 references);
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()) {
248 case NT_operation:
249 static_cast<AstOperation *>(*i)->dumpBlob(writer, constructorIndex++);
250 break;
252 case NT_property:
253 static_cast<AstAttribute *>(*i)->dumpBlob(writer, propertyIndex++, 0);
254 break;
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));
264 break;
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));
276 break;
278 case NT_observes:
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));
285 break;
288 case NT_needs:
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));
295 break;
298 default:
299 OSL_ASSERT( (*i)->getNodeType() == NT_interface || (*i)->getNodeType() == NT_typedef);
300 break;
303 if (m_defaultConstructor) {
304 writer.setMethodData(
305 constructorIndex++, emptyStr, RTMethodMode::TWOWAY,
306 emptyStr, OUString("void"),
307 0, 0);
309 sal_uInt32 size;
310 void const * blob = writer.getBlob(&size);
311 if (localKey.setValue(
312 emptyStr, RegValueType::BINARY, const_cast< void * >(blob),
313 size) != RegError::NO_ERROR)
315 fprintf(
316 stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
317 idlc()->getOptions()->getProgramName().getStr(),
318 getFullName().getStr(),
319 OUStringToOString(
320 localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
321 return false;
323 return true;
326 bool AstAttribute::dumpBlob(
327 typereg::Writer & rBlob, sal_uInt16 index, sal_uInt16 * methodIndex)
329 RTFieldAccess accessMode = RTFieldAccess::INVALID;
331 if (isReadonly())
333 accessMode |= RTFieldAccess::READONLY;
334 } else
336 accessMode |= RTFieldAccess::READWRITE;
338 if (isOptional())
340 accessMode |= RTFieldAccess::OPTIONAL;
342 if (isBound())
344 accessMode |= RTFieldAccess::BOUND;
346 if (isMayBeVoid())
348 accessMode |= RTFieldAccess::MAYBEVOID;
350 if (isConstrained())
352 accessMode |= RTFieldAccess::CONSTRAINED;
354 if (isTransient())
356 accessMode |= RTFieldAccess::TRANSIENT;
358 if (isMayBeAmbiguous())
360 accessMode |= RTFieldAccess::MAYBEAMBIGUOUS;
362 if (isMayBeDefault())
364 accessMode |= RTFieldAccess::MAYBEDEFAULT;
366 if (isRemoveable())
368 accessMode |= RTFieldAccess::REMOVABLE;
371 OUString name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8));
372 rBlob.setFieldData(
373 index, getDocumentation(), OUString(), accessMode, name,
374 OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
375 RTConstValue());
376 dumpExceptions(
377 rBlob, m_getDocumentation, m_getExceptions, RTMethodMode::ATTRIBUTE_GET,
378 methodIndex);
379 dumpExceptions(
380 rBlob, m_setDocumentation, m_setExceptions, RTMethodMode::ATTRIBUTE_SET,
381 methodIndex);
383 return true;
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),
398 OUString("void"), 0,
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++,
406 OStringToOUString(
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: */