1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_idlc.hxx" 30 #include <rtl/alloc.h> 31 #include <idlc/aststack.hxx> 32 #include <idlc/astscope.hxx> 33 34 #define STACKSIZE_INCREMENT 64 35 36 AstStack::AstStack() 37 : m_stack((AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * STACKSIZE_INCREMENT)) 38 , m_size(STACKSIZE_INCREMENT) 39 , m_top(0) 40 { 41 } 42 43 AstStack::~AstStack() 44 { 45 for(sal_uInt32 i=0; i < m_top; i++) 46 { 47 if (m_stack[i]) 48 delete(m_stack[i]); 49 } 50 51 rtl_freeMemory(m_stack); 52 } 53 54 sal_uInt32 AstStack::depth() 55 { 56 return m_top; 57 } 58 59 AstScope* AstStack::top() 60 { 61 if (m_top < 1) 62 return NULL; 63 return m_stack[m_top - 1]; 64 } 65 66 AstScope* AstStack::bottom() 67 { 68 if (m_top == 0) 69 return NULL; 70 return m_stack[0]; 71 } 72 73 AstScope* AstStack::nextToTop() 74 { 75 AstScope *tmp, *retval; 76 77 if (depth() < 2) 78 return NULL; 79 80 tmp = top(); // Save top 81 (void) pop(); // Pop it 82 retval = top(); // Get next one down 83 (void) push(tmp); // Push top back 84 return retval; // Return next one down 85 } 86 87 AstScope* AstStack::topNonNull() 88 { 89 for (sal_uInt32 i = m_top; i > 0; i--) 90 { 91 if ( m_stack[i - 1] ) 92 return m_stack[i - 1]; 93 } 94 return NULL; 95 } 96 97 AstStack* AstStack::push(AstScope* pScope) 98 { 99 AstScope **tmp; 100 // AstDeclaration *pDecl = ScopeAsDecl(pScope); 101 sal_uInt32 newSize; 102 sal_uInt32 i; 103 104 // Make sure there's space for one more 105 if (m_size == m_top) 106 { 107 newSize = m_size; 108 newSize += STACKSIZE_INCREMENT; 109 tmp = (AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * newSize); 110 111 for(i=0; i < m_size; i++) 112 tmp[i] = m_stack[i]; 113 114 rtl_freeMemory(m_stack); 115 m_stack = tmp; 116 } 117 118 // Insert new scope 119 m_stack[m_top++] = pScope; 120 121 return this; 122 } 123 124 void AstStack::pop() 125 { 126 AstScope *pScope; 127 128 if (m_top < 1) 129 return; 130 pScope = m_stack[--m_top]; 131 } 132 133 void AstStack::clear() 134 { 135 m_top = 0; 136 } 137 138