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_vafu.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_vafu.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/tpl/tpltools.hxx>
37 #include <ary/cpp/c_gate.hxx>
38 #include <ary/cpp/c_class.hxx>
39 #include <ary/cpp/c_vari.hxx>
40 #include <ary/cpp/c_vfflag.hxx>
41 #include <ary/cpp/cp_ce.hxx>
42 #include <ary/cpp/inpcontx.hxx>
43 #include "pe_type.hxx"
44 #include "pe_vari.hxx"
45 #include "pe_funct.hxx"
46 #include "pe_ignor.hxx"
47 #include <x_parse.hxx>
56 //*********************** PE_VarFunc ***********************//
59 PE_VarFunc::PE_VarFunc( Cpp_PE
* i_pParent
)
61 pStati( new PeStatusArray
<PE_VarFunc
> ),
70 // pSpuFunctionCastOperator,
71 // pSpuFunctionNormalOperator
74 nCounter_TemplateBrackets(0),
78 eResultType(result_unknown
),
88 Setup_StatusFunctions();
90 pSpType
= new SP_Type(*this);
91 pSpuType
= new SPU_Type(*pSpType
, 0, &PE_VarFunc::SpReturn_Type
);
92 pSpVariable
= new SP_Variable(*this);
93 pSpuVariable
= new SPU_Variable(*pSpVariable
, 0, &PE_VarFunc::SpReturn_Variable
);
94 pSpFunction
= new SP_Function(*this);
95 pSpuFunctionStd
= new SPU_Function(*pSpFunction
, &PE_VarFunc::SpInit_FunctionStd
, &PE_VarFunc::SpReturn_FunctionStd
);
96 pSpuFunctionCtor
= new SPU_Function(*pSpFunction
, &PE_VarFunc::SpInit_FunctionCtor
, &PE_VarFunc::SpReturn_FunctionStd
);
97 pSpuFunctionDtor
= new SPU_Function(*pSpFunction
, &PE_VarFunc::SpInit_FunctionDtor
, &PE_VarFunc::SpReturn_FunctionStd
);
98 pSpuFunctionCastOperator
99 = new SPU_Function(*pSpFunction
, &PE_VarFunc::SpInit_FunctionCastOperator
, &PE_VarFunc::SpReturn_FunctionStd
);
100 pSpuFunctionNormalOperator
101 = new SPU_Function(*pSpFunction
, &PE_VarFunc::SpInit_FunctionNormalOperator
, &PE_VarFunc::SpReturn_FunctionStd
);
102 pSpIgnore
= new SP_Ignore(*this);
103 pSpuIgnore
= new SPU_Ignore(*pSpIgnore
, 0, &PE_VarFunc::SpReturn_Ignore
);
106 PE_VarFunc::~PE_VarFunc()
111 PE_VarFunc::Call_Handler( const cpp::Token
& i_rTok
)
113 pStati
->Cur().Call_Handler(i_rTok
.TypeId(), i_rTok
.Text());
117 PE_VarFunc::Setup_StatusFunctions()
119 typedef CallFunction
<PE_VarFunc
>::F_Tok F_Tok
;
121 static F_Tok stateF_start
[] = { &PE_VarFunc::On_start_Identifier
,
122 &PE_VarFunc::On_start_operator
,
123 &PE_VarFunc::On_start_TypeKey
,
124 &PE_VarFunc::On_start_TypeKey
,
125 &PE_VarFunc::On_start_TypeKey
,
126 &PE_VarFunc::On_start_TypeKey
,
127 &PE_VarFunc::On_start_virtual
,
128 &PE_VarFunc::On_start_Tilde
,
129 &PE_VarFunc::On_start_const
,
130 &PE_VarFunc::On_start_volatile
,
131 &PE_VarFunc::On_start_extern
,
132 &PE_VarFunc::On_start_static
,
133 &PE_VarFunc::On_start_mutable
,
134 &PE_VarFunc::On_start_register
,
135 &PE_VarFunc::On_start_inline
,
136 &PE_VarFunc::On_start_explicit
,
137 &PE_VarFunc::On_start_Bracket_Right
,
138 &PE_VarFunc::On_start_Identifier
,
139 &PE_VarFunc::On_start_typename
,
140 &PE_VarFunc::On_start_Identifier
,
141 &PE_VarFunc::On_start_Identifier
};
142 static INT16 stateT_start
[] = { Tid_Identifier
,
162 Tid_TypeSpecializer
};
164 static F_Tok stateF_expectCtor
[] = { &PE_VarFunc::On_expectCtor_Bracket_Left
};
165 static INT16 stateT_expectCtor
[] = { Tid_Bracket_Left
};
167 static F_Tok stateF_afterClassDecl
[] = { &PE_VarFunc::On_afterClassDecl_Semicolon
};
168 static INT16 stateT_afterClassDecl
[] = { Tid_Semicolon
};
170 static F_Tok stateF_expectName
[] = { &PE_VarFunc::On_expectName_Identifier
,
171 &PE_VarFunc::On_expectName_operator
,
172 &PE_VarFunc::On_expectName_Bracket_Left
};
173 static INT16 stateT_expectName
[] = { Tid_Identifier
,
177 static F_Tok stateF_afterName
[] = { &PE_VarFunc::On_afterName_ArrayBracket_Left
,
178 &PE_VarFunc::On_afterName_Bracket_Left
,
179 &PE_VarFunc::On_afterName_DoubleColon
,
180 &PE_VarFunc::On_afterName_Semicolon
,
181 &PE_VarFunc::On_afterName_Comma
,
182 &PE_VarFunc::On_afterName_Assign
,
183 &PE_VarFunc::On_afterName_Less
};
184 static INT16 stateT_afterName
[] = { Tid_ArrayBracket_Left
,
192 static F_Tok stateF_afterName_inErraneousTemplate
[] =
193 { &PE_VarFunc::On_afterName_inErraneousTemplate_Less
,
194 &PE_VarFunc::On_afterName_inErraneousTemplate_Greater
};
195 static INT16 stateT_afterName_inErraneousTemplate
[] =
199 static F_Tok stateF_finished
[] = { &PE_VarFunc::On_finished_Semicolon
,
200 &PE_VarFunc::On_finished_Comma
};
201 static INT16 stateT_finished
[] = { Tid_Semicolon
,
204 static F_Tok stateF_finishedIncludingFunctionImplementation
[] =
205 { &PE_VarFunc::On_finishedIncludingFunctionImplementation_Default
207 static INT16 stateT_finishedIncludingFunctionImplementation
[] =
208 { Tid_BuiltInType
// Just to have one entry, but it is default handled, too.
211 SEMPARSE_CREATE_STATUS(PE_VarFunc
, start
, Hdl_UnknownToken
);
212 SEMPARSE_CREATE_STATUS(PE_VarFunc
, expectCtor
, Hdl_UnknownToken
);
213 SEMPARSE_CREATE_STATUS(PE_VarFunc
, afterClassDecl
, Hdl_UnknownToken
);
214 SEMPARSE_CREATE_STATUS(PE_VarFunc
, expectName
, Hdl_UnknownToken
);
215 SEMPARSE_CREATE_STATUS(PE_VarFunc
, afterName
, Hdl_UnknownToken
);
216 SEMPARSE_CREATE_STATUS(PE_VarFunc
, afterName_inErraneousTemplate
, On_afterName_inErraneousTemplate_Default
);
217 SEMPARSE_CREATE_STATUS(PE_VarFunc
, finished
, On_finished_Default
);
218 SEMPARSE_CREATE_STATUS(PE_VarFunc
, finishedIncludingFunctionImplementation
, On_finishedIncludingFunctionImplementation_Default
);
222 PE_VarFunc::InitData()
224 pStati
->SetCur(start
);
225 csv::erase_container(aResultIds
);
227 nCounter_TemplateBrackets
= 0;
228 bInDestructor
= false;
230 nResultFrontType
= 0;
231 eResultType
= result_unknown
;
233 bVirtual
= ary::cpp::VIRTUAL_none
;
244 PE_VarFunc::TransferData()
246 pStati
->SetCur(size_of_states
);
250 PE_VarFunc::Hdl_UnknownToken( const char *)
252 pSpuIgnore
->Push(not_done
);
256 PE_VarFunc::SpInit_FunctionStd()
258 if ( nResultFrontType
.IsValid() AND sName
.length() > 0 )
260 pSpuFunctionStd
->Child().Init_Std(
264 CreateFunctionFlags() );
268 throw X_Parser( X_Parser::x_UnexpectedToken
,
276 PE_VarFunc::SpInit_FunctionCtor()
278 ary::cpp::Class
* pOwnerClass
= Env().Context().CurClass();
279 csv_assert( pOwnerClass
!= 0 );
280 pSpuFunctionStd
->Child().Init_Ctor( pOwnerClass
->LocalName(),
281 CreateFunctionFlags() );
285 PE_VarFunc::SpInit_FunctionDtor()
287 pSpuFunctionStd
->Child().Init_Dtor( sName
,
289 CreateFunctionFlags() );
293 PE_VarFunc::SpInit_FunctionCastOperator()
295 pSpuFunctionStd
->Child().Init_CastOperator( bVirtual
,
296 CreateFunctionFlags() );
300 PE_VarFunc::SpInit_FunctionNormalOperator()
302 pSpuFunctionStd
->Child().Init_NormalOperator( nResultFrontType
,
304 CreateFunctionFlags() );
308 PE_VarFunc::SpReturn_Type()
310 switch ( pSpuType
->Child().Result_KindOf() )
312 case PE_Type::is_type
:
313 pStati
->SetCur(expectName
);
315 = pSpuType
->Child().Result_Type().Id();
317 case PE_Type::is_constructor
:
318 pStati
->SetCur(expectCtor
);
319 eResultType
= result_function
;
321 case PE_Type::is_explicit_class_declaration
:
322 case PE_Type::is_explicit_enum_declaration
:
323 pStati
->SetCur(afterClassDecl
);
324 eResultType
= result_ignore
;
326 case PE_Type::is_class_predeclaration
:
327 pStati
->SetCur(afterClassDecl
);
328 eResultType
= result_ignore
;
336 PE_VarFunc::SpReturn_Variable()
338 typedef ary::cpp::VariableFlags VarFlags
;
342 VarFlags
aFlags( UINT16(
343 ( bStatic AND
Env().Context().CurClass() == 0 ? VarFlags::f_static_local
: 0 )
344 | ( bStatic AND
Env().Context().CurClass() != 0 ? VarFlags::f_static_member
: 0 )
345 | ( bMutable
? VarFlags::f_mutable
: 0 ) )
348 // ary::S_InitData aData( 0, Env().CurCeSpace().Id(), i_sName, 0 );
349 ary::cpp::Variable
& rCurParsedVariable
350 = Env().AryGate().Ces().Store_Variable( Env().Context(),
354 pSpuVariable
->Child().Result_SizeExpression(),
355 pSpuVariable
->Child().Result_InitExpression() );
356 Env().Event_Store_Variable(rCurParsedVariable
);
357 aResultIds
.push_back( rCurParsedVariable
.CeId() );
358 eResultType
= result_variable
;
362 eResultType
= result_ignore
;
365 pStati
->SetCur(finished
);
369 PE_VarFunc::SpReturn_FunctionStd()
371 if ( (NOT bExtern
) OR bExternC
)
373 aResultIds
.push_back(pSpuFunctionStd
->Child().Result_Id());
374 eResultType
= result_function
;
378 eResultType
= result_ignore
;
381 if ( NOT pSpuFunctionStd
->Child().Result_WithImplementation() )
382 pStati
->SetCur(finished
);
384 pStati
->SetCur(finishedIncludingFunctionImplementation
);
388 PE_VarFunc::SpReturn_Ignore()
390 pStati
->SetCur(finished
);
394 PE_VarFunc::On_start_Identifier(const char *)
396 pSpuType
->Push(not_done
);
400 PE_VarFunc::On_start_operator(const char *)
402 pSpuFunctionCastOperator
->Push(done
);
406 PE_VarFunc::On_start_TypeKey(const char *)
408 pSpuType
->Push(not_done
);
412 PE_VarFunc::On_start_virtual(const char *)
414 SetTokenResult(done
, stay
);
419 PE_VarFunc::On_start_Tilde(const char *)
421 SetTokenResult(done
, stay
);
422 pStati
->SetCur(expectName
);
424 bInDestructor
= true;
428 PE_VarFunc::On_start_const(const char *)
430 pSpuType
->Push(not_done
);
434 PE_VarFunc::On_start_volatile(const char *)
436 pSpuType
->Push(not_done
);
440 PE_VarFunc::On_start_extern(const char *)
442 SetTokenResult(done
, stay
);
447 PE_VarFunc::On_start_static(const char *)
449 SetTokenResult(done
, stay
);
454 PE_VarFunc::On_start_mutable(const char *)
456 SetTokenResult(done
, stay
);
461 PE_VarFunc::On_start_register(const char *)
463 SetTokenResult(done
, stay
);
468 PE_VarFunc::On_start_inline(const char *)
470 SetTokenResult(done
, stay
);
476 PE_VarFunc::On_start_explicit(const char *)
478 SetTokenResult(done
, stay
);
483 PE_VarFunc::On_start_Bracket_Right(const char *)
485 SetTokenResult(not_done
, pop_success
);
489 PE_VarFunc::On_start_typename(const char *)
491 pSpuType
->Push(not_done
);
495 PE_VarFunc::On_expectCtor_Bracket_Left(const char *)
497 pSpuFunctionCtor
->Push(not_done
);
501 PE_VarFunc::On_afterClassDecl_Semicolon(const char *)
503 SetTokenResult(done
, pop_success
);
507 PE_VarFunc::On_expectName_Identifier(const char * i_sText
)
509 SetTokenResult(done
, stay
);
510 pStati
->SetCur(afterName
);
515 PE_VarFunc::On_expectName_operator(const char *)
517 pSpuFunctionNormalOperator
->Push(done
);
521 PE_VarFunc::On_expectName_Bracket_Left(const char *)
523 // Function pointer declaration
524 pSpuIgnore
->Push(not_done
);
530 PE_VarFunc::On_afterName_ArrayBracket_Left(const char *)
532 pSpuVariable
->Push(not_done
);
536 PE_VarFunc::On_afterName_Bracket_Left(const char *)
538 if ( NOT bInDestructor
)
539 pSpuFunctionStd
->Push(not_done
);
541 pSpuFunctionDtor
->Push(not_done
);
545 PE_VarFunc::On_afterName_DoubleColon(const char *)
547 pSpuIgnore
->Push(done
); // This seems to be only an implementation.
549 // This may have been a template.
550 // In that case, the declaration needs to be closed.
551 Env().Close_OpenTemplate();
555 PE_VarFunc::On_afterName_Semicolon(const char *)
557 pSpuVariable
->Push(not_done
);
561 PE_VarFunc::On_afterName_Comma(const char *)
563 pSpuVariable
->Push(not_done
);
567 PE_VarFunc::On_afterName_Assign(const char * )
569 pSpuVariable
->Push(not_done
);
573 PE_VarFunc::On_afterName_Less(const char * )
575 SetTokenResult(done
, stay
);
576 pStati
->SetCur(afterName_inErraneousTemplate
);
578 nCounter_TemplateBrackets
= 1;
582 PE_VarFunc::On_afterName_inErraneousTemplate_Less(const char * )
584 SetTokenResult(done
, stay
);
586 nCounter_TemplateBrackets
++;
590 PE_VarFunc::On_afterName_inErraneousTemplate_Greater(const char * )
592 SetTokenResult(done
, stay
);
594 nCounter_TemplateBrackets
--;
595 if ( nCounter_TemplateBrackets
== 0 )
596 pStati
->SetCur(afterName
);
600 PE_VarFunc::On_afterName_inErraneousTemplate_Default(const char * )
602 SetTokenResult(done
, stay
);
606 PE_VarFunc::On_finished_Semicolon(const char * ) // Should be Semicolon !!!
608 SetTokenResult(done
, pop_success
);
612 PE_VarFunc::On_finished_Comma(const char * )
614 SetTokenResult(done
, stay
);
615 pStati
->SetCur(expectName
);
619 PE_VarFunc::On_finished_Default(const char * )
621 SetTokenResult(not_done
, pop_success
);
625 PE_VarFunc::On_finishedIncludingFunctionImplementation_Default(const char * )
627 SetTokenResult(not_done
, pop_success
);
630 ary::cpp::FunctionFlags
631 PE_VarFunc::CreateFunctionFlags()
633 typedef ary::cpp::FunctionFlags FuncFlags
;
635 return FuncFlags( UINT16(
636 ( bStatic AND
Env().Context().CurClass() == 0 ? FuncFlags::f_static_local
: 0 )
637 | ( bStatic AND
Env().Context().CurClass() != 0 ? FuncFlags::f_static_member
: 0 )
638 | ( bExtern
? FuncFlags::f_extern
: 0 )
639 | ( Env().IsExternC() ? FuncFlags::f_externC
: 0 )
640 | ( bMutable
? FuncFlags::f_mutable
: 0 )
641 | ( bInline
? FuncFlags::f_inline
: 0 )
642 | ( bRegister
? FuncFlags::f_register
: 0 )
643 | ( bExplicit
? FuncFlags::f_explicit
: 0 ) )