merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / parser / cpp / pe_funct.cxx
blobf341a6c0ff59941398f3340e1e94d021ad3ec44c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pe_funct.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "pe_funct.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/tpl/tpltools.hxx>
37 #include <ary/cpp/c_gate.hxx>
38 #include <ary/cpp/c_funct.hxx>
39 #include <ary/cpp/c_type.hxx>
40 #include <ary/cpp/cp_ce.hxx>
41 #include <ary/cpp/cp_type.hxx>
42 #include <ary/cpp/inpcontx.hxx>
43 #include "pe_type.hxx"
44 #include "pe_param.hxx"
49 namespace cpp
53 inline void
54 PE_Function::PerformFinishingPunctuation()
56 SetTokenResult(not_done,pop_success);
60 PE_Function::PE_Function( Cpp_PE * i_pParent )
61 : Cpp_PE(i_pParent),
62 pStati( new PeStatusArray<PE_Function> ),
63 // pSpParameter,
64 // pSpuParameter,
65 // pSpType,
66 // pSpuException,
67 // pSpuCastOperatorType,
68 nResult(0),
69 bResult_WithImplementation(false),
70 aName(60),
71 eVirtuality(ary::cpp::VIRTUAL_none),
72 eConVol(ary::cpp::CONVOL_none),
73 // aFlags,
74 nReturnType(0),
75 // aParameters
76 // aExceptions,
77 bThrow(false),
78 nBracketCounterInImplementation(0)
80 Setup_StatusFunctions();
82 pSpParameter = new SP_Parameter(*this);
83 pSpType = new SP_Type(*this);
85 pSpuParameter = new SPU_Parameter(*pSpParameter, 0, &PE_Function::SpReturn_Parameter);
86 pSpuException = new SPU_Type(*pSpType, 0, &PE_Function::SpReturn_Exception);
87 pSpuCastOperatorType = new SPU_Type(*pSpType, &PE_Function::SpInit_CastOperatorType, &PE_Function::SpReturn_CastOperatorType);
90 PE_Function::~PE_Function()
95 void
96 PE_Function::Init_Std( const String & i_sName,
97 ary::cpp::Type_id i_nReturnType,
98 bool i_bVirtual,
99 ary::cpp::FunctionFlags i_aFlags )
101 aName << i_sName;
102 eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
103 aFlags = i_aFlags;
104 nReturnType = i_nReturnType;
105 pStati->SetCur(afterName);
108 void
109 PE_Function::Init_Ctor( const String & i_sName,
110 ary::cpp::FunctionFlags i_aFlags )
112 aName << i_sName;
113 eVirtuality = ary::cpp::VIRTUAL_none;
114 aFlags = i_aFlags;
115 nReturnType = 0;
116 pStati->SetCur(afterName);
119 void
120 PE_Function::Init_Dtor( const String & i_sName,
121 bool i_bVirtual,
122 ary::cpp::FunctionFlags i_aFlags )
124 aName << "~" << i_sName;
125 eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
126 aFlags = i_aFlags;
127 nReturnType = 0;
128 pStati->SetCur(afterName);
131 void
132 PE_Function::Init_CastOperator( bool i_bVirtual,
133 ary::cpp::FunctionFlags i_aFlags )
135 aName << "operator ";
136 eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
137 aFlags = i_aFlags;
138 nReturnType = 0;
139 pStati->SetCur(afterCastOperator);
142 void
143 PE_Function::Init_NormalOperator( ary::cpp::Type_id i_nReturnType,
144 bool i_bVirtual,
145 ary::cpp::FunctionFlags i_aFlags )
147 aName << "operator";
148 eVirtuality = i_bVirtual ? ary::cpp::VIRTUAL_virtual : ary::cpp::VIRTUAL_none;
149 aFlags = i_aFlags;
150 nReturnType = i_nReturnType;
151 pStati->SetCur(afterStdOperator);
154 ary::cpp::Ce_id
155 PE_Function::Result_Id() const
157 return nResult;
160 void
161 PE_Function::Call_Handler( const cpp::Token & i_rTok )
163 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
166 void
167 PE_Function::Setup_StatusFunctions()
169 typedef CallFunction<PE_Function>::F_Tok F_Tok;
171 static F_Tok stateF_afterStdOperator[] =
172 { &PE_Function::On_afterOperator_Std_Operator,
173 &PE_Function::On_afterOperator_Std_LeftBracket,
174 &PE_Function::On_afterOperator_Std_LeftBracket,
175 &PE_Function::On_afterOperator_Std_Operator,
176 &PE_Function::On_afterOperator_Std_Operator,
177 &PE_Function::On_afterOperator_Std_Operator,
178 &PE_Function::On_afterOperator_Std_Operator,
179 &PE_Function::On_afterOperator_Std_Operator,
180 &PE_Function::On_afterOperator_Std_Operator };
181 static INT16 stateT_afterStdOperator[] =
182 { Tid_Operator,
183 Tid_ArrayBracket_Left,
184 Tid_Bracket_Left,
185 Tid_Comma,
186 Tid_Assign,
187 Tid_Less,
188 Tid_Greater,
189 Tid_Asterix,
190 Tid_AmpersAnd };
192 static F_Tok stateF_afterStdOperatorLeftBracket[] =
193 { &PE_Function::On_afterStdOperatorLeftBracket_RightBracket,
194 &PE_Function::On_afterStdOperatorLeftBracket_RightBracket };
195 static INT16 stateT_afterStdOperatorLeftBracket[] =
196 { Tid_ArrayBracket_Right,
197 Tid_Bracket_Right };
199 static F_Tok stateF_afterCastOperator[] =
200 { &PE_Function::On_afterOperator_Cast_Type,
201 &PE_Function::On_afterOperator_Cast_Type,
202 &PE_Function::On_afterOperator_Cast_Type,
203 &PE_Function::On_afterOperator_Cast_Type,
204 &PE_Function::On_afterOperator_Cast_Type,
205 &PE_Function::On_afterOperator_Cast_Type,
206 &PE_Function::On_afterOperator_Cast_Type,
207 &PE_Function::On_afterOperator_Cast_Type,
208 &PE_Function::On_afterOperator_Cast_Type,
209 &PE_Function::On_afterOperator_Cast_Type,
210 &PE_Function::On_afterOperator_Cast_Type };
211 static INT16 stateT_afterCastOperator[] =
212 { Tid_Identifier,
213 Tid_class,
214 Tid_struct,
215 Tid_union,
216 Tid_enum,
217 Tid_const,
218 Tid_volatile,
219 Tid_DoubleColon,
220 Tid_typename,
221 Tid_BuiltInType,
222 Tid_TypeSpecializer };
224 static F_Tok stateF_afterName[] = { &PE_Function::On_afterName_Bracket_Left };
225 static INT16 stateT_afterName[] = { Tid_Bracket_Left };
227 static F_Tok stateF_expectParameterSeparator[] =
228 { &PE_Function::On_expectParameterSeparator_BracketRight,
229 &PE_Function::On_expectParameterSeparator_Comma };
230 static INT16 stateT_expectParameterSeparator[] =
231 { Tid_Bracket_Right,
232 Tid_Comma };
234 static F_Tok stateF_afterParameters[] = { &PE_Function::On_afterParameters_const,
235 &PE_Function::On_afterParameters_volatile,
236 &PE_Function::On_afterParameters_throw,
237 &PE_Function::On_afterParameters_SwBracket_Left,
238 &PE_Function::On_afterParameters_Semicolon,
239 &PE_Function::On_afterParameters_Comma,
240 &PE_Function::On_afterParameters_Colon,
241 &PE_Function::On_afterParameters_Assign };
242 static INT16 stateT_afterParameters[] = { Tid_const,
243 Tid_volatile,
244 Tid_throw,
245 Tid_SwBracket_Left,
246 Tid_Semicolon,
247 Tid_Comma,
248 Tid_Colon,
249 Tid_Assign };
251 static F_Tok stateF_afterThrow[] = { &PE_Function::On_afterThrow_Bracket_Left };
252 static INT16 stateT_afterThrow[] = { Tid_Bracket_Left };
254 static F_Tok stateF_expectExceptionSeparator[] =
255 { &PE_Function::On_expectExceptionSeparator_BracketRight,
256 &PE_Function::On_expectExceptionSeparator_Comma };
257 static INT16 stateT_expectExceptionSeparator[] =
258 { Tid_Bracket_Right,
259 Tid_Comma };
261 static F_Tok stateF_afterExceptions[] = { &PE_Function::On_afterExceptions_SwBracket_Left,
262 &PE_Function::On_afterExceptions_Semicolon,
263 &PE_Function::On_afterExceptions_Comma,
264 &PE_Function::On_afterExceptions_Colon,
265 &PE_Function::On_afterExceptions_Assign };
266 static INT16 stateT_afterExceptions[] = { Tid_SwBracket_Left,
267 Tid_Semicolon,
268 Tid_Comma,
269 Tid_Colon,
270 Tid_Assign };
272 static F_Tok stateF_expectZero[] = { &PE_Function::On_expectZero_Constant };
273 static INT16 stateT_expectZero[] = { Tid_Constant };
275 static F_Tok stateF_inImplementation[] =
276 { &PE_Function::On_inImplementation_SwBracket_Left,
277 &PE_Function::On_inImplementation_SwBracket_Right };
278 static INT16 stateT_inImplementation[] =
279 { Tid_SwBracket_Left,
280 Tid_SwBracket_Right };
282 SEMPARSE_CREATE_STATUS(PE_Function, afterStdOperator, Hdl_SyntaxError);
283 SEMPARSE_CREATE_STATUS(PE_Function, afterStdOperatorLeftBracket, Hdl_SyntaxError);
284 SEMPARSE_CREATE_STATUS(PE_Function, afterCastOperator, Hdl_SyntaxError);
285 SEMPARSE_CREATE_STATUS(PE_Function, afterName, Hdl_SyntaxError);
286 SEMPARSE_CREATE_STATUS(PE_Function, expectParameterSeparator, Hdl_SyntaxError);
287 SEMPARSE_CREATE_STATUS(PE_Function, afterParameters, Hdl_SyntaxError);
288 SEMPARSE_CREATE_STATUS(PE_Function, afterThrow, Hdl_SyntaxError);
289 SEMPARSE_CREATE_STATUS(PE_Function, expectExceptionSeparator, Hdl_SyntaxError);
290 SEMPARSE_CREATE_STATUS(PE_Function, afterExceptions, Hdl_SyntaxError);
291 SEMPARSE_CREATE_STATUS(PE_Function, expectZero, Hdl_SyntaxError);
292 SEMPARSE_CREATE_STATUS(PE_Function, inImplementation, On_inImplementation_Default );
295 void
296 PE_Function::InitData()
298 pStati->SetCur( afterName ),
299 nResult = 0;
300 bResult_WithImplementation = false;
301 aName.seekp(0);
302 eVirtuality = ary::cpp::VIRTUAL_none;
303 eConVol = ary::cpp::CONVOL_none;
304 aFlags.Reset();
305 nReturnType = 0;
306 csv::erase_container(aParameters);
307 csv::erase_container(aExceptions);
308 bThrow = false;
311 void
312 PE_Function::TransferData()
314 String sName( aName.c_str() );
315 ary::cpp::Function *
316 pFunction = Env().AryGate().Ces().Store_Operation(
317 Env().Context(),
318 sName,
319 nReturnType,
320 aParameters,
321 eVirtuality,
322 eConVol,
323 aFlags,
324 bThrow,
325 aExceptions );
326 if (pFunction != 0)
328 // KORR_FUTURE: How to handle differing documentation?
330 Dyn< StringVector >
331 pTplParams ( Env().Get_CurTemplateParameters() );
332 if ( pTplParams )
334 for ( StringVector::const_iterator it = pTplParams->begin();
335 it != pTplParams->end();
336 ++it )
338 pFunction->Add_TemplateParameterType( *it, ary::cpp::Type_id(0) );
339 } // end for
342 Env().Event_Store_Function(*pFunction);
345 pStati->SetCur(size_of_states);
348 void
349 PE_Function::Hdl_SyntaxError(const char * i_sText)
351 StdHandlingOfSyntaxError(i_sText);
354 void
355 PE_Function::SpInit_CastOperatorType()
357 pSpuCastOperatorType->Child().Init_AsCastOperatorType();
360 void
361 PE_Function::SpReturn_Parameter()
363 pStati->SetCur(expectParameterSeparator);
365 ary::cpp::Type_id nParamType = pSpuParameter->Child().Result_FrontType();
366 if ( nParamType.IsValid() ) // Check, if there was a parameter, or only the closing ')'.
368 aParameters.push_back( pSpuParameter->Child().Result_ParamInfo() );
372 void
373 PE_Function::SpReturn_Exception()
375 pStati->SetCur(expectExceptionSeparator);
377 ary::cpp::Type_id
378 nException = pSpuException->Child().Result_Type().TypeId();
379 if ( nException.IsValid() AND pSpuException->Child().Result_KindOf() == PE_Type::is_type )
381 aExceptions.push_back( nException );
385 void
386 PE_Function::SpReturn_CastOperatorType()
388 pStati->SetCur(afterName);
390 Env().AryGate().Types().Get_TypeText(
391 aName, pSpuCastOperatorType->Child().Result_Type().TypeId() );
394 void
395 PE_Function::On_afterOperator_Std_Operator(const char * i_sText)
397 SetTokenResult(done,stay);
398 pStati->SetCur(afterName);
400 if ( 'a' <= *i_sText AND *i_sText <= 'z' )
401 aName << ' ';
402 aName << i_sText;
405 void
406 PE_Function::On_afterOperator_Std_LeftBracket(const char * i_sText)
408 SetTokenResult(done,stay);
409 pStati->SetCur(afterStdOperatorLeftBracket);
411 aName << i_sText;
414 void
415 PE_Function::On_afterStdOperatorLeftBracket_RightBracket(const char * i_sText)
417 SetTokenResult(done,stay);
418 pStati->SetCur(afterName);
420 aName << i_sText;
423 void
424 PE_Function::On_afterOperator_Cast_Type(const char *)
426 pSpuCastOperatorType->Push(not_done);
429 void
430 PE_Function::On_afterName_Bracket_Left(const char *)
432 pSpuParameter->Push(done);
435 void
436 PE_Function::On_expectParameterSeparator_BracketRight(const char *)
438 SetTokenResult(done,stay);
439 pStati->SetCur(afterParameters);
442 void
443 PE_Function::On_expectParameterSeparator_Comma(const char *)
445 pSpuParameter->Push(done);
448 void
449 PE_Function::On_afterParameters_const(const char *)
451 SetTokenResult(done,stay);
452 eConVol = static_cast<E_ConVol>(
453 static_cast<int>(eConVol) | static_cast<int>(ary::cpp::CONVOL_const) );
456 void
457 PE_Function::On_afterParameters_volatile(const char *)
459 SetTokenResult(done,stay);
460 eConVol = static_cast<E_ConVol>(
461 static_cast<int>(eConVol) | static_cast<int>(ary::cpp::CONVOL_volatile) );
464 void
465 PE_Function::On_afterParameters_throw(const char *)
467 SetTokenResult(done,stay);
468 pStati->SetCur(afterThrow);
469 bThrow = true;
472 void
473 PE_Function::On_afterParameters_SwBracket_Left(const char *)
475 EnterImplementation(1);
478 void
479 PE_Function::On_afterParameters_Semicolon(const char *)
481 PerformFinishingPunctuation();
484 void
485 PE_Function::On_afterParameters_Comma(const char *)
487 PerformFinishingPunctuation();
490 void
491 PE_Function::On_afterParameters_Colon(const char *)
493 EnterImplementation(0);
496 void
497 PE_Function::On_afterParameters_Assign(const char *)
499 SetTokenResult(done,stay);
500 pStati->SetCur(expectZero);
503 void
504 PE_Function::On_afterThrow_Bracket_Left(const char *)
506 pSpuException->Push(done);
509 void
510 PE_Function::On_expectExceptionSeparator_BracketRight(const char *)
512 SetTokenResult(done,stay);
513 pStati->SetCur(afterExceptions);
516 void
517 PE_Function::On_expectExceptionSeparator_Comma(const char *)
519 pSpuException->Push(done);
522 void
523 PE_Function::On_afterExceptions_SwBracket_Left(const char *)
525 EnterImplementation(1);
528 void
529 PE_Function::On_afterExceptions_Semicolon(const char *)
531 PerformFinishingPunctuation();
534 void
535 PE_Function::On_afterExceptions_Comma(const char *)
537 PerformFinishingPunctuation();
540 void
541 PE_Function::On_afterExceptions_Colon(const char *)
543 EnterImplementation(0);
546 void
547 PE_Function::On_afterExceptions_Assign(const char *)
549 SetTokenResult(done,stay);
550 pStati->SetCur(expectZero);
553 void
554 PE_Function::On_expectZero_Constant(const char * i_sText)
556 if ( strcmp(i_sText,"0") != 0 )
557 Hdl_SyntaxError(i_sText);
559 SetTokenResult(done,stay);
560 pStati->SetCur(afterExceptions);
562 eVirtuality = ary::cpp::VIRTUAL_abstract;
565 void
566 PE_Function::On_inImplementation_SwBracket_Left(const char *)
568 SetTokenResult(done,stay);
569 nBracketCounterInImplementation++;
572 void
573 PE_Function::On_inImplementation_SwBracket_Right(const char *)
575 nBracketCounterInImplementation--;
576 if (nBracketCounterInImplementation == 0)
578 SetTokenResult(done,pop_success);
580 else
582 SetTokenResult(done,stay);
586 void
587 PE_Function::On_inImplementation_Default(const char *)
589 SetTokenResult(done,stay);
592 void
593 PE_Function::EnterImplementation( intt i_nBracketCountStart )
595 SetTokenResult(done,stay);
596 pStati->SetCur(inImplementation);
598 bResult_WithImplementation = true;
599 nBracketCounterInImplementation = i_nBracketCountStart;
600 if ( Env().Context().CurClass() != 0 )
602 aFlags.SetInline();
608 } // namespace cpp