LCOV - code coverage report
Current view: top level - idlc/source - astenum.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 36 50 72.0 %
Date: 2014-11-03 Functions: 4 6 66.7 %
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/astenum.hxx>
      21             : 
      22             : #include <registry/version.h>
      23             : #include <registry/writer.hxx>
      24             : 
      25          82 : AstEnum::AstEnum(const OString& name, AstScope* pScope)
      26             :     : AstType(NT_enum, name, pScope)
      27             :     , AstScope(NT_enum)
      28          82 :     , m_enumValueCount(0)
      29             : {
      30          82 : }
      31             : 
      32           0 : AstEnum::~AstEnum()
      33             : {
      34           0 : }
      35             : 
      36          82 : AstConstant* AstEnum::checkValue(AstExpression* pExpr)
      37             : {
      38          82 :     DeclList::const_iterator iter = getIteratorBegin();
      39          82 :     DeclList::const_iterator end = getIteratorEnd();
      40          82 :     AstConstant*        pConst = NULL;
      41          82 :     AstDeclaration*     pDecl = NULL;
      42             : 
      43         164 :     while ( iter != end)
      44             :     {
      45           0 :         pDecl = *iter;
      46           0 :         pConst = static_cast<AstConstant*>(pDecl);
      47             : 
      48           0 :         if (pConst->getConstValue()->compare(pExpr))
      49           0 :             return pConst;
      50             : 
      51           0 :         ++iter;
      52             :     }
      53             : 
      54          82 :     if ( pExpr->getExprValue()->u.lval > m_enumValueCount )
      55           0 :         m_enumValueCount = pExpr->getExprValue()->u.lval + 1;
      56             : 
      57          82 :     return NULL;
      58             : }
      59             : 
      60          56 : bool AstEnum::dump(RegistryKey& rKey)
      61             : {
      62          56 :     RegistryKey localKey;
      63          56 :     if (rKey.createKey( OStringToOUString(getFullName(), RTL_TEXTENCODING_UTF8 ), localKey))
      64             :     {
      65             :         fprintf(stderr, "%s: warning, could not create key '%s' in '%s'\n",
      66           0 :                 idlc()->getOptions()->getProgramName().getStr(),
      67           0 :                 getFullName().getStr(), OUStringToOString(rKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
      68           0 :         return false;
      69             :     }
      70             : 
      71         112 :     OUString emptyStr;
      72          56 :     sal_uInt16 nConst = getNodeCount(NT_enum_val);
      73          56 :     if ( nConst > 0 )
      74             :     {
      75             :         typereg::Writer aBlob(
      76             :             m_bPublished ? TYPEREG_VERSION_1 : TYPEREG_VERSION_0,
      77          56 :             getDocumentation(), emptyStr, RT_TYPE_ENUM, m_bPublished,
      78          56 :             OStringToOUString(getRelativName(), RTL_TEXTENCODING_UTF8), 0,
      79         168 :             nConst, 0, 0);
      80             : 
      81          56 :         DeclList::const_iterator iter = getIteratorBegin();
      82          56 :         DeclList::const_iterator end = getIteratorEnd();
      83          56 :         AstDeclaration* pDecl = NULL;
      84          56 :         sal_uInt16 index = 0;
      85         168 :         while ( iter != end )
      86             :         {
      87          56 :             pDecl = *iter;
      88          56 :             if ( pDecl->getNodeType() == NT_enum_val )
      89          56 :                 static_cast<AstConstant*>(pDecl)->dumpBlob(aBlob, index++, false);
      90             : 
      91          56 :             ++iter;
      92             :         }
      93             : 
      94             :         sal_uInt32 aBlobSize;
      95          56 :         void const * pBlob = aBlob.getBlob(&aBlobSize);
      96             : 
      97          56 :         if (localKey.setValue(emptyStr, RG_VALUETYPE_BINARY,
      98          56 :                                 (RegValue)pBlob, aBlobSize))
      99             :         {
     100             :             fprintf(stderr, "%s: warning, could not set value of key \"%s\" in %s\n",
     101           0 :                     idlc()->getOptions()->getProgramName().getStr(),
     102           0 :                     getFullName().getStr(), OUStringToOString(localKey.getRegistryName(), RTL_TEXTENCODING_UTF8).getStr());
     103           0 :             return false;
     104          56 :         }
     105             :     }
     106             : 
     107         112 :     return true;
     108             : }
     109             : 
     110          82 : AstDeclaration* AstEnum::addDeclaration(AstDeclaration* pDecl)
     111             : {
     112          82 :     return AstScope::addDeclaration(pDecl);
     113             : }
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10