Update ooo320-m1
[ooovba.git] / autodoc / source / parser / cpp / sownstck.hxx
blob807232985b95fe064f364d1ca4124ce52d2ce47d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sownstck.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef ADC_CPP_SOWNSTCK_HXX
32 #define ADC_CPP_SOWNSTCK_HXX
36 // USED SERVICES
37 // BASE CLASSES
38 #include "cxt2ary.hxx"
39 // COMPONENTS
40 #include <ary/cpp/c_types4cpp.hxx>
41 #include <estack.hxx>
42 // PARAMETERS
43 #include <ary/cpp/c_namesp.hxx>
44 #include <x_parse.hxx>
47 namespace cpp
50 using ary::cpp::E_Protection;
53 /** Implementation struct for cpp::ContextForAry.
55 struct ContextForAry::S_OwnerStack
57 public:
58 S_OwnerStack();
59 void SetGlobalNamespace(
60 ary::cpp::Namespace &
61 io_rGlobalNamespace );
62 ~S_OwnerStack();
64 void Reset();
66 void OpenNamespace(
67 ary::cpp::Namespace &
68 io_rOpenedNamespace );
69 void OpenExternC();
70 void OpenClass(
71 ary::cpp::Class & io_rOpenedClass );
72 void OpenEnum(
73 ary::cpp::Enum & io_rOpenedEnum );
74 void CloseBlock();
75 void CloseClass();
76 void CloseEnum();
77 void SetCurProtection(
78 ary::cpp::E_Protection
79 i_eProtection );
80 ary::cpp::Namespace &
81 CurNamespace() const;
82 ary::cpp::Class * CurClass() const;
83 ary::cpp::Enum * CurEnum() const;
85 Owner & CurOwner() const;
86 ary::cpp::E_Protection
87 CurProtection() const;
88 bool IsExternC() const { return nExternC > 0; }
90 private:
91 typedef std::pair< ary::cpp::Class*, E_Protection > ClassEnv;
92 typedef EStack< ary::cpp::Namespace* > Stack_Namespaces;
93 typedef EStack< ClassEnv > Stack_Classes;
94 typedef ary::cpp::InputContext::Owner Ifc_Owner;
96 void SetOwner_2CurNamespace();
97 void SetOwner_2CurClass();
98 void SetOwner_2None();
100 // DATA
101 Stack_Namespaces aStack_Namespaces;
102 Stack_Classes aStack_Classes;
103 ary::cpp::Enum * pCurEnum;
104 uintt nExternC; /// This is a number, for the case that extern "C" blocks are nested.
106 Dyn<Owner_Namespace>
107 pOwner_Namespace;
108 Dyn<Owner_Class> pOwner_Class;
109 Ifc_Owner * pOwner_Cur;
113 // IMPLEMENTATION
115 /* The implementation is in header, though not inline, because this file is included
116 in cxt2ary.cxx only!
119 inline ary::cpp::Namespace &
120 ContextForAry::
121 S_OwnerStack::CurNamespace() const
123 csv_assert( aStack_Namespaces.size() > 0 );
124 return *aStack_Namespaces.top();
127 inline ary::cpp::Class *
128 ContextForAry::
129 S_OwnerStack::CurClass() const
131 return aStack_Classes.size() > 0
132 ? aStack_Classes.top().first
133 : (ary::cpp::Class *) 0;
136 inline void
137 ContextForAry::
138 S_OwnerStack::SetOwner_2CurNamespace()
140 csv_assert( aStack_Namespaces.size() > 0 );
141 pOwner_Cur = pOwner_Namespace.MutablePtr();
142 pOwner_Namespace->SetAnotherNamespace( CurNamespace() );
145 inline void
146 ContextForAry::
147 S_OwnerStack::SetOwner_2CurClass()
149 csv_assert( aStack_Classes.size() > 0 );
150 pOwner_Cur = pOwner_Class.MutablePtr();
151 pOwner_Class->SetAnotherClass( *CurClass() );
154 ContextForAry::
155 S_OwnerStack::S_OwnerStack()
156 : // aStack_Namespaces,
157 // aStack_Classes,
158 pCurEnum(0),
159 nExternC(0),
160 pOwner_Namespace(new Owner_Namespace),
161 pOwner_Class(new Owner_Class),
162 pOwner_Cur(0)
166 void
167 ContextForAry::
168 S_OwnerStack::Reset()
170 while ( aStack_Namespaces.top()->Owner().IsValid() )
171 aStack_Namespaces.pop();
172 while ( NOT aStack_Classes.empty() )
173 aStack_Classes.pop();
174 pCurEnum = 0;
175 nExternC = 0;
176 SetOwner_2CurNamespace();
179 inline void
180 ContextForAry::
181 S_OwnerStack::SetGlobalNamespace( ary::cpp::Namespace & io_rGlobalNamespace )
183 csv_assert( aStack_Namespaces.size() == 0 );
184 aStack_Namespaces.push(&io_rGlobalNamespace);
185 SetOwner_2CurNamespace();
188 ContextForAry::
189 S_OwnerStack::~S_OwnerStack()
193 inline void
194 ContextForAry::
195 S_OwnerStack::OpenNamespace( ary::cpp::Namespace & io_rOpenedNamespace )
197 csv_assert( aStack_Namespaces.size() > 0 OR io_rOpenedNamespace.Parent() == 0 );
198 aStack_Namespaces.push(&io_rOpenedNamespace);
199 SetOwner_2CurNamespace();
202 inline void
203 ContextForAry::
204 S_OwnerStack::OpenExternC()
206 ++nExternC;
207 // SetOwner_2None();
210 inline void
211 ContextForAry::
212 S_OwnerStack::SetCurProtection( ary::cpp::E_Protection i_eProtection )
214 csv_assert( aStack_Classes.size() > 0 );
215 aStack_Classes.top().second = i_eProtection;
218 inline ary::cpp::Enum *
219 ContextForAry::
220 S_OwnerStack::CurEnum() const
222 return pCurEnum;
226 inline ary::cpp::InputContext::Owner &
227 ContextForAry::
228 S_OwnerStack::CurOwner() const
230 csv_assert( pOwner_Cur != 0 );
231 return *pOwner_Cur;
234 inline E_Protection
235 ContextForAry::
236 S_OwnerStack::CurProtection() const
238 return aStack_Classes.size() > 0
239 ? aStack_Classes.top().second
240 : ary::cpp::PROTECT_global;
243 inline void
244 ContextForAry::
245 S_OwnerStack::SetOwner_2None()
247 pOwner_Cur = 0;
250 void
251 ContextForAry::
252 S_OwnerStack::OpenClass( ary::cpp::Class & io_rOpenedClass )
254 E_Protection eDefaultProtection
255 = io_rOpenedClass.ClassKey() == ary::cpp::CK_class
256 ? ary::cpp::PROTECT_private
257 : ary::cpp::PROTECT_public;
258 aStack_Classes.push( ClassEnv(&io_rOpenedClass, eDefaultProtection) );
259 SetOwner_2CurClass();
262 inline void
263 ContextForAry::
264 S_OwnerStack::OpenEnum( ary::cpp::Enum & io_rOpenedEnum )
266 csv_assert( pCurEnum == 0 );
267 pCurEnum = &io_rOpenedEnum;
268 SetOwner_2None();
271 void
272 ContextForAry::
273 S_OwnerStack::CloseBlock()
275 if (nExternC > 0)
277 --nExternC;
279 else
281 // csv_assert( aStack_Classes.size() == 0 );
282 if ( aStack_Classes.size() > 0 )
283 throw X_Parser(X_Parser::x_UnspecifiedSyntaxError, "", String::Null_(), 0);
285 csv_assert( pCurEnum == 0 );
286 aStack_Namespaces.pop();
288 // csv_assert( aStack_Namespaces.size() > 0 );
289 if( aStack_Namespaces.size() == 0 )
290 throw X_Parser(X_Parser::x_UnspecifiedSyntaxError, "", String::Null_(), 0);
293 SetOwner_2CurNamespace();
296 void
297 ContextForAry::
298 S_OwnerStack::CloseClass()
300 // csv_assert( aStack_Classes.size() > 0 );
301 if ( aStack_Classes.size() == 0 )
302 throw X_Parser(X_Parser::x_UnspecifiedSyntaxError, "", String::Null_(), 0);
304 aStack_Classes.pop();
305 if ( aStack_Classes.size() > 0 )
306 SetOwner_2CurClass();
307 else
308 SetOwner_2CurNamespace();
311 void
312 ContextForAry::
313 S_OwnerStack::CloseEnum()
315 csv_assert( pCurEnum != 0 );
316 pCurEnum = 0;
317 if ( aStack_Classes.size() > 0 )
318 SetOwner_2CurClass();
319 else
320 SetOwner_2CurNamespace();
324 } // namespace cpp
327 #endif