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_iface.hxx>
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/idl/i_interface.hxx>
28 #include <ary/idl/i_gate.hxx>
29 #include <ary/idl/ip_ce.hxx>
30 #include <ary/doc/d_oldidldocu.hxx>
31 #include <s2_luidl/pe_func2.hxx>
32 #include <s2_luidl/pe_attri.hxx>
33 #include <s2_luidl/pe_type2.hxx>
34 #include <s2_luidl/tk_keyw.hxx>
35 #include <s2_luidl/tk_ident.hxx>
36 #include <s2_luidl/tk_punct.hxx>
37 #include <adc_cl.hxx>
38 
39 
40 
41 namespace csi
42 {
43 namespace uidl
44 {
45 
46 #ifdef DF
47 #undef DF
48 #endif
49 #define DF 	&PE_Interface::On_Default
50 
51 PE_Interface::F_TOK
52 PE_Interface::aDispatcher[PE_Interface::e_STATES_MAX][PE_Interface::tt_MAX] =
53 		{ 	{ DF, DF, DF, DF, DF },  // e_none
54 			{ &PE_Interface::On_need_uik_MetaType,
55 				 DF, DF, DF, DF },  // need_uik
56 			{ DF, &PE_Interface::On_uik_Identifier,
57 					 &PE_Interface::On_uik_Punctuation,
58 						 DF, DF },  // uik
59 			{ &PE_Interface::On_need_ident_MetaType,
60 				 DF, DF, DF, DF },  // need_ident
61 			{ DF, &PE_Interface::On_ident_Identifier,
62 					 &PE_Interface::On_ident_Punctuation,
63 						 DF, DF },  // ident
64 			{ &PE_Interface::On_need_interface_MetaType,
65 				 DF, DF, DF, DF },  // need_interface
66 			{ DF, &PE_Interface::On_need_name_Identifer,
67 					DF, DF, DF },  // need_name
68 			{ DF, DF, &PE_Interface::On_wait_for_base_Punctuation,
69 						DF, DF },  // wait_for_base
70 			{ DF, DF, DF, DF, DF },  // in_base
71 			{ DF, DF, &PE_Interface::On_need_curlbr_open_Punctuation,
72 						  DF, DF },  // need_curlbr_open
73 			{ &PE_Interface::On_std_Metatype,
74 			      &PE_Interface::On_std_GotoFunction,
75 					  &PE_Interface::On_std_Punctuation,
76 						  &PE_Interface::On_std_GotoFunction,
77 							  &PE_Interface::On_std_Stereotype },  // e_std
78 			{ DF, DF, DF, DF, DF },  // in_function
79 			{ DF, DF, DF, DF, DF },  // in_attribute
80 			{ DF, DF, &PE_Interface::On_need_finish_Punctuation,
81 						  DF, DF },  // need_finish
82 			{ DF, DF, DF, DF, DF }   // in_base_interface
83 		};
84 
85 
86 
87 inline void
CallHandler(const char * i_sTokenText,E_TokenType i_eTokenType)88 PE_Interface::CallHandler( const char *		i_sTokenText,
89 						   E_TokenType		i_eTokenType )
90 	{ (this->*aDispatcher[eState][i_eTokenType])(i_sTokenText); }
91 
92 
93 
PE_Interface()94 PE_Interface::PE_Interface()
95 	:	eState(e_none),
96 		sData_Name(),
97 		bIsPreDeclaration(false),
98         pCurInterface(0),
99 		nCurInterface(0),
100 		pPE_Function(0),
101 		pPE_Attribute(0),
102 		pPE_Type(0),
103 		nCurParsed_Base(0),
104 		bOptionalMember(false)
105 {
106 	pPE_Function 	= new PE_Function(nCurInterface);
107 	pPE_Type 		= new PE_Type(nCurParsed_Base);
108 	pPE_Attribute   = new PE_Attribute(nCurInterface);
109 }
110 
111 void
EstablishContacts(UnoIDL_PE * io_pParentPE,ary::Repository & io_rRepository,TokenProcessing_Result & o_rResult)112 PE_Interface::EstablishContacts( UnoIDL_PE *				io_pParentPE,
113 								 ary::Repository &		io_rRepository,
114 								 TokenProcessing_Result & 	o_rResult )
115 {
116 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
117 	pPE_Function->EstablishContacts(this,io_rRepository,o_rResult);
118 	pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
119 	pPE_Attribute->EstablishContacts(this,io_rRepository,o_rResult);
120 }
121 
~PE_Interface()122 PE_Interface::~PE_Interface()
123 {
124 }
125 
126 void
ProcessToken(const Token & i_rToken)127 PE_Interface::ProcessToken( const Token & i_rToken )
128 {
129 	i_rToken.Trigger(*this);
130 }
131 
132 
133 void
Process_MetaType(const TokMetaType & i_rToken)134 PE_Interface::Process_MetaType( const TokMetaType &	i_rToken )
135 {
136 	CallHandler( i_rToken.Text(), tt_metatype );
137 }
138 
139 void
Process_Identifier(const TokIdentifier & i_rToken)140 PE_Interface::Process_Identifier( const TokIdentifier & i_rToken )
141 {
142 	CallHandler( i_rToken.Text(), tt_identifier );
143 }
144 
145 void
Process_Punctuation(const TokPunctuation & i_rToken)146 PE_Interface::Process_Punctuation( const TokPunctuation & i_rToken )
147 {
148 	CallHandler( i_rToken.Text(), tt_punctuation );
149 }
150 
151 void
Process_NameSeparator()152 PE_Interface::Process_NameSeparator()
153 {
154 	CallHandler( "", tt_startoftype );
155 }
156 
157 void
Process_BuiltInType(const TokBuiltInType & i_rToken)158 PE_Interface::Process_BuiltInType( const TokBuiltInType & i_rToken )
159 {
160 	CallHandler( i_rToken.Text(), tt_startoftype );
161 }
162 
163 void
Process_TypeModifier(const TokTypeModifier & i_rToken)164 PE_Interface::Process_TypeModifier( const TokTypeModifier & i_rToken )
165 {
166 	CallHandler( i_rToken.Text(), tt_startoftype );
167 }
168 
169 void
Process_Stereotype(const TokStereotype & i_rToken)170 PE_Interface::Process_Stereotype( const TokStereotype & i_rToken )
171 {
172 	CallHandler( i_rToken.Text(), tt_stereotype );
173 }
174 
175 void
Process_Default()176 PE_Interface::Process_Default()
177 {
178 	SetResult(done, stay);
179 }
180 
181 
182 void
On_need_uik_MetaType(const char *)183 PE_Interface::On_need_uik_MetaType(const char *)
184 {
185     // Deprecated, data will be ignored
186 	SetResult(done, stay);
187 	eState = uik;
188 }
189 
190 void
On_uik_Identifier(const char *)191 PE_Interface::On_uik_Identifier(const char *)
192 {
193     // Deprecated, data will be ignored
194 	SetResult(done, stay);
195 }
196 
197 void
On_uik_Punctuation(const char * i_sText)198 PE_Interface::On_uik_Punctuation(const char * i_sText)
199 {
200     // Deprecated, data will be ignored
201 	SetResult(done, stay);
202 	if (strcmp(",",i_sText) == 0)
203 	{
204 		eState = need_ident;
205 	}
206 }
207 
208 void
On_need_ident_MetaType(const char *)209 PE_Interface::On_need_ident_MetaType(const char *)
210 {
211 	SetResult(done, stay);
212 	eState = ident;
213 }
214 
215 void
On_ident_Identifier(const char *)216 PE_Interface::On_ident_Identifier(const char *)
217 {
218 	SetResult(done, stay);
219 }
220 
221 void
On_ident_Punctuation(const char * i_sText)222 PE_Interface::On_ident_Punctuation(const char * i_sText)
223 {
224 	SetResult(done, stay);
225 	if (strcmp(")",i_sText) == 0)
226 	{
227 		eState = need_interface;
228 	}
229 }
230 
231 void
On_need_interface_MetaType(const char *)232 PE_Interface::On_need_interface_MetaType(const char *)
233 {
234 	SetResult(done, stay);
235 	eState = need_name;
236 }
237 
238 void
On_need_name_Identifer(const char * i_sText)239 PE_Interface::On_need_name_Identifer(const char * i_sText)
240 {
241 	SetResult(done, stay);
242 	sData_Name = i_sText;
243 	eState = wait_for_base;
244 }
245 
246 void
On_wait_for_base_Punctuation(const char * i_sText)247 PE_Interface::On_wait_for_base_Punctuation(const char * i_sText)
248 {
249 	if (i_sText[0] != ';')
250 	{
251 		switch (i_sText[0])
252 		{
253 			case ':':
254 				SetResult(done, push_sure, pPE_Type.Ptr());
255 				eState = in_base;
256 				break;
257 			case '{':
258                 store_Interface();
259 
260 				SetResult(done,stay);
261 				eState = e_std;
262 				break;
263 			default:
264 				SetResult(not_done, pop_failure);
265                 eState = e_none;
266 		}	// end switch
267 	}
268 	else
269 	{
270 		bIsPreDeclaration = true;
271 		SetResult(done, pop_success);
272 		eState = e_none;
273 	}
274 }
275 
276 void
On_need_curlbr_open_Punctuation(const char * i_sText)277 PE_Interface::On_need_curlbr_open_Punctuation(const char * i_sText)
278 {
279 	if (i_sText[0] == '{')
280 	{
281         store_Interface();
282 
283 		SetResult(done, stay);
284 		eState = e_std;
285 	}
286 	else {
287     	csv_assert(false);
288     }
289 }
290 
291 
292 void
On_std_Metatype(const char * i_sText)293 PE_Interface::On_std_Metatype(const char * i_sText)
294 {
295     if (strcmp(i_sText,"attribute") ==  0)
296     	On_std_GotoAttribute(i_sText);
297     else if (strcmp(i_sText,"interface") ==  0)
298         On_std_GotoBaseInterface(i_sText);
299     else
300         On_std_GotoFunction(i_sText);
301 }
302 
303 void
On_std_Punctuation(const char * i_sText)304 PE_Interface::On_std_Punctuation(const char * i_sText)
305 {
306 	switch (i_sText[0])
307 	{
308 		case '}':
309 			SetResult(done, stay);
310 			eState = need_finish;
311 			break;
312 		case ';':   // Appears after base interface declarations.
313 			SetResult(done, stay);
314 			break;
315 		default:
316 			SetResult(not_done, pop_failure);
317 			eState = e_none;
318 	}	// end switch
319 }
320 
321 void
On_std_Stereotype(const char * i_sText)322 PE_Interface::On_std_Stereotype(const char * i_sText)
323 {
324     if (strcmp(i_sText,"oneway") ==  0)
325     	On_std_GotoFunction(i_sText);
326     else if (    strcmp(i_sText,"readonly") ==  0
327               OR strcmp(i_sText,"bound") ==  0 )
328         On_std_GotoAttribute(i_sText);
329     else if (strcmp(i_sText,"optional") ==  0)
330     {
331         bOptionalMember = true;
332         SetResult(done, stay);
333     }
334     else
335     	SetResult(not_done, pop_failure);
336 }
337 
338 void
On_std_GotoFunction(const char *)339 PE_Interface::On_std_GotoFunction(const char * )
340 {
341 	SetResult(not_done, push_sure, pPE_Function.Ptr());
342 	eState = in_function;
343 }
344 
345 void
On_std_GotoAttribute(const char *)346 PE_Interface::On_std_GotoAttribute(const char * )
347 {
348     	SetResult(not_done, push_sure, pPE_Attribute.Ptr());
349 	    eState = in_attribute;
350 }
351 
352 void
On_std_GotoBaseInterface(const char *)353 PE_Interface::On_std_GotoBaseInterface(const char * )
354 {
355    	SetResult(done, push_sure, pPE_Type.Ptr());
356     eState = in_base_interface;
357 }
358 
359 void
On_need_finish_Punctuation(const char * i_sText)360 PE_Interface::On_need_finish_Punctuation(const char * i_sText)
361 {
362 	switch (i_sText[0])
363 	{
364 		case ';':
365 			SetResult(done, pop_success);
366 			eState = e_none;
367 			break;
368 		default:
369 			SetResult(not_done, pop_failure);
370 			eState = e_none;
371 	}	// end switch
372 }
373 
374 void
On_Default(const char *)375 PE_Interface::On_Default(const char *)
376 {
377 	SetResult(not_done, pop_failure);
378 }
379 
380 void
InitData()381 PE_Interface::InitData()
382 {
383 	eState = need_interface;
384 
385 	sData_Name.clear();
386 	bIsPreDeclaration = false;
387 	pCurInterface = 0;
388 	nCurInterface = 0;
389 	nCurParsed_Base = 0;
390 	bOptionalMember = false;
391 }
392 
393 void
TransferData()394 PE_Interface::TransferData()
395 {
396 	if (NOT bIsPreDeclaration)
397 	{
398 		csv_assert(!sData_Name.empty());
399 		csv_assert(nCurInterface.IsValid());
400 	}
401 	else
402     {
403      	sData_Name.clear();
404      	pCurInterface = 0;
405         nCurInterface = 0;
406     }
407 
408 	eState = e_none;
409 }
410 
411 void
ReceiveData()412 PE_Interface::ReceiveData()
413 {
414 	switch (eState)
415     {
416 		case in_base:
417 				eState = need_curlbr_open;
418 				break;
419 		case in_function:
420 				eState = e_std;
421 				break;
422 		case in_attribute:
423 				eState = e_std;
424 				break;
425 		case in_base_interface:
426 				if (bOptionalMember)
427 				{
428 					pPE_Type->SetOptional();
429 					bOptionalMember = false;
430 				}
431 				pCurInterface->Add_Base(
432 						            nCurParsed_Base,
433                                     pPE_Type->ReleaseDocu());
434 				nCurParsed_Base = 0;
435 				eState = e_std;
436 				break;
437 		default:
438 			csv_assert(false);
439 	}
440 }
441 
442 UnoIDL_PE &
MyPE()443 PE_Interface::MyPE()
444 {
445  	return *this;
446 }
447 
448 void
store_Interface()449 PE_Interface::store_Interface()
450 {
451     pCurInterface = & Gate().Ces().Store_Interface(
452                                         CurNamespace().CeId(),
453                                         sData_Name,
454                                         nCurParsed_Base );
455     nCurInterface = pCurInterface->CeId();
456 	PassDocuAt(*pCurInterface);
457 }
458 
459 
460 }   // namespace uidl
461 }   // namespace csi
462