Update ooo320-m1
[ooovba.git] / autodoc / source / parser / cpp / pe_class.cxx
blob1daeb07dfdc2385b464fb8de12c56f81273a1550
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_class.cxx,v $
10 * $Revision: 1.11 $
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_class.hxx"
35 // NOT FULLY DECLARED 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_namesp.hxx>
40 #include <ary/cpp/cp_ce.hxx>
41 #include <all_toks.hxx>
42 #include "pe_base.hxx"
43 #include "pe_defs.hxx"
44 #include "pe_enum.hxx"
45 #include "pe_tydef.hxx"
46 #include "pe_vafu.hxx"
47 #include "pe_ignor.hxx"
50 namespace cpp {
52 // using ary::Cid;
54 PE_Class::PE_Class(Cpp_PE * i_pParent )
55 : Cpp_PE(i_pParent),
56 pStati( new PeStatusArray<PE_Class> ),
57 // pSpBase,
58 // pSpTypedef,
59 // pSpVarFunc,
60 // pSpIgnore,
61 // pSpuBase,
62 // pSpuTypedef,
63 // pSpuVarFunc,
64 // pSpuUsing,
65 // pSpuIgnoreFailure,
66 // sLocalName,
67 eClassKey(ary::cpp::CK_class),
68 pCurObject(0),
69 // aBases,
70 eResult_KindOf(is_declaration)
72 Setup_StatusFunctions();
74 pSpBase = new SP_Base(*this);
75 pSpTypedef = new SP_Typedef(*this);
76 pSpVarFunc = new SP_VarFunc(*this);
77 pSpIgnore = new SP_Ignore(*this);
78 pSpDefs = new SP_Defines(*this);
80 pSpuBase = new SPU_Base(*pSpBase, 0, &PE_Class::SpReturn_Base);
81 pSpuTypedef = new SPU_Typedef(*pSpTypedef, 0, 0);
82 pSpuVarFunc = new SPU_VarFunc(*pSpVarFunc, 0, 0);
84 pSpuTemplate= new SPU_Ignore(*pSpIgnore, 0, 0);
85 pSpuUsing = new SPU_Ignore(*pSpIgnore, 0, 0);
86 pSpuIgnoreFailure
87 = new SPU_Ignore(*pSpIgnore, 0, 0);
88 pSpuDefs = new SPU_Defines(*pSpDefs, 0, 0);
92 PE_Class::~PE_Class()
96 void
97 PE_Class::Call_Handler( const cpp::Token & i_rTok )
99 pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
102 Cpp_PE *
103 PE_Class::Handle_ChildFailure()
105 SetCurSPU(pSpuIgnoreFailure.Ptr());
106 return &pSpuIgnoreFailure->Child();
109 void
110 PE_Class::Setup_StatusFunctions()
112 typedef CallFunction<PE_Class>::F_Tok F_Tok;
114 static F_Tok stateF_start[] = { &PE_Class::On_start_class,
115 &PE_Class::On_start_struct,
116 &PE_Class::On_start_union };
117 static INT16 stateT_start[] = { Tid_class,
118 Tid_struct,
119 Tid_union };
121 static F_Tok stateF_expectName[] = { &PE_Class::On_expectName_Identifier,
122 &PE_Class::On_expectName_SwBracket_Left,
123 &PE_Class::On_expectName_Colon
125 static INT16 stateT_expectName[] = { Tid_Identifier,
126 Tid_SwBracket_Left,
127 Tid_Colon
130 static F_Tok stateF_gotName[] = { &PE_Class::On_gotName_SwBracket_Left,
131 &PE_Class::On_gotName_Semicolon,
132 &PE_Class::On_gotName_Colon };
133 static INT16 stateT_gotName[] = { Tid_SwBracket_Left,
134 Tid_Semicolon,
135 Tid_Colon };
137 static F_Tok stateF_bodyStd[] = { &PE_Class::On_bodyStd_VarFunc,
138 &PE_Class::On_bodyStd_VarFunc,
139 &PE_Class::On_bodyStd_ClassKey,
140 &PE_Class::On_bodyStd_ClassKey,
141 &PE_Class::On_bodyStd_ClassKey,
143 &PE_Class::On_bodyStd_enum,
144 &PE_Class::On_bodyStd_typedef,
145 &PE_Class::On_bodyStd_public,
146 &PE_Class::On_bodyStd_protected,
147 &PE_Class::On_bodyStd_private,
149 &PE_Class::On_bodyStd_template,
150 &PE_Class::On_bodyStd_VarFunc,
151 &PE_Class::On_bodyStd_friend,
152 &PE_Class::On_bodyStd_VarFunc,
153 &PE_Class::On_bodyStd_VarFunc,
155 &PE_Class::On_bodyStd_VarFunc,
156 &PE_Class::On_bodyStd_VarFunc,
157 &PE_Class::On_bodyStd_VarFunc,
158 &PE_Class::On_bodyStd_VarFunc,
159 &PE_Class::On_bodyStd_VarFunc,
161 &PE_Class::On_bodyStd_using,
162 &PE_Class::On_bodyStd_SwBracket_Right,
163 &PE_Class::On_bodyStd_VarFunc,
164 &PE_Class::On_bodyStd_DefineName,
165 &PE_Class::On_bodyStd_MacroName,
167 &PE_Class::On_bodyStd_VarFunc,
168 &PE_Class::On_bodyStd_VarFunc,
169 &PE_Class::On_bodyStd_VarFunc, };
171 static INT16 stateT_bodyStd[] = { Tid_Identifier,
172 Tid_operator,
173 Tid_class,
174 Tid_struct,
175 Tid_union,
177 Tid_enum,
178 Tid_typedef,
179 Tid_public,
180 Tid_protected,
181 Tid_private,
183 Tid_template,
184 Tid_virtual,
185 Tid_friend,
186 Tid_Tilde,
187 Tid_const,
189 Tid_volatile,
190 Tid_static,
191 Tid_mutable,
192 Tid_inline,
193 Tid_explicit,
195 Tid_using,
196 Tid_SwBracket_Right,
197 Tid_DoubleColon,
198 Tid_typename,
199 Tid_DefineName,
201 Tid_MacroName,
202 Tid_BuiltInType,
203 Tid_TypeSpecializer };
205 static F_Tok stateF_inProtection[] = { &PE_Class::On_inProtection_Colon };
206 static INT16 stateT_inProtection[] = { Tid_Colon };
208 static F_Tok stateF_afterDecl[] = { &PE_Class::On_afterDecl_Semicolon };
209 static INT16 stateT_afterDecl[] = { Tid_Semicolon };
211 SEMPARSE_CREATE_STATUS(PE_Class, start, Hdl_SyntaxError);
212 SEMPARSE_CREATE_STATUS(PE_Class, expectName, Hdl_SyntaxError);
213 SEMPARSE_CREATE_STATUS(PE_Class, gotName, On_gotName_Return2Type);
214 SEMPARSE_CREATE_STATUS(PE_Class, bodyStd, Hdl_SyntaxError);
215 SEMPARSE_CREATE_STATUS(PE_Class, inProtection, Hdl_SyntaxError);
216 SEMPARSE_CREATE_STATUS(PE_Class, afterDecl, On_afterDecl_Return2Type);
218 #if 0
219 static F_Tok stateF_inFriend[] = { On_inFriend_class,
220 On_inFriend_struct,
221 On_inFriend_union };
222 // Default: On_inFriend_Function
223 static INT16 stateT_inFriend[] = { Tid_class,
224 Tid_struct,
225 Tid_union };
226 #endif // 0
229 void
230 PE_Class::InitData()
232 pStati->SetCur(start);
233 sLocalName.clear();
234 eClassKey = ary::cpp::CK_class;
235 pCurObject = 0;
236 csv::erase_container(aBases);
237 eResult_KindOf = is_declaration;
240 void
241 PE_Class::TransferData()
243 pStati->SetCur(size_of_states);
246 void
247 PE_Class::Hdl_SyntaxError( const char * i_sText)
249 if ( *i_sText == ';' )
251 Cerr() << Env().CurFileName() << ", line "
252 << Env().LineCount()
253 << ": Sourcecode warning: ';' as a toplevel declaration is deprecated."
254 << Endl();
255 SetTokenResult(done,stay);
256 return;
259 StdHandlingOfSyntaxError(i_sText);
262 void
263 PE_Class::Init_CurObject()
265 // KORR_FUTURE
266 // This will have to be done before parsing base classes, because of
267 // possible inline documentation for base classes.
268 pCurObject = & Env().AryGate().Ces().Store_Class( Env().Context(), sLocalName, eClassKey );
270 for ( PE_Base::BaseList::const_iterator it = aBases.begin();
271 it != aBases.end();
272 ++it )
274 pCurObject->Add_BaseClass( *it );
275 } // end for
277 Dyn< StringVector >
278 pTplParams( Env().Get_CurTemplateParameters() );
279 if ( pTplParams )
281 for ( StringVector::const_iterator it = pTplParams->begin();
282 it != pTplParams->end();
283 ++it )
285 pCurObject->Add_TemplateParameterType( *it, ary::cpp::Type_id(0) );
286 } // end for
290 void
291 PE_Class::SpReturn_Base()
293 aBases = pSpuBase->Child().Result_BaseIds();
294 pStati->SetCur(gotName);
297 void
298 PE_Class::On_start_class( const char * )
300 SetTokenResult(done, stay);
301 pStati->SetCur(expectName);
302 eClassKey = ary::cpp::CK_class;
305 void
306 PE_Class::On_start_struct( const char * )
308 SetTokenResult(done, stay);
309 pStati->SetCur(expectName);
310 eClassKey = ary::cpp::CK_struct;
313 void
314 PE_Class::On_start_union( const char * )
316 SetTokenResult(done, stay);
317 pStati->SetCur(expectName);
318 eClassKey = ary::cpp::CK_union;
321 void
322 PE_Class::On_expectName_Identifier( const char * i_sText )
324 SetTokenResult(done, stay);
325 pStati->SetCur(gotName);
326 sLocalName = i_sText;
329 void
330 PE_Class::On_expectName_SwBracket_Left( const char * )
332 SetTokenResult(done, stay);
333 pStati->SetCur(bodyStd);
335 sLocalName = "";
336 Init_CurObject();
337 sLocalName = pCurObject->LocalName();
339 Env().OpenClass(*pCurObject);
342 void
343 PE_Class::On_expectName_Colon( const char * )
345 pStati->SetCur(gotName);
346 sLocalName = "";
348 pSpuBase->Push(done);
351 void
352 PE_Class::On_gotName_SwBracket_Left( const char * )
354 SetTokenResult(done, stay);
355 pStati->SetCur(bodyStd);
357 Init_CurObject();
358 if ( sLocalName.empty() )
359 sLocalName = pCurObject->LocalName();
361 Env().OpenClass(*pCurObject);
364 void
365 PE_Class::On_gotName_Semicolon( const char * )
367 SetTokenResult(not_done, pop_success);
369 eResult_KindOf = is_predeclaration;
372 void
373 PE_Class::On_gotName_Colon( const char * )
375 pSpuBase->Push(done);
378 void
379 PE_Class::On_gotName_Return2Type( const char * )
381 SetTokenResult(not_done, pop_success);
383 eResult_KindOf = is_qualified_typename;
386 void
387 PE_Class::On_bodyStd_VarFunc( const char * )
389 pSpuVarFunc->Push(not_done);
392 void
393 PE_Class::On_bodyStd_ClassKey( const char * )
395 pSpuVarFunc->Push(not_done); // This is correct,
396 // classes are parsed via PE_Type.
399 void
400 PE_Class::On_bodyStd_enum( const char * )
402 pSpuVarFunc->Push(not_done); // This is correct,
403 // enums are parsed via PE_Type.
406 void
407 PE_Class::On_bodyStd_typedef( const char * )
409 pSpuTypedef->Push(not_done);
412 void
413 PE_Class::On_bodyStd_public( const char * )
415 SetTokenResult(done, stay);
416 pStati->SetCur(inProtection);
418 Env().SetCurProtection(ary::cpp::PROTECT_public);
421 void
422 PE_Class::On_bodyStd_protected( const char * )
424 SetTokenResult(done, stay);
425 pStati->SetCur(inProtection);
427 Env().SetCurProtection(ary::cpp::PROTECT_protected);
430 void
431 PE_Class::On_bodyStd_private( const char * )
433 SetTokenResult(done, stay);
434 pStati->SetCur(inProtection);
436 Env().SetCurProtection(ary::cpp::PROTECT_private);
439 void
440 PE_Class::On_bodyStd_template( const char * )
442 pSpuTemplate->Push(done);
445 void
446 PE_Class::On_bodyStd_friend( const char * )
448 // KORR_FUTURE
449 pSpuUsing->Push(done);
452 void
453 PE_Class::On_bodyStd_using( const char * )
455 pSpuUsing->Push(done);
458 void
459 PE_Class::On_bodyStd_SwBracket_Right( const char * )
461 SetTokenResult(done, stay);
462 pStati->SetCur(afterDecl);
464 Env().CloseClass();
467 void
468 PE_Class::On_bodyStd_DefineName(const char * )
470 pSpuDefs->Push(not_done);
473 void
474 PE_Class::On_bodyStd_MacroName(const char * )
476 pSpuDefs->Push(not_done);
480 void
481 PE_Class::On_inProtection_Colon( const char * )
483 SetTokenResult(done, stay);
484 pStati->SetCur(bodyStd);
487 void
488 PE_Class::On_afterDecl_Semicolon( const char * )
490 SetTokenResult(not_done, pop_success);
491 eResult_KindOf = is_declaration;
494 void
495 PE_Class::On_afterDecl_Return2Type( const char * )
497 SetTokenResult(not_done, pop_success);
498 eResult_KindOf = is_implicit_declaration;
502 } // namespace cpp