xref: /trunk/main/autodoc/source/ary/idl/ia_ce.cxx (revision d291ea28)
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 "ia_ce.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <algorithm>
28 #include <cosv/tpl/tpltools.hxx>
29 #include <ary/idl/i_attribute.hxx>
30 #include <ary/idl/i_constant.hxx>
31 #include <ary/idl/i_constgroup.hxx>
32 #include <ary/idl/i_enum.hxx>
33 #include <ary/idl/i_enumvalue.hxx>
34 #include <ary/idl/i_exception.hxx>
35 #include <ary/idl/i_function.hxx>
36 #include <ary/idl/i_interface.hxx>
37 #include <ary/idl/i_module.hxx>
38 #include <ary/idl/i_namelookup.hxx>
39 #include <ary/idl/i_property.hxx>
40 #include <ary/idl/i_service.hxx>
41 #include <ary/idl/i_singleton.hxx>
42 #include <ary/idl/i_siservice.hxx>
43 #include <ary/idl/i_sisingleton.hxx>
44 #include <ary/idl/i_struct.hxx>
45 #include <ary/idl/i_structelem.hxx>
46 #include <ary/idl/i_traits.hxx>
47 #include <ary/idl/i_typedef.hxx>
48 #include <idsort.hxx>
49 #include "ia_type.hxx"
50 #include "is_ce.hxx"
51 #include "it_tplparam.hxx"
52 
53 
54 
55 
56 namespace ary
57 {
58 namespace idl
59 {
60 
61 inline Module &
lhf_Access_Module(Ce_id i_nId)62 CeAdmin::lhf_Access_Module( Ce_id i_nId )
63     { return ary_cast<Module>(Storage()[i_nId]); }
64 
65 inline void
lhf_Put2Storage_and_AssignId(CodeEntity & pass_io_rCe)66 CeAdmin::lhf_Put2Storage_and_AssignId( CodeEntity & pass_io_rCe )
67     { // This also assigns an ID to pass_io_rCe:
68       Storage().Store_Entity(pass_io_rCe);
69       my_NameDictionary().Add_Name( pass_io_rCe.LocalName(),
70                                     pass_io_rCe.CeId(),
71                                     pass_io_rCe.AryClass(),
72                                     pass_io_rCe.Owner() );
73     }
74 
75 inline void
lhf_Store_NewEntity(DYN CodeEntity & pass_io_rCe,Module & i_rOwner)76 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity &  pass_io_rCe,
77                                    Module &          i_rOwner )
78 {
79     lhf_Put2Storage_and_AssignId(pass_io_rCe);
80     i_rOwner.Add_Name(pass_io_rCe.LocalName(), pass_io_rCe.CeId());
81 }
82 
83 inline void
lhf_Store_NewEntity(DYN CodeEntity & pass_io_rCe,Ce_id i_nOwnerModule)84 CeAdmin::lhf_Store_NewEntity( DYN CodeEntity &  pass_io_rCe,
85                                    Ce_id             i_nOwnerModule )
86 {
87     lhf_Store_NewEntity(pass_io_rCe, lhf_Access_Module(i_nOwnerModule));
88 }
89 
90 
91 
CeAdmin(NameLookup & io_rNameDictionary,TypeAdmin & io_rTypePilot)92 CeAdmin::CeAdmin( NameLookup &        io_rNameDictionary,
93                   TypeAdmin &         io_rTypePilot )
94     :   pStorage(new Ce_Storage),
95         pGlobalNamespace(0),
96         pNameDictionary(&io_rNameDictionary),
97         pTypePilot(&io_rTypePilot)
98 {
99     Storage().Set_Reserved(
100                     predefined::ce_GlobalNamespace,
101                     *new Module );
102     pGlobalNamespace = &lhf_Access_Module(Ce_id(predefined::ce_GlobalNamespace));
103 }
104 
~CeAdmin()105 CeAdmin::~CeAdmin()
106 {
107 }
108 
109 
110 
111 Module &
CheckIn_Module(Ce_id i_nParentId,const String & i_sName)112 CeAdmin::CheckIn_Module( Ce_id               i_nParentId,
113                             const String &      i_sName )
114 {
115     Module & rOwner  = lhf_Access_Module(i_nParentId);
116     Ce_id    nId     = rOwner.Search_Name(i_sName);
117     if (nId.IsValid())
118     {
119         return lhf_Access_Module(nId);
120     }
121 
122     Module & ret = *new Module( i_sName,
123                                 rOwner );
124     lhf_Store_NewEntity(ret, rOwner);
125     return ret;
126 }
127 
128 Service &
Store_Service(Ce_id i_nOwner,const String & i_sName)129 CeAdmin::Store_Service( Ce_id           i_nOwner,
130                         const String &  i_sName )
131 {
132     Service & ret = *new Service( i_sName,
133                                   i_nOwner );
134     lhf_Store_NewEntity(ret, i_nOwner);
135     return ret;
136 }
137 
138 SglIfcService &
Store_SglIfcService(Ce_id i_nOwner,const String & i_sName,Type_id i_nBaseInterface)139 CeAdmin::Store_SglIfcService( Ce_id               i_nOwner,
140 								   const String &      i_sName,
141 								   Type_id             i_nBaseInterface )
142 {
143     SglIfcService &
144         ret = *new SglIfcService( i_sName,
145                                   i_nOwner,
146                                   i_nBaseInterface );
147     lhf_Store_NewEntity(ret, i_nOwner);
148     return ret;
149 }
150 
151 Interface &
Store_Interface(Ce_id i_nOwner,const String & i_sName,Type_id i_nBase)152 CeAdmin::Store_Interface( Ce_id               i_nOwner,
153                                   const String &      i_sName,
154                                   Type_id             i_nBase )
155 {
156     Interface & ret = *new Interface( i_sName,
157                                       i_nOwner );
158     lhf_Store_NewEntity(ret, i_nOwner);
159     if (i_nBase.IsValid())
160         ret.Add_Base(i_nBase, 0);
161     return ret;
162 }
163 
164 Struct &
Store_Struct(Ce_id i_nOwner,const String & i_sName,Type_id i_nBase,const String & i_sTemplateParam)165 CeAdmin::Store_Struct( Ce_id               i_nOwner,
166                                const String &      i_sName,
167                                Type_id             i_nBase,
168                                const String &      i_sTemplateParam )
169 {
170     if (NOT i_sTemplateParam.empty())
171     {
172         return lhf_Store_TplStruct( i_nOwner,
173                                     i_sName,
174                                     i_nBase,
175                                     i_sTemplateParam );
176     }
177 
178     Struct & ret = *new Struct( i_sName,
179                                 i_nOwner,
180                                 i_nBase,
181                                 String::Null_(),
182                                 Type_id::Null_() );
183     lhf_Store_NewEntity(ret, i_nOwner);
184 
185     return ret;
186 }
187 
188 Exception &
Store_Exception(Ce_id i_nOwner,const String & i_sName,Type_id i_nBase)189 CeAdmin::Store_Exception( Ce_id               i_nOwner,
190                                   const String &      i_sName,
191                                   Type_id             i_nBase )
192 {
193     Exception & ret = *new Exception( i_sName,
194                                       i_nOwner,
195                                       i_nBase );
196     lhf_Store_NewEntity(ret, i_nOwner);
197     return ret;
198 }
199 
200 Enum &
Store_Enum(Ce_id i_nOwner,const String & i_sName)201 CeAdmin::Store_Enum( Ce_id               i_nOwner,
202                              const String &      i_sName )
203 {
204     Enum & ret = *new Enum( i_sName,
205                             i_nOwner );
206     lhf_Store_NewEntity(ret, i_nOwner);
207     return ret;
208 }
209 
210 Typedef &
Store_Typedef(Ce_id i_nOwner,const String & i_sName,Type_id i_nDefiningType)211 CeAdmin::Store_Typedef( Ce_id               i_nOwner,
212                                 const String &      i_sName,
213                                 Type_id             i_nDefiningType )
214 {
215     Typedef & ret = *new Typedef( i_sName,
216                                   i_nOwner,
217                                   i_nDefiningType );
218     lhf_Store_NewEntity(ret, i_nOwner);
219     return ret;
220 }
221 
222 
223 ConstantsGroup &
Store_ConstantsGroup(Ce_id i_nOwner,const String & i_sName)224 CeAdmin::Store_ConstantsGroup( Ce_id               i_nOwner,
225                                        const String &      i_sName )
226 {
227     ConstantsGroup & ret = *new ConstantsGroup( i_sName,
228                                                 i_nOwner );
229     lhf_Store_NewEntity(ret, i_nOwner);
230     return ret;
231 }
232 
233 Singleton &
Store_Singleton(Ce_id i_nOwner,const String & i_sName)234 CeAdmin::Store_Singleton( Ce_id               i_nOwner,
235                                   const String &      i_sName )
236 {
237     Singleton & ret = *new Singleton( i_sName,
238                                       i_nOwner );
239     lhf_Store_NewEntity(ret, i_nOwner);
240     return ret;
241 }
242 
243 SglIfcSingleton &
Store_SglIfcSingleton(Ce_id i_nOwner,const String & i_sName,Type_id i_nBaseInterface)244 CeAdmin::Store_SglIfcSingleton( Ce_id               i_nOwner,
245 									 const String &      i_sName,
246 									 Type_id             i_nBaseInterface )
247 {
248     SglIfcSingleton &
249         ret = *new SglIfcSingleton( i_sName,
250 									i_nOwner,
251 									i_nBaseInterface );
252     lhf_Store_NewEntity(ret, i_nOwner);
253     return ret;
254 }
255 
256 Constant &
Store_Constant(Ce_id i_nOwner,const String & i_sName,Type_id i_nType,const String & i_sValue)257 CeAdmin::Store_Constant( Ce_id               i_nOwner,
258                                  const String &      i_sName,
259                                  Type_id             i_nType,
260                                  const String &      i_sValue )
261 {
262     ConstantsGroup &
263         rOwner  = ary_cast<ConstantsGroup>(Storage()[i_nOwner]);
264     Constant & ret = *new Constant( i_sName,
265                                     i_nOwner,
266                                     rOwner.NameRoom(),
267                                     i_nType,
268                                     i_sValue );
269     lhf_Put2Storage_and_AssignId(ret);
270     rOwner.Add_Constant(ret.CeId());
271     return ret;
272 }
273 
274 Property &
Store_Property(Ce_id i_nOwner,const String & i_sName,Type_id i_nType,Property::Stereotypes i_stereotypes)275 CeAdmin::Store_Property( Ce_id                  i_nOwner,
276                                  const String &         i_sName,
277                                  Type_id                i_nType,
278                                  Property::Stereotypes  i_stereotypes )
279 {
280     Service &
281         rOwner = ary_cast<Service>(Storage()[i_nOwner]);
282     Property & ret = *new Property( i_sName,
283                                     i_nOwner,
284                                     rOwner.NameRoom(),
285                                     i_nType,
286                                     i_stereotypes );
287     lhf_Put2Storage_and_AssignId(ret);
288     rOwner.Add_Property(ret.CeId());
289     return ret;
290 }
291 
292 Function &
Store_Function(Ce_id i_nOwner,const String & i_sName,Type_id i_nReturnType,bool i_bOneWay)293 CeAdmin::Store_Function( Ce_id               i_nOwner,
294                                  const String &      i_sName,
295                                  Type_id             i_nReturnType,
296                                  bool                i_bOneWay )
297 {
298     Interface &
299         rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
300     Function & ret = *new Function( i_sName,
301 									i_nOwner,
302                                     rOwner.NameRoom(),
303                                     i_nReturnType,
304                               		i_bOneWay);
305     lhf_Put2Storage_and_AssignId(ret);
306     rOwner.Add_Function(ret.CeId());
307     return ret;
308 }
309 
310 Function &
Store_ServiceConstructor(Ce_id i_nOwner,const String & i_sName)311 CeAdmin::Store_ServiceConstructor( Ce_id               i_nOwner,
312 										const String &      i_sName )
313 {
314     SglIfcService &
315                 rOwner = ary_cast<SglIfcService>(Storage()[i_nOwner]);
316     Function &  ret = *new Function( i_sName,
317 									 i_nOwner,
318 									 rOwner.NameRoom() );
319     lhf_Put2Storage_and_AssignId(ret);
320     rOwner.Add_Constructor(ret.CeId());
321     return ret;
322 }
323 
324 StructElement &
Store_StructMember(Ce_id i_nOwner,const String & i_sName,Type_id i_nType)325 CeAdmin::Store_StructMember( Ce_id               i_nOwner,
326                                      const String &      i_sName,
327                                      Type_id             i_nType )
328 {
329     Struct &
330         rOwner = ary_cast<Struct>(Storage()[i_nOwner]);
331     StructElement & ret = *new StructElement( i_sName,
332                                               i_nOwner,
333                                               rOwner.NameRoom(),
334                                               i_nType );
335     lhf_Put2Storage_and_AssignId(ret);
336     rOwner.Add_Member(ret.CeId());
337     return ret;
338 }
339 
340 StructElement &
Store_ExceptionMember(Ce_id i_nOwner,const String & i_sName,Type_id i_nType)341 CeAdmin::Store_ExceptionMember( Ce_id               i_nOwner,
342                                         const String &      i_sName,
343                                         Type_id             i_nType )
344 {
345     Exception &
346         rOwner = ary_cast<Exception>(Storage()[i_nOwner]);
347     StructElement & ret = *new StructElement( i_sName,
348                                               i_nOwner,
349                                               rOwner.NameRoom(),
350                                               i_nType );
351     lhf_Put2Storage_and_AssignId(ret);
352     rOwner.Add_Member(ret.CeId());
353     return ret;
354 }
355 
356 EnumValue &
Store_EnumValue(Ce_id i_nOwner,const String & i_sName,const String & i_sValue)357 CeAdmin::Store_EnumValue( Ce_id               i_nOwner,
358                                   const String &      i_sName,
359                                   const String &      i_sValue )
360 {
361     Enum &
362         rOwner = ary_cast<Enum>(Storage()[i_nOwner]);
363     EnumValue & ret = *new EnumValue( i_sName,
364                                       i_nOwner,
365                                       rOwner.NameRoom(),
366                                       i_sValue );
367     lhf_Put2Storage_and_AssignId(ret);
368     rOwner.Add_Value(ret.CeId());
369     return ret;
370 }
371 
372 Attribute &
Store_Attribute(Ce_id i_nOwner,const String & i_sName,Type_id i_nType,bool i_bReadOnly,bool i_bBound)373 CeAdmin::Store_Attribute( Ce_id               i_nOwner,
374                                   const String &      i_sName,
375                                   Type_id             i_nType,
376                                   bool                i_bReadOnly,
377                                   bool                i_bBound )
378 {
379     Interface &
380         rOwner = ary_cast<Interface>(Storage()[i_nOwner]);
381 
382     Attribute & ret = *new Attribute ( i_sName,
383                                        i_nOwner,
384                                        rOwner.NameRoom(),
385                                        i_nType,
386                                        i_bReadOnly,
387                                        i_bBound );
388     lhf_Put2Storage_and_AssignId(ret);
389     rOwner.Add_Attribute(ret.CeId());
390     return ret;
391 }
392 
393 const Module &
GlobalNamespace() const394 CeAdmin::GlobalNamespace() const
395 {
396     csv_assert(pGlobalNamespace);
397     return *pGlobalNamespace;
398 }
399 
400 const CodeEntity &
Find_Ce(Ce_id i_nId) const401 CeAdmin::Find_Ce( Ce_id i_nId ) const
402 {
403     return Storage()[i_nId];
404 
405 }
406 
407 const Module &
Find_Module(Ce_id i_nId) const408 CeAdmin::Find_Module( Ce_id i_nId ) const
409 {
410     return ary_cast<Module>(Storage()[i_nId]);
411 }
412 
413 const Module *
Search_Module(Ce_id i_nId) const414 CeAdmin::Search_Module( Ce_id i_nId ) const
415 {
416     if (NOT i_nId.IsValid())
417         return 0;
418     return ary_cast<Module>( & Storage()[i_nId] );
419 }
420 
421 const Function &
Find_Function(Ce_id i_nId) const422 CeAdmin::Find_Function( Ce_id i_nId ) const
423 {
424     return ary_cast<Function>(Storage()[i_nId]);
425 }
426 
427 const Property &
Find_Property(Ce_id i_nId) const428 CeAdmin::Find_Property( Ce_id i_nId ) const
429 {
430     return ary_cast<Property>(Storage()[i_nId]);
431 }
432 
433 const EnumValue &
Find_EnumValue(Ce_id i_nId) const434 CeAdmin::Find_EnumValue( Ce_id i_nId ) const
435 {
436     return ary_cast<EnumValue>(Storage()[i_nId]);
437 }
438 
439 const Constant &
Find_Constant(Ce_id i_nId) const440 CeAdmin::Find_Constant( Ce_id i_nId ) const
441 {
442     return ary_cast<Constant>(Storage()[i_nId]);
443 }
444 
445 const StructElement &
Find_StructElement(Ce_id i_nId) const446 CeAdmin::Find_StructElement( Ce_id i_nId ) const
447 {
448     return ary_cast<StructElement>(Storage()[i_nId]);
449 }
450 
451 void
Get_Text(StringVector & o_module,String & o_ce,String & o_member,const CodeEntity & i_ce) const452 CeAdmin::Get_Text( StringVector &      o_module,
453                             String &            o_ce,
454                             String &            o_member,
455                             const CodeEntity &  i_ce ) const
456 {
457     const CodeEntity * pCe = &i_ce;
458     csv::erase_container(o_module);
459     o_ce.clear();
460     o_member.clear();
461 
462     switch ( pCe->SightLevel() )
463     {
464         // Here are intentionally no breaks!
465         case sl_Member:
466                         if ( is_type<Function>(*pCe) )
467                             o_member = StreamLock(200)()
468                                             << pCe->LocalName()
469                                             << "()"
470                                             << c_str;
471                         else
472                             o_member = pCe->LocalName();
473                         pCe = & Storage()[pCe->Owner()];
474         case sl_File:
475                         o_ce = pCe->LocalName();
476                         pCe = & Storage()[pCe->NameRoom()];
477         case sl_Module:
478                         get_ModuleText(o_module,*pCe);
479                         break;
480         default:
481                         csv_assert(false);
482     }   // end switch
483 }
484 
485 const NameLookup &
NameDictionary() const486 CeAdmin::NameDictionary() const
487 {
488     return *pNameDictionary;
489 }
490 
491 
492 void
Get_AlphabeticalIndex(std::vector<Ce_id> & o_rResult,alphabetical_index::E_Letter i_cLetter) const493 CeAdmin::Get_AlphabeticalIndex( std::vector<Ce_id> &            o_rResult,
494                                 alphabetical_index::E_Letter    i_cLetter ) const
495 {
496     const int C_nLowerUpperDiff = 'a'-'A';
497 
498     // Establishing filter:
499     UINT8 filter[256];
500 
501     UINT8 nLetter = static_cast<UINT8>(i_cLetter);
502     memset(filter, 0, 256);
503     filter[nLetter] = 1;
504     if ( i_cLetter != alphabetical_index::non_alpha )
505         filter[nLetter - C_nLowerUpperDiff] = 1;
506 
507     // Gather entities which start with i_cLetter:
508     o_rResult.reserve(1000);
509     idl::Ce_Storage::c_iter
510         itEnd = Storage().End();
511     for ( idl::Ce_Storage::c_iter it = Storage().BeginUnreserved();
512           it != itEnd;
513           ++it )
514     {
515         if ( filter[ static_cast<UINT8>(*(*it).LocalName().c_str()) ] == 1 )
516             o_rResult.push_back( (*it).CeId() );
517     }
518 
519     std::sort( o_rResult.begin(),
520                o_rResult.end(),
521                IdSorter<Ce_Compare>() );
522 }
523 
524 
525 Module &
GlobalNamespace()526 CeAdmin::GlobalNamespace()
527 {
528     csv_assert(pGlobalNamespace);
529     return *pGlobalNamespace;
530 }
531 
532 CodeEntity &
Find_Ce(Ce_id i_nId)533 CeAdmin::Find_Ce( Ce_id i_nId )
534 {
535     return Storage()[i_nId];
536 }
537 
538 void
get_ModuleText(StringVector & o_module,const CodeEntity & i_ce) const539 CeAdmin::get_ModuleText( StringVector &      o_module,
540                               const CodeEntity &  i_ce ) const
541 {
542     if (i_ce.NameRoom().IsValid())
543     {
544         const CodeEntity &
545             rParent = Storage()[i_ce.NameRoom()];
546         get_ModuleText(o_module, rParent);
547         o_module.push_back(i_ce.LocalName());
548     }
549 }
550 
551 Struct &
lhf_Store_TplStruct(Ce_id i_nOwner,const String & i_sName,Type_id i_nBase,const String & i_sTemplateParam)552 CeAdmin::lhf_Store_TplStruct( Ce_id               i_nOwner,
553 								   const String &      i_sName,
554 								   Type_id             i_nBase,
555 								   const String &      i_sTemplateParam )
556 {
557     csv_assert(NOT i_sTemplateParam.empty());
558 
559     TemplateParamType &
560         rTpt = pTypePilot->Store_TemplateParamType(i_sTemplateParam);
561 
562     Struct & ret = *new Struct( i_sName,
563                                 i_nOwner,
564                                 i_nBase,
565                                 i_sTemplateParam,
566                                 rTpt.TypeId() );
567     lhf_Store_NewEntity(ret, i_nOwner);
568     rTpt.Set_StructId(ret.CeId());
569 
570     return ret;
571 }
572 
573 
574 }   // namespace idl
575 }   // namespace ary
576