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_servi.hxx>
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/idl/i_gate.hxx>
28 #include <ary/idl/i_service.hxx>
29 #include <ary/idl/i_siservice.hxx>
30 #include <ary/idl/ip_ce.hxx>
31 #include <ary/doc/d_oldidldocu.hxx>
32 #include <s2_luidl/pe_func2.hxx>
33 #include <s2_luidl/pe_property.hxx>
34 #include <s2_luidl/pe_type2.hxx>
35 #include <s2_luidl/tk_keyw.hxx>
36 #include <s2_luidl/tk_ident.hxx>
37 #include <s2_luidl/tk_punct.hxx>
38 
39 
40 
41 namespace csi
42 {
43 namespace uidl
44 {
45 
46 
47 
48 PE_Service::PE_Service()
49 	:	eState(e_none),
50 		sData_Name(),
51 		bIsPreDeclaration(false),
52 		pCurService(0),
53 		pCurSiService(0),
54 		nCurService(0),
55 		pPE_Property(0),
56 		nCurParsed_Property(0),
57 		pPE_Type(0),
58 		nCurParsed_Type(0),
59 		pPE_Constructor(0),
60 		bOptionalMember(false)
61 {
62 	pPE_Property 	= new PE_Property(nCurService);
63 	pPE_Type 		= new PE_Type(nCurParsed_Type);
64 	pPE_Constructor = new PE_Function(nCurService, PE_Function::constructor);
65 }
66 
67 void
68 PE_Service::EstablishContacts( UnoIDL_PE *				io_pParentPE,
69 							   ary::Repository &		io_rRepository,
70 							   TokenProcessing_Result & o_rResult )
71 {
72 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
73 	pPE_Property->EstablishContacts(this,io_rRepository,o_rResult);
74 	pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
75 	pPE_Constructor->EstablishContacts(this,io_rRepository,o_rResult);
76 }
77 
78 PE_Service::~PE_Service()
79 {
80 }
81 
82 void
83 PE_Service::ProcessToken( const Token & i_rToken )
84 {
85 	i_rToken.Trigger(*this);
86 }
87 
88 
89 void
90 PE_Service::Process_MetaType( const TokMetaType &	i_rToken )
91 {
92 	switch ( i_rToken.Id() )
93 	{
94 		case TokMetaType::mt_service:
95 					if (eState == need_name)
96 						SetResult(done, stay );
97 					else if (eState == e_std)
98 					{
99 						SetResult(done, push_sure, pPE_Type.Ptr());
100 						eState = in_service_type;
101 					}
102 					else
103 						On_Default();
104 					break;
105 		case TokMetaType::mt_interface:
106 					if (eState == e_std)
107 					{
108 						SetResult(done, push_sure, pPE_Type.Ptr());
109 						eState = in_ifc_type;
110 					}
111 					else
112 						On_Default();
113 					break;
114 		case TokMetaType::mt_property:
115 					if (eState == e_std)
116 					{
117 						StartProperty();
118 					}
119 					else
120 						On_Default();
121 					break;
122         default:
123             // KORR_FUTURE:
124             // Should throw syntax error warning.
125                     ;
126 	}	// end switch
127 }
128 
129 void
130 PE_Service::Process_Identifier( const TokIdentifier & i_rToken )
131 {
132 	if (eState == need_name)
133 	{
134 		sData_Name = i_rToken.Text();
135 		SetResult(done, stay);
136 		eState = need_curlbr_open;
137 	}
138 	else if (eState == e_std_sib)
139 	{
140 		SetResult(not_done, push_sure, pPE_Constructor.Ptr());
141 	}
142 	else
143 		On_Default();
144 }
145 
146 void
147 PE_Service::Process_Punctuation( const TokPunctuation & i_rToken )
148 {
149 	switch (i_rToken.Id())
150 	{
151 		case TokPunctuation::Colon:
152 					if (eState == need_curlbr_open)
153 					{
154 						SetResult(done, push_sure, pPE_Type.Ptr());
155 						eState = need_base_interface;
156 					}
157 					else
158 						On_Default();
159 					break;
160 
161 		case TokPunctuation::CurledBracketOpen:
162 					if (eState == need_curlbr_open)
163 					{
164                         pCurService = &Gate().Ces().Store_Service(
165                                                         CurNamespace().CeId(),
166                                                         sData_Name );
167                         nCurService = pCurService->CeId();
168 						PassDocuAt(*pCurService);
169 						SetResult(done, stay);
170 						eState = e_std;
171 					}
172 					else if (eState == need_curlbr_open_sib)
173 					{
174 						SetResult(done, stay);
175 						eState = e_std_sib;
176 					}
177 					else
178 						On_Default();
179 					break;
180 		case TokPunctuation::CurledBracketClose:
181 					if (eState == e_std OR eState == e_std_sib)
182 					{
183 						SetResult(done, stay);
184 						eState = need_finish;
185 					}
186 					else
187 						On_Default();
188 					break;
189 		case TokPunctuation::Comma:
190 					if (eState == expect_ifc_separator)
191 					{
192 						SetResult(done, push_sure, pPE_Type.Ptr());
193 						eState = in_ifc_type;
194 					}
195 					else if (eState == expect_service_separator)
196 					{
197 						SetResult(done, push_sure, pPE_Type.Ptr());
198 						eState = in_service_type;
199 					}
200 					else if (eState == e_std)
201 					{
202 						SetResult(done, stay);
203 					}
204 					else
205 						On_Default();
206 					break;
207 		case TokPunctuation::Semicolon:
208 					switch (eState)
209 					{
210 					   case need_curlbr_open:
211 									sData_Name.clear();
212 									bIsPreDeclaration = true;
213 									SetResult(done, pop_success);
214 									eState = e_none;
215 									break;
216     				   case need_curlbr_open_sib:
217 						            SetResult(done, pop_success);
218 						            eState = e_none;
219 					                break;
220 					   case expect_ifc_separator:
221 					   case expect_service_separator:
222 									SetResult(done, stay);
223 									eState = e_std;
224 									break;
225 					   case need_finish:
226 									SetResult(done, pop_success);
227 									eState = e_none;
228 									break;
229 					   case at_ignore:
230 									SetResult(done, stay);
231 									eState = e_std;
232 									break;
233 					   default:
234 									On_Default();
235 					}	// end switch
236 					break;
237 		default:
238 					On_Default();
239 	}	// end switch
240 }
241 
242 void
243 PE_Service::Process_Stereotype( const TokStereotype & i_rToken )
244 {
245     if (i_rToken.Id() == TokStereotype::ste_optional)
246 	{
247 		bOptionalMember = true;
248 		SetResult(done, stay);
249 	}
250 	else if ( eState == e_std )
251 	{
252 		StartProperty();
253 	}
254 	else
255 		On_Default();
256 }
257 
258 void
259 PE_Service::Process_Needs()
260 {
261 	SetResult(done,stay);
262 	eState = at_ignore;
263 }
264 
265 void
266 PE_Service::Process_Observes()
267 {
268 	SetResult(done,stay);
269 	eState = at_ignore;
270 }
271 
272 void
273 PE_Service::Process_Default()
274 {
275 	On_Default();
276 }
277 
278 
279 void
280 PE_Service::On_Default()
281 {
282 	if (eState == at_ignore)
283 		SetResult(done, stay);
284 	else
285 		SetResult(not_done, pop_failure);
286 }
287 
288 void
289 PE_Service::InitData()
290 {
291 	eState = need_name;
292 	sData_Name.clear();
293 	bIsPreDeclaration = false;
294 	pCurService = 0;
295 	pCurSiService = 0;
296 	nCurService = 0;
297 	nCurParsed_Property = 0;
298 	nCurParsed_Type = 0;
299 	bOptionalMember = false;
300 }
301 
302 void
303 PE_Service::TransferData()
304 {
305 	if (NOT bIsPreDeclaration)
306 	{
307 		csv_assert(sData_Name.size() > 0);
308 		csv_assert( (pCurService != 0) != (pCurSiService != 0) );
309 	}
310 
311 	eState = e_none;
312 }
313 
314 void
315 PE_Service::ReceiveData()
316 {
317 	switch (eState)
318 	{
319 		case in_property:
320 				eState = e_std;
321 				break;
322 		case in_ifc_type:
323 				if (bOptionalMember)
324 				{
325 					pPE_Type->SetOptional();
326 				}
327 				pCurService->AddRef_SupportedInterface(
328 						            nCurParsed_Type,
329                                     pPE_Type->ReleaseDocu());
330 				nCurParsed_Type = 0;
331 				eState = expect_ifc_separator;
332 				break;
333 		case in_service_type:
334 				if (bOptionalMember)
335                 {
336 					pPE_Type->SetOptional();
337 				}
338 				pCurService->AddRef_IncludedService(
339 						            nCurParsed_Type,
340                                     pPE_Type->ReleaseDocu());
341 				nCurParsed_Type = 0;
342 				eState = expect_service_separator;
343 				break;
344         case need_base_interface:
345                 pCurSiService = &Gate().Ces().Store_SglIfcService(
346                                                 CurNamespace().CeId(),
347                                                 sData_Name,
348                                                 nCurParsed_Type );
349                 nCurService = pCurSiService->CeId();
350 				PassDocuAt(*pCurSiService);
351 
352                 nCurParsed_Type = 0;
353                 eState = need_curlbr_open_sib;
354 				break;
355 		case e_std_sib:
356 		        break;
357 		default:
358 			csv_assert(false);
359 	}
360 
361     bOptionalMember = false;
362 }
363 
364 
365 UnoIDL_PE &
366 PE_Service::MyPE()
367 {
368 	return *this;
369 }
370 
371 void
372 PE_Service::StartProperty()
373 {
374 	SetResult(not_done, push_sure, pPE_Property.Ptr());
375 	eState = in_property;
376 
377 	if (bOptionalMember)
378     {
379 		pPE_Property->PresetOptional();
380         bOptionalMember = false;
381 	}
382 }
383 
384 
385 }   // namespace uidl
386 }   // namespace csi
387 
388