fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / idlc / source / aststack.cxx
blobe971152b8715a754d822dbb5d48e0316c1f96865
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(static_cast<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);
45 AstScope* AstStack::top()
47 if (m_top < 1)
48 return NULL;
49 return m_stack[m_top - 1];
52 AstScope* AstStack::bottom()
54 if (m_top == 0)
55 return NULL;
56 return m_stack[0];
59 AstScope* AstStack::nextToTop()
61 AstScope *tmp, *retval;
63 if (depth() < 2)
64 return NULL;
66 tmp = top(); // Save top
67 (void) pop(); // Pop it
68 retval = top(); // Get next one down
69 (void) push(tmp); // Push top back
70 return retval; // Return next one down
73 AstScope* AstStack::topNonNull()
75 for (sal_uInt32 i = m_top; i > 0; i--)
77 if ( m_stack[i - 1] )
78 return m_stack[i - 1];
80 return NULL;
83 AstStack* AstStack::push(AstScope* pScope)
85 AstScope **tmp;
86 // AstDeclaration *pDecl = ScopeAsDecl(pScope);
87 sal_uInt32 newSize;
88 sal_uInt32 i;
90 // Make sure there's space for one more
91 if (m_size == m_top)
93 newSize = m_size;
94 newSize += STACKSIZE_INCREMENT;
95 tmp = static_cast<AstScope**>(rtl_allocateZeroMemory(sizeof(AstScope*) * newSize));
97 for(i=0; i < m_size; i++)
98 tmp[i] = m_stack[i];
100 rtl_freeMemory(m_stack);
101 m_stack = tmp;
104 // Insert new scope
105 m_stack[m_top++] = pScope;
107 return this;
110 void AstStack::pop()
112 if (m_top < 1)
113 return;
114 --m_top;
117 void AstStack::clear()
119 m_top = 0;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */