1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sownstck.hxx,v $
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
38 #include "cxt2ary.hxx"
40 #include <ary/cpp/c_types4cpp.hxx>
43 #include <ary/cpp/c_namesp.hxx>
44 #include <x_parse.hxx>
50 using ary::cpp::E_Protection
;
53 /** Implementation struct for cpp::ContextForAry.
55 struct ContextForAry::S_OwnerStack
59 void SetGlobalNamespace(
61 io_rGlobalNamespace
);
68 io_rOpenedNamespace
);
71 ary::cpp::Class
& io_rOpenedClass
);
73 ary::cpp::Enum
& io_rOpenedEnum
);
77 void SetCurProtection(
78 ary::cpp::E_Protection
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; }
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();
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.
108 Dyn
<Owner_Class
> pOwner_Class
;
109 Ifc_Owner
* pOwner_Cur
;
115 /* The implementation is in header, though not inline, because this file is included
119 inline ary::cpp::Namespace
&
121 S_OwnerStack::CurNamespace() const
123 csv_assert( aStack_Namespaces
.size() > 0 );
124 return *aStack_Namespaces
.top();
127 inline ary::cpp::Class
*
129 S_OwnerStack::CurClass() const
131 return aStack_Classes
.size() > 0
132 ? aStack_Classes
.top().first
133 : (ary::cpp::Class
*) 0;
138 S_OwnerStack::SetOwner_2CurNamespace()
140 csv_assert( aStack_Namespaces
.size() > 0 );
141 pOwner_Cur
= pOwner_Namespace
.MutablePtr();
142 pOwner_Namespace
->SetAnotherNamespace( CurNamespace() );
147 S_OwnerStack::SetOwner_2CurClass()
149 csv_assert( aStack_Classes
.size() > 0 );
150 pOwner_Cur
= pOwner_Class
.MutablePtr();
151 pOwner_Class
->SetAnotherClass( *CurClass() );
155 S_OwnerStack::S_OwnerStack()
156 : // aStack_Namespaces,
160 pOwner_Namespace(new Owner_Namespace
),
161 pOwner_Class(new Owner_Class
),
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();
176 SetOwner_2CurNamespace();
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();
189 S_OwnerStack::~S_OwnerStack()
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();
204 S_OwnerStack::OpenExternC()
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
*
220 S_OwnerStack::CurEnum() const
226 inline ary::cpp::InputContext::Owner
&
228 S_OwnerStack::CurOwner() const
230 csv_assert( pOwner_Cur
!= 0 );
236 S_OwnerStack::CurProtection() const
238 return aStack_Classes
.size() > 0
239 ? aStack_Classes
.top().second
240 : ary::cpp::PROTECT_global
;
245 S_OwnerStack::SetOwner_2None()
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();
264 S_OwnerStack::OpenEnum( ary::cpp::Enum
& io_rOpenedEnum
)
266 csv_assert( pCurEnum
== 0 );
267 pCurEnum
= &io_rOpenedEnum
;
273 S_OwnerStack::CloseBlock()
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();
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();
308 SetOwner_2CurNamespace();
313 S_OwnerStack::CloseEnum()
315 csv_assert( pCurEnum
!= 0 );
317 if ( aStack_Classes
.size() > 0 )
318 SetOwner_2CurClass();
320 SetOwner_2CurNamespace();