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