Bump version to 4.3-4
[LibreOffice.git] / idlc / source / aststack.cxx
blob9f3ae824de4246467c5b363d2db0d3de82061670
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rtl/alloc.h>
21 #include <idlc/aststack.hxx>
22 #include <idlc/astscope.hxx>
24 #define STACKSIZE_INCREMENT 64
26 AstStack::AstStack()
27 : m_stack((AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * STACKSIZE_INCREMENT))
28 , m_size(STACKSIZE_INCREMENT)
29 , m_top(0)
33 AstStack::~AstStack()
35 for(sal_uInt32 i=0; i < m_top; i++)
37 if (m_stack[i])
38 delete(m_stack[i]);
41 rtl_freeMemory(m_stack);
44 sal_uInt32 AstStack::depth()
46 return m_top;
49 AstScope* AstStack::top()
51 if (m_top < 1)
52 return NULL;
53 return m_stack[m_top - 1];
56 AstScope* AstStack::bottom()
58 if (m_top == 0)
59 return NULL;
60 return m_stack[0];
63 AstScope* AstStack::nextToTop()
65 AstScope *tmp, *retval;
67 if (depth() < 2)
68 return NULL;
70 tmp = top(); // Save top
71 (void) pop(); // Pop it
72 retval = top(); // Get next one down
73 (void) push(tmp); // Push top back
74 return retval; // Return next one down
77 AstScope* AstStack::topNonNull()
79 for (sal_uInt32 i = m_top; i > 0; i--)
81 if ( m_stack[i - 1] )
82 return m_stack[i - 1];
84 return NULL;
87 AstStack* AstStack::push(AstScope* pScope)
89 AstScope **tmp;
90 // AstDeclaration *pDecl = ScopeAsDecl(pScope);
91 sal_uInt32 newSize;
92 sal_uInt32 i;
94 // Make sure there's space for one more
95 if (m_size == m_top)
97 newSize = m_size;
98 newSize += STACKSIZE_INCREMENT;
99 tmp = (AstScope**)rtl_allocateZeroMemory(sizeof(AstScope*) * newSize);
101 for(i=0; i < m_size; i++)
102 tmp[i] = m_stack[i];
104 rtl_freeMemory(m_stack);
105 m_stack = tmp;
108 // Insert new scope
109 m_stack[m_top++] = pScope;
111 return this;
114 void AstStack::pop()
116 if (m_top < 1)
117 return;
118 --m_top;
121 void AstStack::clear()
123 m_top = 0;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */