merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / parser / cpp / pe_vafu.cxx
blob3e76b3e3e04b6e8c3228552f2f8d9aa31ee45d89
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_vafu.cxx,v $
10 * $Revision: 1.12 $
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_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>
52 namespace cpp {
56 //*********************** PE_VarFunc ***********************//
59 PE_VarFunc::PE_VarFunc( Cpp_PE * i_pParent )
60 : Cpp_PE(i_pParent),
61 pStati( new PeStatusArray<PE_VarFunc> ),
62 // pSpType,
63 // pSpuType,
64 // pSpVariable,
65 // pSpuVariable,
66 // pSpFunction,
67 // pSpuFunctionStd,
68 // pSpuFunctionCtor,
69 // pSpuFunctionDtor,
70 // pSpuFunctionCastOperator,
71 // pSpuFunctionNormalOperator
72 // pSpIgnore,
73 // pSpuIgnore,
74 nCounter_TemplateBrackets(0),
75 bInDestructor(false),
76 // aResultIds,
77 nResultFrontType(0),
78 eResultType(result_unknown),
79 bVirtual(false),
80 bStatic(false),
81 bExtern(false),
82 bExternC(false),
83 bMutable(false),
84 bInline(false),
85 bRegister(false),
86 bExplicit(false)
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()
110 void
111 PE_VarFunc::Call_Handler( const cpp::Token & i_rTok )
113 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
116 void
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,
143 Tid_operator,
144 Tid_class,
145 Tid_struct,
146 Tid_union,
147 Tid_enum,
148 Tid_virtual,
149 Tid_Tilde,
150 Tid_const,
151 Tid_volatile,
152 Tid_extern,
153 Tid_static,
154 Tid_mutable,
155 Tid_register,
156 Tid_inline,
157 Tid_explicit,
158 Tid_Bracket_Right,
159 Tid_DoubleColon,
160 Tid_typename,
161 Tid_BuiltInType,
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,
174 Tid_operator,
175 Tid_Bracket_Left };
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,
185 Tid_Bracket_Left,
186 Tid_DoubleColon,
187 Tid_Semicolon,
188 Tid_Comma,
189 Tid_Assign,
190 Tid_Less };
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[] =
196 { Tid_Less,
197 Tid_Greater };
199 static F_Tok stateF_finished[] = { &PE_VarFunc::On_finished_Semicolon,
200 &PE_VarFunc::On_finished_Comma };
201 static INT16 stateT_finished[] = { Tid_Semicolon,
202 Tid_Comma };
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);
221 void
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;
232 sName.clear();
233 bVirtual = ary::cpp::VIRTUAL_none;
234 bStatic = false;
235 bExtern = false;
236 bExternC = false;
237 bMutable = false;
238 bInline = false;
239 bRegister = false;
240 bExplicit = false;
243 void
244 PE_VarFunc::TransferData()
246 pStati->SetCur(size_of_states);
249 void
250 PE_VarFunc::Hdl_UnknownToken( const char *)
252 pSpuIgnore->Push(not_done);
255 void
256 PE_VarFunc::SpInit_FunctionStd()
258 if ( nResultFrontType.IsValid() AND sName.length() > 0 )
260 pSpuFunctionStd->Child().Init_Std(
261 sName,
262 nResultFrontType,
263 bVirtual,
264 CreateFunctionFlags() );
266 else
268 throw X_Parser( X_Parser::x_UnexpectedToken,
270 Env().CurFileName(),
271 Env().LineCount() );
275 void
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() );
284 void
285 PE_VarFunc::SpInit_FunctionDtor()
287 pSpuFunctionStd->Child().Init_Dtor( sName,
288 bVirtual,
289 CreateFunctionFlags() );
292 void
293 PE_VarFunc::SpInit_FunctionCastOperator()
295 pSpuFunctionStd->Child().Init_CastOperator( bVirtual,
296 CreateFunctionFlags() );
299 void
300 PE_VarFunc::SpInit_FunctionNormalOperator()
302 pSpuFunctionStd->Child().Init_NormalOperator( nResultFrontType,
303 bVirtual,
304 CreateFunctionFlags() );
307 void
308 PE_VarFunc::SpReturn_Type()
310 switch ( pSpuType->Child().Result_KindOf() )
312 case PE_Type::is_type:
313 pStati->SetCur(expectName);
314 nResultFrontType
315 = pSpuType->Child().Result_Type().Id();
316 break;
317 case PE_Type::is_constructor:
318 pStati->SetCur(expectCtor);
319 eResultType = result_function;
320 break;
321 case PE_Type::is_explicit_class_declaration:
322 case PE_Type::is_explicit_enum_declaration:
323 pStati->SetCur(afterClassDecl);
324 eResultType = result_ignore;
325 break;
326 case PE_Type::is_class_predeclaration:
327 pStati->SetCur(afterClassDecl);
328 eResultType = result_ignore;
329 break;
330 default:
335 void
336 PE_VarFunc::SpReturn_Variable()
338 typedef ary::cpp::VariableFlags VarFlags;
340 if ( NOT bExtern )
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(),
351 sName,
352 nResultFrontType,
353 aFlags,
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;
360 else if (bExtern)
362 eResultType = result_ignore;
365 pStati->SetCur(finished);
368 void
369 PE_VarFunc::SpReturn_FunctionStd()
371 if ( (NOT bExtern) OR bExternC )
373 aResultIds.push_back(pSpuFunctionStd->Child().Result_Id());
374 eResultType = result_function;
376 else
378 eResultType = result_ignore;
381 if ( NOT pSpuFunctionStd->Child().Result_WithImplementation() )
382 pStati->SetCur(finished);
383 else
384 pStati->SetCur(finishedIncludingFunctionImplementation);
387 void
388 PE_VarFunc::SpReturn_Ignore()
390 pStati->SetCur(finished);
393 void
394 PE_VarFunc::On_start_Identifier(const char *)
396 pSpuType->Push(not_done);
399 void
400 PE_VarFunc::On_start_operator(const char *)
402 pSpuFunctionCastOperator->Push(done);
405 void
406 PE_VarFunc::On_start_TypeKey(const char *)
408 pSpuType->Push(not_done);
411 void
412 PE_VarFunc::On_start_virtual(const char *)
414 SetTokenResult(done, stay);
415 bVirtual = true;
418 void
419 PE_VarFunc::On_start_Tilde(const char *)
421 SetTokenResult(done, stay);
422 pStati->SetCur(expectName);
424 bInDestructor = true;
427 void
428 PE_VarFunc::On_start_const(const char *)
430 pSpuType->Push(not_done);
433 void
434 PE_VarFunc::On_start_volatile(const char *)
436 pSpuType->Push(not_done);
439 void
440 PE_VarFunc::On_start_extern(const char *)
442 SetTokenResult(done, stay);
443 bExtern = true;
446 void
447 PE_VarFunc::On_start_static(const char *)
449 SetTokenResult(done, stay);
450 bStatic = true;
453 void
454 PE_VarFunc::On_start_mutable(const char *)
456 SetTokenResult(done, stay);
457 bMutable = true;
460 void
461 PE_VarFunc::On_start_register(const char *)
463 SetTokenResult(done, stay);
464 bRegister = true;
467 void
468 PE_VarFunc::On_start_inline(const char *)
470 SetTokenResult(done, stay);
472 bInline = true;
475 void
476 PE_VarFunc::On_start_explicit(const char *)
478 SetTokenResult(done, stay);
479 bExplicit = true;
482 void
483 PE_VarFunc::On_start_Bracket_Right(const char *)
485 SetTokenResult(not_done, pop_success);
488 void
489 PE_VarFunc::On_start_typename(const char *)
491 pSpuType->Push(not_done);
494 void
495 PE_VarFunc::On_expectCtor_Bracket_Left(const char *)
497 pSpuFunctionCtor->Push(not_done);
500 void
501 PE_VarFunc::On_afterClassDecl_Semicolon(const char *)
503 SetTokenResult(done, pop_success);
506 void
507 PE_VarFunc::On_expectName_Identifier(const char * i_sText)
509 SetTokenResult(done, stay);
510 pStati->SetCur(afterName);
511 sName = i_sText;
514 void
515 PE_VarFunc::On_expectName_operator(const char *)
517 pSpuFunctionNormalOperator->Push(done);
520 void
521 PE_VarFunc::On_expectName_Bracket_Left(const char *)
523 // Function pointer declaration
524 pSpuIgnore->Push(not_done);
525 // TODO
529 void
530 PE_VarFunc::On_afterName_ArrayBracket_Left(const char *)
532 pSpuVariable->Push(not_done);
535 void
536 PE_VarFunc::On_afterName_Bracket_Left(const char *)
538 if ( NOT bInDestructor)
539 pSpuFunctionStd->Push(not_done);
540 else
541 pSpuFunctionDtor->Push(not_done);
544 void
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();
554 void
555 PE_VarFunc::On_afterName_Semicolon(const char *)
557 pSpuVariable->Push(not_done);
560 void
561 PE_VarFunc::On_afterName_Comma(const char *)
563 pSpuVariable->Push(not_done);
566 void
567 PE_VarFunc::On_afterName_Assign(const char * )
569 pSpuVariable->Push(not_done);
572 void
573 PE_VarFunc::On_afterName_Less(const char * )
575 SetTokenResult(done, stay);
576 pStati->SetCur(afterName_inErraneousTemplate);
578 nCounter_TemplateBrackets = 1;
581 void
582 PE_VarFunc::On_afterName_inErraneousTemplate_Less(const char * )
584 SetTokenResult(done, stay);
586 nCounter_TemplateBrackets++;
589 void
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);
599 void
600 PE_VarFunc::On_afterName_inErraneousTemplate_Default(const char * )
602 SetTokenResult(done, stay);
605 void
606 PE_VarFunc::On_finished_Semicolon(const char * ) // Should be Semicolon !!!
608 SetTokenResult(done, pop_success);
611 void
612 PE_VarFunc::On_finished_Comma(const char * )
614 SetTokenResult(done, stay);
615 pStati->SetCur(expectName);
618 void
619 PE_VarFunc::On_finished_Default(const char * )
621 SetTokenResult(not_done, pop_success);
624 void
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 ) )
649 } // namespace cpp