Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / TAO_IDL / util / utl_stack.cpp
blobdd93042e7fa95e97a2fa1f5d1dc83fc7095d8cf9
1 /*
3 COPYRIGHT
5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
49 52.227-19.
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
54 SunSoft, Inc.
55 2550 Garcia Avenue
56 Mountain View, California 94043
58 NOTE:
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 #include "utl_stack.h"
66 #include "utl_scoped_name.h"
67 #include "utl_scope.h"
68 #include "ast_decl.h"
69 #include "global_extern.h"
71 const size_t UTL_ScopeStack::increments = 64;
73 UTL_ScopeStack::UTL_ScopeStack ()
74 : pd_stack_data_nalloced (increments),
75 pd_stack_top (0)
77 ACE_NEW (this->pd_stack_data, UTL_Scope *[increments]);
80 UTL_ScopeStack::~UTL_ScopeStack ()
82 if (this->pd_stack_data != nullptr)
84 delete [] this->pd_stack_data;
88 // Push an element on the stack.
89 UTL_ScopeStack *
90 UTL_ScopeStack::push (UTL_Scope *el)
92 UTL_Scope **tmp = nullptr;
93 long ostack_data_nalloced;
94 long i;
96 // Make sure there's space for one more.
97 if (this->pd_stack_data_nalloced == this->pd_stack_top)
99 ostack_data_nalloced = this->pd_stack_data_nalloced;
100 this->pd_stack_data_nalloced += increments;
102 ACE_NEW_RETURN (tmp,
103 UTL_Scope *[this->pd_stack_data_nalloced],
104 nullptr);
106 for (i = 0; i < ostack_data_nalloced; ++i)
108 tmp[i] = this->pd_stack_data[i];
111 delete [] this->pd_stack_data;
112 this->pd_stack_data = tmp;
115 // Insert new scope.
116 this->pd_stack_data[this->pd_stack_top++] = el;
118 return this;
121 // Pop an element from the stack.
122 void
123 UTL_ScopeStack::pop ()
125 if (this->pd_stack_top <= 0)
127 return;
130 UTL_Scope *current = this->top ();
132 // If our top scope has a #pragma prefix associated with it,
133 // it goes away with the scope.
134 if (current != nullptr && current->has_prefix ())
136 char *trash = nullptr;
137 idl_global->pragma_prefixes ().pop (trash);
138 delete [] trash;
141 --this->pd_stack_top;
144 // Return top element on stack.
145 UTL_Scope *
146 UTL_ScopeStack::top ()
148 if (this->pd_stack_top <= 0)
150 return nullptr;
153 return this->pd_stack_data[pd_stack_top - 1];
156 // Return bottom element on stack.
157 UTL_Scope *
158 UTL_ScopeStack::bottom ()
160 if (this->pd_stack_top == 0)
162 return nullptr;
165 return this->pd_stack_data[0];
168 // Clear entire stack.
169 void
170 UTL_ScopeStack::clear ()
172 this->pd_stack_top = 0;
175 // How deep is the stack?
176 unsigned long
177 UTL_ScopeStack::depth ()
179 return this->pd_stack_top;
182 // Return (top - 1) element on stack.
183 UTL_Scope *
184 UTL_ScopeStack::next_to_top ()
186 UTL_Scope *tmp, *retval;
188 if (this->depth () < 2)
190 return nullptr;
193 tmp = top (); // Save top
194 (void) pop (); // Pop it
195 retval = top (); // Get next one down
196 (void) push (tmp); // Push top back
197 return retval; // Return next one down
200 // Return topmost non-NULL element.
201 UTL_Scope *
202 UTL_ScopeStack::top_non_null ()
204 for (long i = this->pd_stack_top - 1; i >= 0; --i)
206 if (this->pd_stack_data[i] != nullptr)
208 return this->pd_stack_data[i];
212 return nullptr;
215 AST_Decl *
216 UTL_ScopeStack::lookup_by_name (
217 UTL_ScopedName *name, bool full_def_only, bool for_add)
219 for (long i = pd_stack_top - 1; i >= 0; --i)
221 UTL_Scope *scope = pd_stack_data[i];
222 if (scope)
224 AST_Decl *node = scope->lookup_by_name (name, full_def_only, for_add);
225 if (node) return node;
228 return nullptr;
231 UTL_ScopeStackActiveIterator::UTL_ScopeStackActiveIterator (UTL_ScopeStack &s)
232 : source (s),
233 il (s.pd_stack_top - 1)
237 // Advance to next item
238 void
239 UTL_ScopeStackActiveIterator::next ()
241 il--;
244 // Get current item.
245 UTL_Scope *
246 UTL_ScopeStackActiveIterator::item ()
248 if (this->il >= 0)
250 return this->source.pd_stack_data[il];
253 return nullptr;
256 // Is this iteration done?
257 bool
258 UTL_ScopeStackActiveIterator::is_done () const
260 if (this->il >= 0)
262 return false;
265 return true;