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