1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include <s2_luidl/pe_struc.hxx>
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
33*cdf0e10cSrcweir #include <ary/idl/i_gate.hxx>
34*cdf0e10cSrcweir #include <ary/idl/i_struct.hxx>
35*cdf0e10cSrcweir #include <ary/idl/ip_ce.hxx>
36*cdf0e10cSrcweir #include <ary/doc/d_oldidldocu.hxx>
37*cdf0e10cSrcweir #include <s2_luidl/tk_ident.hxx>
38*cdf0e10cSrcweir #include <s2_luidl/tk_punct.hxx>
39*cdf0e10cSrcweir #include <s2_luidl/tk_keyw.hxx>
40*cdf0e10cSrcweir #include <s2_luidl/pe_type2.hxx>
41*cdf0e10cSrcweir #include <s2_luidl/pe_selem.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace csi
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir namespace uidl
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir PE_Struct::PE_Struct()
52*cdf0e10cSrcweir     // :    aWork,
53*cdf0e10cSrcweir     //      pStati
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir     pStati = new S_Stati(*this);
56*cdf0e10cSrcweir }
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir void
59*cdf0e10cSrcweir PE_Struct::EstablishContacts( UnoIDL_PE *               io_pParentPE,
60*cdf0e10cSrcweir                               ary::Repository &			io_rRepository,
61*cdf0e10cSrcweir                               TokenProcessing_Result & 	o_rResult )
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir     UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
64*cdf0e10cSrcweir     Work().pPE_Element->EstablishContacts(this,io_rRepository,o_rResult);
65*cdf0e10cSrcweir     Work().pPE_Type->EstablishContacts(this,io_rRepository,o_rResult);
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir PE_Struct::~PE_Struct()
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir void
73*cdf0e10cSrcweir PE_Struct::ProcessToken( const Token & i_rToken )
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     i_rToken.Trigger(*Stati().pCurStatus);
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir void
80*cdf0e10cSrcweir PE_Struct::InitData()
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     Work().InitData();
83*cdf0e10cSrcweir     Stati().pCurStatus = &Stati().aWaitForName;
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir void
87*cdf0e10cSrcweir PE_Struct::TransferData()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     if (NOT Work().bIsPreDeclaration)
90*cdf0e10cSrcweir     {
91*cdf0e10cSrcweir         csv_assert(Work().sData_Name.size() > 0);
92*cdf0e10cSrcweir         csv_assert(Work().nCurStruct.IsValid());
93*cdf0e10cSrcweir     }
94*cdf0e10cSrcweir     Stati().pCurStatus = &Stati().aNone;
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir void
98*cdf0e10cSrcweir PE_Struct::ReceiveData()
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     Stati().pCurStatus->On_SubPE_Left();
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir PE_Struct::S_Work::S_Work()
104*cdf0e10cSrcweir     :   sData_Name(),
105*cdf0e10cSrcweir         sData_TemplateParam(),
106*cdf0e10cSrcweir         bIsPreDeclaration(false),
107*cdf0e10cSrcweir         nCurStruct(0),
108*cdf0e10cSrcweir         pPE_Element(0),
109*cdf0e10cSrcweir         nCurParsed_ElementRef(0),
110*cdf0e10cSrcweir         pPE_Type(0),
111*cdf0e10cSrcweir         nCurParsed_Base(0)
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     pPE_Element = new PE_StructElement(nCurParsed_ElementRef,nCurStruct,sData_TemplateParam);
115*cdf0e10cSrcweir     pPE_Type = new PE_Type(nCurParsed_Base);
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir void
119*cdf0e10cSrcweir PE_Struct::S_Work::InitData()
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir     sData_Name.clear();
122*cdf0e10cSrcweir     sData_TemplateParam.clear();
123*cdf0e10cSrcweir     bIsPreDeclaration = false;
124*cdf0e10cSrcweir     nCurStruct = 0;
125*cdf0e10cSrcweir     nCurParsed_ElementRef = 0;
126*cdf0e10cSrcweir     nCurParsed_Base = 0;
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir void
130*cdf0e10cSrcweir PE_Struct::S_Work::Prepare_PE_QualifiedName()
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     nCurParsed_ElementRef = 0;
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir void
136*cdf0e10cSrcweir PE_Struct::S_Work::Prepare_PE_Element()
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir     nCurParsed_Base = 0;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir void
142*cdf0e10cSrcweir PE_Struct::S_Work::Data_Set_Name( const char * i_sName )
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     sData_Name = i_sName;
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void
148*cdf0e10cSrcweir PE_Struct::S_Work::Data_Set_TemplateParam( const char * i_sTemplateParam )
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     sData_TemplateParam = i_sTemplateParam;
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir PE_Struct::S_Stati::S_Stati(PE_Struct & io_rStruct)
154*cdf0e10cSrcweir     :   aNone(io_rStruct),
155*cdf0e10cSrcweir         aWaitForName(io_rStruct),
156*cdf0e10cSrcweir         aGotName(io_rStruct),
157*cdf0e10cSrcweir         aWaitForTemplateParam(io_rStruct),
158*cdf0e10cSrcweir         aWaitForTemplateEnd(io_rStruct),
159*cdf0e10cSrcweir         aWaitForBase(io_rStruct),
160*cdf0e10cSrcweir         aGotBase(io_rStruct),
161*cdf0e10cSrcweir         aWaitForElement(io_rStruct),
162*cdf0e10cSrcweir         aWaitForFinish(io_rStruct),
163*cdf0e10cSrcweir         pCurStatus(0)
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     pCurStatus = &aNone;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir //***********************       Stati       ***************************//
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir UnoIDL_PE &
173*cdf0e10cSrcweir PE_Struct::PE_StructState::MyPE()
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     return rStruct;
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir void
180*cdf0e10cSrcweir PE_Struct::State_WaitForName::Process_Identifier( const TokIdentifier & i_rToken )
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     Work().Data_Set_Name(i_rToken.Text());
183*cdf0e10cSrcweir     MoveState( Stati().aGotName );
184*cdf0e10cSrcweir     SetResult(done,stay);
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir void
188*cdf0e10cSrcweir PE_Struct::State_GotName::Process_Punctuation( const TokPunctuation & i_rToken )
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     if ( i_rToken.Id() != TokPunctuation::Semicolon )
191*cdf0e10cSrcweir     {
192*cdf0e10cSrcweir         switch (i_rToken.Id())
193*cdf0e10cSrcweir     	{
194*cdf0e10cSrcweir             case TokPunctuation::Colon:
195*cdf0e10cSrcweir                 MoveState( Stati().aWaitForBase );
196*cdf0e10cSrcweir                 SetResult(done,push_sure,Work().pPE_Type.Ptr());
197*cdf0e10cSrcweir                 Work().Prepare_PE_QualifiedName();
198*cdf0e10cSrcweir             	break;
199*cdf0e10cSrcweir             case TokPunctuation::CurledBracketOpen:
200*cdf0e10cSrcweir                 PE().store_Struct();
201*cdf0e10cSrcweir                 MoveState( Stati().aWaitForElement );
202*cdf0e10cSrcweir                 SetResult(done,stay);
203*cdf0e10cSrcweir             	break;
204*cdf0e10cSrcweir             case TokPunctuation::Lesser:
205*cdf0e10cSrcweir                 MoveState( Stati().aWaitForTemplateParam );
206*cdf0e10cSrcweir                 SetResult(done,stay);
207*cdf0e10cSrcweir             	break;
208*cdf0e10cSrcweir             default:
209*cdf0e10cSrcweir                 SetResult(not_done,pop_failure);
210*cdf0e10cSrcweir         }   // end switch
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir     else
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         Work().sData_Name.clear();
215*cdf0e10cSrcweir         SetResult(done,pop_success);
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir void
220*cdf0e10cSrcweir PE_Struct::State_WaitForTemplateParam::Process_Identifier( const TokIdentifier & i_rToken )
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir     Work().Data_Set_TemplateParam(i_rToken.Text());
223*cdf0e10cSrcweir     MoveState( Stati().aWaitForTemplateEnd );
224*cdf0e10cSrcweir     SetResult(done,stay);
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir void
228*cdf0e10cSrcweir PE_Struct::State_WaitForTemplateEnd::Process_Punctuation( const TokPunctuation & )
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir     // Assume:  TokPunctuation::Greater
231*cdf0e10cSrcweir     MoveState( Stati().aGotName );
232*cdf0e10cSrcweir     SetResult(done,stay);
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir void
236*cdf0e10cSrcweir PE_Struct::State_WaitForBase::On_SubPE_Left()
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     MoveState(Stati().aGotBase);
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir void
242*cdf0e10cSrcweir PE_Struct::State_GotBase::Process_Punctuation( const TokPunctuation & i_rToken )
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir     if ( i_rToken.Id() == TokPunctuation::CurledBracketOpen )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         PE().store_Struct();
247*cdf0e10cSrcweir         MoveState( Stati().aWaitForElement );
248*cdf0e10cSrcweir         SetResult(done,stay);
249*cdf0e10cSrcweir     }
250*cdf0e10cSrcweir     else
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir         SetResult(not_done,pop_failure);
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir void
257*cdf0e10cSrcweir PE_Struct::State_WaitForElement::Process_Identifier( const TokIdentifier & )
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     SetResult( not_done, push_sure, Work().pPE_Element.Ptr() );
260*cdf0e10cSrcweir     Work().Prepare_PE_Element();
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir void
264*cdf0e10cSrcweir PE_Struct::State_WaitForElement::Process_NameSeparator()
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir     SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
267*cdf0e10cSrcweir     Work().Prepare_PE_Element();
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir void
271*cdf0e10cSrcweir PE_Struct::State_WaitForElement::Process_BuiltInType( const TokBuiltInType & )
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir     SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
274*cdf0e10cSrcweir     Work().Prepare_PE_Element();
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir void
278*cdf0e10cSrcweir PE_Struct::State_WaitForElement::Process_TypeModifier(const TokTypeModifier & )
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir     SetResult( not_done, push_sure, Work().pPE_Element.Ptr());
281*cdf0e10cSrcweir     Work().Prepare_PE_Element();
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir void
285*cdf0e10cSrcweir PE_Struct::State_WaitForElement::Process_Punctuation( const TokPunctuation & i_rToken )
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir     if ( i_rToken.Id() == TokPunctuation::CurledBracketClose )
288*cdf0e10cSrcweir     {
289*cdf0e10cSrcweir         MoveState( Stati().aWaitForFinish );
290*cdf0e10cSrcweir         SetResult( done, stay );
291*cdf0e10cSrcweir     }
292*cdf0e10cSrcweir     else
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         SetResult( not_done, pop_failure );
295*cdf0e10cSrcweir     }
296*cdf0e10cSrcweir }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir void
299*cdf0e10cSrcweir PE_Struct::State_WaitForFinish::Process_Punctuation( const TokPunctuation & i_rToken )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir     if (i_rToken.Id() == TokPunctuation::Semicolon)
302*cdf0e10cSrcweir     {
303*cdf0e10cSrcweir         MoveState( Stati().aNone );
304*cdf0e10cSrcweir         SetResult( done, pop_success );
305*cdf0e10cSrcweir     }
306*cdf0e10cSrcweir     else
307*cdf0e10cSrcweir     {
308*cdf0e10cSrcweir         SetResult( not_done, pop_failure );
309*cdf0e10cSrcweir     }
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir void
313*cdf0e10cSrcweir PE_Struct::store_Struct()
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     ary::idl::Struct &
316*cdf0e10cSrcweir         rCe = Gate().Ces().Store_Struct(
317*cdf0e10cSrcweir                         CurNamespace().CeId(),
318*cdf0e10cSrcweir                         Work().sData_Name,
319*cdf0e10cSrcweir                         Work().nCurParsed_Base,
320*cdf0e10cSrcweir                         Work().sData_TemplateParam );
321*cdf0e10cSrcweir     PassDocuAt(rCe);
322*cdf0e10cSrcweir     Work().nCurStruct = rCe.CeId();
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir }   // namespace uidl
327*cdf0e10cSrcweir }   // namespace csi
328