Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
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"
31 : :
32 : : #include "registry/version.h"
33 : : #include "registry/writer.hxx"
34 : :
35 : : using namespace ::rtl;
36 : :
37 : 31079 : sal_Bool AstModule::dump(RegistryKey& rKey)
38 : : {
39 : 31079 : OUString emptyStr;
40 [ + - ]: 31079 : RegistryKey localKey;
41 [ + + ]: 31079 : if ( getNodeType() == NT_root )
42 : : {
43 [ + - ]: 5978 : localKey = rKey;
44 : : }else
45 : : {
46 [ + - ][ + - ]: 25101 : if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
[ - + ]
47 : : {
48 : : fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
49 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
50 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
51 : 0 : return sal_False;
52 : : }
53 : : }
54 : :
55 [ + - ]: 31079 : sal_uInt16 nConst = getNodeCount(NT_const);
56 : :
57 [ + + ]: 31079 : if ( nConst > 0 )
58 : : {
59 : 1238 : RTTypeClass typeClass = RT_TYPE_MODULE;
60 [ + - ]: 1238 : if ( getNodeType() == NT_constants )
61 : 1238 : typeClass = RT_TYPE_CONSTANTS;
62 : :
63 : : typereg::Writer aBlob(
64 : : m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
65 : 1238 : getDocumentation(), emptyStr, typeClass,
66 : : m_bPublished,
67 [ + - ]: 1238 : OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
68 [ + - + + ]: 2476 : nConst, 0, 0);
[ + - ]
69 : :
70 : 1238 : DeclList::const_iterator iter = getIteratorBegin();
71 : 1238 : DeclList::const_iterator end = getIteratorEnd();
72 : 1238 : AstDeclaration* pDecl = NULL;
73 : 1238 : sal_uInt16 index = 0;
74 [ + + ]: 13440 : while ( iter != end )
75 : : {
76 : 12202 : pDecl = *iter;
77 [ + - ]: 24404 : if ( pDecl->getNodeType() == NT_const &&
[ + - + - ]
78 : 12202 : pDecl->isInMainfile() )
79 : : {
80 : : ((AstConstant*)pDecl)->dumpBlob(
81 : : aBlob, index++,
82 [ - + ][ # # ]: 12202 : getNodeType() == NT_module && pDecl->isPublished());
[ + - ]
83 : : }
84 : 12202 : ++iter;
85 : : }
86 : :
87 : : sal_uInt32 aBlobSize;
88 [ + - ]: 1238 : void const * pBlob = aBlob.getBlob(&aBlobSize);
89 : :
90 [ - + ]: 1238 : if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
91 [ + - ]: 1238 : (RegValue)pBlob, aBlobSize))
92 : : {
93 : : fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
94 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
95 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
96 : 1238 : return sal_False;
97 [ + - ]: 1238 : }
98 : : } else
99 : : {
100 : 29841 : RTTypeClass typeClass = RT_TYPE_MODULE;
101 [ - + ]: 29841 : if ( getNodeType() == NT_constants )
102 : 0 : typeClass = RT_TYPE_CONSTANTS;
103 : :
104 : : typereg::Writer aBlob(
105 : : m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
106 : 29841 : getDocumentation(), emptyStr, typeClass, m_bPublished,
107 [ + - ]: 29841 : OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0, 0, 0,
108 [ + - - + ]: 59682 : 0);
[ + - ]
109 : :
110 : : sal_uInt32 aBlobSize;
111 [ + - ]: 29841 : void const * pBlob = aBlob.getBlob(&aBlobSize);
112 : :
113 [ + + ]: 29841 : if ( getNodeType() != NT_root )
114 : : {
115 [ - + ]: 23863 : if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
116 [ + - ]: 23863 : (RegValue)pBlob, aBlobSize))
117 : : {
118 : : fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
119 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
120 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
121 : 29841 : return sal_False;
122 : : }
123 [ + - ]: 29841 : }
124 : : }
125 [ + + ]: 31079 : if ( getNodeType() == NT_root )
126 : : {
127 [ + - ]: 5978 : localKey.releaseKey();
128 : : }
129 [ + - ][ + - ]: 31079 : return AstDeclaration::dump(rKey);
130 : : }
131 : :
132 : 74 : sal_Bool AstTypeDef::dump(RegistryKey& rKey)
133 : : {
134 : 74 : OUString emptyStr;
135 [ + - ]: 74 : RegistryKey localKey;
136 [ + - ][ + - ]: 74 : if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
[ - + ]
137 : : {
138 : : fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
139 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
140 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
141 : 0 : return sal_False;
142 : : }
143 : :
144 : : typereg::Writer aBlob(
145 : : m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
146 : 74 : getDocumentation(), emptyStr, RT_TYPE_TYPEDEF, m_bPublished,
147 [ + - ]: 148 : OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 1, 0, 0, 0);
[ + - + + ]
[ + - ]
148 : : aBlob.setSuperTypeName(
149 : : 0,
150 : : OStringToOUString(
151 [ + - ][ + - ]: 74 : getBaseType()->getRelativName(), RTL_TEXTENCODING_UTF8));
[ + - ]
152 : :
153 : : sal_uInt32 aBlobSize;
154 [ + - ]: 74 : void const * pBlob = aBlob.getBlob(&aBlobSize);
155 : :
156 [ + - ][ - + ]: 74 : if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY, (RegValue)pBlob, aBlobSize))
157 : : {
158 : : fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
159 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
160 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
161 : 0 : return sal_False;
162 : : }
163 : :
164 [ + - ]: 74 : return sal_True;
165 : : }
166 : :
167 : 1818 : sal_Bool AstService::dump(RegistryKey& rKey)
168 : : {
169 : 1818 : OUString emptyStr;
170 : : typereg_Version version = m_bPublished
171 [ + + ]: 1818 : ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0;
172 : 1818 : OString superName;
173 : 1818 : sal_uInt16 constructors = 0;
174 : 1818 : sal_uInt16 properties = 0;
175 : 1818 : sal_uInt16 references = 0;
176 [ + + ]: 9689 : {for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
177 : : ++i)
178 : : {
179 [ + + + + : 7871 : switch ((*i)->getNodeType()) {
+ - ]
180 : : case NT_interface:
181 : : case NT_typedef:
182 : 496 : version = TYPEREG_VERSION_1;
183 : : OSL_ASSERT(superName.isEmpty());
184 [ + - ]: 496 : superName = (*i)->getRelativName();
185 : 496 : break;
186 : :
187 : : case NT_operation:
188 : : OSL_ASSERT(getNodeType() == NT_service);
189 : 242 : ++constructors;
190 : 242 : break;
191 : :
192 : : case NT_property:
193 : : OSL_ASSERT(getNodeType() == NT_service);
194 : 3716 : ++properties;
195 : 3716 : break;
196 : :
197 : : case NT_service_member:
198 [ + + ]: 985 : if (getNodeType() == NT_singleton) {
199 : : OSL_ASSERT(superName.isEmpty());
200 : 5 : superName = ((AstServiceMember *)(*i))->
201 [ + - ]: 5 : getRealService()->getRelativName();
202 : 5 : break;
203 : : }
204 : : case NT_interface_member:
205 : : case NT_observes:
206 : : case NT_needs:
207 : : OSL_ASSERT(getNodeType() == NT_service);
208 : 3412 : ++references;
209 : 3412 : break;
210 : :
211 : : default:
212 : : OSL_ASSERT(false);
213 : 0 : break;
214 : : }
215 : : }}
216 : : OSL_ASSERT(constructors == 0 || !m_defaultConstructor);
217 [ + + ]: 1818 : if (m_defaultConstructor) {
218 : 107 : constructors = 1;
219 : : }
220 [ + - ]: 1818 : RegistryKey localKey;
221 [ - + ]: 1818 : if (rKey.createKey(
222 : 1818 : rtl::OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8),
223 [ + - ][ + - ]: 1818 : localKey)) {
224 : : fprintf(
225 : : stderr, "%s: warning, could not create key '%s' in '%s'\n",
226 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
227 : 0 : getFullName().getStr(),
228 : : rtl::OUStringToOString(
229 [ # # ][ # # ]: 0 : rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
230 : 0 : return false;
231 : : }
232 : : typereg::Writer writer(
233 : 1818 : version, getDocumentation(), emptyStr,
234 : 1818 : getNodeType() == NT_singleton ? RT_TYPE_SINGLETON : RT_TYPE_SERVICE,
235 : : m_bPublished,
236 [ + - ]: 1818 : rtl::OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
237 : 1818 : superName.isEmpty() ? 0 : 1, properties, constructors,
238 [ + - + + ]: 7272 : references);
[ + - ][ + + ]
239 [ + + ]: 1818 : if (!superName.isEmpty()) {
240 : : writer.setSuperTypeName(
241 [ + - ][ + - ]: 501 : 0, rtl::OStringToOUString(superName, RTL_TEXTENCODING_UTF8));
242 : : }
243 : 1818 : sal_uInt16 constructorIndex = 0;
244 : 1818 : sal_uInt16 propertyIndex = 0;
245 : 1818 : sal_uInt16 referenceIndex = 0;
246 [ + + ]: 9689 : for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd(); ++i)
247 : : {
248 [ + + + + : 7871 : switch ((*i)->getNodeType()) {
- - + ]
249 : : case NT_operation:
250 [ + - ]: 242 : ((AstOperation *)(*i))->dumpBlob(writer, constructorIndex++);
251 : 242 : break;
252 : :
253 : : case NT_property:
254 [ + - ]: 3716 : ((AstAttribute *)(*i))->dumpBlob(writer, propertyIndex++, 0);
255 : 3716 : break;
256 : :
257 : : case NT_interface_member:
258 : : {
259 : 2432 : AstInterfaceMember * decl = (AstInterfaceMember *)(*i);
260 : : writer.setReferenceData(
261 : 2432 : referenceIndex++, decl->getDocumentation(), RT_REF_SUPPORTS,
262 : 2432 : (decl->isOptional() ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID),
263 [ + - ]: 2432 : rtl::OStringToOUString( decl->getRealInterface()->getRelativName(),
264 [ + - + + ]: 7296 : RTL_TEXTENCODING_UTF8));
[ + - ]
265 : 2432 : break;
266 : : }
267 : :
268 : : case NT_service_member:
269 [ + + ]: 985 : if (getNodeType() == NT_service)
270 : : {
271 : 980 : AstServiceMember * decl = (AstServiceMember *)(*i);
272 : 980 : writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RT_REF_EXPORTS,
273 : 980 : (decl->isOptional() ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID),
274 [ + - ]: 980 : rtl::OStringToOUString(decl->getRealService()->getRelativName(),
275 [ + - + + ]: 2940 : RTL_TEXTENCODING_UTF8));
[ + - ]
276 : : }
277 : 985 : break;
278 : :
279 : : case NT_observes:
280 : : {
281 : 0 : AstObserves * decl = (AstObserves *)(*i);
282 : 0 : writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RT_REF_OBSERVES,
283 : : RT_ACCESS_INVALID,
284 [ # # ]: 0 : rtl::OStringToOUString( decl->getRealInterface()->getRelativName(),
285 [ # # # # ]: 0 : RTL_TEXTENCODING_UTF8));
286 : 0 : break;
287 : : }
288 : :
289 : : case NT_needs:
290 : : {
291 : 0 : AstNeeds * decl = (AstNeeds *)(*i);
292 : 0 : writer.setReferenceData( referenceIndex++, decl->getDocumentation(), RT_REF_NEEDS,
293 : : RT_ACCESS_INVALID,
294 [ # # ]: 0 : rtl::OStringToOUString( decl->getRealService()->getRelativName(),
295 [ # # # # ]: 0 : RTL_TEXTENCODING_UTF8));
296 : 0 : break;
297 : : }
298 : :
299 : : default:
300 : : OSL_ASSERT( (*i)->getNodeType() == NT_interface || (*i)->getNodeType() == NT_typedef);
301 : 496 : break;
302 : : }
303 : : }
304 [ + + ]: 1818 : if (m_defaultConstructor) {
305 : : writer.setMethodData(
306 : : constructorIndex++, emptyStr, RT_MODE_TWOWAY,
307 : : emptyStr, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")),
308 [ + - ][ + - ]: 107 : 0, 0);
309 : : }
310 : : sal_uInt32 size;
311 [ + - ]: 1818 : void const * blob = writer.getBlob(&size);
312 [ - + ]: 1818 : if (localKey.setValue(
313 : : emptyStr, RG_VALUETYPE_BINARY, const_cast< void * >(blob),
314 [ + - ]: 1818 : size))
315 : : {
316 : : fprintf(
317 : : stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
318 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
319 : 0 : getFullName().getStr(),
320 : : rtl::OUStringToOString(
321 [ # # ][ # # ]: 0 : localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
322 : 0 : return false;
323 : : }
324 [ + - ]: 1818 : return true;
325 : : }
326 : :
327 : 4895 : sal_Bool AstAttribute::dumpBlob(
328 : : typereg::Writer & rBlob, sal_uInt16 index, sal_uInt16 * methodIndex)
329 : : {
330 : 4895 : RTFieldAccess accessMode = RT_ACCESS_INVALID;
331 : :
332 [ + + ]: 4895 : if (isReadonly())
333 : : {
334 : 530 : accessMode |= RT_ACCESS_READONLY;
335 : : } else
336 : : {
337 : 4365 : accessMode |= RT_ACCESS_READWRITE;
338 : : }
339 [ + + ]: 4895 : if (isOptional())
340 : : {
341 : 1244 : accessMode |= RT_ACCESS_OPTIONAL;
342 : : }
343 [ + + ]: 4895 : if (isBound())
344 : : {
345 : 157 : accessMode |= RT_ACCESS_BOUND;
346 : : }
347 [ + + ]: 4895 : if (isMayBeVoid())
348 : : {
349 : 146 : accessMode |= RT_ACCESS_MAYBEVOID;
350 : : }
351 [ - + ]: 4895 : if (isConstrained())
352 : : {
353 : 0 : accessMode |= RT_ACCESS_CONSTRAINED;
354 : : }
355 [ + + ]: 4895 : if (isTransient())
356 : : {
357 : 6 : accessMode |= RT_ACCESS_TRANSIENT;
358 : : }
359 [ - + ]: 4895 : if (isMayBeAmbiguous())
360 : : {
361 : 0 : accessMode |= RT_ACCESS_MAYBEAMBIGUOUS;
362 : : }
363 [ + + ]: 4895 : if (isMayBeDefault())
364 : : {
365 : 3 : accessMode |= RT_ACCESS_MAYBEDEFAULT;
366 : : }
367 [ - + ]: 4895 : if (isRemoveable())
368 : : {
369 : 0 : accessMode |= RT_ACCESS_REMOVEABLE;
370 : : }
371 : :
372 [ + - ]: 4895 : OUString name(OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8));
373 : : rBlob.setFieldData(
374 : 4895 : index, getDocumentation(), OUString(), accessMode, name,
375 [ + - ]: 4895 : OStringToOUString(getType()->getRelativName(), RTL_TEXTENCODING_UTF8),
376 [ + - ][ + - ]: 14685 : RTConstValue());
377 : : dumpExceptions(
378 : : rBlob, m_getDocumentation, m_getExceptions, RT_MODE_ATTRIBUTE_GET,
379 [ + - ]: 4895 : methodIndex);
380 : : dumpExceptions(
381 : : rBlob, m_setDocumentation, m_setExceptions, RT_MODE_ATTRIBUTE_SET,
382 [ + - ]: 4895 : methodIndex);
383 : :
384 : 4895 : return sal_True;
385 : : }
386 : :
387 : 9790 : void AstAttribute::dumpExceptions(
388 : : typereg::Writer & writer, rtl::OUString const & documentation,
389 : : DeclList const & exceptions, RTMethodMode flags, sal_uInt16 * methodIndex)
390 : : {
391 [ + + ]: 9790 : if (!exceptions.empty()) {
392 : : OSL_ASSERT(methodIndex != 0);
393 : 193 : sal_uInt16 idx = (*methodIndex)++;
394 : : // exceptions.size() <= SAL_MAX_UINT16 already checked in
395 : : // AstInterface::dump:
396 : : writer.setMethodData(
397 : : idx, documentation, flags,
398 : 193 : OStringToOUString(getLocalName(), RTL_TEXTENCODING_UTF8),
399 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")), 0,
400 [ + - ][ + - ]: 386 : static_cast< sal_uInt16 >(exceptions.size()));
401 : 193 : sal_uInt16 exceptionIndex = 0;
402 [ + + ]: 794 : for (DeclList::const_iterator i(exceptions.begin());
403 : 397 : i != exceptions.end(); ++i)
404 : : {
405 : : writer.setMethodExceptionTypeName(
406 : : idx, exceptionIndex++,
407 : : rtl::OStringToOUString(
408 [ + - ][ + - ]: 204 : (*i)->getRelativName(), RTL_TEXTENCODING_UTF8));
[ + - ]
409 : : }
410 : : }
411 : 9790 : }
412 : :
413 : 1750 : const sal_Char* AstSequence::getRelativName() const
414 : : {
415 [ + + ]: 1750 : if ( !m_pRelativName )
416 : : {
417 [ + - ]: 1139 : m_pRelativName = new OString("[]");
418 : 1139 : AstDeclaration const * pType = resolveTypedefs( m_pMemberType );
419 [ + - ]: 1139 : *m_pRelativName += pType->getRelativName();
420 : : }
421 : :
422 : 1750 : return m_pRelativName->getStr();
423 : : }
424 : :
425 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|