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

Generated by: LCOV version 1.11