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 <s2_luidl/pe_singl.hxx>
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/idl/i_gate.hxx>
28 #include <ary/idl/i_singleton.hxx>
29 #include <ary/idl/i_sisingleton.hxx>
30 #include <ary/idl/ip_ce.hxx>
31 #include <ary/doc/d_oldidldocu.hxx>
32 #include <s2_luidl/pe_type2.hxx>
33 #include <s2_luidl/tk_keyw.hxx>
34 #include <s2_luidl/tk_ident.hxx>
35 #include <s2_luidl/tk_punct.hxx>
36 
37 
38 
39 namespace csi
40 {
41 namespace uidl
42 {
43 
44 
45 
46 #if 0
47 #ifdef DF
48 #undef DF
49 #endif
50 #define DF 	&PE_Singleton::On_Default
51 
52 
53 PE_Singleton::F_TOK
54 PE_Singleton::aDispatcher[PE_Singleton::e_STATES_MAX][PE_Singleton::tt_MAX] =
55 		{ 	{ DF, DF, DF },  // e_none
56 			{ DF, &PE_Singleton::On_need_name_Identifer,
57 					  DF },  // need_name
58 			{ DF, DF, &PE_Singleton::On_need_curlbr_open_Punctuation,
59 						 },  // need_curlbr_open
60 			{ &PE_Singleton::On_std_GotoService,
61 				  DF, &PE_Singleton::On_std_Punctuation,
62 						 },  // e_std
63 			{ DF, DF, DF },  // in_service
64 			{ DF, DF, &PE_Interface::On_need_finish_Punctuation,
65 						 }   // need_finish
66 		};
67 #endif // 0
68 
69 
PE_Singleton()70 PE_Singleton::PE_Singleton()
71 	:	eState(e_none),
72 		sData_Name(),
73 		bIsPreDeclaration(false),
74 		pCurSingleton(0),
75         pCurSiSingleton(0),
76 		pPE_Type(0),
77 		nCurParsed_Type(0)
78 {
79 	pPE_Type 		= new PE_Type(nCurParsed_Type);
80 }
81 
82 void
EstablishContacts(UnoIDL_PE * io_pParentPE,ary::Repository & io_rRepository,TokenProcessing_Result & o_rResult)83 PE_Singleton::EstablishContacts( UnoIDL_PE *				io_pParentPE,
84 							   ary::Repository &		io_rRepository,
85 							   TokenProcessing_Result & o_rResult )
86 {
87 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
88 	pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
89 }
90 
~PE_Singleton()91 PE_Singleton::~PE_Singleton()
92 {
93 }
94 
95 void
ProcessToken(const Token & i_rToken)96 PE_Singleton::ProcessToken( const Token & i_rToken )
97 {
98 	i_rToken.Trigger(*this);
99 }
100 
101 
102 void
Process_MetaType(const TokMetaType & i_rToken)103 PE_Singleton::Process_MetaType( const TokMetaType &	i_rToken )
104 {
105 	switch ( i_rToken.Id() )
106 	{
107 		case TokMetaType::mt_service:
108 					if (eState == e_std)
109 					{
110 						SetResult(done, push_sure, pPE_Type.Ptr());
111 						eState = in_service;
112 					}
113 					else
114 						On_Default();
115 					break;
116 		case TokMetaType::mt_singleton:
117 					if (eState == need_name)
118 						SetResult(done, stay);
119 					else
120 						On_Default();
121 					break;
122         default:
123             // KORR_FUTURE
124             // Should throw syntax error warning
125                     ;
126 
127 	}	// end switch
128 }
129 
130 void
Process_Identifier(const TokIdentifier & i_rToken)131 PE_Singleton::Process_Identifier( const TokIdentifier & i_rToken )
132 {
133 	if (eState == need_name)
134 	{
135 		sData_Name = i_rToken.Text();
136 		SetResult(done, stay);
137 		eState = need_curlbr_open;
138 	}
139 	else
140 		On_Default();
141 }
142 
143 void
Process_Punctuation(const TokPunctuation & i_rToken)144 PE_Singleton::Process_Punctuation( const TokPunctuation & i_rToken )
145 {
146 	switch (i_rToken.Id())
147 	{
148 		case TokPunctuation::CurledBracketOpen:
149 					if (eState == need_curlbr_open)
150 					{
151                         pCurSingleton = &Gate().Ces().Store_Singleton(
152                                                         CurNamespace().CeId(),
153                                                         sData_Name );
154 						PassDocuAt(*pCurSingleton);
155 						SetResult(done, stay);
156 						eState = e_std;
157 					}
158 					else
159 						On_Default();
160 					break;
161 		case TokPunctuation::CurledBracketClose:
162 					if (eState == e_std)
163 					{
164 						SetResult(done, stay);
165 						eState = need_finish;
166 					}
167 					else
168 						On_Default();
169 					break;
170 		case TokPunctuation::Semicolon:
171 					switch (eState)
172 					{
173 					   case e_std:  SetResult(done, stay);
174 									break;
175 					   case need_finish:
176 									SetResult(done, pop_success);
177 									eState = e_none;
178 									break;
179 					   default:
180 									On_Default();
181 					}	// end switch
182 					break;
183 		case TokPunctuation::Colon:
184 					switch (eState)
185 					{
186 					   case need_curlbr_open:
187 					                SetResult(done, push_sure, pPE_Type.Ptr());
188                                     eState = in_base_interface;
189 									break;
190 					   default:
191 									On_Default();
192 					}	// end switch
193 		            break;
194 		default:
195 					On_Default();
196 	}	// end switch
197 }
198 
199 void
Process_Default()200 PE_Singleton::Process_Default()
201 {
202 	On_Default();
203 }
204 
205 
206 void
On_Default()207 PE_Singleton::On_Default()
208 {
209     SetResult(not_done, pop_failure);
210 }
211 
212 void
InitData()213 PE_Singleton::InitData()
214 {
215 	eState = need_name;
216 	sData_Name.clear();
217 	bIsPreDeclaration = false;
218 	pCurSingleton = 0;
219     pCurSiSingleton = 0;
220 	nCurParsed_Type = 0;
221 }
222 
223 void
TransferData()224 PE_Singleton::TransferData()
225 {
226 	if (NOT bIsPreDeclaration)
227 	{
228 		csv_assert(! sData_Name.empty());
229 		csv_assert( (pCurSingleton != 0) != (pCurSiSingleton != 0) );
230 	}
231 
232 	eState = e_none;
233 }
234 
235 void
ReceiveData()236 PE_Singleton::ReceiveData()
237 {
238     switch (eState)
239     {
240         case in_service:
241                     pCurSingleton->Set_Service(nCurParsed_Type);
242 					nCurParsed_Type = 0;
243 					eState = e_std;
244                     break;
245         case in_base_interface:
246                     pCurSiSingleton = &Gate().Ces().Store_SglIfcSingleton(
247                                                     CurNamespace().CeId(),
248                                                     sData_Name,
249                                                     nCurParsed_Type );
250 					PassDocuAt(*pCurSiSingleton);
251 					nCurParsed_Type = 0;
252 					eState = need_finish;
253                     break;
254         default:
255             csv_assert(false);
256     }   // end switch
257 }
258 
259 UnoIDL_PE &
MyPE()260 PE_Singleton::MyPE()
261 {
262 	return *this;
263 }
264 
265 }   // namespace uidl
266 }   // namespace csi
267