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