1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <precomp.h>
23 #include "cxt2ary.hxx"
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/entity.hxx>
28 #include <ary/cpp/c_class.hxx>
29 #include <ary/cpp/c_define.hxx>
30 #include <ary/cpp/c_enum.hxx>
31 #include <ary/cpp/c_enuval.hxx>
32 #include <ary/cpp/c_funct.hxx>
33 #include <ary/cpp/c_macro.hxx>
34 #include <ary/cpp/c_tydef.hxx>
35 #include <ary/cpp/c_vari.hxx>
36 #include <ary/cpp/c_gate.hxx>
37 #include <ary/cpp/cp_ce.hxx>
38 #include <ary/loc/loc_file.hxx>
39 #include <ary/doc/d_oldcppdocu.hxx>
40 #include <ary/info/docstore.hxx>
41 #include "icprivow.hxx"
42
43 // Implementationheaders, only to be used in this file!
44 #include "sfscope.hxx"
45 #include "sownstck.hxx"
46 #include "sdocdist.hxx"
47 #include "srecover.hxx"
48
49
50
51
52
53 namespace cpp
54 {
55
56 using ary::cpp::E_Protection;
57
ContextForAry(ary::cpp::Gate & io_rAryGate)58 ContextForAry::ContextForAry( ary::cpp::Gate & io_rAryGate )
59 : pGate(&io_rAryGate),
60 aTokenResult(),
61 pFileScopeInfo( new S_FileScopeInfo ),
62 pOwnerStack( new S_OwnerStack ),
63 pDocuDistributor( new S_DocuDistributor ),
64 pRecoveryGuard( new S_RecoveryGuard )
65 {
66 OpenNamespace( pGate->Ces().GlobalNamespace() );
67 }
68
~ContextForAry()69 ContextForAry::~ContextForAry()
70 {
71 }
72
73 ary::loc::File &
inq_CurFile() const74 ContextForAry::inq_CurFile() const
75 {
76 csv_assert(pFileScopeInfo->pCurFile != 0);
77
78 return *pFileScopeInfo->pCurFile;
79 }
80
81 ary::cpp::Namespace &
inq_CurNamespace() const82 ContextForAry::inq_CurNamespace() const
83 {
84 return pOwnerStack->CurNamespace();
85 }
86
87 ary::cpp::Class *
inq_CurClass() const88 ContextForAry::inq_CurClass() const
89 {
90 return pOwnerStack->CurClass();
91 }
92
93 ary::cpp::Enum *
inq_CurEnum() const94 ContextForAry::inq_CurEnum() const
95 {
96 return pOwnerStack->CurEnum();
97 }
98
99
100 ary::cpp::InputContext::Owner &
inq_CurOwner() const101 ContextForAry::inq_CurOwner() const
102 {
103 return pOwnerStack->CurOwner();
104 }
105
106 E_Protection
inq_CurProtection() const107 ContextForAry::inq_CurProtection() const
108 {
109 return pOwnerStack->CurProtection();
110 }
111
112 void
do_SetTokenResult(E_TokenDone i_eDone,E_EnvStackAction i_eWhat2DoWithEnvStack,ParseEnvironment * i_pParseEnv2Push)113 ContextForAry::do_SetTokenResult( E_TokenDone i_eDone,
114 E_EnvStackAction i_eWhat2DoWithEnvStack,
115 ParseEnvironment * i_pParseEnv2Push )
116 {
117 aTokenResult.eDone = i_eDone;
118 aTokenResult.eStackAction = i_eWhat2DoWithEnvStack;
119 aTokenResult.pEnv2Push = i_pParseEnv2Push;
120 }
121
122 void
do_OpenNamespace(ary::cpp::Namespace & io_rOpenedNamespace)123 ContextForAry::do_OpenNamespace( ary::cpp::Namespace & io_rOpenedNamespace )
124 {
125 pOwnerStack->OpenNamespace( io_rOpenedNamespace );
126 }
127
128 void
do_OpenExternC(bool)129 ContextForAry::do_OpenExternC( bool )
130 {
131 pOwnerStack->OpenExternC();
132 // KORR_FUTURE
133 // use i_bOnlyForOneDeclaration
134 }
135
136 void
do_OpenClass(ary::cpp::Class & io_rOpenedClass)137 ContextForAry::do_OpenClass( ary::cpp::Class & io_rOpenedClass )
138 {
139 pOwnerStack->OpenClass(io_rOpenedClass);
140 pDocuDistributor->SetCurrentlyStoredRe(io_rOpenedClass);
141 }
142
143 void
do_OpenEnum(ary::cpp::Enum & io_rOpenedEnum)144 ContextForAry::do_OpenEnum( ary::cpp::Enum & io_rOpenedEnum )
145 {
146 pOwnerStack->OpenEnum(io_rOpenedEnum);
147 pDocuDistributor->SetCurrentlyStoredRe(io_rOpenedEnum);
148 }
149
150 void
do_CloseBlock()151 ContextForAry::do_CloseBlock()
152 {
153 pOwnerStack->CloseBlock();
154 }
155
156 void
do_CloseClass()157 ContextForAry::do_CloseClass()
158 {
159 pOwnerStack->CloseClass();
160 }
161
162 void
do_CloseEnum()163 ContextForAry::do_CloseEnum()
164 {
165 pOwnerStack->CloseEnum();
166 }
167
168 void
do_SetCurProtection(ary::cpp::E_Protection i_eProtection)169 ContextForAry::do_SetCurProtection( ary::cpp::E_Protection i_eProtection )
170 {
171 pOwnerStack->SetCurProtection(i_eProtection);
172 }
173
174 void
do_OpenTemplate(const StringVector & i_rParameters)175 ContextForAry::do_OpenTemplate( const StringVector & i_rParameters )
176 {
177 pFileScopeInfo->pCurTemplateParameters = new StringVector(i_rParameters);
178 }
179
180 DYN StringVector *
do_Get_CurTemplateParameters()181 ContextForAry::do_Get_CurTemplateParameters()
182 {
183 return pFileScopeInfo->pCurTemplateParameters.Release();
184 }
185
186 void
do_Close_OpenTemplate()187 ContextForAry::do_Close_OpenTemplate()
188 {
189 if (pFileScopeInfo->pCurTemplateParameters)
190 delete pFileScopeInfo->pCurTemplateParameters.Release();
191 }
192
193 void
do_Event_Class_FinishedBase(const String &)194 ContextForAry::do_Event_Class_FinishedBase( const String & )
195 {
196 // KORR_FUTURE
197 }
198
199 void
do_Event_Store_Typedef(ary::cpp::Typedef & io_rTypedef)200 ContextForAry::do_Event_Store_Typedef( ary::cpp::Typedef & io_rTypedef )
201 {
202 pDocuDistributor->SetCurrentlyStoredRe(io_rTypedef);
203 }
204
205 void
do_Event_Store_EnumValue(ary::cpp::EnumValue & io_rEnumValue)206 ContextForAry::do_Event_Store_EnumValue( ary::cpp::EnumValue & io_rEnumValue )
207 {
208 pDocuDistributor->SetCurrentlyStoredRe(io_rEnumValue);
209 }
210
211 void
do_Event_Store_CppDefinition(ary::cpp::DefineEntity & io_rDefinition)212 ContextForAry::do_Event_Store_CppDefinition( ary::cpp::DefineEntity & io_rDefinition )
213 {
214 pDocuDistributor->SetCurrentlyStoredRe(io_rDefinition);
215 }
216
217 void
do_Event_EnterFunction_ParameterList()218 ContextForAry::do_Event_EnterFunction_ParameterList()
219 {
220 // KORR_FUTURE
221 // Inform pDocuDistributor about possibility of parameters' inline documentation.
222 }
223
224 void
do_Event_Function_FinishedParameter(const String &)225 ContextForAry::do_Event_Function_FinishedParameter( const String & )
226 {
227 // KORR_FUTURE
228 }
229
230 void
do_Event_LeaveFunction_ParameterList()231 ContextForAry::do_Event_LeaveFunction_ParameterList()
232 {
233 // KORR_FUTURE
234 }
235
236 void
do_Event_EnterFunction_Implementation()237 ContextForAry::do_Event_EnterFunction_Implementation()
238 {
239 // KORR_FUTURE
240 }
241
242 void
do_Event_LeaveFunction_Implementation()243 ContextForAry::do_Event_LeaveFunction_Implementation()
244 {
245 // KORR_FUTURE
246 }
247
248 void
do_Event_Store_Function(ary::cpp::Function & io_rFunction)249 ContextForAry::do_Event_Store_Function( ary::cpp::Function & io_rFunction )
250 {
251 pDocuDistributor->SetCurrentlyStoredRe(io_rFunction);
252 }
253
254
255 void
do_Event_Store_Variable(ary::cpp::Variable & io_rVariable)256 ContextForAry::do_Event_Store_Variable( ary::cpp::Variable & io_rVariable )
257 {
258 pDocuDistributor->SetCurrentlyStoredRe(io_rVariable);
259 }
260
261 void
do_TakeDocu(DYN ary::doc::OldCppDocu & let_drInfo)262 ContextForAry::do_TakeDocu( DYN ary::doc::OldCppDocu & let_drInfo )
263 {
264 let_drInfo.Store2(*pDocuDistributor);
265 }
266
267 void
do_StartWaitingFor_Recovery()268 ContextForAry::do_StartWaitingFor_Recovery()
269 {
270 pRecoveryGuard->StartWaitingFor_Recovery();
271 }
272
273 ary::cpp::Gate &
inq_AryGate() const274 ContextForAry::inq_AryGate() const
275 {
276 return * const_cast< ary::cpp::Gate* >(pGate);
277 }
278
279 const ary::cpp::InputContext &
inq_Context() const280 ContextForAry::inq_Context() const
281 {
282 return *this;
283 }
284
285 String
inq_CurFileName() const286 ContextForAry::inq_CurFileName() const
287 {
288 return pFileScopeInfo->pCurFile != 0
289 ? pFileScopeInfo->pCurFile->LocalName()
290 : String::Null_();
291 }
292
293 uintt
inq_LineCount() const294 ContextForAry::inq_LineCount() const
295 {
296 return pFileScopeInfo->nLineCount;
297 }
298
299 bool
inq_IsWaitingFor_Recovery() const300 ContextForAry::inq_IsWaitingFor_Recovery() const
301 {
302 return pRecoveryGuard->IsWithinRecovery();
303 }
304
305 bool
inq_IsExternC() const306 ContextForAry::inq_IsExternC() const
307 {
308 return pOwnerStack->IsExternC();
309 }
310
311 void
do_SetCurFile(ary::loc::File & io_rCurFile)312 ContextForAry::do_SetCurFile( ary::loc::File & io_rCurFile )
313 {
314 pFileScopeInfo->pCurFile = &io_rCurFile;
315 pFileScopeInfo->nLineCount = 0;
316 pFileScopeInfo->pCurTemplateParameters = 0;
317
318 pOwnerStack->Reset();
319 pDocuDistributor->Reset();
320 pRecoveryGuard->Reset();
321 }
322
323 void
do_Event_IncrLineCount()324 ContextForAry::do_Event_IncrLineCount()
325 {
326 ++pFileScopeInfo->nLineCount;
327 pDocuDistributor->Event_LineBreak();
328 }
329
330 void
do_Event_SwBracketOpen()331 ContextForAry::do_Event_SwBracketOpen()
332 {
333 pRecoveryGuard->Hdl_SwBracketOpen();
334 }
335
336 void
do_Event_SwBracketClose()337 ContextForAry::do_Event_SwBracketClose()
338 {
339 pRecoveryGuard->Hdl_SwBracketClose();
340 }
341
342 void
do_Event_Semicolon()343 ContextForAry::do_Event_Semicolon()
344 {
345 pRecoveryGuard->Hdl_Semicolon();
346 }
347
348
349
350
351 } // namespace cpp
352