1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include <s2_luidl/pe_func2.hxx>
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_function.hxx>
34 #include <ary/idl/i_type.hxx>
35 #include <ary/idl/i_gate.hxx>
36 #include <ary/idl/ip_ce.hxx>
37 #include <ary/idl/ip_type.hxx>
38 #include <ary/doc/d_oldidldocu.hxx>
39 #include <s2_luidl/pe_type2.hxx>
40 #include <s2_luidl/pe_vari2.hxx>
41 #include <s2_luidl/tk_keyw.hxx>
42 #include <s2_luidl/tk_ident.hxx>
43 #include <s2_luidl/tk_punct.hxx>
44 #include <x_parse2.hxx>
45 
46 
47 namespace csi
48 {
49 namespace uidl
50 {
51 
52 
53 PE_Function::PE_Function( const RParent &	    i_rCurInterface )
54 	:	eState(e_none),
55 		sData_Name(),
56         nData_ReturnType(0),
57         bData_Oneway(false),
58         pCurFunction(0),
59 		pCurParent(&i_rCurInterface),
60 		pPE_Type(0),
61 		nCurParsedType(0),
62 		sName(),
63 		pPE_Variable(0),
64 		eCurParsedParam_Direction(ary::idl::param_in),
65 		nCurParsedParam_Type(0),
66 		sCurParsedParam_Name(),
67 		bIsForConstructors(false)
68 {
69 	pPE_Type 		= new PE_Type(nCurParsedType);
70 	pPE_Variable 	= new PE_Variable(nCurParsedParam_Type, sCurParsedParam_Name);
71 }
72 
73 PE_Function::PE_Function( const RParent &	  i_rCurService,
74 						  E_Constructor        )
75 	:	eState(expect_name),
76 		sData_Name(),
77         nData_ReturnType(0),
78         bData_Oneway(false),
79         pCurFunction(0),
80 		pCurParent(&i_rCurService),
81 		pPE_Type(0),
82 		nCurParsedType(0),
83 		sName(),
84 		pPE_Variable(0),
85 		eCurParsedParam_Direction(ary::idl::param_in),
86 		nCurParsedParam_Type(0),
87 		sCurParsedParam_Name(),
88 		bIsForConstructors(true)
89 {
90 	pPE_Type 		= new PE_Type(nCurParsedType);
91 	pPE_Variable 	= new PE_Variable(nCurParsedParam_Type, sCurParsedParam_Name);
92 }
93 
94 void
95 PE_Function::EstablishContacts( UnoIDL_PE *				 io_pParentPE,
96 								ary::Repository &	     io_rRepository,
97 								TokenProcessing_Result & o_rResult )
98 {
99 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
100 	pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
101 	pPE_Variable->EstablishContacts(this,io_rRepository,o_rResult);
102 }
103 
104 PE_Function::~PE_Function()
105 {
106 }
107 
108 void
109 PE_Function::ProcessToken( const Token & i_rToken )
110 {
111 	i_rToken.Trigger(*this);
112 }
113 
114 void
115 PE_Function::Process_Stereotype( const TokStereotype & i_rToken )
116 {
117 	if (eState == e_start)
118 	{
119 		switch (i_rToken.Id())
120 		{
121 			case TokStereotype::ste_oneway:
122 						bData_Oneway = true;
123 						SetResult(done, stay);
124 						break;
125 			default:
126 						OnDefault();
127 		}	// end switch
128 	}
129 	else
130 		OnDefault();
131 }
132 
133 void
134 PE_Function::Process_Identifier( const TokIdentifier & i_rToken )
135 {
136 	switch (eState)
137     {
138 		case e_start:
139 					GoIntoReturnType();
140 					break;
141 		case expect_name:
142 					sData_Name = i_rToken.Text();
143 					SetResult(done,stay);
144 					eState = expect_params_list;
145 
146 					if (NOT bIsForConstructors)
147 					{
148                         pCurFunction = &Gate().Ces().Store_Function(
149                                                         *pCurParent,
150                                                         sData_Name,
151                                                         nData_ReturnType,
152                                                         bData_Oneway );
153 					}
154 					else
155 					{
156                         pCurFunction = &Gate().Ces().Store_ServiceConstructor(
157                                                         *pCurParent,
158                                                         sData_Name );
159 					}
160 	                PassDocuAt(*pCurFunction);
161 					break;
162 		case expect_parameter_variable:
163 					GoIntoParameterVariable();
164 					break;
165 		case expect_exception:
166 					GoIntoException();
167 					break;
168 		default:
169         			OnDefault();
170 	}
171 }
172 
173 void
174 PE_Function::Process_Punctuation( const TokPunctuation & i_rToken )
175 {
176 	switch (eState)
177 	{
178 		case e_start:
179 					SetResult(done,stay);
180 					break;
181 		case expect_params_list:
182 					if (i_rToken.Id() != TokPunctuation::BracketOpen)
183 					{
184 						OnDefault();
185 						return;
186 					}
187 					SetResult(done,stay);
188 					eState = expect_parameter;
189 					break;
190 		case expect_parameter:
191 					if (i_rToken.Id() == TokPunctuation::BracketClose)
192 					{
193 						SetResult(done,stay);
194 						eState = params_finished;
195 					}
196 					else
197 					{
198 						OnDefault();
199 						return;
200 					}
201 					break;
202 		case expect_parameter_separator:
203 					if (i_rToken.Id() == TokPunctuation::Comma)
204 					{
205 						SetResult(done,stay);
206 						eState = expect_parameter;
207 					}
208 					else if (i_rToken.Id() == TokPunctuation::BracketClose)
209 					{
210 						SetResult(done,stay);
211 						eState = params_finished;
212 					}
213 					else
214 					{
215 						OnDefault();
216 						return;
217 					}
218 					break;
219 		case params_finished:
220 		case exceptions_finished:
221 					if (i_rToken.Id() != TokPunctuation::Semicolon)
222 					{
223 						OnDefault();
224 						return;
225 					}
226 					SetResult(done,pop_success);
227 					eState = e_none;
228 					break;
229 		case expect_exceptions_list:
230 					if (i_rToken.Id() != TokPunctuation::BracketOpen)
231 					{
232 						OnDefault();
233 						return;
234 					}
235 					SetResult(done,stay);
236 					eState = expect_exception;
237 					break;
238 		case expect_exception_separator:
239 					if (i_rToken.Id() == TokPunctuation::Comma)
240 					{
241 						SetResult(done,stay);
242 						eState = expect_exception;
243 					}
244 					else if (i_rToken.Id() == TokPunctuation::BracketClose)
245 					{
246 						SetResult(done,stay);
247 						eState = exceptions_finished;
248 					}
249 					else
250 					{
251 						OnDefault();
252 						return;
253 					}
254 					break;
255 		default:
256 					OnDefault();
257 	}
258 }
259 
260 void
261 PE_Function::Process_BuiltInType( const TokBuiltInType & i_rToken )
262 {
263 	switch (eState)
264 	{
265 		case e_start:
266 				GoIntoReturnType();
267 				break;
268 		case expect_parameter_variable:
269    				GoIntoParameterVariable();
270                 break;
271 		case expect_parameter_separator:
272                 if (i_rToken.Id() != TokBuiltInType::bty_ellipse)
273                 {
274                     OnDefault();
275                 }
276                 else
277                 {
278                     pCurFunction->Set_Ellipse();
279                    	SetResult(done,stay);
280 		        	// eState stays the same, because we wait for the closing ")" now.
281                 }
282 		        break;
283 		case expect_exception:
284 				GoIntoException();
285 				break;
286 		default:
287 			OnDefault();
288 	}	// end switch
289 }
290 
291 void
292 PE_Function::Process_ParameterHandling( const TokParameterHandling & i_rToken )
293 {
294 	if (eState != expect_parameter)
295 	{
296 		OnDefault();
297 		return;
298 	}
299 
300 	switch (i_rToken.Id())
301 	{
302 		case TokParameterHandling::ph_in:
303 					eCurParsedParam_Direction = ary::idl::param_in;
304 					break;
305 		case TokParameterHandling::ph_out:
306 					eCurParsedParam_Direction = ary::idl::param_out;
307 					break;
308 		case TokParameterHandling::ph_inout:
309 					eCurParsedParam_Direction = ary::idl::param_inout;
310 					break;
311 		default:
312 					csv_assert(false);
313 	}
314 	SetResult(done,stay);
315 	eState = expect_parameter_variable;
316 }
317 
318 void
319 PE_Function::Process_Raises()
320 {
321 	if (eState != params_finished)
322 	{
323 		OnDefault();
324 		return;
325 	}
326 	SetResult(done,stay);
327 	eState = expect_exceptions_list;
328 }
329 
330 void
331 PE_Function::Process_Default()
332 {
333 	switch (eState)
334 	{
335 		case e_start:
336 				GoIntoReturnType();
337 				break;
338 		case expect_parameter_variable:
339 				GoIntoParameterVariable();
340 				break;
341 		case expect_exception:
342 				GoIntoException();
343 				break;
344 		default:
345 			OnDefault();
346 	}	// end switch
347 }
348 
349 void
350 PE_Function::GoIntoReturnType()
351 {
352 	SetResult(not_done, push_sure, pPE_Type.Ptr());
353 	eState = in_return_type;
354 }
355 
356 void
357 PE_Function::GoIntoParameterVariable()
358 {
359 	SetResult(not_done, push_sure, pPE_Variable.Ptr());
360 	eState = in_parameter_variable;
361 }
362 
363 void
364 PE_Function::GoIntoException()
365 {
366 	SetResult(not_done, push_sure, pPE_Type.Ptr());
367 	eState = in_exception;
368 }
369 
370 void
371 PE_Function::OnDefault()
372 {
373 	throw X_AutodocParser(X_AutodocParser::x_Any);
374 }
375 
376 void
377 PE_Function::InitData()
378 {
379 	eState = e_start;
380 
381 	sData_Name.clear();
382     nData_ReturnType = 0;
383     bData_Oneway = false;
384     pCurFunction = 0;
385 
386 	nCurParsedType = 0;
387 	eCurParsedParam_Direction = ary::idl::param_in;
388 	nCurParsedParam_Type = 0;
389 	sCurParsedParam_Name.clear();
390 
391 	if (bIsForConstructors)
392 	{
393         eState = expect_name;
394 	}
395 }
396 
397 void
398 PE_Function::ReceiveData()
399 {
400 	switch (eState)
401 	{
402 		case in_return_type:
403 				nData_ReturnType = nCurParsedType;
404 				nCurParsedType = 0;
405 				eState = expect_name;
406 				break;
407 		case in_parameter_variable:
408                 csv_assert(pCurFunction != 0);
409 				pCurFunction->Add_Parameter(
410                                     sCurParsedParam_Name,
411 									nCurParsedParam_Type,
412 									eCurParsedParam_Direction );
413 				sCurParsedParam_Name = "";
414 				nCurParsedParam_Type = 0;
415 				eCurParsedParam_Direction = ary::idl::param_in;
416 				eState = expect_parameter_separator;
417 				break;
418 		case in_exception:
419                 csv_assert(pCurFunction != 0);
420 				pCurFunction->Add_Exception(nCurParsedType);
421 				eState = expect_exception_separator;
422 				break;
423 		default:
424 			csv_assert(false);
425 	}   // end switch
426 }
427 
428 void
429 PE_Function::TransferData()
430 {
431     pCurFunction = 0;
432 	eState = e_none;
433 }
434 
435 UnoIDL_PE &
436 PE_Function::MyPE()
437 {
438 	return *this;
439 }
440 
441 
442 
443 }   // namespace uidl
444 }   // namespace csi
445 
446