xref: /AOO41X/main/autodoc/source/parser/cpp/pe_funct.cxx (revision 78bc99aafea97f4987aed12e674c2d2f1166dd91)
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 "pe_funct.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/tpl/tpltools.hxx>
28 #include <ary/cpp/c_gate.hxx>
29 #include <ary/cpp/c_funct.hxx>
30 #include <ary/cpp/c_type.hxx>
31 #include <ary/cpp/cp_ce.hxx>
32 #include <ary/cpp/cp_type.hxx>
33 #include <ary/cpp/inpcontx.hxx>
34 #include "pe_type.hxx"
35 #include "pe_param.hxx"
36 
37 
38 
39 
40 namespace cpp
41 {
42 
43 
44 inline void
PerformFinishingPunctuation()45 PE_Function::PerformFinishingPunctuation()
46 {
47     SetTokenResult(not_done,pop_success);
48 }
49 
50 
PE_Function(Cpp_PE * i_pParent)51 PE_Function::PE_Function( Cpp_PE * i_pParent )
52     :   Cpp_PE(i_pParent),
53         pStati( new PeStatusArray<PE_Function> ),
54         // pSpParameter,
55         // pSpuParameter,
56         // pSpType,
57         // pSpuException,
58         // pSpuCastOperatorType,
59         nResult(0),
60         bResult_WithImplementation(false),
61         aName(60),
62         eVirtuality(ary::cpp::VIRTUAL_none),
63         eConVol(ary::cpp::CONVOL_none),
64         // aFlags,
65         nReturnType(0),
66         // aParameters
67         // aExceptions,
68         bThrow(false),
69         nBracketCounterInImplementation(0)
70 {
71     Setup_StatusFunctions();
72 
73     pSpParameter     = new SP_Parameter(*this);
74     pSpType          = new SP_Type(*this);
75 
76     pSpuParameter           = new SPU_Parameter(*pSpParameter, 0, &PE_Function::SpReturn_Parameter);
77     pSpuException           = new SPU_Type(*pSpType, 0, &PE_Function::SpReturn_Exception);
78     pSpuCastOperatorType    = new SPU_Type(*pSpType, &PE_Function::SpInit_CastOperatorType, &PE_Function::SpReturn_CastOperatorType);
79 }
80 
~PE_Function()81 PE_Function::~PE_Function()
82 {
83 
84 }
85 
86 void
Init_Std(const String & i_sName,ary::cpp::Type_id i_nReturnType,bool i_bVirtual,ary::cpp::FunctionFlags i_aFlags)87 PE_Function::Init_Std( const String  &          i_sName,
88                        ary::cpp::Type_id        i_nReturnType,
89                        bool                     i_bVirtual,
90                        ary::cpp::FunctionFlags  i_aFlags )
91 {
92     aName << i_sName;
93     eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
94     aFlags = i_aFlags;
95     nReturnType = i_nReturnType;
96     pStati->SetCur(afterName);
97 }
98 
99 void
Init_Ctor(const String & i_sName,ary::cpp::FunctionFlags i_aFlags)100 PE_Function::Init_Ctor( const String  &         i_sName,
101                         ary::cpp::FunctionFlags i_aFlags )
102 {
103     aName << i_sName;
104     eVirtuality = ary::cpp::VIRTUAL_none;
105     aFlags = i_aFlags;
106     nReturnType = 0;
107     pStati->SetCur(afterName);
108 }
109 
110 void
Init_Dtor(const String & i_sName,bool i_bVirtual,ary::cpp::FunctionFlags i_aFlags)111 PE_Function::Init_Dtor( const String  &         i_sName,
112                         bool                    i_bVirtual,
113                         ary::cpp::FunctionFlags i_aFlags )
114 {
115     aName << "~" << i_sName;
116     eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
117     aFlags = i_aFlags;
118     nReturnType = 0;
119     pStati->SetCur(afterName);
120 }
121 
122 void
Init_CastOperator(bool i_bVirtual,ary::cpp::FunctionFlags i_aFlags)123 PE_Function::Init_CastOperator( bool                    i_bVirtual,
124                                 ary::cpp::FunctionFlags i_aFlags )
125 {
126     aName << "operator ";
127     eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
128     aFlags = i_aFlags;
129     nReturnType = 0;
130     pStati->SetCur(afterCastOperator);
131 }
132 
133 void
Init_NormalOperator(ary::cpp::Type_id i_nReturnType,bool i_bVirtual,ary::cpp::FunctionFlags i_aFlags)134 PE_Function::Init_NormalOperator( ary::cpp::Type_id                  i_nReturnType,
135                                   bool                      i_bVirtual,
136                                   ary::cpp::FunctionFlags   i_aFlags )
137 {
138     aName << "operator";
139     eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
140     aFlags = i_aFlags;
141     nReturnType = i_nReturnType;
142     pStati->SetCur(afterStdOperator);
143 }
144 
145 ary::cpp::Ce_id
Result_Id() const146 PE_Function::Result_Id() const
147 {
148     return nResult;
149 }
150 
151 void
Call_Handler(const cpp::Token & i_rTok)152 PE_Function::Call_Handler( const cpp::Token & i_rTok )
153 {
154     pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
155 }
156 
157 void
Setup_StatusFunctions()158 PE_Function::Setup_StatusFunctions()
159 {
160     typedef CallFunction<PE_Function>::F_Tok    F_Tok;
161 
162     static F_Tok stateF_afterStdOperator[] =
163                                             { &PE_Function::On_afterOperator_Std_Operator,
164                                               &PE_Function::On_afterOperator_Std_LeftBracket,
165                                               &PE_Function::On_afterOperator_Std_LeftBracket,
166                                               &PE_Function::On_afterOperator_Std_Operator,
167                                               &PE_Function::On_afterOperator_Std_Operator,
168                                               &PE_Function::On_afterOperator_Std_Operator,
169                                               &PE_Function::On_afterOperator_Std_Operator,
170                                               &PE_Function::On_afterOperator_Std_Operator,
171                                               &PE_Function::On_afterOperator_Std_Operator };
172     static INT16 stateT_afterStdOperator[] =
173                                             { Tid_Operator,
174                                               Tid_ArrayBracket_Left,
175                                               Tid_Bracket_Left,
176                                               Tid_Comma,
177                                               Tid_Assign,
178                                               Tid_Less,
179                                               Tid_Greater,
180                                               Tid_Asterix,
181                                               Tid_AmpersAnd };
182 
183     static F_Tok stateF_afterStdOperatorLeftBracket[] =
184                                             { &PE_Function::On_afterStdOperatorLeftBracket_RightBracket,
185                                               &PE_Function::On_afterStdOperatorLeftBracket_RightBracket };
186     static INT16 stateT_afterStdOperatorLeftBracket[] =
187                                             { Tid_ArrayBracket_Right,
188                                               Tid_Bracket_Right };
189 
190     static F_Tok stateF_afterCastOperator[] =
191                                             { &PE_Function::On_afterOperator_Cast_Type,
192                                               &PE_Function::On_afterOperator_Cast_Type,
193                                               &PE_Function::On_afterOperator_Cast_Type,
194                                               &PE_Function::On_afterOperator_Cast_Type,
195                                               &PE_Function::On_afterOperator_Cast_Type,
196                                               &PE_Function::On_afterOperator_Cast_Type,
197                                               &PE_Function::On_afterOperator_Cast_Type,
198                                               &PE_Function::On_afterOperator_Cast_Type,
199                                               &PE_Function::On_afterOperator_Cast_Type,
200                                               &PE_Function::On_afterOperator_Cast_Type,
201                                               &PE_Function::On_afterOperator_Cast_Type };
202     static INT16 stateT_afterCastOperator[] =
203                                             { Tid_Identifier,
204                                               Tid_class,
205                                               Tid_struct,
206                                               Tid_union,
207                                               Tid_enum,
208                                               Tid_const,
209                                               Tid_volatile,
210                                               Tid_DoubleColon,
211                                               Tid_typename,
212                                               Tid_BuiltInType,
213                                               Tid_TypeSpecializer };
214 
215     static F_Tok stateF_afterName[] =       { &PE_Function::On_afterName_Bracket_Left };
216     static INT16 stateT_afterName[] =       { Tid_Bracket_Left };
217 
218     static F_Tok stateF_expectParameterSeparator[] =
219                                             { &PE_Function::On_expectParameterSeparator_BracketRight,
220                                               &PE_Function::On_expectParameterSeparator_Comma };
221     static INT16 stateT_expectParameterSeparator[] =
222                                             { Tid_Bracket_Right,
223                                               Tid_Comma };
224 
225     static F_Tok stateF_afterParameters[] = { &PE_Function::On_afterParameters_const,
226                                               &PE_Function::On_afterParameters_volatile,
227                                               &PE_Function::On_afterParameters_throw,
228                                               &PE_Function::On_afterParameters_SwBracket_Left,
229                                               &PE_Function::On_afterParameters_Semicolon,
230                                               &PE_Function::On_afterParameters_Comma,
231                                               &PE_Function::On_afterParameters_Colon,
232                                               &PE_Function::On_afterParameters_Assign };
233     static INT16 stateT_afterParameters[] = { Tid_const,
234                                               Tid_volatile,
235                                               Tid_throw,
236                                               Tid_SwBracket_Left,
237                                               Tid_Semicolon,
238                                               Tid_Comma,
239                                               Tid_Colon,
240                                               Tid_Assign };
241 
242     static F_Tok stateF_afterThrow[] =      { &PE_Function::On_afterThrow_Bracket_Left };
243     static INT16 stateT_afterThrow[] =      { Tid_Bracket_Left };
244 
245     static F_Tok stateF_expectExceptionSeparator[] =
246                                             { &PE_Function::On_expectExceptionSeparator_BracketRight,
247                                               &PE_Function::On_expectExceptionSeparator_Comma };
248     static INT16 stateT_expectExceptionSeparator[] =
249                                             { Tid_Bracket_Right,
250                                               Tid_Comma };
251 
252     static F_Tok stateF_afterExceptions[] = { &PE_Function::On_afterExceptions_SwBracket_Left,
253                                               &PE_Function::On_afterExceptions_Semicolon,
254                                               &PE_Function::On_afterExceptions_Comma,
255                                               &PE_Function::On_afterExceptions_Colon,
256                                               &PE_Function::On_afterExceptions_Assign };
257     static INT16 stateT_afterExceptions[] = { Tid_SwBracket_Left,
258                                               Tid_Semicolon,
259                                               Tid_Comma,
260                                               Tid_Colon,
261                                               Tid_Assign };
262 
263     static F_Tok stateF_expectZero[] =      { &PE_Function::On_expectZero_Constant };
264     static INT16 stateT_expectZero[] =      { Tid_Constant };
265 
266     static F_Tok stateF_inImplementation[] =
267                                             { &PE_Function::On_inImplementation_SwBracket_Left,
268                                               &PE_Function::On_inImplementation_SwBracket_Right };
269     static INT16 stateT_inImplementation[] =
270                                             { Tid_SwBracket_Left,
271                                               Tid_SwBracket_Right };
272 
273     SEMPARSE_CREATE_STATUS(PE_Function, afterStdOperator, Hdl_SyntaxError);
274     SEMPARSE_CREATE_STATUS(PE_Function, afterStdOperatorLeftBracket, Hdl_SyntaxError);
275     SEMPARSE_CREATE_STATUS(PE_Function, afterCastOperator, Hdl_SyntaxError);
276     SEMPARSE_CREATE_STATUS(PE_Function, afterName, Hdl_SyntaxError);
277     SEMPARSE_CREATE_STATUS(PE_Function, expectParameterSeparator, Hdl_SyntaxError);
278     SEMPARSE_CREATE_STATUS(PE_Function, afterParameters, Hdl_SyntaxError);
279     SEMPARSE_CREATE_STATUS(PE_Function, afterThrow, Hdl_SyntaxError);
280     SEMPARSE_CREATE_STATUS(PE_Function, expectExceptionSeparator, Hdl_SyntaxError);
281     SEMPARSE_CREATE_STATUS(PE_Function, afterExceptions, Hdl_SyntaxError);
282     SEMPARSE_CREATE_STATUS(PE_Function, expectZero, Hdl_SyntaxError);
283     SEMPARSE_CREATE_STATUS(PE_Function, inImplementation, On_inImplementation_Default );
284 }
285 
286 void
InitData()287 PE_Function::InitData()
288 {
289     pStati->SetCur( afterName ),
290     nResult = 0;
291     bResult_WithImplementation = false;
292     aName.seekp(0);
293     eVirtuality = ary::cpp::VIRTUAL_none;
294     eConVol = ary::cpp::CONVOL_none;
295     aFlags.Reset();
296     nReturnType = 0;
297     csv::erase_container(aParameters);
298     csv::erase_container(aExceptions);
299     bThrow = false;
300 }
301 
302 void
TransferData()303 PE_Function::TransferData()
304 {
305     String  sName( aName.c_str() );
306     ary::cpp::Function *
307         pFunction = Env().AryGate().Ces().Store_Operation(
308                                                 Env().Context(),
309                                                 sName,
310                                                 nReturnType,
311                                                 aParameters,
312                                                 eVirtuality,
313                                                 eConVol,
314                                                 aFlags,
315                                                 bThrow,
316                                                 aExceptions );
317     if (pFunction != 0)
318     {
319         // KORR_FUTURE: How to handle differing documentation?
320 
321         Dyn< StringVector >
322                 pTplParams ( Env().Get_CurTemplateParameters() );
323         if ( pTplParams )
324         {
325             for ( StringVector::const_iterator it = pTplParams->begin();
326                   it !=  pTplParams->end();
327                   ++it )
328             {
329                 pFunction->Add_TemplateParameterType( *it, ary::cpp::Type_id(0) );
330             }  // end for
331         }
332 
333         Env().Event_Store_Function(*pFunction);
334     }
335 
336     pStati->SetCur(size_of_states);
337 }
338 
339 void
Hdl_SyntaxError(const char * i_sText)340 PE_Function::Hdl_SyntaxError(const char * i_sText)
341 {
342     StdHandlingOfSyntaxError(i_sText);
343 }
344 
345 void
SpInit_CastOperatorType()346 PE_Function::SpInit_CastOperatorType()
347 {
348     pSpuCastOperatorType->Child().Init_AsCastOperatorType();
349 }
350 
351 void
SpReturn_Parameter()352 PE_Function::SpReturn_Parameter()
353 {
354     pStati->SetCur(expectParameterSeparator);
355 
356     ary::cpp::Type_id nParamType = pSpuParameter->Child().Result_FrontType();
357     if ( nParamType.IsValid() )      // Check, if there was a parameter, or only the closing ')'.
358     {
359         aParameters.push_back( pSpuParameter->Child().Result_ParamInfo() );
360     }
361 }
362 
363 void
SpReturn_Exception()364 PE_Function::SpReturn_Exception()
365 {
366     pStati->SetCur(expectExceptionSeparator);
367 
368     ary::cpp::Type_id
369         nException = pSpuException->Child().Result_Type().TypeId();
370     if ( nException.IsValid() AND pSpuException->Child().Result_KindOf() == PE_Type::is_type )
371     {
372         aExceptions.push_back( nException );
373     }
374 }
375 
376 void
SpReturn_CastOperatorType()377 PE_Function::SpReturn_CastOperatorType()
378 {
379     pStati->SetCur(afterName);
380 
381     Env().AryGate().Types().Get_TypeText(
382             aName, pSpuCastOperatorType->Child().Result_Type().TypeId() );
383 }
384 
385 void
On_afterOperator_Std_Operator(const char * i_sText)386 PE_Function::On_afterOperator_Std_Operator(const char * i_sText)
387 {
388     SetTokenResult(done,stay);
389     pStati->SetCur(afterName);
390 
391     if ( 'a' <= *i_sText AND *i_sText <= 'z' )
392         aName << ' ';
393     aName << i_sText;
394 }
395 
396 void
On_afterOperator_Std_LeftBracket(const char * i_sText)397 PE_Function::On_afterOperator_Std_LeftBracket(const char * i_sText)
398 {
399     SetTokenResult(done,stay);
400     pStati->SetCur(afterStdOperatorLeftBracket);
401 
402     aName << i_sText;
403 }
404 
405 void
On_afterStdOperatorLeftBracket_RightBracket(const char * i_sText)406 PE_Function::On_afterStdOperatorLeftBracket_RightBracket(const char * i_sText)
407 {
408     SetTokenResult(done,stay);
409     pStati->SetCur(afterName);
410 
411     aName << i_sText;
412 }
413 
414 void
On_afterOperator_Cast_Type(const char *)415 PE_Function::On_afterOperator_Cast_Type(const char *)
416 {
417     pSpuCastOperatorType->Push(not_done);
418 }
419 
420 void
On_afterName_Bracket_Left(const char *)421 PE_Function::On_afterName_Bracket_Left(const char *)
422 {
423     pSpuParameter->Push(done);
424 }
425 
426 void
On_expectParameterSeparator_BracketRight(const char *)427 PE_Function::On_expectParameterSeparator_BracketRight(const char *)
428 {
429     SetTokenResult(done,stay);
430     pStati->SetCur(afterParameters);
431 }
432 
433 void
On_expectParameterSeparator_Comma(const char *)434 PE_Function::On_expectParameterSeparator_Comma(const char *)
435 {
436     pSpuParameter->Push(done);
437 }
438 
439 void
On_afterParameters_const(const char *)440 PE_Function::On_afterParameters_const(const char *)
441 {
442     SetTokenResult(done,stay);
443     eConVol = static_cast<E_ConVol>(
444                     static_cast<int>(eConVol) | static_cast<int>(ary::cpp::CONVOL_const) );
445 }
446 
447 void
On_afterParameters_volatile(const char *)448 PE_Function::On_afterParameters_volatile(const char *)
449 {
450     SetTokenResult(done,stay);
451     eConVol = static_cast<E_ConVol>(
452                     static_cast<int>(eConVol) | static_cast<int>(ary::cpp::CONVOL_volatile) );
453 }
454 
455 void
On_afterParameters_throw(const char *)456 PE_Function::On_afterParameters_throw(const char *)
457 {
458     SetTokenResult(done,stay);
459     pStati->SetCur(afterThrow);
460     bThrow = true;
461 }
462 
463 void
On_afterParameters_SwBracket_Left(const char *)464 PE_Function::On_afterParameters_SwBracket_Left(const char *)
465 {
466     EnterImplementation(1);
467 }
468 
469 void
On_afterParameters_Semicolon(const char *)470 PE_Function::On_afterParameters_Semicolon(const char *)
471 {
472     PerformFinishingPunctuation();
473 }
474 
475 void
On_afterParameters_Comma(const char *)476 PE_Function::On_afterParameters_Comma(const char *)
477 {
478     PerformFinishingPunctuation();
479 }
480 
481 void
On_afterParameters_Colon(const char *)482 PE_Function::On_afterParameters_Colon(const char *)
483 {
484     EnterImplementation(0);
485 }
486 
487 void
On_afterParameters_Assign(const char *)488 PE_Function::On_afterParameters_Assign(const char *)
489 {
490     SetTokenResult(done,stay);
491     pStati->SetCur(expectZero);
492 }
493 
494 void
On_afterThrow_Bracket_Left(const char *)495 PE_Function::On_afterThrow_Bracket_Left(const char *)
496 {
497     pSpuException->Push(done);
498 }
499 
500 void
On_expectExceptionSeparator_BracketRight(const char *)501 PE_Function::On_expectExceptionSeparator_BracketRight(const char *)
502 {
503     SetTokenResult(done,stay);
504     pStati->SetCur(afterExceptions);
505 }
506 
507 void
On_expectExceptionSeparator_Comma(const char *)508 PE_Function::On_expectExceptionSeparator_Comma(const char *)
509 {
510     pSpuException->Push(done);
511 }
512 
513 void
On_afterExceptions_SwBracket_Left(const char *)514 PE_Function::On_afterExceptions_SwBracket_Left(const char *)
515 {
516     EnterImplementation(1);
517 }
518 
519 void
On_afterExceptions_Semicolon(const char *)520 PE_Function::On_afterExceptions_Semicolon(const char *)
521 {
522     PerformFinishingPunctuation();
523 }
524 
525 void
On_afterExceptions_Comma(const char *)526 PE_Function::On_afterExceptions_Comma(const char *)
527 {
528     PerformFinishingPunctuation();
529 }
530 
531 void
On_afterExceptions_Colon(const char *)532 PE_Function::On_afterExceptions_Colon(const char *)
533 {
534     EnterImplementation(0);
535 }
536 
537 void
On_afterExceptions_Assign(const char *)538 PE_Function::On_afterExceptions_Assign(const char *)
539 {
540     SetTokenResult(done,stay);
541     pStati->SetCur(expectZero);
542 }
543 
544 void
On_expectZero_Constant(const char * i_sText)545 PE_Function::On_expectZero_Constant(const char * i_sText)
546 {
547     if ( strcmp(i_sText,"0") != 0 )
548         Hdl_SyntaxError(i_sText);
549 
550     SetTokenResult(done,stay);
551     pStati->SetCur(afterExceptions);
552 
553     eVirtuality = ary::cpp::VIRTUAL_abstract;
554 }
555 
556 void
On_inImplementation_SwBracket_Left(const char *)557 PE_Function::On_inImplementation_SwBracket_Left(const char *)
558 {
559     SetTokenResult(done,stay);
560     nBracketCounterInImplementation++;
561 }
562 
563 void
On_inImplementation_SwBracket_Right(const char *)564 PE_Function::On_inImplementation_SwBracket_Right(const char *)
565 {
566     nBracketCounterInImplementation--;
567     if (nBracketCounterInImplementation == 0)
568     {
569         SetTokenResult(done,pop_success);
570     }
571     else
572     {
573         SetTokenResult(done,stay);
574     }
575 }
576 
577 void
On_inImplementation_Default(const char *)578 PE_Function::On_inImplementation_Default(const char *)
579 {
580     SetTokenResult(done,stay);
581 }
582 
583 void
EnterImplementation(intt i_nBracketCountStart)584 PE_Function::EnterImplementation( intt i_nBracketCountStart )
585 {
586     SetTokenResult(done,stay);
587     pStati->SetCur(inImplementation);
588 
589     bResult_WithImplementation = true;
590     nBracketCounterInImplementation = i_nBracketCountStart;
591     if ( Env().Context().CurClass() != 0 )
592     {
593         aFlags.SetInline();
594     }
595 }
596 
597 
598 
599 }   // namespace cpp
600 
601 
602 
603 
604 
605