xref: /aoo41x/main/idlc/source/astinterface.cxx (revision 2fe1ca3d)
1*2fe1ca3dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2fe1ca3dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2fe1ca3dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2fe1ca3dSAndrew Rist  * distributed with this work for additional information
6*2fe1ca3dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2fe1ca3dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2fe1ca3dSAndrew Rist  * "License"); you may not use this file except in compliance
9*2fe1ca3dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2fe1ca3dSAndrew Rist  *
11*2fe1ca3dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2fe1ca3dSAndrew Rist  *
13*2fe1ca3dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2fe1ca3dSAndrew Rist  * software distributed under the License is distributed on an
15*2fe1ca3dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2fe1ca3dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2fe1ca3dSAndrew Rist  * specific language governing permissions and limitations
18*2fe1ca3dSAndrew Rist  * under the License.
19*2fe1ca3dSAndrew Rist  *
20*2fe1ca3dSAndrew Rist  *************************************************************/
21*2fe1ca3dSAndrew Rist 
22*2fe1ca3dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_idlc.hxx"
26cdf0e10cSrcweir #include <idlc/astinterface.hxx>
27cdf0e10cSrcweir #include <idlc/astattribute.hxx>
28cdf0e10cSrcweir #include <idlc/astoperation.hxx>
29cdf0e10cSrcweir #include "idlc/idlc.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "registry/version.h"
32cdf0e10cSrcweir #include "registry/writer.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::rtl;
35cdf0e10cSrcweir 
AstInterface(const::rtl::OString & name,AstInterface const * pInherits,AstScope * pScope)36cdf0e10cSrcweir AstInterface::AstInterface(const ::rtl::OString& name,
37cdf0e10cSrcweir 						   AstInterface const * pInherits,
38cdf0e10cSrcweir 						   AstScope* pScope)
39cdf0e10cSrcweir 	: AstType(NT_interface, name, pScope)
40cdf0e10cSrcweir 	, AstScope(NT_interface)
41cdf0e10cSrcweir     , m_mandatoryInterfaces(0)
42cdf0e10cSrcweir     , m_bIsDefined(false)
43cdf0e10cSrcweir 	, m_bForwarded(sal_False)
44cdf0e10cSrcweir 	, m_bForwardedInSameFile(sal_False)
45cdf0e10cSrcweir     , m_bSingleInheritance(pInherits != 0)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     if (pInherits != 0) {
48cdf0e10cSrcweir         addInheritedInterface(pInherits, false, rtl::OUString());
49cdf0e10cSrcweir     }
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
~AstInterface()52cdf0e10cSrcweir AstInterface::~AstInterface()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
checkInheritedInterfaceClashes(AstInterface const * ifc,bool optional) const56cdf0e10cSrcweir AstInterface::DoubleDeclarations AstInterface::checkInheritedInterfaceClashes(
57cdf0e10cSrcweir     AstInterface const * ifc, bool optional) const
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     DoubleDeclarations doubleDecls;
60cdf0e10cSrcweir     std::set< rtl::OString > seen;
61cdf0e10cSrcweir     checkInheritedInterfaceClashes(
62cdf0e10cSrcweir         doubleDecls, seen, ifc, true, optional, optional);
63cdf0e10cSrcweir     return doubleDecls;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
addInheritedInterface(AstType const * ifc,bool optional,rtl::OUString const & documentation)66cdf0e10cSrcweir void AstInterface::addInheritedInterface(
67cdf0e10cSrcweir     AstType const * ifc, bool optional, rtl::OUString const & documentation)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     m_inheritedInterfaces.push_back(
70cdf0e10cSrcweir         InheritedInterface(ifc, optional, documentation));
71cdf0e10cSrcweir     if (!optional) {
72cdf0e10cSrcweir         ++m_mandatoryInterfaces;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir     AstInterface const * resolved = resolveInterfaceTypedefs(ifc);
75cdf0e10cSrcweir     addVisibleInterface(resolved, true, optional);
76cdf0e10cSrcweir     if (optional) {
77cdf0e10cSrcweir         addOptionalVisibleMembers(resolved);
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
checkMemberClashes(AstDeclaration const * member) const81cdf0e10cSrcweir AstInterface::DoubleMemberDeclarations AstInterface::checkMemberClashes(
82cdf0e10cSrcweir     AstDeclaration const * member) const
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     DoubleMemberDeclarations doubleMembers;
85cdf0e10cSrcweir     checkMemberClashes(doubleMembers, member, true);
86cdf0e10cSrcweir     return doubleMembers;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
addMember(AstDeclaration * member)89cdf0e10cSrcweir void AstInterface::addMember(AstDeclaration /*TODO: const*/ * member) {
90cdf0e10cSrcweir     addDeclaration(member);
91cdf0e10cSrcweir     m_visibleMembers.insert(
92cdf0e10cSrcweir         VisibleMembers::value_type(
93cdf0e10cSrcweir             member->getLocalName(), VisibleMember(member)));
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
forwardDefined(AstInterface const & def)96cdf0e10cSrcweir void AstInterface::forwardDefined(AstInterface const & def)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     setImported(def.isImported());
99cdf0e10cSrcweir     setInMainfile(def.isInMainfile());
100cdf0e10cSrcweir     setLineNumber(def.getLineNumber());
101cdf0e10cSrcweir     setFileName(def.getFileName());
102cdf0e10cSrcweir     setDocumentation(def.getDocumentation());
103cdf0e10cSrcweir     m_inheritedInterfaces = def.m_inheritedInterfaces;
104cdf0e10cSrcweir     m_mandatoryInterfaces = def.m_mandatoryInterfaces;
105cdf0e10cSrcweir     m_bIsDefined = true;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
dump(RegistryKey & rKey)108cdf0e10cSrcweir sal_Bool AstInterface::dump(RegistryKey& rKey)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	if ( !isDefined() )
111cdf0e10cSrcweir 		return sal_True;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	RegistryKey localKey;
114cdf0e10cSrcweir 	if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		fprintf(stderr, "%s: warning, could	not create key '%s' in '%s'\n",
117cdf0e10cSrcweir 			    idlc()->getOptions()->getProgramName().getStr(),
118cdf0e10cSrcweir 			    getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
119cdf0e10cSrcweir 		return sal_False;
120cdf0e10cSrcweir 	}
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     if (m_mandatoryInterfaces > SAL_MAX_UINT16
123cdf0e10cSrcweir         || m_inheritedInterfaces.size() - m_mandatoryInterfaces
124cdf0e10cSrcweir             > SAL_MAX_UINT16)
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         fprintf(
127cdf0e10cSrcweir             stderr, "%s: interface %s has too many direct base interfaces\n",
128cdf0e10cSrcweir             idlc()->getOptions()->getProgramName().getStr(),
129cdf0e10cSrcweir             getScopedName().getStr());
130cdf0e10cSrcweir         return false;
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir     sal_uInt16 nBaseTypes = static_cast< sal_uInt16 >(m_mandatoryInterfaces);
133cdf0e10cSrcweir 	sal_uInt16 nAttributes = 0;
134cdf0e10cSrcweir 	sal_uInt16 nMethods = 0;
135cdf0e10cSrcweir     sal_uInt16 nReferences = static_cast< sal_uInt16 >(
136cdf0e10cSrcweir         m_inheritedInterfaces.size() - m_mandatoryInterfaces);
137cdf0e10cSrcweir     typereg_Version version
138cdf0e10cSrcweir         = (nBaseTypes <= 1 && nReferences == 0 && !m_bPublished
139cdf0e10cSrcweir            ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1);
140cdf0e10cSrcweir     {for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
141cdf0e10cSrcweir           ++i)
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         switch ((*i)->getNodeType()) {
144cdf0e10cSrcweir         case NT_attribute:
145cdf0e10cSrcweir             {
146cdf0e10cSrcweir                 if (!increment(&nAttributes, "attributes")) {
147cdf0e10cSrcweir                     return false;
148cdf0e10cSrcweir                 }
149cdf0e10cSrcweir //                AstAttribute * attr = static_cast< AstAttribute * >(*i);
150cdf0e10cSrcweir                 AstAttribute * attr = (AstAttribute *)(*i);
151cdf0e10cSrcweir                 if (attr->isBound()) {
152cdf0e10cSrcweir                     version = TYPEREG_VERSION_1;
153cdf0e10cSrcweir                 }
154cdf0e10cSrcweir                 DeclList::size_type getCount = attr->getGetExceptionCount();
155cdf0e10cSrcweir                 if (getCount > SAL_MAX_UINT16) {
156cdf0e10cSrcweir                     fprintf(
157cdf0e10cSrcweir                         stderr,
158cdf0e10cSrcweir                         ("%s: raises clause of getter for attribute %s of"
159cdf0e10cSrcweir                          " interface %s is too long\n"),
160cdf0e10cSrcweir                         idlc()->getOptions()->getProgramName().getStr(),
161cdf0e10cSrcweir                         (*i)->getLocalName().getStr(),
162cdf0e10cSrcweir                         getScopedName().getStr());
163cdf0e10cSrcweir                     return false;
164cdf0e10cSrcweir                 }
165cdf0e10cSrcweir                 if (getCount > 0) {
166cdf0e10cSrcweir                     version = TYPEREG_VERSION_1;
167cdf0e10cSrcweir                     if (!increment(&nMethods, "attributes")) {
168cdf0e10cSrcweir                         return false;
169cdf0e10cSrcweir                     }
170cdf0e10cSrcweir                 }
171cdf0e10cSrcweir                 DeclList::size_type setCount = attr->getSetExceptionCount();
172cdf0e10cSrcweir                 if (setCount > SAL_MAX_UINT16) {
173cdf0e10cSrcweir                     fprintf(
174cdf0e10cSrcweir                         stderr,
175cdf0e10cSrcweir                         ("%s: raises clause of setter for attribute %s of"
176cdf0e10cSrcweir                          " interface %s is too long\n"),
177cdf0e10cSrcweir                         idlc()->getOptions()->getProgramName().getStr(),
178cdf0e10cSrcweir                         (*i)->getLocalName().getStr(),
179cdf0e10cSrcweir                         getScopedName().getStr());
180cdf0e10cSrcweir                     return false;
181cdf0e10cSrcweir                 }
182cdf0e10cSrcweir                 if (setCount > 0) {
183cdf0e10cSrcweir                     version = TYPEREG_VERSION_1;
184cdf0e10cSrcweir                     if (!increment(&nMethods, "attributes")) {
185cdf0e10cSrcweir                         return false;
186cdf0e10cSrcweir                     }
187cdf0e10cSrcweir                 }
188cdf0e10cSrcweir                 break;
189cdf0e10cSrcweir             }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         case NT_operation:
192cdf0e10cSrcweir             if (!increment(&nMethods, "methods")) {
193cdf0e10cSrcweir                 return false;
194cdf0e10cSrcweir             }
195cdf0e10cSrcweir             break;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         default:
198cdf0e10cSrcweir             OSL_ASSERT(false);
199cdf0e10cSrcweir             break;
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir     }}
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     OUString emptyStr;
204cdf0e10cSrcweir 	typereg::Writer aBlob(
205cdf0e10cSrcweir         version, getDocumentation(), emptyStr, RT_TYPE_INTERFACE, m_bPublished,
206cdf0e10cSrcweir         OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), nBaseTypes,
207cdf0e10cSrcweir         nAttributes, nMethods, nReferences);
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     sal_uInt16 superTypeIndex = 0;
210cdf0e10cSrcweir     sal_uInt16 referenceIndex = 0;
211cdf0e10cSrcweir     {for (InheritedInterfaces::iterator i = m_inheritedInterfaces.begin();
212cdf0e10cSrcweir           i != m_inheritedInterfaces.end(); ++i)
213cdf0e10cSrcweir     {
214cdf0e10cSrcweir         if (i->isOptional()) {
215cdf0e10cSrcweir             aBlob.setReferenceData(
216cdf0e10cSrcweir                 referenceIndex++, i->getDocumentation(), RT_REF_SUPPORTS,
217cdf0e10cSrcweir                 RT_ACCESS_OPTIONAL,
218cdf0e10cSrcweir                 OStringToOUString(
219cdf0e10cSrcweir                     i->getInterface()->getRelativName(),
220cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8));
221cdf0e10cSrcweir         } else {
222cdf0e10cSrcweir             aBlob.setSuperTypeName(
223cdf0e10cSrcweir                 superTypeIndex++,
224cdf0e10cSrcweir                 OStringToOUString(
225cdf0e10cSrcweir                     i->getInterface()->getRelativName(),
226cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8));
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir     }}
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     sal_uInt16 attributeIndex = 0;
231cdf0e10cSrcweir     sal_uInt16 methodIndex = 0;
232cdf0e10cSrcweir     {for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
233cdf0e10cSrcweir           ++i)
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         switch ((*i)->getNodeType()) {
236cdf0e10cSrcweir         case NT_attribute:
237cdf0e10cSrcweir //           static_cast< AstAttribute * >(*i)->dumpBlob(
238cdf0e10cSrcweir 
239cdf0e10cSrcweir             ((AstAttribute *)(*i))->dumpBlob(
240cdf0e10cSrcweir                 aBlob, attributeIndex++, &methodIndex);
241cdf0e10cSrcweir             break;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         case NT_operation:
244cdf0e10cSrcweir //            static_cast< AstOperation * >(*i)->dumpBlob(aBlob, methodIndex++);
245cdf0e10cSrcweir             ((AstOperation *)(*i))->dumpBlob(aBlob, methodIndex++);
246cdf0e10cSrcweir             break;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         default:
249cdf0e10cSrcweir             OSL_ASSERT(false);
250cdf0e10cSrcweir             break;
251cdf0e10cSrcweir         }
252cdf0e10cSrcweir     }}
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     sal_uInt32 aBlobSize;
255cdf0e10cSrcweir     void const * pBlob = aBlob.getBlob(&aBlobSize);
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY, (RegValue)pBlob, aBlobSize))
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir 		fprintf(stderr, "%s: warning, could	not set value of key \"%s\" in %s\n",
260cdf0e10cSrcweir 			    idlc()->getOptions()->getProgramName().getStr(),
261cdf0e10cSrcweir 				getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
262cdf0e10cSrcweir 		return sal_False;
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	return true;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
checkInheritedInterfaceClashes(DoubleDeclarations & doubleDeclarations,std::set<rtl::OString> & seenInterfaces,AstInterface const * ifc,bool direct,bool optional,bool mainOptional) const268cdf0e10cSrcweir void AstInterface::checkInheritedInterfaceClashes(
269cdf0e10cSrcweir     DoubleDeclarations & doubleDeclarations,
270cdf0e10cSrcweir     std::set< rtl::OString > & seenInterfaces, AstInterface const * ifc,
271cdf0e10cSrcweir     bool direct, bool optional, bool mainOptional) const
272cdf0e10cSrcweir {
273cdf0e10cSrcweir     if (direct || optional
274cdf0e10cSrcweir         || seenInterfaces.insert(ifc->getScopedName()).second)
275cdf0e10cSrcweir     {
276cdf0e10cSrcweir         VisibleInterfaces::const_iterator visible(
277cdf0e10cSrcweir             m_visibleInterfaces.find(ifc->getScopedName()));
278cdf0e10cSrcweir         if (visible != m_visibleInterfaces.end()) {
279cdf0e10cSrcweir             switch (visible->second) {
280cdf0e10cSrcweir             case INTERFACE_INDIRECT_OPTIONAL:
281cdf0e10cSrcweir                 if (direct && optional) {
282cdf0e10cSrcweir                     doubleDeclarations.interfaces.push_back(ifc);
283cdf0e10cSrcweir                     return;
284cdf0e10cSrcweir                 }
285cdf0e10cSrcweir                 break;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir             case INTERFACE_DIRECT_OPTIONAL:
288cdf0e10cSrcweir                 if (direct || !mainOptional) {
289cdf0e10cSrcweir                     doubleDeclarations.interfaces.push_back(ifc);
290cdf0e10cSrcweir                 }
291cdf0e10cSrcweir                 return;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir             case INTERFACE_INDIRECT_MANDATORY:
294cdf0e10cSrcweir                 if (direct) {
295cdf0e10cSrcweir                     doubleDeclarations.interfaces.push_back(ifc);
296cdf0e10cSrcweir                 }
297cdf0e10cSrcweir                 return;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir             case INTERFACE_DIRECT_MANDATORY:
300cdf0e10cSrcweir                 if (direct || (!optional && !mainOptional)) {
301cdf0e10cSrcweir                     doubleDeclarations.interfaces.push_back(ifc);
302cdf0e10cSrcweir                 }
303cdf0e10cSrcweir                 return;
304cdf0e10cSrcweir             }
305cdf0e10cSrcweir         }
306cdf0e10cSrcweir         if (direct || !optional) {
307cdf0e10cSrcweir             {for (DeclList::const_iterator i(ifc->getIteratorBegin());
308cdf0e10cSrcweir                   i != ifc->getIteratorEnd(); ++i)
309cdf0e10cSrcweir             {
310cdf0e10cSrcweir                 checkMemberClashes(
311cdf0e10cSrcweir                     doubleDeclarations.members, *i, !mainOptional);
312cdf0e10cSrcweir             }}
313cdf0e10cSrcweir             {for (InheritedInterfaces::const_iterator i(
314cdf0e10cSrcweir                       ifc->m_inheritedInterfaces.begin());
315cdf0e10cSrcweir                   i != ifc->m_inheritedInterfaces.end(); ++i)
316cdf0e10cSrcweir             {
317cdf0e10cSrcweir                 checkInheritedInterfaceClashes(
318cdf0e10cSrcweir                     doubleDeclarations, seenInterfaces, i->getResolved(),
319cdf0e10cSrcweir                     false, i->isOptional(), mainOptional);
320cdf0e10cSrcweir             }}
321cdf0e10cSrcweir         }
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
checkMemberClashes(DoubleMemberDeclarations & doubleMembers,AstDeclaration const * member,bool checkOptional) const325cdf0e10cSrcweir void AstInterface::checkMemberClashes(
326cdf0e10cSrcweir     DoubleMemberDeclarations & doubleMembers, AstDeclaration const * member,
327cdf0e10cSrcweir     bool checkOptional) const
328cdf0e10cSrcweir {
329cdf0e10cSrcweir     VisibleMembers::const_iterator i(
330cdf0e10cSrcweir         m_visibleMembers.find(member->getLocalName()));
331cdf0e10cSrcweir     if (i != m_visibleMembers.end()) {
332cdf0e10cSrcweir         if (i->second.mandatory != 0) {
333cdf0e10cSrcweir             if (i->second.mandatory->getScopedName() != member->getScopedName())
334cdf0e10cSrcweir             {
335cdf0e10cSrcweir                 DoubleMemberDeclaration d;
336cdf0e10cSrcweir                 d.first = i->second.mandatory;
337cdf0e10cSrcweir                 d.second = member;
338cdf0e10cSrcweir                 doubleMembers.push_back(d);
339cdf0e10cSrcweir             }
340cdf0e10cSrcweir         } else if (checkOptional) {
341cdf0e10cSrcweir             for (VisibleMember::Optionals::const_iterator j(
342cdf0e10cSrcweir                      i->second.optionals.begin());
343cdf0e10cSrcweir                  j != i->second.optionals.end(); ++j)
344cdf0e10cSrcweir             {
345cdf0e10cSrcweir                 if (j->second->getScopedName() != member->getScopedName()) {
346cdf0e10cSrcweir                     DoubleMemberDeclaration d;
347cdf0e10cSrcweir                     d.first = j->second;
348cdf0e10cSrcweir                     d.second = member;
349cdf0e10cSrcweir                     doubleMembers.push_back(d);
350cdf0e10cSrcweir                 }
351cdf0e10cSrcweir             }
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
addVisibleInterface(AstInterface const * ifc,bool direct,bool optional)356cdf0e10cSrcweir void AstInterface::addVisibleInterface(
357cdf0e10cSrcweir     AstInterface const * ifc, bool direct, bool optional)
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     InterfaceKind kind = optional
360cdf0e10cSrcweir         ? direct ? INTERFACE_DIRECT_OPTIONAL : INTERFACE_INDIRECT_OPTIONAL
361cdf0e10cSrcweir         : direct ? INTERFACE_DIRECT_MANDATORY : INTERFACE_INDIRECT_MANDATORY;
362cdf0e10cSrcweir     std::pair< VisibleInterfaces::iterator, bool > result(
363cdf0e10cSrcweir         m_visibleInterfaces.insert(
364cdf0e10cSrcweir             VisibleInterfaces::value_type(ifc->getScopedName(), kind)));
365cdf0e10cSrcweir     bool seen = !result.second
366cdf0e10cSrcweir         && result.first->second >= INTERFACE_INDIRECT_MANDATORY;
367cdf0e10cSrcweir     if (!result.second && kind > result.first->second) {
368cdf0e10cSrcweir         result.first->second = kind;
369cdf0e10cSrcweir     }
370cdf0e10cSrcweir     if (!optional && !seen) {
371cdf0e10cSrcweir         {for (DeclList::const_iterator i(ifc->getIteratorBegin());
372cdf0e10cSrcweir               i != ifc->getIteratorEnd(); ++i)
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir             m_visibleMembers.insert(
375cdf0e10cSrcweir                 VisibleMembers::value_type(
376cdf0e10cSrcweir                     (*i)->getLocalName(), VisibleMember(*i)));
377cdf0e10cSrcweir         }}
378cdf0e10cSrcweir         {for (InheritedInterfaces::const_iterator i(
379cdf0e10cSrcweir                   ifc->m_inheritedInterfaces.begin());
380cdf0e10cSrcweir               i != ifc->m_inheritedInterfaces.end(); ++i)
381cdf0e10cSrcweir         {
382cdf0e10cSrcweir             addVisibleInterface(i->getResolved(), false, i->isOptional());
383cdf0e10cSrcweir         }}
384cdf0e10cSrcweir     }
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
addOptionalVisibleMembers(AstInterface const * ifc)387cdf0e10cSrcweir void AstInterface::addOptionalVisibleMembers(AstInterface const * ifc) {
388cdf0e10cSrcweir     {for (DeclList::const_iterator i(ifc->getIteratorBegin());
389cdf0e10cSrcweir           i != ifc->getIteratorEnd(); ++i)
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         VisibleMembers::iterator visible(
392cdf0e10cSrcweir             m_visibleMembers.find((*i)->getLocalName()));
393cdf0e10cSrcweir         if (visible == m_visibleMembers.end()) {
394cdf0e10cSrcweir             visible = m_visibleMembers.insert(
395cdf0e10cSrcweir                 VisibleMembers::value_type(
396cdf0e10cSrcweir                     (*i)->getLocalName(), VisibleMember())).first;
397cdf0e10cSrcweir         }
398cdf0e10cSrcweir         if (visible->second.mandatory == 0) {
399cdf0e10cSrcweir             visible->second.optionals.insert(
400cdf0e10cSrcweir                 VisibleMember::Optionals::value_type(ifc->getScopedName(), *i));
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir     }}
403cdf0e10cSrcweir     {for (InheritedInterfaces::const_iterator i(
404cdf0e10cSrcweir               ifc->m_inheritedInterfaces.begin());
405cdf0e10cSrcweir           i != ifc->m_inheritedInterfaces.end(); ++i)
406cdf0e10cSrcweir     {
407cdf0e10cSrcweir         if (!i->isOptional()) {
408cdf0e10cSrcweir             addOptionalVisibleMembers(i->getResolved());
409cdf0e10cSrcweir         }
410cdf0e10cSrcweir     }}
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
increment(sal_uInt16 * counter,char const * sort) const413cdf0e10cSrcweir bool AstInterface::increment(sal_uInt16 * counter, char const * sort) const {
414cdf0e10cSrcweir     if (*counter == SAL_MAX_UINT16) {
415cdf0e10cSrcweir         fprintf(
416cdf0e10cSrcweir             stderr, "%s: interface %s has too many direct %s\n",
417cdf0e10cSrcweir             idlc()->getOptions()->getProgramName().getStr(),
418cdf0e10cSrcweir             getScopedName().getStr(), sort);
419cdf0e10cSrcweir         return false;
420cdf0e10cSrcweir     }
421cdf0e10cSrcweir     ++*counter;
422cdf0e10cSrcweir     return true;
423cdf0e10cSrcweir }
424