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_const.hxx>
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
26cdf0e10cSrcweir #include <ary/idl/i_gate.hxx>
27cdf0e10cSrcweir #include <ary/idl/i_constant.hxx>
28cdf0e10cSrcweir #include <ary/idl/i_constgroup.hxx>
29cdf0e10cSrcweir #include <ary/idl/ip_ce.hxx>
30cdf0e10cSrcweir #include <ary/doc/d_oldidldocu.hxx>
31cdf0e10cSrcweir #include <s2_luidl/pe_type2.hxx>
32cdf0e10cSrcweir #include <s2_luidl/pe_evalu.hxx>
33cdf0e10cSrcweir #include <s2_luidl/tk_punct.hxx>
34cdf0e10cSrcweir #include <s2_luidl/tk_ident.hxx>
35cdf0e10cSrcweir #include <s2_luidl/tk_keyw.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace csi
39cdf0e10cSrcweir {
40cdf0e10cSrcweir namespace uidl
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #ifdef DF
45cdf0e10cSrcweir #undef DF
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #define DF 	&PE_Constant::On_Default
48cdf0e10cSrcweir 
49cdf0e10cSrcweir PE_Constant::F_TOK
50cdf0e10cSrcweir PE_Constant::aDispatcher[PE_Constant::e_STATES_MAX][PE_Constant::tt_MAX] =
51cdf0e10cSrcweir 		{ 	{ DF, DF, DF },  // e_none
52cdf0e10cSrcweir 			{ DF, &PE_Constant::On_expect_name_Identifier,
53cdf0e10cSrcweir 					  DF },  // expect_name
54cdf0e10cSrcweir 			{ DF, DF, &PE_Constant::On_expect_curl_bracket_open_Punctuation },  // expect_curl_bracket_open
55cdf0e10cSrcweir 			{ &PE_Constant::On_expect_const_Stereotype,
56cdf0e10cSrcweir 				  DF, &PE_Constant::On_expect_const_Punctuation },  // expect_const
57cdf0e10cSrcweir 			{ DF, &PE_Constant::On_expect_value_Identifier,
58cdf0e10cSrcweir 					  DF },  // expect_value
59cdf0e10cSrcweir 			{ DF, DF, &PE_Constant::On_expect_finish_Punctuation }  // expect_finish
60cdf0e10cSrcweir 		};
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
64cdf0e10cSrcweir inline void
CallHandler(const char * i_sTokenText,E_TokenType i_eTokenType)65cdf0e10cSrcweir PE_Constant::CallHandler( const char *		i_sTokenText,
66cdf0e10cSrcweir 						  E_TokenType		i_eTokenType )
67cdf0e10cSrcweir 	{ (this->*aDispatcher[eState][i_eTokenType])(i_sTokenText); }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
PE_Constant()72cdf0e10cSrcweir PE_Constant::PE_Constant()
73cdf0e10cSrcweir 	:	eState(e_none),
74cdf0e10cSrcweir 		sData_Name(),
75cdf0e10cSrcweir         nDataId(0),
76cdf0e10cSrcweir 		pPE_Type(0),
77cdf0e10cSrcweir 		nType(0),
78cdf0e10cSrcweir 		pPE_Value(0),
79cdf0e10cSrcweir 		sName(),
80cdf0e10cSrcweir 		sAssignment()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	pPE_Type = new PE_Type(nType);
83cdf0e10cSrcweir 	pPE_Value = new PE_Value(sName, sAssignment, true);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir void
EstablishContacts(UnoIDL_PE * io_pParentPE,ary::Repository & io_rRepository,TokenProcessing_Result & o_rResult)87cdf0e10cSrcweir PE_Constant::EstablishContacts( UnoIDL_PE *					io_pParentPE,
88cdf0e10cSrcweir 								ary::Repository &		io_rRepository,
89cdf0e10cSrcweir 								TokenProcessing_Result & 	o_rResult )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
92cdf0e10cSrcweir 	pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
93cdf0e10cSrcweir 	pPE_Value->EstablishContacts(this,io_rRepository,o_rResult);
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
~PE_Constant()96cdf0e10cSrcweir PE_Constant::~PE_Constant()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir void
ProcessToken(const Token & i_rToken)101cdf0e10cSrcweir PE_Constant::ProcessToken( const Token & i_rToken )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	i_rToken.Trigger(*this);
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir void
Process_Identifier(const TokIdentifier & i_rToken)107cdf0e10cSrcweir PE_Constant::Process_Identifier( const TokIdentifier & i_rToken )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	CallHandler(i_rToken.Text(), tt_identifier);
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir void
Process_Punctuation(const TokPunctuation & i_rToken)113cdf0e10cSrcweir PE_Constant::Process_Punctuation( const TokPunctuation & i_rToken )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	CallHandler(i_rToken.Text(), tt_punctuation);
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir void
Process_Stereotype(const TokStereotype & i_rToken)119cdf0e10cSrcweir PE_Constant::Process_Stereotype( const TokStereotype & i_rToken )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	CallHandler(i_rToken.Text(), tt_stereotype);
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir void
On_expect_name_Identifier(const char * i_sText)125cdf0e10cSrcweir PE_Constant::On_expect_name_Identifier(const char * i_sText)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	sName = i_sText;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	SetResult(done,stay);
130cdf0e10cSrcweir 	eState = expect_curl_bracket_open;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir void
On_expect_curl_bracket_open_Punctuation(const char * i_sText)134cdf0e10cSrcweir PE_Constant::On_expect_curl_bracket_open_Punctuation(const char * i_sText)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	if ( i_sText[0] == '{')
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		sData_Name = sName;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         ary::idl::ConstantsGroup &
141cdf0e10cSrcweir         rCe = Gate().Ces().
142cdf0e10cSrcweir                     Store_ConstantsGroup(CurNamespace().CeId(),sData_Name);
143cdf0e10cSrcweir 		PassDocuAt(rCe);
144cdf0e10cSrcweir         nDataId = rCe.CeId();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		SetResult(done,stay);
147cdf0e10cSrcweir 		eState = expect_const;
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 	else
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		On_Default(i_sText);
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir void
On_expect_const_Stereotype(const char *)156cdf0e10cSrcweir PE_Constant::On_expect_const_Stereotype(const char *)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir 	SetResult( done, push_sure, pPE_Type.Ptr() );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir void
On_expect_const_Punctuation(const char * i_sText)162cdf0e10cSrcweir PE_Constant::On_expect_const_Punctuation(const char * i_sText)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	if ( i_sText[0] == '}')
165cdf0e10cSrcweir 	{
166cdf0e10cSrcweir 		SetResult(done,stay);
167cdf0e10cSrcweir 		eState = expect_finish;
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 	else
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		On_Default(i_sText);
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir void
On_expect_value_Identifier(const char *)176cdf0e10cSrcweir PE_Constant::On_expect_value_Identifier(const char *)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	SetResult( not_done, push_sure, pPE_Value.Ptr() );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir void
On_expect_finish_Punctuation(const char * i_sText)182cdf0e10cSrcweir PE_Constant::On_expect_finish_Punctuation(const char * i_sText)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	if ( i_sText[0] == ';')
185cdf0e10cSrcweir 	{
186cdf0e10cSrcweir 		SetResult(done,pop_success);
187cdf0e10cSrcweir 		eState = e_none;
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 	else
190cdf0e10cSrcweir 	{
191cdf0e10cSrcweir 		On_Default(i_sText);
192cdf0e10cSrcweir 	}
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir void
On_Default(const char *)196cdf0e10cSrcweir PE_Constant::On_Default(const char * )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	SetResult(not_done,pop_failure);
199cdf0e10cSrcweir 	eState = e_none;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir void
EmptySingleConstData()203cdf0e10cSrcweir PE_Constant::EmptySingleConstData()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	nType = 0;
206cdf0e10cSrcweir 	sName = "";
207cdf0e10cSrcweir 	sAssignment = "";
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir void
CreateSingleConstant()211cdf0e10cSrcweir PE_Constant::CreateSingleConstant()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     ary::idl::Constant &
214cdf0e10cSrcweir         rCe = Gate().Ces().Store_Constant( nDataId,
215cdf0e10cSrcweir                                            sName,
216cdf0e10cSrcweir                                            nType,
217cdf0e10cSrcweir                                            sAssignment );
218cdf0e10cSrcweir 	pPE_Type->PassDocuAt(rCe);
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir void
InitData()222cdf0e10cSrcweir PE_Constant::InitData()
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	eState = expect_name;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	sData_Name.clear();
227cdf0e10cSrcweir 	nDataId = 0;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	EmptySingleConstData();
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir void
ReceiveData()233cdf0e10cSrcweir PE_Constant::ReceiveData()
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	switch (eState)
236cdf0e10cSrcweir 	{
237cdf0e10cSrcweir 		case expect_const:
238cdf0e10cSrcweir 					eState = expect_value;
239cdf0e10cSrcweir 					break;
240cdf0e10cSrcweir 		case expect_value:
241cdf0e10cSrcweir 		{
242cdf0e10cSrcweir 					if (sName.length() == 0 OR sAssignment.length() == 0 OR NOT nType.IsValid())
243cdf0e10cSrcweir 					{
244cdf0e10cSrcweir 						Cerr() << "Constant without value found." << Endl();
245cdf0e10cSrcweir 						eState = expect_const;
246cdf0e10cSrcweir 						break;
247cdf0e10cSrcweir 					}
248cdf0e10cSrcweir 
249cdf0e10cSrcweir                     CreateSingleConstant();
250cdf0e10cSrcweir 					EmptySingleConstData();
251cdf0e10cSrcweir 					eState = expect_const;
252cdf0e10cSrcweir 		}			break;
253cdf0e10cSrcweir 		default:
254cdf0e10cSrcweir 					SetResult(not_done, pop_failure);
255cdf0e10cSrcweir 					eState = e_none;
256cdf0e10cSrcweir 	}	// end switch
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir void
TransferData()260cdf0e10cSrcweir PE_Constant::TransferData()
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	csv_assert(nDataId.IsValid());
263cdf0e10cSrcweir 	eState = e_none;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir UnoIDL_PE &
MyPE()267cdf0e10cSrcweir PE_Constant::MyPE()
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	return *this;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir }   // namespace uidl
273cdf0e10cSrcweir }   // namespace csi
274cdf0e10cSrcweir 
275