1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include "pe_file.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
32*cdf0e10cSrcweir #include "pe_defs.hxx"
33*cdf0e10cSrcweir #include "pe_enum.hxx"
34*cdf0e10cSrcweir #include "pe_namsp.hxx"
35*cdf0e10cSrcweir #include "pe_tpltp.hxx"
36*cdf0e10cSrcweir #include "pe_tydef.hxx"
37*cdf0e10cSrcweir #include "pe_vafu.hxx"
38*cdf0e10cSrcweir #include "pe_ignor.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace cpp
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir PE_File::PE_File( cpp::PeEnvironment & io_rEnv)
48*cdf0e10cSrcweir 	:   Cpp_PE(io_rEnv),
49*cdf0e10cSrcweir 		pEnv(&io_rEnv),
50*cdf0e10cSrcweir 		pStati( new PeStatusArray<PE_File> ),
51*cdf0e10cSrcweir 		// pSpNamespace,
52*cdf0e10cSrcweir         // pSpTypedef,
53*cdf0e10cSrcweir 		// pSpVarFunc,
54*cdf0e10cSrcweir 		// pSpIgnore,
55*cdf0e10cSrcweir 		// pSpuNamespace,
56*cdf0e10cSrcweir 		// pSpuClass,
57*cdf0e10cSrcweir 		// pSpuTypedef,
58*cdf0e10cSrcweir 		// pSpuVarFunc,
59*cdf0e10cSrcweir 		// pSpuTemplate,
60*cdf0e10cSrcweir 		// pSpuUsing,
61*cdf0e10cSrcweir         // pSpuIgnoreFailure,
62*cdf0e10cSrcweir         bWithinSingleExternC(false)
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir 	Setup_StatusFunctions();
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 	pSpNamespace = new SP_Namespace(*this);
67*cdf0e10cSrcweir 	pSpTypedef   = new SP_Typedef(*this);
68*cdf0e10cSrcweir 	pSpVarFunc   = new SP_VarFunc(*this);
69*cdf0e10cSrcweir     pSpTemplate  = new SP_Template(*this);
70*cdf0e10cSrcweir 	pSpDefs      = new SP_Defines(*this);
71*cdf0e10cSrcweir 	pSpIgnore    = new SP_Ignore(*this);
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	pSpuNamespace	= new SPU_Namespace(*pSpNamespace, 0, 0);
74*cdf0e10cSrcweir 	pSpuTypedef		= new SPU_Typedef(*pSpTypedef, 0, 0);
75*cdf0e10cSrcweir 	pSpuVarFunc		= new SPU_VarFunc(*pSpVarFunc, 0, &PE_File::SpReturn_VarFunc);
76*cdf0e10cSrcweir 	pSpuTemplate	= new SPU_Template(*pSpTemplate, 0, &PE_File::SpReturn_Template);
77*cdf0e10cSrcweir 	pSpuDefs	    = new SPU_Defines(*pSpDefs, 0, 0);
78*cdf0e10cSrcweir 	pSpuUsing		= new SPU_Ignore(*pSpIgnore, 0, 0);
79*cdf0e10cSrcweir     pSpuIgnoreFailure
80*cdf0e10cSrcweir                     = new SPU_Ignore(*pSpIgnore, 0, 0);
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir PE_File::~PE_File()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir void
88*cdf0e10cSrcweir PE_File::Call_Handler( const cpp::Token &	i_rTok )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir Cpp_PE *
94*cdf0e10cSrcweir PE_File::Handle_ChildFailure()
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     SetCurSPU(pSpuIgnoreFailure.Ptr());
97*cdf0e10cSrcweir     return &pSpuIgnoreFailure->Child();
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir void
101*cdf0e10cSrcweir PE_File::Setup_StatusFunctions()
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir 	typedef CallFunction<PE_File>::F_Tok	F_Tok;
104*cdf0e10cSrcweir 	static F_Tok stateF_std[] =				{ &PE_File::On_std_VarFunc,
105*cdf0e10cSrcweir 											  &PE_File::On_std_ClassKey,
106*cdf0e10cSrcweir 											  &PE_File::On_std_ClassKey,
107*cdf0e10cSrcweir 											  &PE_File::On_std_ClassKey,
108*cdf0e10cSrcweir 											  &PE_File::On_std_enum,
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 											  &PE_File::On_std_typedef,
111*cdf0e10cSrcweir 											  &PE_File::On_std_template,
112*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc,
113*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc,
114*cdf0e10cSrcweir 											  &PE_File::On_std_extern,
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc,
117*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc,
118*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc,
119*cdf0e10cSrcweir 											  &PE_File::On_std_namespace,
120*cdf0e10cSrcweir 											  &PE_File::On_std_using,
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 											  &PE_File::On_std_SwBracketRight,
123*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc,
124*cdf0e10cSrcweir                                               &PE_File::On_std_VarFunc,
125*cdf0e10cSrcweir                                               &PE_File::On_std_DefineName,
126*cdf0e10cSrcweir                                               &PE_File::On_std_MacroName,
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc,
129*cdf0e10cSrcweir 											  &PE_File::On_std_VarFunc };
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	static INT16 stateT_std[] =       		{ Tid_Identifier,
132*cdf0e10cSrcweir 											  Tid_class,
133*cdf0e10cSrcweir 											  Tid_struct,
134*cdf0e10cSrcweir 											  Tid_union,
135*cdf0e10cSrcweir 											  Tid_enum,
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 											  Tid_typedef,
138*cdf0e10cSrcweir 											  Tid_template,
139*cdf0e10cSrcweir 											  Tid_const,
140*cdf0e10cSrcweir 											  Tid_volatile,
141*cdf0e10cSrcweir 											  Tid_extern,
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 											  Tid_static,
144*cdf0e10cSrcweir 											  Tid_register,
145*cdf0e10cSrcweir 											  Tid_inline,
146*cdf0e10cSrcweir 											  Tid_namespace,
147*cdf0e10cSrcweir 											  Tid_using,
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 											  Tid_SwBracket_Right,
150*cdf0e10cSrcweir 											  Tid_DoubleColon,
151*cdf0e10cSrcweir                                               Tid_typename,
152*cdf0e10cSrcweir                                               Tid_DefineName,
153*cdf0e10cSrcweir                                               Tid_MacroName,
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 											  Tid_BuiltInType,
156*cdf0e10cSrcweir 											  Tid_TypeSpecializer };
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	static F_Tok stateF_in_extern[] =		{ &PE_File::On_in_extern_Constant };
159*cdf0e10cSrcweir 	static INT16 stateT_in_extern[] =       { Tid_Constant };
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	static F_Tok stateF_in_externC[] =		{ &PE_File::On_in_externC_SwBracket_Left };
162*cdf0e10cSrcweir 	static INT16 stateT_in_externC[] =      { Tid_SwBracket_Left };
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	SEMPARSE_CREATE_STATUS(PE_File, std, Hdl_SyntaxError);
166*cdf0e10cSrcweir 	SEMPARSE_CREATE_STATUS(PE_File, in_extern, On_in_extern_Ignore);
167*cdf0e10cSrcweir 	SEMPARSE_CREATE_STATUS(PE_File, in_externC, On_in_externC_NoBlock);
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir void
171*cdf0e10cSrcweir PE_File::InitData()
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir 	pStati->SetCur(std);
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir void
177*cdf0e10cSrcweir PE_File::TransferData()
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir 	pStati->SetCur(size_of_states);
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir void
183*cdf0e10cSrcweir PE_File::Hdl_SyntaxError( const char * i_sText)
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     if ( *i_sText == ';' )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir      	Cerr() << Env().CurFileName() << ", line "
188*cdf0e10cSrcweir                   << Env().LineCount()
189*cdf0e10cSrcweir                   << ": Sourcecode warning: ';' as a toplevel declaration is deprecated."
190*cdf0e10cSrcweir                   << Endl();
191*cdf0e10cSrcweir     	SetTokenResult(done,stay);
192*cdf0e10cSrcweir         return;
193*cdf0e10cSrcweir     }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	StdHandlingOfSyntaxError(i_sText);
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir void
199*cdf0e10cSrcweir PE_File::SpReturn_VarFunc()
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir  	if (bWithinSingleExternC)
202*cdf0e10cSrcweir     {
203*cdf0e10cSrcweir         access_Env().CloseBlock();
204*cdf0e10cSrcweir      	bWithinSingleExternC = false;
205*cdf0e10cSrcweir     }
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir void
209*cdf0e10cSrcweir PE_File::SpReturn_Template()
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     access_Env().OpenTemplate( pSpuTemplate->Child().Result_Parameters() );
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir void
215*cdf0e10cSrcweir PE_File::On_std_namespace(const char * )
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	pSpuNamespace->Push(done);
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir void
221*cdf0e10cSrcweir PE_File::On_std_ClassKey(const char * )
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir 	pSpuVarFunc->Push(not_done);		// This is correct,
224*cdf0e10cSrcweir 										//   classes are parsed via PE_Type.
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir void
228*cdf0e10cSrcweir PE_File::On_std_typedef(const char * )
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir 	pSpuTypedef->Push(not_done);
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir void
234*cdf0e10cSrcweir PE_File::On_std_enum(const char * )
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir 	pSpuVarFunc->Push(not_done);		// This is correct,
237*cdf0e10cSrcweir 										//   enums are parsed via PE_Type.
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir void
241*cdf0e10cSrcweir PE_File::On_std_VarFunc(const char * )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir 	pSpuVarFunc->Push(not_done);
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void
247*cdf0e10cSrcweir PE_File::On_std_template(const char * )
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir     pSpuTemplate->Push(done);
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void
253*cdf0e10cSrcweir PE_File::On_std_extern(const char * )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir 	SetTokenResult(done, stay);
256*cdf0e10cSrcweir     pStati->SetCur(in_extern);
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir void
260*cdf0e10cSrcweir PE_File::On_std_using(const char * )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	pSpuUsing->Push(done);
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir void
266*cdf0e10cSrcweir PE_File::On_std_SwBracketRight(const char * )
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir 	SetTokenResult(done,stay);
269*cdf0e10cSrcweir 	access_Env().CloseBlock();
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir void
273*cdf0e10cSrcweir PE_File::On_std_DefineName(const char * )
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir 	pSpuDefs->Push(not_done);
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir void
279*cdf0e10cSrcweir PE_File::On_std_MacroName(const char * )
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	pSpuDefs->Push(not_done);
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir void
285*cdf0e10cSrcweir PE_File::On_in_extern_Constant(const char * )
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir 	SetTokenResult(done,stay);
288*cdf0e10cSrcweir     pStati->SetCur(in_externC);
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     access_Env().OpenExternC();
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir void
294*cdf0e10cSrcweir PE_File::On_in_extern_Ignore(const char * )
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir 	SetTokenResult(not_done, stay);
297*cdf0e10cSrcweir     pStati->SetCur(std);
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir void
301*cdf0e10cSrcweir PE_File::On_in_externC_SwBracket_Left(const char * )
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir 	SetTokenResult(done, stay);
304*cdf0e10cSrcweir     pStati->SetCur(std);
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir void
308*cdf0e10cSrcweir PE_File::On_in_externC_NoBlock(const char * )
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir 	SetTokenResult(not_done, stay);
311*cdf0e10cSrcweir     pStati->SetCur(std);
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     bWithinSingleExternC = true;
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir }   // namespace cpp
318