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_class.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_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"
54 PE_Class::PE_Class(Cpp_PE
* i_pParent
)
56 pStati( new PeStatusArray
<PE_Class
> ),
67 eClassKey(ary::cpp::CK_class
),
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);
87 = new SPU_Ignore(*pSpIgnore
, 0, 0);
88 pSpuDefs
= new SPU_Defines(*pSpDefs
, 0, 0);
97 PE_Class::Call_Handler( const cpp::Token
& i_rTok
)
99 pStati
->Cur().Call_Handler(i_rTok
.TypeId(), i_rTok
.Text());
103 PE_Class::Handle_ChildFailure()
105 SetCurSPU(pSpuIgnoreFailure
.Ptr());
106 return &pSpuIgnoreFailure
->Child();
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
,
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
,
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
,
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
,
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
);
219 static F_Tok stateF_inFriend
[] = { On_inFriend_class
,
222 // Default: On_inFriend_Function
223 static INT16 stateT_inFriend
[] = { Tid_class
,
232 pStati
->SetCur(start
);
234 eClassKey
= ary::cpp::CK_class
;
236 csv::erase_container(aBases
);
237 eResult_KindOf
= is_declaration
;
241 PE_Class::TransferData()
243 pStati
->SetCur(size_of_states
);
247 PE_Class::Hdl_SyntaxError( const char * i_sText
)
249 if ( *i_sText
== ';' )
251 Cerr() << Env().CurFileName() << ", line "
253 << ": Sourcecode warning: ';' as a toplevel declaration is deprecated."
255 SetTokenResult(done
,stay
);
259 StdHandlingOfSyntaxError(i_sText
);
263 PE_Class::Init_CurObject()
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();
274 pCurObject
->Add_BaseClass( *it
);
278 pTplParams( Env().Get_CurTemplateParameters() );
281 for ( StringVector::const_iterator it
= pTplParams
->begin();
282 it
!= pTplParams
->end();
285 pCurObject
->Add_TemplateParameterType( *it
, ary::cpp::Type_id(0) );
291 PE_Class::SpReturn_Base()
293 aBases
= pSpuBase
->Child().Result_BaseIds();
294 pStati
->SetCur(gotName
);
298 PE_Class::On_start_class( const char * )
300 SetTokenResult(done
, stay
);
301 pStati
->SetCur(expectName
);
302 eClassKey
= ary::cpp::CK_class
;
306 PE_Class::On_start_struct( const char * )
308 SetTokenResult(done
, stay
);
309 pStati
->SetCur(expectName
);
310 eClassKey
= ary::cpp::CK_struct
;
314 PE_Class::On_start_union( const char * )
316 SetTokenResult(done
, stay
);
317 pStati
->SetCur(expectName
);
318 eClassKey
= ary::cpp::CK_union
;
322 PE_Class::On_expectName_Identifier( const char * i_sText
)
324 SetTokenResult(done
, stay
);
325 pStati
->SetCur(gotName
);
326 sLocalName
= i_sText
;
330 PE_Class::On_expectName_SwBracket_Left( const char * )
332 SetTokenResult(done
, stay
);
333 pStati
->SetCur(bodyStd
);
337 sLocalName
= pCurObject
->LocalName();
339 Env().OpenClass(*pCurObject
);
343 PE_Class::On_expectName_Colon( const char * )
345 pStati
->SetCur(gotName
);
348 pSpuBase
->Push(done
);
352 PE_Class::On_gotName_SwBracket_Left( const char * )
354 SetTokenResult(done
, stay
);
355 pStati
->SetCur(bodyStd
);
358 if ( sLocalName
.empty() )
359 sLocalName
= pCurObject
->LocalName();
361 Env().OpenClass(*pCurObject
);
365 PE_Class::On_gotName_Semicolon( const char * )
367 SetTokenResult(not_done
, pop_success
);
369 eResult_KindOf
= is_predeclaration
;
373 PE_Class::On_gotName_Colon( const char * )
375 pSpuBase
->Push(done
);
379 PE_Class::On_gotName_Return2Type( const char * )
381 SetTokenResult(not_done
, pop_success
);
383 eResult_KindOf
= is_qualified_typename
;
387 PE_Class::On_bodyStd_VarFunc( const char * )
389 pSpuVarFunc
->Push(not_done
);
393 PE_Class::On_bodyStd_ClassKey( const char * )
395 pSpuVarFunc
->Push(not_done
); // This is correct,
396 // classes are parsed via PE_Type.
400 PE_Class::On_bodyStd_enum( const char * )
402 pSpuVarFunc
->Push(not_done
); // This is correct,
403 // enums are parsed via PE_Type.
407 PE_Class::On_bodyStd_typedef( const char * )
409 pSpuTypedef
->Push(not_done
);
413 PE_Class::On_bodyStd_public( const char * )
415 SetTokenResult(done
, stay
);
416 pStati
->SetCur(inProtection
);
418 Env().SetCurProtection(ary::cpp::PROTECT_public
);
422 PE_Class::On_bodyStd_protected( const char * )
424 SetTokenResult(done
, stay
);
425 pStati
->SetCur(inProtection
);
427 Env().SetCurProtection(ary::cpp::PROTECT_protected
);
431 PE_Class::On_bodyStd_private( const char * )
433 SetTokenResult(done
, stay
);
434 pStati
->SetCur(inProtection
);
436 Env().SetCurProtection(ary::cpp::PROTECT_private
);
440 PE_Class::On_bodyStd_template( const char * )
442 pSpuTemplate
->Push(done
);
446 PE_Class::On_bodyStd_friend( const char * )
449 pSpuUsing
->Push(done
);
453 PE_Class::On_bodyStd_using( const char * )
455 pSpuUsing
->Push(done
);
459 PE_Class::On_bodyStd_SwBracket_Right( const char * )
461 SetTokenResult(done
, stay
);
462 pStati
->SetCur(afterDecl
);
468 PE_Class::On_bodyStd_DefineName(const char * )
470 pSpuDefs
->Push(not_done
);
474 PE_Class::On_bodyStd_MacroName(const char * )
476 pSpuDefs
->Push(not_done
);
481 PE_Class::On_inProtection_Colon( const char * )
483 SetTokenResult(done
, stay
);
484 pStati
->SetCur(bodyStd
);
488 PE_Class::On_afterDecl_Semicolon( const char * )
490 SetTokenResult(not_done
, pop_success
);
491 eResult_KindOf
= is_declaration
;
495 PE_Class::On_afterDecl_Return2Type( const char * )
497 SetTokenResult(not_done
, pop_success
);
498 eResult_KindOf
= is_implicit_declaration
;