xref: /AOO41X/main/autodoc/source/parser_i/idl/pe_file2.cxx (revision 78bc99aafea97f4987aed12e674c2d2f1166dd91)
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_file2.hxx>
24 
25 
26 // NOT FULLY DECLARED SERVICES
27 #include <ary/idl/i_gate.hxx>
28 #include <ary/idl/i_module.hxx>
29 #include <ary/idl/ip_ce.hxx>
30 #include <ary/doc/d_oldidldocu.hxx>
31 #include <s2_luidl/distrib.hxx>
32 #include <s2_luidl/pe_servi.hxx>
33 #include <s2_luidl/pe_iface.hxx>
34 #include <s2_luidl/pe_singl.hxx>
35 #include <s2_luidl/pe_struc.hxx>
36 #include <s2_luidl/pe_excp.hxx>
37 #include <s2_luidl/pe_const.hxx>
38 #include <s2_luidl/pe_enum2.hxx>
39 #include <s2_luidl/pe_tydf2.hxx>
40 #include <s2_luidl/tk_keyw.hxx>
41 #include <s2_luidl/tk_ident.hxx>
42 #include <s2_luidl/tk_punct.hxx>
43 
44 
45 
46 
47 namespace csi
48 {
49 namespace uidl
50 {
51 
52 
PE_File(TokenDistributor & i_rTokenAdmin,const ParserInfo & i_parseInfo)53 PE_File::PE_File( TokenDistributor & i_rTokenAdmin,
54                   const ParserInfo & i_parseInfo )
55     :   pTokenAdmin(&i_rTokenAdmin),
56         pPE_Service(new PE_Service),
57         pPE_Singleton(new PE_Singleton),
58         pPE_Interface(new PE_Interface),
59         pPE_Struct(new PE_Struct),
60         pPE_Exception(new PE_Exception),
61         pPE_Constant(new PE_Constant),
62         pPE_Enum(new PE_Enum),
63         pPE_Typedef(new PE_Typedef),
64         pCurNamespace(0),
65         pParseInfo(&i_parseInfo),
66         eState(e_none),
67         nBracketCount_inDefMode(0)
68 {
69 }
70 
71 void
EstablishContacts(UnoIDL_PE * io_pParentPE,ary::Repository & io_rRepository,TokenProcessing_Result & o_rResult)72 PE_File::EstablishContacts( UnoIDL_PE *                 io_pParentPE,
73                             ary::Repository &       io_rRepository,
74                             TokenProcessing_Result &    o_rResult )
75 {
76     UnoIDL_PE::EstablishContacts(io_pParentPE,io_rRepository,o_rResult);
77     pPE_Service->EstablishContacts(this,io_rRepository,o_rResult);
78     pPE_Singleton->EstablishContacts(this,io_rRepository,o_rResult);
79     pPE_Interface->EstablishContacts(this,io_rRepository,o_rResult);
80     pPE_Struct->EstablishContacts(this,io_rRepository,o_rResult);
81     pPE_Exception->EstablishContacts(this,io_rRepository,o_rResult);
82     pPE_Constant->EstablishContacts(this,io_rRepository,o_rResult);
83     pPE_Enum->EstablishContacts(this,io_rRepository,o_rResult);
84     pPE_Typedef->EstablishContacts(this,io_rRepository,o_rResult);
85 
86     pCurNamespace = &Gate().Ces().GlobalNamespace();
87 }
88 
~PE_File()89 PE_File::~PE_File()
90 {
91 }
92 
93 void
ProcessToken(const Token & i_rToken)94 PE_File::ProcessToken( const Token & i_rToken )
95 {
96     i_rToken.Trigger(*this);
97 }
98 
99 void
Process_Identifier(const TokIdentifier & i_rToken)100 PE_File::Process_Identifier( const TokIdentifier & i_rToken )
101 {
102     switch (eState)
103     {
104         case wait_for_module:
105         {
106                 csv_assert(pCurNamespace != 0);
107 
108                 ary::idl::Module & rCe = Gate().Ces().CheckIn_Module(pCurNamespace->CeId(), i_rToken.Text());
109                 pCurNamespace = &rCe;
110 
111                 // Get docu out of normal:
112                 SetDocu(pTokenAdmin->ReleaseLastParsedDocu());
113                 PassDocuAt(rCe);
114 
115                 csv_assert(pCurNamespace != 0);
116 
117                 SetResult(done, stay);
118                 eState = wait_for_module_bracket;
119         }       break;
120         case on_default:
121                 SetResult(done, stay);
122                 break;
123         default:
124             csv_assert(false);
125     }
126 }
127 
128 void
Process_Punctuation(const TokPunctuation & i_rToken)129 PE_File::Process_Punctuation( const TokPunctuation & i_rToken )
130 {
131     switch (eState)
132     {
133         case e_std:
134                 if (i_rToken.Id() == TokPunctuation::CurledBracketClose)
135                 {
136                     csv_assert(pCurNamespace != 0);
137 
138                     pCurNamespace = &Gate().Ces().Find_Module(pCurNamespace->Owner());
139 
140                     SetResult(done, stay);
141                     eState = wait_for_module_semicolon;
142                 }
143                 else
144                 {
145                     csv_assert(false);
146                 }
147                 break;
148         case wait_for_module_bracket:
149                 if (i_rToken.Id() == TokPunctuation::CurledBracketOpen)
150                 {
151                     SetResult(done, stay);
152                     eState = e_std;
153                 }
154                 else
155                 {
156                     csv_assert(false);
157                 }
158                 break;
159         case wait_for_module_semicolon:
160                 if (i_rToken.Id() == TokPunctuation::Semicolon)
161                 {
162                     SetResult(done, stay);
163                     eState = e_std;
164                 }
165                 else
166                 {
167                     csv_assert(false);
168                 }
169                 break;
170         case on_default:
171                 if (i_rToken.Id() == TokPunctuation::CurledBracketClose)
172                 {
173                     nBracketCount_inDefMode--;
174                 }
175                 else if (i_rToken.Id() == TokPunctuation::CurledBracketOpen)
176                 {
177                     nBracketCount_inDefMode++;
178                 }
179                 else if (i_rToken.Id() == TokPunctuation::Semicolon)
180                 {
181                     if (nBracketCount_inDefMode <= 0)
182                     {
183                         eState = e_std;
184                     }
185                 }
186                 SetResult(done, stay);
187                 break;
188         default:
189             csv_assert(false);
190     }
191 }
192 
193 void
Process_MetaType(const TokMetaType & i_rToken)194 PE_File::Process_MetaType( const TokMetaType &  i_rToken )
195 {
196     switch (i_rToken.Id())
197     {
198         case TokMetaType::mt_service:
199                 eState = in_sub_pe;
200                 SetResult( not_done, push_sure, pPE_Service.Ptr());
201                 break;
202         case TokMetaType::mt_singleton:
203                 eState = in_sub_pe;
204                 SetResult( not_done, push_sure, pPE_Singleton.Ptr());
205                 break;
206         case TokMetaType::mt_uik:
207                 Cerr() << "Syntax error: [uik ....] is obsolete now." << Endl();
208                 SetResult( not_done, pop_failure);
209                 break;
210         case TokMetaType::mt_interface:
211                 eState = in_sub_pe;
212                 SetResult( not_done, push_sure, pPE_Interface.Ptr());
213                 break;
214         case TokMetaType::mt_module:
215                 eState = wait_for_module;
216                 SetResult( done, stay );
217                 break;
218         case TokMetaType::mt_struct:
219                 eState = in_sub_pe;
220                 SetResult( done, push_sure, pPE_Struct.Ptr());
221                 break;
222         case TokMetaType::mt_exception:
223                 eState = in_sub_pe;
224                 SetResult( done, push_sure, pPE_Exception.Ptr());
225                 break;
226         case TokMetaType::mt_constants:
227                 eState = in_sub_pe;
228                 SetResult( done, push_sure, pPE_Constant.Ptr());
229                 break;
230         case TokMetaType::mt_enum:
231                 eState = in_sub_pe;
232                 SetResult( done, push_sure, pPE_Enum.Ptr());
233                 break;
234         case TokMetaType::mt_typedef:
235                 eState = in_sub_pe;
236                 SetResult( done, push_sure, pPE_Typedef.Ptr());
237                 break;
238 
239         default:
240                 Process_Default();
241     }   // end switch
242 }
243 
244 void
Process_Stereotype(const TokStereotype & i_rToken)245 PE_File::Process_Stereotype( const TokStereotype & i_rToken )
246 {
247     if (i_rToken.Id() == TokStereotype::ste_published)
248     {
249         pTokenAdmin->Set_PublishedOn();
250 
251         SetResult(done, stay);
252     }
253     else
254     {
255         Process_Default();
256     }
257 }
258 
259 void
Process_Default()260 PE_File::Process_Default()
261 {
262     if (eState != on_default)
263     {
264         eState = on_default;
265         nBracketCount_inDefMode = 0;
266     }
267     SetResult(done, stay);
268 }
269 
270 const ary::idl::Module &
CurNamespace() const271 PE_File::CurNamespace() const
272 {
273     csv_assert(pCurNamespace);
274     return *pCurNamespace;
275 }
276 
277 const ParserInfo &
ParseInfo() const278 PE_File::ParseInfo() const
279 {
280     csv_assert(pParseInfo);
281     return *pParseInfo;
282 }
283 
284 void
InitData()285 PE_File::InitData()
286 {
287     eState = e_std;
288 }
289 
290 void
TransferData()291 PE_File::TransferData()
292 {
293     eState = e_none;
294 }
295 
296 void
ReceiveData()297 PE_File::ReceiveData()
298 {
299     eState = e_std;
300 }
301 
302 
303 UnoIDL_PE &
MyPE()304 PE_File::MyPE()
305 {
306     return *this;
307 }
308 
309 }   // namespace uidl
310 }   // namespace csi
311 
312 
313