LCOV - code coverage report
Current view: top level - idlc/source - aststruct.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 75 81.3 %
Date: 2012-08-25 Functions: 5 7 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 54 122 44.3 %

           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/aststruct.hxx>
      21                 :            : #include <idlc/astmember.hxx>
      22                 :            : 
      23                 :            : #include "registry/version.h"
      24                 :            : #include "registry/writer.hxx"
      25                 :            : 
      26                 :            : using namespace ::rtl;
      27                 :            : 
      28                 :      13686 : AstStruct::AstStruct(
      29                 :            :     const OString& name, std::vector< rtl::OString > const & typeParameters,
      30                 :            :     AstStruct* pBaseType, AstScope* pScope)
      31                 :            :     : AstType(NT_struct, name, pScope)
      32                 :            :     , AstScope(NT_struct)
      33 [ +  - ][ +  - ]:      13686 :     , m_pBaseType(pBaseType)
      34                 :            : {
      35 [ +  - ][ +  + ]:      27508 :     for (std::vector< rtl::OString >::const_iterator i(typeParameters.begin());
      36                 :      13754 :          i != typeParameters.end(); ++i)
      37                 :            :     {
      38                 :            :         m_typeParameters.push_back(
      39 [ +  - ][ +  - ]:         68 :             new AstDeclaration(NT_type_parameter, *i, 0));
                 [ +  - ]
      40                 :            :     }
      41                 :      13686 : }
      42                 :            : 
      43                 :      13137 : AstStruct::AstStruct(const NodeType type,
      44                 :            :                         const OString& name,
      45                 :            :                        AstStruct* pBaseType,
      46                 :            :                      AstScope* pScope)
      47                 :            :     : AstType(type, name, pScope)
      48                 :            :     , AstScope(type)
      49 [ +  - ][ +  - ]:      13137 :     , m_pBaseType(pBaseType)
      50                 :            : {
      51                 :      13137 : }
      52                 :            : 
      53         [ #  # ]:          0 : AstStruct::~AstStruct()
      54                 :            : {
      55         [ #  # ]:          0 :     for (DeclList::iterator i(m_typeParameters.begin());
      56                 :          0 :          i != m_typeParameters.end(); ++i)
      57                 :            :     {
      58 [ #  # ][ #  # ]:          0 :         delete *i;
      59                 :            :     }
      60         [ #  # ]:          0 : }
      61                 :            : 
      62                 :       9916 : AstDeclaration const * AstStruct::findTypeParameter(rtl::OString const & name)
      63                 :            :     const
      64                 :            : {
      65         [ +  + ]:      19868 :     for (DeclList::const_iterator i(m_typeParameters.begin());
      66                 :       9934 :          i != m_typeParameters.end(); ++i)
      67                 :            :     {
      68         [ +  + ]:         84 :         if ((*i)->getLocalName() == name) {
      69                 :         66 :             return *i;
      70                 :            :         }
      71                 :            :     }
      72                 :       9916 :     return 0;
      73                 :            : }
      74                 :            : 
      75                 :      15942 : bool AstStruct::isType() const {
      76                 :      15942 :     return getNodeType() == NT_struct
      77         [ +  - ]:      15942 :         ? getTypeParameterCount() == 0 : AstDeclaration::isType();
      78                 :            : }
      79                 :            : 
      80                 :        802 : sal_Bool AstStruct::dump(RegistryKey& rKey)
      81                 :            : {
      82         [ +  - ]:        802 :     RegistryKey localKey;
      83 [ +  - ][ +  - ]:        802 :     if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
                 [ -  + ]
      84                 :            :     {
      85                 :            :         fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
      86 [ #  # ][ #  # ]:          0 :                 idlc()->getOptions()->getProgramName().getStr(),
      87 [ #  # ][ #  # ]:          0 :                 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
                 [ #  # ]
      88                 :          0 :         return sal_False;
      89                 :            :     }
      90                 :            : 
      91         [ -  + ]:        802 :     if (m_typeParameters.size() > SAL_MAX_UINT16) {
      92                 :            :         fprintf(
      93                 :            :             stderr,
      94                 :            :             ("%s: polymorphic struct type template %s has too many type"
      95                 :            :              " parameters\n"),
      96 [ #  # ][ #  # ]:          0 :             idlc()->getOptions()->getProgramName().getStr(),
      97         [ #  # ]:          0 :             getScopedName().getStr());
      98                 :          0 :         return false;
      99                 :            :     }
     100                 :            : 
     101         [ +  - ]:        802 :     sal_uInt16 nMember = getNodeCount(NT_member);
     102                 :            : 
     103                 :        802 :     RTTypeClass typeClass = RT_TYPE_STRUCT;
     104         [ +  + ]:        802 :     if ( getNodeType() == NT_exception )
     105                 :        269 :         typeClass = RT_TYPE_EXCEPTION;
     106                 :            : 
     107                 :        802 :     OUString emptyStr;
     108                 :            :     typereg::Writer aBlob(
     109                 :        802 :         (m_typeParameters.empty() && !m_bPublished
     110                 :            :          ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1),
     111                 :        802 :         getDocumentation(), emptyStr, typeClass, m_bPublished,
     112         [ +  - ]:        802 :         OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
     113                 :            :         m_pBaseType == 0 ? 0 : 1, nMember, 0,
     114   [ +  -  +  + ]:       2406 :         static_cast< sal_uInt16 >(m_typeParameters.size()));
         [ +  + ][ +  - ]
     115         [ +  + ]:        802 :     if (m_pBaseType != 0) {
     116                 :            :         aBlob.setSuperTypeName(
     117                 :            :             0,
     118                 :            :             OStringToOUString(
     119 [ +  - ][ +  - ]:        392 :                 m_pBaseType->getRelativName(), RTL_TEXTENCODING_UTF8));
                 [ +  - ]
     120                 :            :     }
     121                 :            : 
     122         [ +  + ]:        802 :     if ( nMember > 0 )
     123                 :            :     {
     124                 :        639 :         DeclList::const_iterator iter = getIteratorBegin();
     125                 :        639 :         DeclList::const_iterator end = getIteratorEnd();
     126                 :        639 :         AstDeclaration* pDecl = NULL;
     127                 :        639 :         AstMember*  pMember = NULL;
     128                 :        639 :         sal_uInt16  index = 0;
     129         [ +  + ]:       2785 :         while ( iter != end )
     130                 :            :         {
     131                 :       2146 :             pDecl = *iter;
     132         [ +  - ]:       2146 :             if ( pDecl->getNodeType() == NT_member )
     133                 :            :             {
     134                 :       2146 :                 pMember = (AstMember*)pDecl;
     135                 :       2146 :                 RTFieldAccess flags = RT_ACCESS_READWRITE;
     136                 :       2146 :                 rtl::OString typeName;
     137         [ +  + ]:       2146 :                 if (pMember->getType()->getNodeType() == NT_type_parameter) {
     138                 :          9 :                     flags |= RT_ACCESS_PARAMETERIZED_TYPE;
     139                 :          9 :                     typeName = pMember->getType()->getLocalName();
     140                 :            :                 } else {
     141         [ +  - ]:       2137 :                     typeName = pMember->getType()->getRelativName();
     142                 :            :                 }
     143                 :            :                 aBlob.setFieldData(
     144                 :       2146 :                     index++, pMember->getDocumentation(), emptyStr, flags,
     145                 :            :                     OStringToOUString(
     146                 :       2146 :                         pMember->getLocalName(), RTL_TEXTENCODING_UTF8),
     147                 :            :                     OStringToOUString(typeName, RTL_TEXTENCODING_UTF8),
     148   [ +  -  +  -  :       6438 :                     RTConstValue());
                   +  - ]
     149                 :            :             }
     150                 :       2146 :             ++iter;
     151                 :            :         }
     152                 :            :     }
     153                 :            : 
     154                 :        802 :     sal_uInt16 index = 0;
     155         [ +  + ]:       1626 :     for (DeclList::iterator i(m_typeParameters.begin());
     156                 :        813 :          i != m_typeParameters.end(); ++i)
     157                 :            :     {
     158                 :            :         aBlob.setReferenceData(
     159                 :            :             index++, emptyStr, RT_REF_TYPE_PARAMETER, RT_ACCESS_INVALID,
     160                 :            :             OStringToOUString(
     161 [ +  - ][ +  - ]:         11 :                 (*i)->getLocalName(), RTL_TEXTENCODING_UTF8));
     162                 :            :     }
     163                 :            : 
     164                 :            :     sal_uInt32 aBlobSize;
     165         [ +  - ]:        802 :     void const * pBlob = aBlob.getBlob(&aBlobSize);
     166                 :            : 
     167         [ -  + ]:        802 :     if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
     168         [ +  - ]:        802 :                             (RegValue)pBlob, aBlobSize))
     169                 :            :     {
     170                 :            :         fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
     171 [ #  # ][ #  # ]:          0 :                 idlc()->getOptions()->getProgramName().getStr(),
     172 [ #  # ][ #  # ]:          0 :                 getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
                 [ #  # ]
     173                 :          0 :         return sal_False;
     174                 :            :     }
     175                 :            : 
     176         [ +  - ]:        802 :     return sal_True;
     177                 :            : }
     178                 :            : 
     179                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10