LCOV - code coverage report
Current view: top level - idlc/source - aststruct.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 61 75 81.3 %
Date: 2014-04-11 Functions: 5 7 71.4 %
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/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         130 : AstStruct::AstStruct(
      29             :     const OString& name, std::vector< OString > const & typeParameters,
      30             :     AstStruct const* pBaseType, AstScope* pScope)
      31             :     : AstType(NT_struct, name, pScope)
      32             :     , AstScope(NT_struct)
      33         130 :     , m_pBaseType(pBaseType)
      34             : {
      35         615 :     for (std::vector< OString >::const_iterator i(typeParameters.begin());
      36         410 :          i != typeParameters.end(); ++i)
      37             :     {
      38             :         m_typeParameters.push_back(
      39          75 :             new AstType(NT_type_parameter, *i, 0));
      40             :     }
      41         130 : }
      42             : 
      43          40 : AstStruct::AstStruct(const NodeType type,
      44             :                         const OString& name,
      45             :                        AstStruct const* pBaseType,
      46             :                      AstScope* pScope)
      47             :     : AstType(type, name, pScope)
      48             :     , AstScope(type)
      49          40 :     , m_pBaseType(pBaseType)
      50             : {
      51          40 : }
      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          42 : AstDeclaration const * AstStruct::findTypeParameter(OString const & name)
      63             :     const
      64             : {
      65         132 :     for (DeclList::const_iterator i(m_typeParameters.begin());
      66          88 :          i != m_typeParameters.end(); ++i)
      67             :     {
      68          28 :         if ((*i)->getLocalName() == name) {
      69          26 :             return *i;
      70             :         }
      71             :     }
      72          16 :     return 0;
      73             : }
      74             : 
      75           5 : bool AstStruct::isType() const {
      76           5 :     return getNodeType() == NT_struct
      77           5 :         ? getTypeParameterCount() == 0 : AstDeclaration::isType();
      78             : }
      79             : 
      80          79 : bool AstStruct::dump(RegistryKey& rKey)
      81             : {
      82          79 :     RegistryKey localKey;
      83          79 :     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 false;
      89             :     }
      90             : 
      91          79 :     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          79 :     sal_uInt16 nMember = getNodeCount(NT_member);
     102             : 
     103          79 :     RTTypeClass typeClass = RT_TYPE_STRUCT;
     104          79 :     if ( getNodeType() == NT_exception )
     105          26 :         typeClass = RT_TYPE_EXCEPTION;
     106             : 
     107         158 :     OUString emptyStr;
     108             :     typereg::Writer aBlob(
     109          79 :         (m_typeParameters.empty() && !m_bPublished
     110             :          ? TYPEREG_VERSION_0 : TYPEREG_VERSION_1),
     111          79 :         getDocumentation(), emptyStr, typeClass, m_bPublished,
     112          79 :         OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8),
     113             :         m_pBaseType == 0 ? 0 : 1, nMember, 0,
     114         316 :         static_cast< sal_uInt16 >(m_typeParameters.size()));
     115          79 :     if (m_pBaseType != 0) {
     116             :         aBlob.setSuperTypeName(
     117             :             0,
     118             :             OStringToOUString(
     119           7 :                 m_pBaseType->getRelativName(), RTL_TEXTENCODING_UTF8));
     120             :     }
     121             : 
     122          79 :     if ( nMember > 0 )
     123             :     {
     124          56 :         DeclList::const_iterator iter = getIteratorBegin();
     125          56 :         DeclList::const_iterator end = getIteratorEnd();
     126          56 :         AstDeclaration* pDecl = NULL;
     127          56 :         AstMember*  pMember = NULL;
     128          56 :         sal_uInt16  index = 0;
     129         168 :         while ( iter != end )
     130             :         {
     131          56 :             pDecl = *iter;
     132          56 :             if ( pDecl->getNodeType() == NT_member )
     133             :             {
     134          56 :                 pMember = (AstMember*)pDecl;
     135          56 :                 RTFieldAccess flags = RT_ACCESS_READWRITE;
     136          56 :                 OString typeName;
     137          56 :                 if (pMember->getType()->getNodeType() == NT_type_parameter) {
     138          15 :                     flags |= RT_ACCESS_PARAMETERIZED_TYPE;
     139          15 :                     typeName = pMember->getType()->getLocalName();
     140             :                 } else {
     141          41 :                     typeName = pMember->getType()->getRelativName();
     142             :                 }
     143             :                 aBlob.setFieldData(
     144          56 :                     index++, pMember->getDocumentation(), emptyStr, flags,
     145             :                     OStringToOUString(
     146          56 :                         pMember->getLocalName(), RTL_TEXTENCODING_UTF8),
     147             :                     OStringToOUString(typeName, RTL_TEXTENCODING_UTF8),
     148         168 :                     RTConstValue());
     149             :             }
     150          56 :             ++iter;
     151             :         }
     152             :     }
     153             : 
     154          79 :     sal_uInt16 index = 0;
     155         312 :     for (DeclList::iterator i(m_typeParameters.begin());
     156         208 :          i != m_typeParameters.end(); ++i)
     157             :     {
     158             :         aBlob.setReferenceData(
     159             :             index++, emptyStr, RT_REF_TYPE_PARAMETER, RT_ACCESS_INVALID,
     160             :             OStringToOUString(
     161          25 :                 (*i)->getLocalName(), RTL_TEXTENCODING_UTF8));
     162             :     }
     163             : 
     164             :     sal_uInt32 aBlobSize;
     165          79 :     void const * pBlob = aBlob.getBlob(&aBlobSize);
     166             : 
     167          79 :     if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
     168          79 :                             (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 false;
     174             :     }
     175             : 
     176         158 :     return true;
     177             : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10