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 <s2_luidl/pe_struc.hxx>
24 
25 
26 // NOT FULLY DECLARED SERVICES
27 #include <ary/idl/i_gate.hxx>
28 #include <ary/idl/i_struct.hxx>
29 #include <ary/idl/ip_ce.hxx>
30 #include <ary/doc/d_oldidldocu.hxx>
31 #include <s2_luidl/tk_ident.hxx>
32 #include <s2_luidl/tk_punct.hxx>
33 #include <s2_luidl/tk_keyw.hxx>
34 #include <s2_luidl/pe_type2.hxx>
35 #include <s2_luidl/pe_selem.hxx>
36 
37 
38 
39 namespace csi
40 {
41 namespace uidl
42 {
43 
44 
45 PE_Struct::PE_Struct()
46     // :    aWork,
47     //      pStati
48 {
49     pStati = new S_Stati(*this);
50 }
51 
52 void
53 PE_Struct::EstablishContacts( UnoIDL_PE *               io_pParentPE,
54                               ary::Repository &			io_rRepository,
55                               TokenProcessing_Result & 	o_rResult )
56 {
57     UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
58     Work().pPE_Element->EstablishContacts(this,io_rRepository,o_rResult);
59     Work().pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
60 }
61 
62 PE_Struct::~PE_Struct()
63 {
64 }
65 
66 void
67 PE_Struct::ProcessToken( const Token & i_rToken )
68 {
69     i_rToken.Trigger(*Stati().pCurStatus);
70 }
71 
72 
73 void
74 PE_Struct::InitData()
75 {
76     Work().InitData();
77     Stati().pCurStatus = &Stati().aWaitForName;
78 }
79 
80 void
81 PE_Struct::TransferData()
82 {
83     if (NOT Work().bIsPreDeclaration)
84     {
85         csv_assert(Work().sData_Name.size() > 0);
86         csv_assert(Work().nCurStruct.IsValid());
87     }
88     Stati().pCurStatus = &Stati().aNone;
89 }
90 
91 void
92 PE_Struct::ReceiveData()
93 {
94     Stati().pCurStatus->On_SubPE_Left();
95 }
96 
97 PE_Struct::S_Work::S_Work()
98     :   sData_Name(),
99         sData_TemplateParam(),
100         bIsPreDeclaration(false),
101         nCurStruct(0),
102         pPE_Element(0),
103         nCurParsed_ElementRef(0),
104         pPE_Type(0),
105         nCurParsed_Base(0)
106 
107 {
108     pPE_Element = new PE_StructElement(nCurParsed_ElementRef,nCurStruct,sData_TemplateParam);
109     pPE_Type = new PE_Type(nCurParsed_Base);
110 }
111 
112 void
113 PE_Struct::S_Work::InitData()
114 {
115     sData_Name.clear();
116     sData_TemplateParam.clear();
117     bIsPreDeclaration = false;
118     nCurStruct = 0;
119     nCurParsed_ElementRef = 0;
120     nCurParsed_Base = 0;
121 }
122 
123 void
124 PE_Struct::S_Work::Prepare_PE_QualifiedName()
125 {
126     nCurParsed_ElementRef = 0;
127 }
128 
129 void
130 PE_Struct::S_Work::Prepare_PE_Element()
131 {
132     nCurParsed_Base = 0;
133 }
134 
135 void
136 PE_Struct::S_Work::Data_Set_Name( const char * i_sName )
137 {
138     sData_Name = i_sName;
139 }
140 
141 void
142 PE_Struct::S_Work::Data_Set_TemplateParam( const char * i_sTemplateParam )
143 {
144     sData_TemplateParam = i_sTemplateParam;
145 }
146 
147 PE_Struct::S_Stati::S_Stati(PE_Struct & io_rStruct)
148     :   aNone(io_rStruct),
149         aWaitForName(io_rStruct),
150         aGotName(io_rStruct),
151         aWaitForTemplateParam(io_rStruct),
152         aWaitForTemplateEnd(io_rStruct),
153         aWaitForBase(io_rStruct),
154         aGotBase(io_rStruct),
155         aWaitForElement(io_rStruct),
156         aWaitForFinish(io_rStruct),
157         pCurStatus(0)
158 {
159     pCurStatus = &aNone;
160 }
161 
162 
163 //***********************       Stati       ***************************//
164 
165 
166 UnoIDL_PE &
167 PE_Struct::PE_StructState::MyPE()
168 {
169     return rStruct;
170 }
171 
172 
173 void
174 PE_Struct::State_WaitForName::Process_Identifier( const TokIdentifier & i_rToken )
175 {
176     Work().Data_Set_Name(i_rToken.Text());
177     MoveState( Stati().aGotName );
178     SetResult(done,stay);
179 }
180 
181 void
182 PE_Struct::State_GotName::Process_Punctuation( const TokPunctuation & i_rToken )
183 {
184     if ( i_rToken.Id() != TokPunctuation::Semicolon )
185     {
186         switch (i_rToken.Id())
187     	{
188             case TokPunctuation::Colon:
189                 MoveState( Stati().aWaitForBase );
190                 SetResult(done,push_sure,Work().pPE_Type.Ptr());
191                 Work().Prepare_PE_QualifiedName();
192             	break;
193             case TokPunctuation::CurledBracketOpen:
194                 PE().store_Struct();
195                 MoveState( Stati().aWaitForElement );
196                 SetResult(done,stay);
197             	break;
198             case TokPunctuation::Lesser:
199                 MoveState( Stati().aWaitForTemplateParam );
200                 SetResult(done,stay);
201             	break;
202             default:
203                 SetResult(not_done,pop_failure);
204         }   // end switch
205     }
206     else
207     {
208         Work().sData_Name.clear();
209         SetResult(done,pop_success);
210     }
211 }
212 
213 void
214 PE_Struct::State_WaitForTemplateParam::Process_Identifier( const TokIdentifier & i_rToken )
215 {
216     Work().Data_Set_TemplateParam(i_rToken.Text());
217     MoveState( Stati().aWaitForTemplateEnd );
218     SetResult(done,stay);
219 }
220 
221 void
222 PE_Struct::State_WaitForTemplateEnd::Process_Punctuation( const TokPunctuation & )
223 {
224     // Assume:  TokPunctuation::Greater
225     MoveState( Stati().aGotName );
226     SetResult(done,stay);
227 }
228 
229 void
230 PE_Struct::State_WaitForBase::On_SubPE_Left()
231 {
232     MoveState(Stati().aGotBase);
233 }
234 
235 void
236 PE_Struct::State_GotBase::Process_Punctuation( const TokPunctuation & i_rToken )
237 {
238     if ( i_rToken.Id() == TokPunctuation::CurledBracketOpen )
239     {
240         PE().store_Struct();
241         MoveState( Stati().aWaitForElement );
242         SetResult(done,stay);
243     }
244     else
245     {
246         SetResult(not_done,pop_failure);
247     }
248 }
249 
250 void
251 PE_Struct::State_WaitForElement::Process_Identifier( const TokIdentifier & )
252 {
253     SetResult( not_done, push_sure, Work().pPE_Element.Ptr() );
254     Work().Prepare_PE_Element();
255 }
256 
257 void
258 PE_Struct::State_WaitForElement::Process_NameSeparator()
259 {
260     SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
261     Work().Prepare_PE_Element();
262 }
263 
264 void
265 PE_Struct::State_WaitForElement::Process_BuiltInType( const TokBuiltInType & )
266 {
267     SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
268     Work().Prepare_PE_Element();
269 }
270 
271 void
272 PE_Struct::State_WaitForElement::Process_TypeModifier(const TokTypeModifier & )
273 {
274     SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
275     Work().Prepare_PE_Element();
276 }
277 
278 void
279 PE_Struct::State_WaitForElement::Process_Punctuation( const TokPunctuation & i_rToken )
280 {
281     if ( i_rToken.Id() == TokPunctuation::CurledBracketClose )
282     {
283         MoveState( Stati().aWaitForFinish );
284         SetResult( done, stay );
285     }
286     else
287     {
288         SetResult( not_done, pop_failure );
289     }
290 }
291 
292 void
293 PE_Struct::State_WaitForFinish::Process_Punctuation( const TokPunctuation & i_rToken )
294 {
295     if (i_rToken.Id() == TokPunctuation::Semicolon)
296     {
297         MoveState( Stati().aNone );
298         SetResult( done, pop_success );
299     }
300     else
301     {
302         SetResult( not_done, pop_failure );
303     }
304 }
305 
306 void
307 PE_Struct::store_Struct()
308 {
309     ary::idl::Struct &
310         rCe = Gate().Ces().Store_Struct(
311                         CurNamespace().CeId(),
312                         Work().sData_Name,
313                         Work().nCurParsed_Base,
314                         Work().sData_TemplateParam );
315     PassDocuAt(rCe);
316     Work().nCurStruct = rCe.CeId();
317 }
318 
319 
320 }   // namespace uidl
321 }   // namespace csi
322