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