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