Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / idlc / source / astdump.cxx
blob5382685e47627456835c7c7e640176effafa434e
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 "registry/version.h"
33 #include "registry/writer.hxx"
35 using namespace ::rtl;
37 sal_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))
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 sal_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 AstDeclaration* pDecl = NULL;
73 sal_uInt16 index = 0;
74 while ( iter != end )
76 pDecl = *iter;
77 if ( pDecl->getNodeType() == NT_const &&
78 pDecl->isInMainfile() )
80 ((AstConstant*)pDecl)->dumpBlob(
81 aBlob, index++,
82 getNodeType() == NT_module && pDecl->isPublished());
84 ++iter;
87 sal_uInt32 aBlobSize;
88 void const * pBlob = aBlob.getBlob(&aBlobSize);
90 if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
91 (RegValue)pBlob, aBlobSize))
93 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
94 idlc()->getOptions()->getProgramName().getStr(),
95 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
96 return sal_False;
98 } else
100 RTTypeClass typeClass = RT_TYPE_MODULE;
101 if ( getNodeType() == NT_constants )
102 typeClass = RT_TYPE_CONSTANTS;
104 typereg::Writer aBlob(
105 m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
106 getDocumentation(), emptyStr, typeClass, m_bPublished,
107 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0, 0, 0,
110 sal_uInt32 aBlobSize;
111 void const * pBlob = aBlob.getBlob(&aBlobSize);
113 if ( getNodeType() != NT_root )
115 if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
116 (RegValue)pBlob, aBlobSize))
118 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
119 idlc()->getOptions()->getProgramName().getStr(),
120 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
121 return sal_False;
125 if ( getNodeType() == NT_root )
127 localKey.releaseKey();
129 return AstDeclaration::dump(rKey);
132 sal_Bool AstTypeDef::dump(RegistryKey& rKey)
134 OUString emptyStr;
135 RegistryKey localKey;
136 if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
138 fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
139 idlc()->getOptions()->getProgramName().getStr(),
140 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
141 return sal_False;
144 typereg::Writer aBlob(
145 m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
146 getDocumentation(), emptyStr, RT_TYPE_TYPEDEF, m_bPublished,
147 OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 1, 0, 0, 0);
148 aBlob.setSuperTypeName(
150 OStringToOUString(
151 getBaseType()->getRelativName(), RTL_TEXTENCODING_UTF8));
153 sal_uInt32 aBlobSize;
154 void const * pBlob = aBlob.getBlob(&aBlobSize);
156 if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY, (RegValue)pBlob, aBlobSize))
158 fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
159 idlc()->getOptions()->getProgramName().getStr(),
160 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
161 return sal_False;
164 return sal_True;
167 sal_Bool AstService::dump(RegistryKey& rKey)
169 OUString emptyStr;
170 typereg_Version version = m_bPublished
171 ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0;
172 OString superName;
173 sal_uInt16 constructors = 0;
174 sal_uInt16 properties = 0;
175 sal_uInt16 references = 0;
176 {for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
177 ++i)
179 switch ((*i)->getNodeType()) {
180 case NT_interface:
181 case NT_typedef:
182 version = TYPEREG_VERSION_1;
183 OSL_ASSERT(superName.isEmpty());
184 superName = (*i)->getRelativName();
185 break;
187 case NT_operation:
188 OSL_ASSERT(getNodeType() == NT_service);
189 ++constructors;
190 break;
192 case NT_property:
193 OSL_ASSERT(getNodeType() == NT_service);
194 ++properties;
195 break;
197 case NT_service_member:
198 if (getNodeType() == NT_singleton) {
199 OSL_ASSERT(superName.isEmpty());
200 superName = ((AstServiceMember *)(*i))->
201 getRealService()->getRelativName();
202 break;
204 case NT_interface_member:
205 case NT_observes:
206 case NT_needs:
207 OSL_ASSERT(getNodeType() == NT_service);
208 ++references;
209 break;
211 default:
212 OSL_ASSERT(false);
213 break;
216 OSL_ASSERT(constructors == 0 || !m_defaultConstructor);
217 if (m_defaultConstructor) {
218 constructors = 1;
220 RegistryKey localKey;
221 if (rKey.createKey(
222 rtl::OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8),
223 localKey)) {
224 fprintf(
225 stderr, "%s: warning, could not create key '%s' in '%s'\n",
226 idlc()->getOptions()->getProgramName().getStr(),
227 getFullName().getStr(),
228 rtl::OUStringToOString(
229 rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
230 return false;
232 typereg::Writer writer(
233 version, getDocumentation(), emptyStr,
234 getNodeType() == NT_singleton ? RT_TYPE_SINGLETON : RT_TYPE_SERVICE,
235 m_bPublished,
236 rtl::OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
237 superName.isEmpty() ? 0 : 1, properties, constructors,
238 references);
239 if (!superName.isEmpty()) {
240 writer.setSuperTypeName(
241 0, rtl::OStringToOUString(superName, RTL_TEXTENCODING_UTF8));
243 sal_uInt16 constructorIndex = 0;
244 sal_uInt16 propertyIndex = 0;
245 sal_uInt16 referenceIndex = 0;
246 for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd(); ++i)
248 switch ((*i)->getNodeType()) {
249 case NT_operation:
250 ((AstOperation *)(*i))->dumpBlob(writer, constructorIndex++);
251 break;
253 case NT_property:
254 ((AstAttribute *)(*i))->dumpBlob(writer, propertyIndex++, 0);
255 break;
257 case NT_interface_member:
259 AstInterfaceMember * decl = (AstInterfaceMember *)(*i);
260 writer.setReferenceData(
261 referenceIndex++, decl->getDocumentation(), RT_REF_SUPPORTS,
262 (decl->isOptional() ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID),
263 rtl::OStringToOUString( decl->getRealInterface()->getRelativName(),
264 RTL_TEXTENCODING_UTF8));
265 break;
268 case NT_service_member:
269 if (getNodeType() == NT_service)
271 AstServiceMember * decl = (AstServiceMember *)(*i);
272 writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RT_REF_EXPORTS,
273 (decl->isOptional() ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID),
274 rtl::OStringToOUString(decl->getRealService()->getRelativName(),
275 RTL_TEXTENCODING_UTF8));
277 break;
279 case NT_observes:
281 AstObserves * decl = (AstObserves *)(*i);
282 writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RT_REF_OBSERVES,
283 RT_ACCESS_INVALID,
284 rtl::OStringToOUString( decl->getRealInterface()->getRelativName(),
285 RTL_TEXTENCODING_UTF8));
286 break;
289 case NT_needs:
291 AstNeeds * decl = (AstNeeds *)(*i);
292 writer.setReferenceData( referenceIndex++, decl->getDocumentation(), RT_REF_NEEDS,
293 RT_ACCESS_INVALID,
294 rtl::OStringToOUString( decl->getRealService()->getRelativName(),
295 RTL_TEXTENCODING_UTF8));
296 break;
299 default:
300 OSL_ASSERT( (*i)->getNodeType() == NT_interface || (*i)->getNodeType() == NT_typedef);
301 break;
304 if (m_defaultConstructor) {
305 writer.setMethodData(
306 constructorIndex++, emptyStr, RT_MODE_TWOWAY,
307 emptyStr, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")),
308 0, 0);
310 sal_uInt32 size;
311 void const * blob = writer.getBlob(&size);
312 if (localKey.setValue(
313 emptyStr, RG_VALUETYPE_BINARY, const_cast< void * >(blob),
314 size))
316 fprintf(
317 stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
318 idlc()->getOptions()->getProgramName().getStr(),
319 getFullName().getStr(),
320 rtl::OUStringToOString(
321 localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
322 return false;
324 return true;
327 sal_Bool AstAttribute::dumpBlob(
328 typereg::Writer & rBlob, sal_uInt16 index, sal_uInt16 * methodIndex)
330 RTFieldAccess accessMode = RT_ACCESS_INVALID;
332 if (isReadonly())
334 accessMode |= RT_ACCESS_READONLY;
335 } else
337 accessMode |= RT_ACCESS_READWRITE;
339 if (isOptional())
341 accessMode |= RT_ACCESS_OPTIONAL;
343 if (isBound())
345 accessMode |= RT_ACCESS_BOUND;
347 if (isMayBeVoid())
349 accessMode |= RT_ACCESS_MAYBEVOID;
351 if (isConstrained())
353 accessMode |= RT_ACCESS_CONSTRAINED;
355 if (isTransient())
357 accessMode |= RT_ACCESS_TRANSIENT;
359 if (isMayBeAmbiguous())
361 accessMode |= RT_ACCESS_MAYBEAMBIGUOUS;
363 if (isMayBeDefault())
365 accessMode |= RT_ACCESS_MAYBEDEFAULT;
367 if (isRemoveable())
369 accessMode |= RT_ACCESS_REMOVEABLE;
372 OUString name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8));
373 rBlob.setFieldData(
374 index, getDocumentation(), OUString(), accessMode, name,
375 OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
376 RTConstValue());
377 dumpExceptions(
378 rBlob, m_getDocumentation, m_getExceptions, RT_MODE_ATTRIBUTE_GET,
379 methodIndex);
380 dumpExceptions(
381 rBlob, m_setDocumentation, m_setExceptions, RT_MODE_ATTRIBUTE_SET,
382 methodIndex);
384 return sal_True;
387 void AstAttribute::dumpExceptions(
388 typereg::Writer & writer, rtl::OUString const & documentation,
389 DeclList const & exceptions, RTMethodMode flags, sal_uInt16 * methodIndex)
391 if (!exceptions.empty()) {
392 OSL_ASSERT(methodIndex != 0);
393 sal_uInt16 idx = (*methodIndex)++;
394 // exceptions.size() <= SAL_MAX_UINT16 already checked in
395 // AstInterface::dump:
396 writer.setMethodData(
397 idx, documentation, flags,
398 OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
399 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")), 0,
400 static_cast< sal_uInt16 >(exceptions.size()));
401 sal_uInt16 exceptionIndex = 0;
402 for (DeclList::const_iterator i(exceptions.begin());
403 i != exceptions.end(); ++i)
405 writer.setMethodExceptionTypeName(
406 idx, exceptionIndex++,
407 rtl::OStringToOUString(
408 (*i)->getRelativName(), RTL_TEXTENCODING_UTF8));
413 const sal_Char* AstSequence::getRelativName() const
415 if ( !m_pRelativName )
417 m_pRelativName = new OString("[]");
418 AstDeclaration const * pType = resolveTypedefs( m_pMemberType );
419 *m_pRelativName += pType->getRelativName();
422 return m_pRelativName->getStr();
425 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */