LCOV - code coverage report
Current view: top level - idlc/source - astinterface.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 201 0.0 %
Date: 2014-04-14 Functions: 0 14 0.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           0 : 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(false)
      38             :     , m_bForwardedInSameFile(false)
      39           0 :     , m_bSingleInheritance(pInherits != 0)
      40             : {
      41           0 :     if (pInherits != 0) {
      42           0 :         addInheritedInterface(pInherits, false, OUString());
      43             :     }
      44           0 : }
      45             : 
      46           0 : AstInterface::~AstInterface()
      47             : {
      48           0 : }
      49             : 
      50           0 : AstInterface::DoubleDeclarations AstInterface::checkInheritedInterfaceClashes(
      51             :     AstInterface const * ifc, bool optional) const
      52             : {
      53           0 :     DoubleDeclarations doubleDecls;
      54           0 :     std::set< OString > seen;
      55             :     checkInheritedInterfaceClashes(
      56           0 :         doubleDecls, seen, ifc, true, optional, optional);
      57           0 :     return doubleDecls;
      58             : }
      59             : 
      60           0 : void AstInterface::addInheritedInterface(
      61             :     AstType const * ifc, bool optional, OUString const & documentation)
      62             : {
      63             :     m_inheritedInterfaces.push_back(
      64           0 :         InheritedInterface(ifc, optional, documentation));
      65           0 :     if (!optional) {
      66           0 :         ++m_mandatoryInterfaces;
      67             :     }
      68           0 :     AstInterface const * resolved = resolveInterfaceTypedefs(ifc);
      69           0 :     addVisibleInterface(resolved, true, optional);
      70           0 :     if (optional) {
      71           0 :         addOptionalVisibleMembers(resolved);
      72             :     }
      73           0 : }
      74             : 
      75           0 : AstInterface::DoubleMemberDeclarations AstInterface::checkMemberClashes(
      76             :     AstDeclaration const * member) const
      77             : {
      78           0 :     DoubleMemberDeclarations doubleMembers;
      79           0 :     checkMemberClashes(doubleMembers, member, true);
      80           0 :     return doubleMembers;
      81             : }
      82             : 
      83           0 : void AstInterface::addMember(AstDeclaration /*TODO: const*/ * member) {
      84           0 :     addDeclaration(member);
      85             :     m_visibleMembers.insert(
      86             :         VisibleMembers::value_type(
      87           0 :             member->getLocalName(), VisibleMember(member)));
      88           0 : }
      89             : 
      90           0 : void AstInterface::forwardDefined(AstInterface const & def)
      91             : {
      92           0 :     setImported(def.isImported());
      93           0 :     setInMainfile(def.isInMainfile());
      94           0 :     setLineNumber(def.getLineNumber());
      95           0 :     setFileName(def.getFileName());
      96           0 :     setDocumentation(def.getDocumentation());
      97           0 :     m_inheritedInterfaces = def.m_inheritedInterfaces;
      98           0 :     m_mandatoryInterfaces = def.m_mandatoryInterfaces;
      99           0 :     m_bIsDefined = true;
     100           0 : }
     101             : 
     102           0 : bool AstInterface::dump(RegistryKey& rKey)
     103             : {
     104           0 :     if ( !isDefined() )
     105           0 :         return true;
     106             : 
     107           0 :     RegistryKey localKey;
     108           0 :     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 false;
     114             :     }
     115             : 
     116           0 :     if (m_mandatoryInterfaces > SAL_MAX_UINT16
     117           0 :         || 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           0 :     sal_uInt16 nBaseTypes = static_cast< sal_uInt16 >(m_mandatoryInterfaces);
     127           0 :     sal_uInt16 nAttributes = 0;
     128           0 :     sal_uInt16 nMethods = 0;
     129             :     sal_uInt16 nReferences = static_cast< sal_uInt16 >(
     130           0 :         m_inheritedInterfaces.size() - m_mandatoryInterfaces);
     131             :     typereg_Version version
     132           0 :         = (nBaseTypes <= 1 && nReferences == 0 && !m_bPublished
     133           0 :            ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1);
     134           0 :     for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
     135             :           ++i)
     136             :     {
     137           0 :         switch ((*i)->getNodeType()) {
     138             :         case NT_attribute:
     139             :             {
     140           0 :                 if (!increment(&nAttributes, "attributes")) {
     141           0 :                     return false;
     142             :                 }
     143           0 :                 AstAttribute * attr = (AstAttribute *)(*i);
     144           0 :                 if (attr->isBound()) {
     145           0 :                     version = TYPEREG_VERSION_1;
     146             :                 }
     147           0 :                 DeclList::size_type getCount = attr->getGetExceptionCount();
     148           0 :                 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           0 :                 if (getCount > 0) {
     159           0 :                     version = TYPEREG_VERSION_1;
     160           0 :                     if (!increment(&nMethods, "attributes")) {
     161           0 :                         return false;
     162             :                     }
     163             :                 }
     164           0 :                 DeclList::size_type setCount = attr->getSetExceptionCount();
     165           0 :                 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           0 :                 if (setCount > 0) {
     176           0 :                     version = TYPEREG_VERSION_1;
     177           0 :                     if (!increment(&nMethods, "attributes")) {
     178           0 :                         return false;
     179             :                     }
     180             :                 }
     181           0 :                 break;
     182             :             }
     183             : 
     184             :         case NT_operation:
     185           0 :             if (!increment(&nMethods, "methods")) {
     186           0 :                 return false;
     187             :             }
     188           0 :             break;
     189             : 
     190             :         default:
     191             :             OSL_ASSERT(false);
     192           0 :             break;
     193             :         }
     194             :     }
     195             : 
     196           0 :     OUString emptyStr;
     197             :     typereg::Writer aBlob(
     198           0 :         version, getDocumentation(), emptyStr, RT_TYPE_INTERFACE, m_bPublished,
     199           0 :         OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), nBaseTypes,
     200           0 :         nAttributes, nMethods, nReferences);
     201             : 
     202           0 :     sal_uInt16 superTypeIndex = 0;
     203           0 :     sal_uInt16 referenceIndex = 0;
     204           0 :     for (InheritedInterfaces::iterator i = m_inheritedInterfaces.begin();
     205           0 :           i != m_inheritedInterfaces.end(); ++i)
     206             :     {
     207           0 :         if (i->isOptional()) {
     208             :             aBlob.setReferenceData(
     209             :                 referenceIndex++, i->getDocumentation(), RT_REF_SUPPORTS,
     210             :                 RT_ACCESS_OPTIONAL,
     211             :                 OStringToOUString(
     212           0 :                     i->getInterface()->getRelativName(),
     213           0 :                     RTL_TEXTENCODING_UTF8));
     214             :         } else {
     215             :             aBlob.setSuperTypeName(
     216             :                 superTypeIndex++,
     217             :                 OStringToOUString(
     218           0 :                     i->getInterface()->getRelativName(),
     219           0 :                     RTL_TEXTENCODING_UTF8));
     220             :         }
     221             :     }
     222             : 
     223           0 :     sal_uInt16 attributeIndex = 0;
     224           0 :     sal_uInt16 methodIndex = 0;
     225           0 :     for (DeclList::const_iterator i(getIteratorBegin()); i != getIteratorEnd();
     226             :           ++i)
     227             :     {
     228           0 :         switch ((*i)->getNodeType()) {
     229             :         case NT_attribute:
     230             : 
     231           0 :             ((AstAttribute *)(*i))->dumpBlob(
     232           0 :                 aBlob, attributeIndex++, &methodIndex);
     233           0 :             break;
     234             : 
     235             :         case NT_operation:
     236           0 :             ((AstOperation *)(*i))->dumpBlob(aBlob, methodIndex++);
     237           0 :             break;
     238             : 
     239             :         default:
     240             :             OSL_ASSERT(false);
     241           0 :             break;
     242             :         }
     243             :     }
     244             : 
     245             :     sal_uInt32 aBlobSize;
     246           0 :     void const * pBlob = aBlob.getBlob(&aBlobSize);
     247             : 
     248           0 :     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 false;
     254             :     }
     255             : 
     256           0 :     return true;
     257             : }
     258             : 
     259           0 : void AstInterface::checkInheritedInterfaceClashes(
     260             :     DoubleDeclarations & doubleDeclarations,
     261             :     std::set< OString > & seenInterfaces, AstInterface const * ifc,
     262             :     bool direct, bool optional, bool mainOptional) const
     263             : {
     264           0 :     if (direct || optional
     265           0 :         || seenInterfaces.insert(ifc->getScopedName()).second)
     266             :     {
     267             :         VisibleInterfaces::const_iterator visible(
     268           0 :             m_visibleInterfaces.find(ifc->getScopedName()));
     269           0 :         if (visible != m_visibleInterfaces.end()) {
     270           0 :             switch (visible->second) {
     271             :             case INTERFACE_INDIRECT_OPTIONAL:
     272           0 :                 if (direct && optional) {
     273           0 :                     doubleDeclarations.interfaces.push_back(ifc);
     274           0 :                     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           0 :                 return;
     283             : 
     284             :             case INTERFACE_INDIRECT_MANDATORY:
     285           0 :                 if (direct) {
     286           0 :                     doubleDeclarations.interfaces.push_back(ifc);
     287             :                 }
     288           0 :                 return;
     289             : 
     290             :             case INTERFACE_DIRECT_MANDATORY:
     291           0 :                 if (direct || (!optional && !mainOptional)) {
     292           0 :                     doubleDeclarations.interfaces.push_back(ifc);
     293             :                 }
     294           0 :                 return;
     295             :             }
     296             :         }
     297           0 :         if (direct || !optional) {
     298           0 :             for (DeclList::const_iterator i(ifc->getIteratorBegin());
     299           0 :                   i != ifc->getIteratorEnd(); ++i)
     300             :             {
     301             :                 checkMemberClashes(
     302           0 :                     doubleDeclarations.members, *i, !mainOptional);
     303             :             }
     304           0 :             for (InheritedInterfaces::const_iterator i(
     305           0 :                       ifc->m_inheritedInterfaces.begin());
     306           0 :                   i != ifc->m_inheritedInterfaces.end(); ++i)
     307             :             {
     308             :                 checkInheritedInterfaceClashes(
     309             :                     doubleDeclarations, seenInterfaces, i->getResolved(),
     310           0 :                     false, i->isOptional(), mainOptional);
     311             :             }
     312             :         }
     313             :     }
     314             : }
     315             : 
     316           0 : void AstInterface::checkMemberClashes(
     317             :     DoubleMemberDeclarations & doubleMembers, AstDeclaration const * member,
     318             :     bool checkOptional) const
     319             : {
     320             :     VisibleMembers::const_iterator i(
     321           0 :         m_visibleMembers.find(member->getLocalName()));
     322           0 :     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           0 : }
     346             : 
     347           0 : 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           0 :         : direct ? INTERFACE_DIRECT_MANDATORY : INTERFACE_INDIRECT_MANDATORY;
     353             :     std::pair< VisibleInterfaces::iterator, bool > result(
     354             :         m_visibleInterfaces.insert(
     355           0 :             VisibleInterfaces::value_type(ifc->getScopedName(), kind)));
     356           0 :     bool seen = !result.second
     357           0 :         && result.first->second >= INTERFACE_INDIRECT_MANDATORY;
     358           0 :     if (!result.second && kind > result.first->second) {
     359           0 :         result.first->second = kind;
     360             :     }
     361           0 :     if (!optional && !seen) {
     362           0 :         for (DeclList::const_iterator i(ifc->getIteratorBegin());
     363           0 :               i != ifc->getIteratorEnd(); ++i)
     364             :         {
     365             :             m_visibleMembers.insert(
     366             :                 VisibleMembers::value_type(
     367           0 :                     (*i)->getLocalName(), VisibleMember(*i)));
     368             :         }
     369           0 :         for (InheritedInterfaces::const_iterator i(
     370           0 :                   ifc->m_inheritedInterfaces.begin());
     371           0 :               i != ifc->m_inheritedInterfaces.end(); ++i)
     372             :         {
     373           0 :             addVisibleInterface(i->getResolved(), false, i->isOptional());
     374             :         }
     375             :     }
     376           0 : }
     377             : 
     378           0 : void AstInterface::addOptionalVisibleMembers(AstInterface const * ifc) {
     379           0 :     for (DeclList::const_iterator i(ifc->getIteratorBegin());
     380           0 :           i != ifc->getIteratorEnd(); ++i)
     381             :     {
     382             :         VisibleMembers::iterator visible(
     383           0 :             m_visibleMembers.find((*i)->getLocalName()));
     384           0 :         if (visible == m_visibleMembers.end()) {
     385             :             visible = m_visibleMembers.insert(
     386             :                 VisibleMembers::value_type(
     387           0 :                     (*i)->getLocalName(), VisibleMember())).first;
     388             :         }
     389           0 :         if (visible->second.mandatory == 0) {
     390           0 :             visible->second.optionals.insert(
     391           0 :                 VisibleMember::Optionals::value_type(ifc->getScopedName(), *i));
     392             :         }
     393             :     }
     394           0 :     for (InheritedInterfaces::const_iterator i(
     395           0 :               ifc->m_inheritedInterfaces.begin());
     396           0 :           i != ifc->m_inheritedInterfaces.end(); ++i)
     397             :     {
     398           0 :         if (!i->isOptional()) {
     399           0 :             addOptionalVisibleMembers(i->getResolved());
     400             :         }
     401             :     }
     402           0 : }
     403             : 
     404           0 : bool AstInterface::increment(sal_uInt16 * counter, char const * sort) const {
     405           0 :     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           0 :     ++*counter;
     413           0 :     return true;
     414             : }
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10