1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pe_funct.cxx,v $
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 ************************************************************************/
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"
54 PE_Function::PerformFinishingPunctuation()
56 SetTokenResult(not_done
,pop_success
);
60 PE_Function::PE_Function( Cpp_PE
* i_pParent
)
62 pStati( new PeStatusArray
<PE_Function
> ),
67 // pSpuCastOperatorType,
69 bResult_WithImplementation(false),
71 eVirtuality(ary::cpp::VIRTUAL_none
),
72 eConVol(ary::cpp::CONVOL_none
),
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()
96 PE_Function::Init_Std( const String
& i_sName
,
97 ary::cpp::Type_id i_nReturnType
,
99 ary::cpp::FunctionFlags i_aFlags
)
102 eVirtuality
= i_bVirtual
? ary::cpp::VIRTUAL_virtual
: ary::cpp::VIRTUAL_none
;
104 nReturnType
= i_nReturnType
;
105 pStati
->SetCur(afterName
);
109 PE_Function::Init_Ctor( const String
& i_sName
,
110 ary::cpp::FunctionFlags i_aFlags
)
113 eVirtuality
= ary::cpp::VIRTUAL_none
;
116 pStati
->SetCur(afterName
);
120 PE_Function::Init_Dtor( const String
& i_sName
,
122 ary::cpp::FunctionFlags i_aFlags
)
124 aName
<< "~" << i_sName
;
125 eVirtuality
= i_bVirtual
? ary::cpp::VIRTUAL_virtual
: ary::cpp::VIRTUAL_none
;
128 pStati
->SetCur(afterName
);
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
;
139 pStati
->SetCur(afterCastOperator
);
143 PE_Function::Init_NormalOperator( ary::cpp::Type_id i_nReturnType
,
145 ary::cpp::FunctionFlags i_aFlags
)
148 eVirtuality
= i_bVirtual
? ary::cpp::VIRTUAL_virtual
: ary::cpp::VIRTUAL_none
;
150 nReturnType
= i_nReturnType
;
151 pStati
->SetCur(afterStdOperator
);
155 PE_Function::Result_Id() const
161 PE_Function::Call_Handler( const cpp::Token
& i_rTok
)
163 pStati
->Cur().Call_Handler(i_rTok
.TypeId(), i_rTok
.Text());
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
[] =
183 Tid_ArrayBracket_Left
,
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
,
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
[] =
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
[] =
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
,
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
[] =
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
,
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
);
296 PE_Function::InitData()
298 pStati
->SetCur( afterName
),
300 bResult_WithImplementation
= false;
302 eVirtuality
= ary::cpp::VIRTUAL_none
;
303 eConVol
= ary::cpp::CONVOL_none
;
306 csv::erase_container(aParameters
);
307 csv::erase_container(aExceptions
);
312 PE_Function::TransferData()
314 String
sName( aName
.c_str() );
316 pFunction
= Env().AryGate().Ces().Store_Operation(
328 // KORR_FUTURE: How to handle differing documentation?
331 pTplParams ( Env().Get_CurTemplateParameters() );
334 for ( StringVector::const_iterator it
= pTplParams
->begin();
335 it
!= pTplParams
->end();
338 pFunction
->Add_TemplateParameterType( *it
, ary::cpp::Type_id(0) );
342 Env().Event_Store_Function(*pFunction
);
345 pStati
->SetCur(size_of_states
);
349 PE_Function::Hdl_SyntaxError(const char * i_sText
)
351 StdHandlingOfSyntaxError(i_sText
);
355 PE_Function::SpInit_CastOperatorType()
357 pSpuCastOperatorType
->Child().Init_AsCastOperatorType();
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() );
373 PE_Function::SpReturn_Exception()
375 pStati
->SetCur(expectExceptionSeparator
);
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
);
386 PE_Function::SpReturn_CastOperatorType()
388 pStati
->SetCur(afterName
);
390 Env().AryGate().Types().Get_TypeText(
391 aName
, pSpuCastOperatorType
->Child().Result_Type().TypeId() );
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' )
406 PE_Function::On_afterOperator_Std_LeftBracket(const char * i_sText
)
408 SetTokenResult(done
,stay
);
409 pStati
->SetCur(afterStdOperatorLeftBracket
);
415 PE_Function::On_afterStdOperatorLeftBracket_RightBracket(const char * i_sText
)
417 SetTokenResult(done
,stay
);
418 pStati
->SetCur(afterName
);
424 PE_Function::On_afterOperator_Cast_Type(const char *)
426 pSpuCastOperatorType
->Push(not_done
);
430 PE_Function::On_afterName_Bracket_Left(const char *)
432 pSpuParameter
->Push(done
);
436 PE_Function::On_expectParameterSeparator_BracketRight(const char *)
438 SetTokenResult(done
,stay
);
439 pStati
->SetCur(afterParameters
);
443 PE_Function::On_expectParameterSeparator_Comma(const char *)
445 pSpuParameter
->Push(done
);
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
) );
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
) );
465 PE_Function::On_afterParameters_throw(const char *)
467 SetTokenResult(done
,stay
);
468 pStati
->SetCur(afterThrow
);
473 PE_Function::On_afterParameters_SwBracket_Left(const char *)
475 EnterImplementation(1);
479 PE_Function::On_afterParameters_Semicolon(const char *)
481 PerformFinishingPunctuation();
485 PE_Function::On_afterParameters_Comma(const char *)
487 PerformFinishingPunctuation();
491 PE_Function::On_afterParameters_Colon(const char *)
493 EnterImplementation(0);
497 PE_Function::On_afterParameters_Assign(const char *)
499 SetTokenResult(done
,stay
);
500 pStati
->SetCur(expectZero
);
504 PE_Function::On_afterThrow_Bracket_Left(const char *)
506 pSpuException
->Push(done
);
510 PE_Function::On_expectExceptionSeparator_BracketRight(const char *)
512 SetTokenResult(done
,stay
);
513 pStati
->SetCur(afterExceptions
);
517 PE_Function::On_expectExceptionSeparator_Comma(const char *)
519 pSpuException
->Push(done
);
523 PE_Function::On_afterExceptions_SwBracket_Left(const char *)
525 EnterImplementation(1);
529 PE_Function::On_afterExceptions_Semicolon(const char *)
531 PerformFinishingPunctuation();
535 PE_Function::On_afterExceptions_Comma(const char *)
537 PerformFinishingPunctuation();
541 PE_Function::On_afterExceptions_Colon(const char *)
543 EnterImplementation(0);
547 PE_Function::On_afterExceptions_Assign(const char *)
549 SetTokenResult(done
,stay
);
550 pStati
->SetCur(expectZero
);
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
;
566 PE_Function::On_inImplementation_SwBracket_Left(const char *)
568 SetTokenResult(done
,stay
);
569 nBracketCounterInImplementation
++;
573 PE_Function::On_inImplementation_SwBracket_Right(const char *)
575 nBracketCounterInImplementation
--;
576 if (nBracketCounterInImplementation
== 0)
578 SetTokenResult(done
,pop_success
);
582 SetTokenResult(done
,stay
);
587 PE_Function::On_inImplementation_Default(const char *)
589 SetTokenResult(done
,stay
);
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 )