1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include <s2_luidl/pe_file2.hxx>
30 
31 
32 // NOT FULLY DECLARED SERVICES
33 #include <ary/idl/i_gate.hxx>
34 #include <ary/idl/i_module.hxx>
35 #include <ary/idl/ip_ce.hxx>
36 #include <ary/doc/d_oldidldocu.hxx>
37 #include <s2_luidl/distrib.hxx>
38 #include <s2_luidl/pe_servi.hxx>
39 #include <s2_luidl/pe_iface.hxx>
40 #include <s2_luidl/pe_singl.hxx>
41 #include <s2_luidl/pe_struc.hxx>
42 #include <s2_luidl/pe_excp.hxx>
43 #include <s2_luidl/pe_const.hxx>
44 #include <s2_luidl/pe_enum2.hxx>
45 #include <s2_luidl/pe_tydf2.hxx>
46 #include <s2_luidl/tk_keyw.hxx>
47 #include <s2_luidl/tk_ident.hxx>
48 #include <s2_luidl/tk_punct.hxx>
49 
50 
51 
52 
53 namespace csi
54 {
55 namespace uidl
56 {
57 
58 
59 PE_File::PE_File( TokenDistributor & i_rTokenAdmin,
60 				  const ParserInfo & i_parseInfo )
61 	:	pTokenAdmin(&i_rTokenAdmin),
62     	pPE_Service(new PE_Service),
63     	pPE_Singleton(new PE_Singleton),
64 		pPE_Interface(new PE_Interface),
65 		pPE_Struct(new PE_Struct),
66 		pPE_Exception(new PE_Exception),
67 		pPE_Constant(new PE_Constant),
68 		pPE_Enum(new PE_Enum),
69 		pPE_Typedef(new PE_Typedef),
70 		pCurNamespace(0),
71 		pParseInfo(&i_parseInfo),
72 		eState(e_none),
73 		nBracketCount_inDefMode(0)
74 {
75 }
76 
77 void
78 PE_File::EstablishContacts( UnoIDL_PE *					io_pParentPE,
79 							ary::Repository &		io_rRepository,
80 							TokenProcessing_Result & 	o_rResult )
81 {
82 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
83 	pPE_Service->EstablishContacts(this,io_rRepository,o_rResult);
84 	pPE_Singleton->EstablishContacts(this,io_rRepository,o_rResult);
85 	pPE_Interface->EstablishContacts(this,io_rRepository,o_rResult);
86 	pPE_Struct->EstablishContacts(this,io_rRepository,o_rResult);
87 	pPE_Exception->EstablishContacts(this,io_rRepository,o_rResult);
88 	pPE_Constant->EstablishContacts(this,io_rRepository,o_rResult);
89 	pPE_Enum->EstablishContacts(this,io_rRepository,o_rResult);
90 	pPE_Typedef->EstablishContacts(this,io_rRepository,o_rResult);
91 
92 	pCurNamespace = &Gate().Ces().GlobalNamespace();
93 }
94 
95 PE_File::~PE_File()
96 {
97 }
98 
99 void
100 PE_File::ProcessToken( const Token & i_rToken )
101 {
102 	i_rToken.Trigger(*this);
103 }
104 
105 void
106 PE_File::Process_Identifier( const TokIdentifier & i_rToken )
107 {
108 	switch (eState)
109 	{
110 		case wait_for_module:
111 		{
112 				csv_assert(pCurNamespace != 0);
113 
114 				ary::idl::Module & rCe = Gate().Ces().CheckIn_Module(pCurNamespace->CeId(), i_rToken.Text());
115 				pCurNamespace = &rCe;
116 
117                 // Get docu out of normal:
118                 SetDocu(pTokenAdmin->ReleaseLastParsedDocu());
119         		PassDocuAt(rCe);
120 
121 				csv_assert(pCurNamespace != 0);
122 
123 				SetResult(done, stay);
124 				eState = wait_for_module_bracket;
125 		}		break;
126 		case on_default:
127 				SetResult(done, stay);
128 				break;
129 		default:
130 			csv_assert(false);
131 	}
132 }
133 
134 void
135 PE_File::Process_Punctuation( const TokPunctuation & i_rToken )
136 {
137 	switch (eState)
138 	{
139 		case e_std:
140 				if (i_rToken.Id() == TokPunctuation::CurledBracketClose)
141 				{
142 					csv_assert(pCurNamespace != 0);
143 
144 					pCurNamespace = &Gate().Ces().Find_Module(pCurNamespace->Owner());
145 
146 					SetResult(done, stay);
147 					eState = wait_for_module_semicolon;
148 				}
149 				else
150 				{
151 					csv_assert(false);
152 				}
153 				break;
154 		case wait_for_module_bracket:
155 				if (i_rToken.Id() == TokPunctuation::CurledBracketOpen)
156 				{
157 					SetResult(done, stay);
158 					eState = e_std;
159 				}
160 				else
161 				{
162 					csv_assert(false);
163 				}
164 				break;
165 		case wait_for_module_semicolon:
166 				if (i_rToken.Id() == TokPunctuation::Semicolon)
167 				{
168 					SetResult(done, stay);
169 					eState = e_std;
170 				}
171 				else
172 				{
173 					csv_assert(false);
174 				}
175 				break;
176 		case on_default:
177 				if (i_rToken.Id() == TokPunctuation::CurledBracketClose)
178 				{
179 					nBracketCount_inDefMode--;
180 				}
181 				else if (i_rToken.Id() == TokPunctuation::CurledBracketOpen)
182 				{
183 					nBracketCount_inDefMode++;
184 				}
185 				else if (i_rToken.Id() == TokPunctuation::Semicolon)
186 				{
187 					if (nBracketCount_inDefMode <= 0)
188 					{
189 						eState = e_std;
190 					}
191 				}
192 				SetResult(done, stay);
193 				break;
194 		default:
195 			csv_assert(false);
196 	}
197 }
198 
199 void
200 PE_File::Process_MetaType( const TokMetaType &	i_rToken )
201 {
202 	switch (i_rToken.Id())
203 	{
204 		case TokMetaType::mt_service:
205 				eState = in_sub_pe;
206 				SetResult( not_done, push_sure, pPE_Service.Ptr());
207 				break;
208 		case TokMetaType::mt_singleton:
209 				eState = in_sub_pe;
210 				SetResult( not_done, push_sure, pPE_Singleton.Ptr());
211 				break;
212 		case TokMetaType::mt_uik:
213 				Cerr() << "Syntax error: [uik ....] is obsolete now." << Endl();
214 				SetResult( not_done, pop_failure);
215 				break;
216 		case TokMetaType::mt_interface:
217 				eState = in_sub_pe;
218 				SetResult( not_done, push_sure, pPE_Interface.Ptr());
219 				break;
220 		case TokMetaType::mt_module:
221 				eState = wait_for_module;
222 				SetResult( done, stay );
223 				break;
224 		case TokMetaType::mt_struct:
225 				eState = in_sub_pe;
226 				SetResult( done, push_sure, pPE_Struct.Ptr());
227 				break;
228 		case TokMetaType::mt_exception:
229 				eState = in_sub_pe;
230 				SetResult( done, push_sure, pPE_Exception.Ptr());
231 				break;
232 		case TokMetaType::mt_constants:
233 				eState = in_sub_pe;
234 				SetResult( done, push_sure, pPE_Constant.Ptr());
235 				break;
236 		case TokMetaType::mt_enum:
237 				eState = in_sub_pe;
238 				SetResult( done, push_sure, pPE_Enum.Ptr());
239 				break;
240 		case TokMetaType::mt_typedef:
241 				eState = in_sub_pe;
242 				SetResult( done, push_sure, pPE_Typedef.Ptr());
243 				break;
244 
245 		default:
246 				Process_Default();
247 	} 	// end switch
248 }
249 
250 void
251 PE_File::Process_Stereotype( const TokStereotype & i_rToken )
252 {
253     if (i_rToken.Id() == TokStereotype::ste_published)
254     {
255         pTokenAdmin->Set_PublishedOn();
256 
257         SetResult(done, stay);
258     }
259     else
260     {
261         Process_Default();
262     }
263 }
264 
265 void
266 PE_File::Process_Default()
267 {
268 	if (eState != on_default)
269 	{
270 		eState = on_default;
271 		nBracketCount_inDefMode = 0;
272 	}
273 	SetResult(done, stay);
274 }
275 
276 const ary::idl::Module &
277 PE_File::CurNamespace() const
278 {
279 	csv_assert(pCurNamespace);
280 	return *pCurNamespace;
281 }
282 
283 const ParserInfo &
284 PE_File::ParseInfo() const
285 {
286 	csv_assert(pParseInfo);
287 	return *pParseInfo;
288 }
289 
290 void
291 PE_File::InitData()
292 {
293 	eState = e_std;
294 }
295 
296 void
297 PE_File::TransferData()
298 {
299 	eState = e_none;
300 }
301 
302 void
303 PE_File::ReceiveData()
304 {
305 	eState = e_std;
306 }
307 
308 
309 UnoIDL_PE &
310 PE_File::MyPE()
311 {
312  	return *this;
313 }
314 
315 }   // namespace uidl
316 }   // namespace csi
317 
318 
319