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