LCOV - code coverage report
Current view: top level - idlc/source - aststack.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 51 0.0 %
Date: 2014-04-14 Functions: 0 11 0.0 %
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 <rtl/alloc.h>
      21             : #include <idlc/aststack.hxx>
      22             : #include <idlc/astscope.hxx>
      23             : 
      24             : #define STACKSIZE_INCREMENT 64
      25             : 
      26           0 : AstStack::AstStack()
      27           0 :     : m_stack((AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * STACKSIZE_INCREMENT))
      28             :     , m_size(STACKSIZE_INCREMENT)
      29           0 :     , m_top(0)
      30             : {
      31           0 : }
      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           0 : sal_uInt32 AstStack::depth()
      45             : {
      46           0 :     return m_top;
      47             : }
      48             : 
      49           0 : AstScope* AstStack::top()
      50             : {
      51           0 :     if (m_top < 1)
      52           0 :         return NULL;
      53           0 :     return m_stack[m_top - 1];
      54             : }
      55             : 
      56           0 : AstScope* AstStack::bottom()
      57             : {
      58           0 :     if (m_top == 0)
      59           0 :         return NULL;
      60           0 :     return m_stack[0];
      61             : }
      62             : 
      63           0 : AstScope* AstStack::nextToTop()
      64             : {
      65             :     AstScope *tmp, *retval;
      66             : 
      67           0 :     if (depth() < 2)
      68           0 :         return NULL;
      69             : 
      70           0 :     tmp = top();        // Save top
      71           0 :     (void) pop();       // Pop it
      72           0 :     retval = top();     // Get next one down
      73           0 :     (void) push(tmp);   // Push top back
      74           0 :     return retval;      // Return next one down
      75             : }
      76             : 
      77           0 : AstScope* AstStack::topNonNull()
      78             : {
      79           0 :     for (sal_uInt32 i = m_top; i > 0; i--)
      80             :     {
      81           0 :         if ( m_stack[i - 1] )
      82           0 :             return m_stack[i - 1];
      83             :       }
      84           0 :     return NULL;
      85             : }
      86             : 
      87           0 : 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           0 :     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           0 :     m_stack[m_top++] = pScope;
     110             : 
     111           0 :     return this;
     112             : }
     113             : 
     114           0 : void AstStack::pop()
     115             : {
     116           0 :     if (m_top < 1)
     117           0 :         return;
     118           0 :     --m_top;
     119             : }
     120             : 
     121           0 : void AstStack::clear()
     122             : {
     123           0 :     m_top = 0;
     124           0 : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10