LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/idlc/source - astinterface.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 175 201 87.1 %
Date: 2013-07-09 Functions: 14 14 100.0 %
Legend: Lines: hit not hit

          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       37458 : AstInterface::AstInterface(const 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       37458 :     , m_bSingleInheritance(pInherits != 0)
      40             : {
      41       37458 :     if (pInherits != 0) {
      42       22435 :         addInheritedInterface(pInherits, false, OUString());
      43             :     }
      44       37458 : }
      45             : 
      46        4094 : AstInterface::~AstInterface()
      47             : {
      48        4094 : }
      49             : 
      50        2839 : AstInterface::DoubleDeclarations AstInterface::checkInheritedInterfaceClashes(
      51             :     AstInterface const * ifc, bool optional) const
      52             : {
      53        2839 :     DoubleDeclarations doubleDecls;
      54        5678 :     std::set< OString > seen;
      55             :     checkInheritedInterfaceClashes(
      56        2839 :         doubleDecls, seen, ifc, true, optional, optional);
      57        5678 :     return doubleDecls;
      58             : }
      59             : 
      60       25257 : void AstInterface::addInheritedInterface(
      61             :     AstType const * ifc, bool optional, OUString const & documentation)
      62             : {
      63             :     m_inheritedInterfaces.push_back(
      64       25257 :         InheritedInterface(ifc, optional, documentation));
      65       25257 :     if (!optional) {
      66       25196 :         ++m_mandatoryInterfaces;
      67             :     }
      68       25257 :     AstInterface const * resolved = resolveInterfaceTypedefs(ifc);
      69       25257 :     addVisibleInterface(resolved, true, optional);
      70       25257 :     if (optional) {
      71          61 :         addOptionalVisibleMembers(resolved);
      72             :     }
      73       25257 : }
      74             : 
      75      112939 : AstInterface::DoubleMemberDeclarations AstInterface::checkMemberClashes(
      76             :     AstDeclaration const * member) const
      77             : {
      78      112939 :     DoubleMemberDeclarations doubleMembers;
      79      112939 :     checkMemberClashes(doubleMembers, member, true);
      80      112939 :     return doubleMembers;
      81             : }
      82             : 
      83      114293 : void AstInterface::addMember(AstDeclaration /*TODO: const*/ * member) {
      84      114293 :     addDeclaration(member);
      85             :     m_visibleMembers.insert(
      86             :         VisibleMembers::value_type(
      87      114293 :             member->getLocalName(), VisibleMember(member)));
      88      114293 : }
      89             : 
      90         916 : void AstInterface::forwardDefined(AstInterface const & def)
      91             : {
      92         916 :     setImported(def.isImported());
      93         916 :     setInMainfile(def.isInMainfile());
      94         916 :     setLineNumber(def.getLineNumber());
      95         916 :     setFileName(def.getFileName());
      96         916 :     setDocumentation(def.getDocumentation());
      97         916 :     m_inheritedInterfaces = def.m_inheritedInterfaces;
      98         916 :     m_mandatoryInterfaces = def.m_mandatoryInterfaces;
      99         916 :     m_bIsDefined = true;
     100         916 : }
     101             : 
     102        2668 : sal_Bool AstInterface::dump(RegistryKey& rKey)
     103             : {
     104        2668 :     if ( !isDefined() )
     105         644 :         return sal_True;
     106             : 
     107        2024 :     RegistryKey localKey;
     108        2024 :     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        4048 :     if (m_mandatoryInterfaces > SAL_MAX_UINT16
     117        2024 :         || 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        2024 :     sal_uInt16 nBaseTypes = static_cast< sal_uInt16 >(m_mandatoryInterfaces);
     127        2024 :     sal_uInt16 nAttributes = 0;
     128        2024 :     sal_uInt16 nMethods = 0;
     129             :     sal_uInt16 nReferences = static_cast< sal_uInt16 >(
     130        2024 :         m_inheritedInterfaces.size() - m_mandatoryInterfaces);
     131             :     typereg_Version version
     132        1902 :         = (nBaseTypes <= 1 && nReferences == 0 && !m_bPublished
     133        3907 :            ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1);
     134        9561 :     for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
     135             :           ++i)
     136             :     {
     137        7537 :         switch ((*i)->getNodeType()) {
     138             :         case NT_attribute:
     139             :             {
     140        1215 :                 if (!increment(&nAttributes, "attributes")) {
     141           0 :                     return false;
     142             :                 }
     143        1215 :                 AstAttribute * attr = (AstAttribute *)(*i);
     144        1215 :                 if (attr->isBound()) {
     145         157 :                     version = TYPEREG_VERSION_1;
     146             :                 }
     147        1215 :                 DeclList::size_type getCount = attr->getGetExceptionCount();
     148        1215 :                 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        1215 :                 if (getCount > 0) {
     159          95 :                     version = TYPEREG_VERSION_1;
     160          95 :                     if (!increment(&nMethods, "attributes")) {
     161           0 :                         return false;
     162             :                     }
     163             :                 }
     164        1215 :                 DeclList::size_type setCount = attr->getSetExceptionCount();
     165        1215 :                 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        1215 :                 if (setCount > 0) {
     176         113 :                     version = TYPEREG_VERSION_1;
     177         113 :                     if (!increment(&nMethods, "attributes")) {
     178           0 :                         return false;
     179             :                     }
     180             :                 }
     181        1215 :                 break;
     182             :             }
     183             : 
     184             :         case NT_operation:
     185        6322 :             if (!increment(&nMethods, "methods")) {
     186           0 :                 return false;
     187             :             }
     188        6322 :             break;
     189             : 
     190             :         default:
     191             :             OSL_ASSERT(false);
     192           0 :             break;
     193             :         }
     194             :     }
     195             : 
     196        2024 :     OUString emptyStr;
     197             :     typereg::Writer aBlob(
     198        2024 :         version, getDocumentation(), emptyStr, RT_TYPE_INTERFACE, m_bPublished,
     199        4048 :         OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), nBaseTypes,
     200        8096 :         nAttributes, nMethods, nReferences);
     201             : 
     202        2024 :     sal_uInt16 superTypeIndex = 0;
     203        2024 :     sal_uInt16 referenceIndex = 0;
     204       12993 :     for (InheritedInterfaces::iterator i = m_inheritedInterfaces.begin();
     205        8662 :           i != m_inheritedInterfaces.end(); ++i)
     206             :     {
     207        2307 :         if (i->isOptional()) {
     208             :             aBlob.setReferenceData(
     209             :                 referenceIndex++, i->getDocumentation(), RT_REF_SUPPORTS,
     210             :                 RT_ACCESS_OPTIONAL,
     211             :                 OStringToOUString(
     212          34 :                     i->getInterface()->getRelativName(),
     213          34 :                     RTL_TEXTENCODING_UTF8));
     214             :         } else {
     215             :             aBlob.setSuperTypeName(
     216             :                 superTypeIndex++,
     217             :                 OStringToOUString(
     218        2273 :                     i->getInterface()->getRelativName(),
     219        2273 :                     RTL_TEXTENCODING_UTF8));
     220             :         }
     221             :     }
     222             : 
     223        2024 :     sal_uInt16 attributeIndex = 0;
     224        2024 :     sal_uInt16 methodIndex = 0;
     225        9561 :     for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
     226             :           ++i)
     227             :     {
     228        7537 :         switch ((*i)->getNodeType()) {
     229             :         case NT_attribute:
     230             : 
     231        1215 :             ((AstAttribute *)(*i))->dumpBlob(
     232        2430 :                 aBlob, attributeIndex++, &methodIndex);
     233        1215 :             break;
     234             : 
     235             :         case NT_operation:
     236        6322 :             ((AstOperation *)(*i))->dumpBlob(aBlob, methodIndex++);
     237        6322 :             break;
     238             : 
     239             :         default:
     240             :             OSL_ASSERT(false);
     241           0 :             break;
     242             :         }
     243             :     }
     244             : 
     245             :     sal_uInt32 aBlobSize;
     246        2024 :     void const * pBlob = aBlob.getBlob(&aBlobSize);
     247             : 
     248        2024 :     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        4048 :     return true;
     257             : }
     258             : 
     259        6544 : void AstInterface::checkInheritedInterfaceClashes(
     260             :     DoubleDeclarations & doubleDeclarations,
     261             :     std::set< OString > & seenInterfaces, AstInterface const * ifc,
     262             :     bool direct, bool optional, bool mainOptional) const
     263             : {
     264       19640 :     if (direct || optional
     265       20482 :         || seenInterfaces.insert(ifc->getScopedName()).second)
     266             :     {
     267             :         VisibleInterfaces::const_iterator visible(
     268        6279 :             m_visibleInterfaces.find(ifc->getScopedName()));
     269        6279 :         if (visible != m_visibleInterfaces.end()) {
     270        1197 :             switch (visible->second) {
     271             :             case INTERFACE_INDIRECT_OPTIONAL:
     272           2 :                 if (direct && optional) {
     273           1 :                     doubleDeclarations.interfaces.push_back(ifc);
     274        1197 :                     return;
     275             :                 }
     276           1 :                 break;
     277             : 
     278             :             case INTERFACE_DIRECT_OPTIONAL:
     279           6 :                 if (direct || !mainOptional) {
     280           4 :                     doubleDeclarations.interfaces.push_back(ifc);
     281             :                 }
     282           6 :                 return;
     283             : 
     284             :             case INTERFACE_INDIRECT_MANDATORY:
     285        1181 :                 if (direct) {
     286           2 :                     doubleDeclarations.interfaces.push_back(ifc);
     287             :                 }
     288        1181 :                 return;
     289             : 
     290             :             case INTERFACE_DIRECT_MANDATORY:
     291           8 :                 if (direct || (!optional && !mainOptional)) {
     292           5 :                     doubleDeclarations.interfaces.push_back(ifc);
     293             :                 }
     294           8 :                 return;
     295             :             }
     296             :         }
     297        5083 :         if (direct || !optional) {
     298       65946 :             for (DeclList::const_iterator i(ifc->getIteratorBegin());
     299       43964 :                   i != ifc->getIteratorEnd(); ++i)
     300             :             {
     301             :                 checkMemberClashes(
     302       16903 :                     doubleDeclarations.members, *i, !mainOptional);
     303             :             }
     304       26352 :             for (InheritedInterfaces::const_iterator i(
     305        5079 :                       ifc->m_inheritedInterfaces.begin());
     306       17568 :                   i != ifc->m_inheritedInterfaces.end(); ++i)
     307             :             {
     308             :                 checkInheritedInterfaceClashes(
     309             :                     doubleDeclarations, seenInterfaces, i->getResolved(),
     310        3705 :                     false, i->isOptional(), mainOptional);
     311             :             }
     312             :         }
     313             :     }
     314             : }
     315             : 
     316      129842 : void AstInterface::checkMemberClashes(
     317             :     DoubleMemberDeclarations & doubleMembers, AstDeclaration const * member,
     318             :     bool checkOptional) const
     319             : {
     320             :     VisibleMembers::const_iterator i(
     321      129842 :         m_visibleMembers.find(member->getLocalName()));
     322      129842 :     if (i != m_visibleMembers.end()) {
     323         102 :         if (i->second.mandatory != 0) {
     324           6 :             if (i->second.mandatory->getScopedName() != member->getScopedName())
     325             :             {
     326             :                 DoubleMemberDeclaration d;
     327           5 :                 d.first = i->second.mandatory;
     328           5 :                 d.second = member;
     329           5 :                 doubleMembers.push_back(d);
     330             :             }
     331          96 :         } else if (checkOptional) {
     332         480 :             for (VisibleMember::Optionals::const_iterator j(
     333          80 :                      i->second.optionals.begin());
     334         320 :                  j != i->second.optionals.end(); ++j)
     335             :             {
     336          80 :                 if (j->second->getScopedName() != member->getScopedName()) {
     337             :                     DoubleMemberDeclaration d;
     338           2 :                     d.first = j->second;
     339           2 :                     d.second = member;
     340           2 :                     doubleMembers.push_back(d);
     341             :                 }
     342             :             }
     343             :         }
     344             :     }
     345      129842 : }
     346             : 
     347       38845 : 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       38845 :         : direct ? INTERFACE_DIRECT_MANDATORY : INTERFACE_INDIRECT_MANDATORY;
     353             :     std::pair< VisibleInterfaces::iterator, bool > result(
     354             :         m_visibleInterfaces.insert(
     355       38845 :             VisibleInterfaces::value_type(ifc->getScopedName(), kind)));
     356       38845 :     bool seen = !result.second
     357       38845 :         && result.first->second >= INTERFACE_INDIRECT_MANDATORY;
     358       38845 :     if (!result.second && kind > result.first->second) {
     359           1 :         result.first->second = kind;
     360             :     }
     361       38845 :     if (!optional && !seen) {
     362      436782 :         for (DeclList::const_iterator i(ifc->getIteratorBegin());
     363      291188 :               i != ifc->getIteratorEnd(); ++i)
     364             :         {
     365             :             m_visibleMembers.insert(
     366             :                 VisibleMembers::value_type(
     367      108234 :                     (*i)->getLocalName(), VisibleMember(*i)));
     368             :         }
     369      152844 :         for (InheritedInterfaces::const_iterator i(
     370       37360 :                   ifc->m_inheritedInterfaces.begin());
     371      101896 :               i != ifc->m_inheritedInterfaces.end(); ++i)
     372             :         {
     373       13588 :             addVisibleInterface(i->getResolved(), false, i->isOptional());
     374             :         }
     375             :     }
     376       38845 : }
     377             : 
     378         130 : void AstInterface::addOptionalVisibleMembers(AstInterface const * ifc) {
     379        1305 :     for (DeclList::const_iterator i(ifc->getIteratorBegin());
     380         870 :           i != ifc->getIteratorEnd(); ++i)
     381             :     {
     382             :         VisibleMembers::iterator visible(
     383         305 :             m_visibleMembers.find((*i)->getLocalName()));
     384         305 :         if (visible == m_visibleMembers.end()) {
     385             :             visible = m_visibleMembers.insert(
     386             :                 VisibleMembers::value_type(
     387         193 :                     (*i)->getLocalName(), VisibleMember())).first;
     388             :         }
     389         305 :         if (visible->second.mandatory == 0) {
     390         212 :             visible->second.optionals.insert(
     391         424 :                 VisibleMember::Optionals::value_type(ifc->getScopedName(), *i));
     392             :         }
     393             :     }
     394         609 :     for (InheritedInterfaces::const_iterator i(
     395         130 :               ifc->m_inheritedInterfaces.begin());
     396         406 :           i != ifc->m_inheritedInterfaces.end(); ++i)
     397             :     {
     398          73 :         if (!i->isOptional()) {
     399          69 :             addOptionalVisibleMembers(i->getResolved());
     400             :         }
     401             :     }
     402         130 : }
     403             : 
     404        7745 : bool AstInterface::increment(sal_uInt16 * counter, char const * sort) const {
     405        7745 :     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        7745 :     ++*counter;
     413        7745 :     return true;
     414             : }
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10