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

Generated by: LCOV version 1.10