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/astinterface.hxx>
21 : : #include <idlc/astattribute.hxx>
22 : : #include <idlc/astoperation.hxx>
23 : : #include "idlc/idlc.hxx"
24 : :
25 : : #include "registry/version.h"
26 : : #include "registry/writer.hxx"
27 : :
28 : : using namespace ::rtl;
29 : :
30 : 40662 : AstInterface::AstInterface(const ::rtl::OString& name,
31 : : AstInterface const * pInherits,
32 : : AstScope* pScope)
33 : : : AstType(NT_interface, name, pScope)
34 : : , AstScope(NT_interface)
35 : : , m_mandatoryInterfaces(0)
36 : : , m_bIsDefined(false)
37 : : , m_bForwarded(sal_False)
38 : : , m_bForwardedInSameFile(sal_False)
39 [ + - ][ + - ]: 40662 : , m_bSingleInheritance(pInherits != 0)
[ + - ][ + - ]
40 : : {
41 [ + + ]: 40662 : if (pInherits != 0) {
42 [ + - ]: 25002 : addInheritedInterface(pInherits, false, rtl::OUString());
43 : : }
44 : 40662 : }
45 : :
46 [ + - ]: 2110 : AstInterface::~AstInterface()
47 : : {
48 [ - + ]: 4220 : }
49 : :
50 : 2117 : AstInterface::DoubleDeclarations AstInterface::checkInheritedInterfaceClashes(
51 : : AstInterface const * ifc, bool optional) const
52 : : {
53 [ + - ]: 2117 : DoubleDeclarations doubleDecls;
54 [ + - ]: 2117 : std::set< rtl::OString > seen;
55 : : checkInheritedInterfaceClashes(
56 [ + - ]: 2117 : doubleDecls, seen, ifc, true, optional, optional);
57 : 2117 : return doubleDecls;
58 : : }
59 : :
60 : 27119 : void AstInterface::addInheritedInterface(
61 : : AstType const * ifc, bool optional, rtl::OUString const & documentation)
62 : : {
63 : : m_inheritedInterfaces.push_back(
64 [ + - ]: 27119 : InheritedInterface(ifc, optional, documentation));
65 [ + + ]: 27119 : if (!optional) {
66 : 27099 : ++m_mandatoryInterfaces;
67 : : }
68 : 27119 : AstInterface const * resolved = resolveInterfaceTypedefs(ifc);
69 : 27119 : addVisibleInterface(resolved, true, optional);
70 [ + + ]: 27119 : if (optional) {
71 : 20 : addOptionalVisibleMembers(resolved);
72 : : }
73 : 27119 : }
74 : :
75 : 123346 : AstInterface::DoubleMemberDeclarations AstInterface::checkMemberClashes(
76 : : AstDeclaration const * member) const
77 : : {
78 : 123346 : DoubleMemberDeclarations doubleMembers;
79 [ + - ]: 123346 : checkMemberClashes(doubleMembers, member, true);
80 : 123346 : return doubleMembers;
81 : : }
82 : :
83 : 123844 : void AstInterface::addMember(AstDeclaration /*TODO: const*/ * member) {
84 : 123844 : addDeclaration(member);
85 : : m_visibleMembers.insert(
86 : : VisibleMembers::value_type(
87 [ + - ]: 123844 : member->getLocalName(), VisibleMember(member)));
88 : 123844 : }
89 : :
90 : 938 : void AstInterface::forwardDefined(AstInterface const & def)
91 : : {
92 : 938 : setImported(def.isImported());
93 : 938 : setInMainfile(def.isInMainfile());
94 : 938 : setLineNumber(def.getLineNumber());
95 : 938 : setFileName(def.getFileName());
96 : 938 : setDocumentation(def.getDocumentation());
97 : 938 : m_inheritedInterfaces = def.m_inheritedInterfaces;
98 : 938 : m_mandatoryInterfaces = def.m_mandatoryInterfaces;
99 : 938 : m_bIsDefined = true;
100 : 938 : }
101 : :
102 : 2976 : sal_Bool AstInterface::dump(RegistryKey& rKey)
103 : : {
104 [ + + ]: 2976 : if ( !isDefined() )
105 : 742 : return sal_True;
106 : :
107 [ + - ]: 2234 : RegistryKey localKey;
108 [ + - ][ + - ]: 2234 : if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
[ - + ]
109 : : {
110 : : fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
111 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
112 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
113 : 0 : return sal_False;
114 : : }
115 : :
116 [ + - - + ]: 4468 : if (m_mandatoryInterfaces > SAL_MAX_UINT16
[ - + ]
117 : 2234 : || m_inheritedInterfaces.size() - m_mandatoryInterfaces
118 : : > SAL_MAX_UINT16)
119 : : {
120 : : fprintf(
121 : : stderr, "%s: interface %s has too many direct base interfaces\n",
122 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
123 [ # # ]: 0 : getScopedName().getStr());
124 : 0 : return false;
125 : : }
126 : 2234 : sal_uInt16 nBaseTypes = static_cast< sal_uInt16 >(m_mandatoryInterfaces);
127 : 2234 : sal_uInt16 nAttributes = 0;
128 : 2234 : sal_uInt16 nMethods = 0;
129 : : sal_uInt16 nReferences = static_cast< sal_uInt16 >(
130 : 2234 : m_inheritedInterfaces.size() - m_mandatoryInterfaces);
131 : : typereg_Version version
132 : : = (nBaseTypes <= 1 && nReferences == 0 && !m_bPublished
133 [ + - ][ + + ]: 2234 : ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1);
[ + + ]
134 [ + + ]: 11014 : for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
135 : : ++i)
136 : : {
137 [ + + - ]: 8780 : switch ((*i)->getNodeType()) {
138 : : case NT_attribute:
139 : : {
140 [ + - ][ - + ]: 1179 : if (!increment(&nAttributes, "attributes")) {
141 : 0 : return false;
142 : : }
143 : 1179 : AstAttribute * attr = (AstAttribute *)(*i);
144 [ + + ]: 1179 : if (attr->isBound()) {
145 : 153 : version = TYPEREG_VERSION_1;
146 : : }
147 : 1179 : DeclList::size_type getCount = attr->getGetExceptionCount();
148 [ - + ]: 1179 : if (getCount > SAL_MAX_UINT16) {
149 : : fprintf(
150 : : stderr,
151 : : ("%s: raises clause of getter for attribute %s of"
152 : : " interface %s is too long\n"),
153 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
154 : 0 : (*i)->getLocalName().getStr(),
155 [ # # ]: 0 : getScopedName().getStr());
156 : 0 : return false;
157 : : }
158 [ + + ]: 1179 : if (getCount > 0) {
159 : 86 : version = TYPEREG_VERSION_1;
160 [ + - ][ - + ]: 86 : if (!increment(&nMethods, "attributes")) {
161 : 0 : return false;
162 : : }
163 : : }
164 : 1179 : DeclList::size_type setCount = attr->getSetExceptionCount();
165 [ - + ]: 1179 : if (setCount > SAL_MAX_UINT16) {
166 : : fprintf(
167 : : stderr,
168 : : ("%s: raises clause of setter for attribute %s of"
169 : : " interface %s is too long\n"),
170 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
171 : 0 : (*i)->getLocalName().getStr(),
172 [ # # ]: 0 : getScopedName().getStr());
173 : 0 : return false;
174 : : }
175 [ + + ]: 1179 : if (setCount > 0) {
176 : 107 : version = TYPEREG_VERSION_1;
177 [ + - ][ - + ]: 107 : if (!increment(&nMethods, "attributes")) {
178 : 0 : return false;
179 : : }
180 : : }
181 : 1179 : break;
182 : : }
183 : :
184 : : case NT_operation:
185 [ + - ][ - + ]: 7601 : if (!increment(&nMethods, "methods")) {
186 : 0 : return false;
187 : : }
188 : 7601 : break;
189 : :
190 : : default:
191 : : OSL_ASSERT(false);
192 : 0 : break;
193 : : }
194 : : }
195 : :
196 : 2234 : OUString emptyStr;
197 : : typereg::Writer aBlob(
198 : 2234 : version, getDocumentation(), emptyStr, RT_TYPE_INTERFACE, m_bPublished,
199 [ + - ]: 2234 : OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), nBaseTypes,
200 [ + - + - ]: 4468 : nAttributes, nMethods, nReferences);
201 : :
202 : 2234 : sal_uInt16 superTypeIndex = 0;
203 : 2234 : sal_uInt16 referenceIndex = 0;
204 [ + - ][ + + ]: 9282 : for (InheritedInterfaces::iterator i = m_inheritedInterfaces.begin();
205 : 4641 : i != m_inheritedInterfaces.end(); ++i)
206 : : {
207 [ + + ]: 2407 : if (i->isOptional()) {
208 : : aBlob.setReferenceData(
209 : : referenceIndex++, i->getDocumentation(), RT_REF_SUPPORTS,
210 : : RT_ACCESS_OPTIONAL,
211 : : OStringToOUString(
212 [ + - ]: 6 : i->getInterface()->getRelativName(),
213 [ + - ][ + - ]: 6 : RTL_TEXTENCODING_UTF8));
214 : : } else {
215 : : aBlob.setSuperTypeName(
216 : : superTypeIndex++,
217 : : OStringToOUString(
218 [ + - ]: 2401 : i->getInterface()->getRelativName(),
219 [ + - ][ + - ]: 2401 : RTL_TEXTENCODING_UTF8));
220 : : }
221 : : }
222 : :
223 : 2234 : sal_uInt16 attributeIndex = 0;
224 : 2234 : sal_uInt16 methodIndex = 0;
225 [ + + ]: 11014 : for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
226 : : ++i)
227 : : {
228 [ + + - ]: 8780 : switch ((*i)->getNodeType()) {
229 : : case NT_attribute:
230 : :
231 : 1179 : ((AstAttribute *)(*i))->dumpBlob(
232 [ + - ]: 1179 : aBlob, attributeIndex++, &methodIndex);
233 : 1179 : break;
234 : :
235 : : case NT_operation:
236 [ + - ]: 7601 : ((AstOperation *)(*i))->dumpBlob(aBlob, methodIndex++);
237 : 7601 : break;
238 : :
239 : : default:
240 : : OSL_ASSERT(false);
241 : 0 : break;
242 : : }
243 : : }
244 : :
245 : : sal_uInt32 aBlobSize;
246 [ + - ]: 2234 : void const * pBlob = aBlob.getBlob(&aBlobSize);
247 : :
248 [ + - ][ - + ]: 2234 : if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY, (RegValue)pBlob, aBlobSize))
249 : : {
250 : : fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
251 [ # # ][ # # ]: 0 : idlc()->getOptions()->getProgramName().getStr(),
252 [ # # ][ # # ]: 0 : getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
[ # # ]
253 : 0 : return sal_False;
254 : : }
255 : :
256 [ + - ]: 2976 : return true;
257 : : }
258 : :
259 : 5256 : void AstInterface::checkInheritedInterfaceClashes(
260 : : DoubleDeclarations & doubleDeclarations,
261 : : std::set< rtl::OString > & seenInterfaces, AstInterface const * ifc,
262 : : bool direct, bool optional, bool mainOptional) const
263 : : {
264 [ + + ]: 8395 : if (direct || optional
[ + - + - ]
[ + + ][ + + ]
[ + + # # ]
265 : 3139 : || seenInterfaces.insert(ifc->getScopedName()).second)
266 : : {
267 : : VisibleInterfaces::const_iterator visible(
268 [ + - ]: 4968 : m_visibleInterfaces.find(ifc->getScopedName()));
269 [ + + ]: 4968 : if (visible != m_visibleInterfaces.end()) {
270 [ - - + - : 797 : switch (visible->second) {
- ]
271 : : case INTERFACE_INDIRECT_OPTIONAL:
272 [ # # ][ # # ]: 0 : if (direct && optional) {
273 [ # # ]: 0 : doubleDeclarations.interfaces.push_back(ifc);
274 : : return;
275 : : }
276 : 0 : break;
277 : :
278 : : case INTERFACE_DIRECT_OPTIONAL:
279 [ # # ][ # # ]: 0 : if (direct || !mainOptional) {
280 [ # # ]: 0 : doubleDeclarations.interfaces.push_back(ifc);
281 : : }
282 : : return;
283 : :
284 : : case INTERFACE_INDIRECT_MANDATORY:
285 [ - + ]: 797 : if (direct) {
286 [ # # ]: 0 : doubleDeclarations.interfaces.push_back(ifc);
287 : : }
288 : : return;
289 : :
290 : : case INTERFACE_DIRECT_MANDATORY:
291 [ # # ][ # # ]: 0 : if (direct || (!optional && !mainOptional)) {
[ # # ]
292 [ # # ]: 0 : doubleDeclarations.interfaces.push_back(ifc);
293 : : }
294 : : return;
295 : : }
296 : : }
297 [ + + ][ + - ]: 4171 : if (direct || !optional) {
298 [ + + ]: 36442 : for (DeclList::const_iterator i(ifc->getIteratorBegin());
299 : 18221 : i != ifc->getIteratorEnd(); ++i)
300 : : {
301 : : checkMemberClashes(
302 [ + - ]: 14050 : doubleDeclarations.members, *i, !mainOptional);
303 : : }
304 [ + - ][ + + ]: 15705 : for (InheritedInterfaces::const_iterator i(
305 : 4171 : ifc->m_inheritedInterfaces.begin());
306 : 7310 : i != ifc->m_inheritedInterfaces.end(); ++i)
307 : : {
308 : : checkInheritedInterfaceClashes(
309 : : doubleDeclarations, seenInterfaces, i->getResolved(),
310 [ + - ][ + - ]: 3139 : false, i->isOptional(), mainOptional);
311 : : }
312 : : }
313 : : }
314 : : }
315 : :
316 : 137396 : void AstInterface::checkMemberClashes(
317 : : DoubleMemberDeclarations & doubleMembers, AstDeclaration const * member,
318 : : bool checkOptional) const
319 : : {
320 : : VisibleMembers::const_iterator i(
321 [ + - ]: 137396 : m_visibleMembers.find(member->getLocalName()));
322 [ - + ]: 137396 : if (i != m_visibleMembers.end()) {
323 [ # # ]: 0 : if (i->second.mandatory != 0) {
324 [ # # ]: 0 : if (i->second.mandatory->getScopedName() != member->getScopedName())
325 : : {
326 : : DoubleMemberDeclaration d;
327 : 0 : d.first = i->second.mandatory;
328 : 0 : d.second = member;
329 [ # # ]: 0 : doubleMembers.push_back(d);
330 : : }
331 [ # # ]: 0 : } else if (checkOptional) {
332 [ # # ]: 0 : for (VisibleMember::Optionals::const_iterator j(
333 : 0 : i->second.optionals.begin());
334 : 0 : j != i->second.optionals.end(); ++j)
335 : : {
336 [ # # ]: 0 : if (j->second->getScopedName() != member->getScopedName()) {
337 : : DoubleMemberDeclaration d;
338 : 0 : d.first = j->second;
339 : 0 : d.second = member;
340 [ # # ]: 0 : doubleMembers.push_back(d);
341 : : }
342 : : }
343 : : }
344 : : }
345 : 137396 : }
346 : :
347 : 41628 : void AstInterface::addVisibleInterface(
348 : : AstInterface const * ifc, bool direct, bool optional)
349 : : {
350 : : InterfaceKind kind = optional
351 : : ? direct ? INTERFACE_DIRECT_OPTIONAL : INTERFACE_INDIRECT_OPTIONAL
352 [ + + ][ + - ]: 41628 : : direct ? INTERFACE_DIRECT_MANDATORY : INTERFACE_INDIRECT_MANDATORY;
[ + + ]
353 : : std::pair< VisibleInterfaces::iterator, bool > result(
354 : : m_visibleInterfaces.insert(
355 [ + - ][ + - ]: 41628 : VisibleInterfaces::value_type(ifc->getScopedName(), kind)));
356 : 41628 : bool seen = !result.second
357 [ + - ][ + + ]: 41628 : && result.first->second >= INTERFACE_INDIRECT_MANDATORY;
358 [ + + ][ - + ]: 41628 : if (!result.second && kind > result.first->second) {
[ - + ]
359 : 0 : result.first->second = kind;
360 : : }
361 [ + + ][ + + ]: 41628 : if (!optional && !seen) {
362 [ + + ]: 311822 : for (DeclList::const_iterator i(ifc->getIteratorBegin());
363 : 155911 : i != ifc->getIteratorEnd(); ++i)
364 : : {
365 : : m_visibleMembers.insert(
366 : : VisibleMembers::value_type(
367 [ + - ][ + - ]: 115372 : (*i)->getLocalName(), VisibleMember(*i)));
368 : : }
369 [ + - ][ + + ]: 110096 : for (InheritedInterfaces::const_iterator i(
370 : 40539 : ifc->m_inheritedInterfaces.begin());
371 : 55048 : i != ifc->m_inheritedInterfaces.end(); ++i)
372 : : {
373 [ + - ][ + - ]: 14509 : addVisibleInterface(i->getResolved(), false, i->isOptional());
374 : : }
375 : : }
376 : 41628 : }
377 : :
378 : 40 : void AstInterface::addOptionalVisibleMembers(AstInterface const * ifc) {
379 [ + + ]: 396 : for (DeclList::const_iterator i(ifc->getIteratorBegin());
380 : 198 : i != ifc->getIteratorEnd(); ++i)
381 : : {
382 : : VisibleMembers::iterator visible(
383 [ + - ]: 158 : m_visibleMembers.find((*i)->getLocalName()));
384 [ + + ]: 158 : if (visible == m_visibleMembers.end()) {
385 : : visible = m_visibleMembers.insert(
386 : : VisibleMembers::value_type(
387 [ + - ][ + - ]: 98 : (*i)->getLocalName(), VisibleMember())).first;
388 : : }
389 [ + + ]: 158 : if (visible->second.mandatory == 0) {
390 : 98 : visible->second.optionals.insert(
391 [ + - ]: 196 : VisibleMember::Optionals::value_type(ifc->getScopedName(), *i));
392 : : }
393 : : }
394 [ + - ][ + + ]: 120 : for (InheritedInterfaces::const_iterator i(
395 : 40 : ifc->m_inheritedInterfaces.begin());
396 : 60 : i != ifc->m_inheritedInterfaces.end(); ++i)
397 : : {
398 [ + - ]: 20 : if (!i->isOptional()) {
399 [ + - ][ + - ]: 20 : addOptionalVisibleMembers(i->getResolved());
400 : : }
401 : : }
402 : 40 : }
403 : :
404 : 8973 : bool AstInterface::increment(sal_uInt16 * counter, char const * sort) const {
405 [ - + ]: 8973 : if (*counter == SAL_MAX_UINT16) {
406 : : fprintf(
407 : : stderr, "%s: interface %s has too many direct %s\n",
408 : 0 : idlc()->getOptions()->getProgramName().getStr(),
409 : 0 : getScopedName().getStr(), sort);
410 : 0 : return false;
411 : : }
412 : 8973 : ++*counter;
413 : 8973 : return true;
414 : : }
415 : :
416 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|