LCOV - code coverage report
Current view: top level - idlc/source - aststack.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 51 68.6 %
Date: 2012-08-25 Functions: 9 11 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 24 33.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 <rtl/alloc.h>
      21                 :            : #include <idlc/aststack.hxx>
      22                 :            : #include <idlc/astscope.hxx>
      23                 :            : 
      24                 :            : #define STACKSIZE_INCREMENT 64
      25                 :            : 
      26                 :        166 : AstStack::AstStack()
      27                 :        166 :     : m_stack((AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * STACKSIZE_INCREMENT))
      28                 :            :     , m_size(STACKSIZE_INCREMENT)
      29                 :        332 :     , m_top(0)
      30                 :            : {
      31                 :        166 : }
      32                 :            : 
      33                 :          0 : AstStack::~AstStack()
      34                 :            : {
      35         [ #  # ]:          0 :     for(sal_uInt32 i=0; i < m_top; i++)
      36                 :            :     {
      37         [ #  # ]:          0 :         if (m_stack[i])
      38         [ #  # ]:          0 :             delete(m_stack[i]);
      39                 :            :     }
      40                 :            : 
      41                 :          0 :     rtl_freeMemory(m_stack);
      42         [ #  # ]:          0 : }
      43                 :            : 
      44                 :     141791 : sal_uInt32 AstStack::depth()
      45                 :            : {
      46                 :     141791 :     return m_top;
      47                 :            : }
      48                 :            : 
      49                 :     648317 : AstScope* AstStack::top()
      50                 :            : {
      51         [ -  + ]:     648317 :     if (m_top < 1)
      52                 :          0 :         return NULL;
      53                 :     648317 :     return m_stack[m_top - 1];
      54                 :            : }
      55                 :            : 
      56                 :     234629 : AstScope* AstStack::bottom()
      57                 :            : {
      58         [ -  + ]:     234629 :     if (m_top == 0)
      59                 :          0 :         return NULL;
      60                 :     234629 :     return m_stack[0];
      61                 :            : }
      62                 :            : 
      63                 :      48013 : AstScope* AstStack::nextToTop()
      64                 :            : {
      65                 :            :     AstScope *tmp, *retval;
      66                 :            : 
      67         [ -  + ]:      48013 :     if (depth() < 2)
      68                 :          0 :         return NULL;
      69                 :            : 
      70                 :      48013 :     tmp = top();        // Save top
      71                 :      48013 :     (void) pop();       // Pop it
      72                 :      48013 :     retval = top();     // Get next one down
      73                 :      48013 :     (void) push(tmp);   // Push top back
      74                 :      48013 :     return retval;      // Return next one down
      75                 :            : }
      76                 :            : 
      77                 :     830036 : AstScope* AstStack::topNonNull()
      78                 :            : {
      79         [ +  - ]:     844572 :     for (sal_uInt32 i = m_top; i > 0; i--)
      80                 :            :     {
      81         [ +  + ]:     844572 :         if ( m_stack[i - 1] )
      82                 :     830036 :             return m_stack[i - 1];
      83                 :            :       }
      84                 :     830036 :     return NULL;
      85                 :            : }
      86                 :            : 
      87                 :     545498 : AstStack* AstStack::push(AstScope* pScope)
      88                 :            : {
      89                 :            :     AstScope        **tmp;
      90                 :            : //  AstDeclaration  *pDecl = ScopeAsDecl(pScope);
      91                 :            :     sal_uInt32  newSize;
      92                 :            :     sal_uInt32  i;
      93                 :            : 
      94                 :            :     // Make sure there's space for one more
      95         [ -  + ]:     545498 :     if (m_size == m_top)
      96                 :            :     {
      97                 :          0 :         newSize = m_size;
      98                 :          0 :         newSize += STACKSIZE_INCREMENT;
      99                 :          0 :         tmp = (AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * newSize);
     100                 :            : 
     101         [ #  # ]:          0 :         for(i=0; i < m_size; i++)
     102                 :          0 :             tmp[i] = m_stack[i];
     103                 :            : 
     104                 :          0 :         rtl_freeMemory(m_stack);
     105                 :          0 :         m_stack = tmp;
     106                 :            :     }
     107                 :            : 
     108                 :            :     // Insert new scope
     109                 :     545498 :     m_stack[m_top++] = pScope;
     110                 :            : 
     111                 :     545498 :     return this;
     112                 :            : }
     113                 :            : 
     114                 :     539354 : void AstStack::pop()
     115                 :            : {
     116         [ -  + ]:     539354 :     if (m_top < 1)
     117                 :     539354 :         return;
     118                 :     539354 :     --m_top;
     119                 :            : }
     120                 :            : 
     121                 :       5978 : void AstStack::clear()
     122                 :            : {
     123                 :       5978 :     m_top = 0;
     124                 :       5978 : }
     125                 :            : 
     126                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10