LCOV - code coverage report
Current view: top level - libreoffice/autodoc/source/ary/idl - ia_type.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 126 134 94.0 %
Date: 2012-12-27 Functions: 22 23 95.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <precomp.h>
      21             : #include "ia_type.hxx"
      22             : 
      23             : 
      24             : // NOT FULLY DEFINED SERVICES
      25             : #include <ary/qualiname.hxx>
      26             : #include <ary/idl/i_module.hxx>
      27             : #include <ary/idl/i_type.hxx>
      28             : #include <ary/idl/ip_ce.hxx>
      29             : #include "ia_ce.hxx"
      30             : #include "is_type.hxx"
      31             : #include "it_builtin.hxx"
      32             : #include "it_ce.hxx"
      33             : #include "it_explicit.hxx"
      34             : #include "it_sequence.hxx"
      35             : #include "it_tplparam.hxx"
      36             : #include "it_xnameroom.hxx"
      37             : 
      38             : 
      39             : 
      40             : namespace ary
      41             : {
      42             : namespace idl
      43             : {
      44             : 
      45             : String              MakeTemplateName(
      46             :                         const String &      i_localName );
      47             : 
      48             : 
      49             : 
      50             : inline CeAdmin &
      51             : TypeAdmin::my_Ces() const
      52             :     { return *pCes; }
      53             : 
      54             : inline void
      55        5078 : TypeAdmin::lhf_Put2Storage_and_AssignId( DYN Type & pass_io_rType )
      56             :     { // This also assigns an ID to pass_io_rType:
      57        5078 :       Storage().Store_Entity(pass_io_rType); }
      58             : 
      59             : inline Type_id
      60       27487 : TypeAdmin::lhf_findBuiltInType( const String & i_sName )
      61       27487 :     { return ary_cast<ExplicitNameRoom>(Storage()[nXNameRoom_Root])
      62       27487 :                         .Search_Name(i_sName); }
      63             : 
      64             : inline const ExplicitNameRoom &
      65           7 : TypeAdmin::find_ExplicitNameRoom( Type_id i_nType ) const
      66             : {
      67           7 :     return ary_cast<ExplicitNameRoom>(Storage()[i_nType]);
      68             : }
      69             : 
      70             : inline ExplicitNameRoom &
      71       62081 : TypeAdmin::find_ExplicitNameRoom( Type_id i_nType )
      72             : {
      73       62081 :     return ary_cast<ExplicitNameRoom>(Storage()[i_nType]);
      74             : }
      75             : 
      76             : ExplicitNameRoom &
      77       12729 : TypeAdmin::lhf_CheckIn_XNameRoom( const QualifiedName & i_rName,
      78             :                                        Ce_id                 i_nModuleOfOccurrence )
      79             : {
      80       12729 :     Type_id nRoot = i_rName.IsAbsolute()
      81             :                         ?   Type_id( predefined::type_GlobalXNameRoom )
      82       12729 :                         :   lhf_Get_NameRoomRoot_forModuleofOccurrence( i_nModuleOfOccurrence ).TypeId();
      83             : 
      84       12729 :     if ( i_rName.NamespaceDepth() == 0 )
      85        2876 :         return find_ExplicitNameRoom(nRoot);
      86             : 
      87        9853 :     QualifiedName::namespace_iterator it = i_rName.first_namespace();
      88             :     ExplicitNameRoom *
      89        9853 :         ret = & find_ExplicitNameRoom(nRoot);
      90       49539 :     for ( ; it != i_rName.end_namespace(); ++it )
      91             :     {
      92             :         Type_id
      93       39686 :             found = ret->Search_Name(*it);
      94       39686 :         if (found.IsValid())
      95             :         {
      96       38698 :             ret = & find_ExplicitNameRoom(found);
      97             :         }
      98             :         else
      99             :         {
     100             :             ExplicitNameRoom &
     101         988 :                 rNew = *new ExplicitNameRoom(*it, *ret);
     102         988 :             lhf_Put2Storage_and_AssignId(rNew);
     103         988 :             ret->Add_Name( rNew.Name(), rNew.TypeId() );
     104         988 :             ret = &rNew;
     105             :         }
     106             : 
     107             :     }   // end for
     108        9853 :     return *ret;
     109             : }
     110             : 
     111             : Type_id
     112       12729 : TypeAdmin::lhf_CheckIn_TypeName( const String &        i_sLocalName,
     113             :                                       ExplicitNameRoom &    io_rXNameRoom,
     114             :                                       Ce_id                 i_nModuleOfOccurrence,
     115             :                                  const std::vector<Type_id> *   i_templateParameters )
     116             : {
     117       12729 :     String sSearchLocalName( i_sLocalName );
     118       25457 :     if ( i_templateParameters != 0
     119       12728 :          ?  (!i_templateParameters->empty())
     120             :          :  false )
     121             :     {
     122          18 :         sSearchLocalName = MakeTemplateName(i_sLocalName);
     123             :     }
     124             : 
     125             :     Type_id
     126       12729 :         ret = io_rXNameRoom.Search_Name(sSearchLocalName);
     127       12729 :     if (NOT ret.IsValid())
     128             :     {
     129             :         DYN Type &
     130             :             rNewType = *new ExplicitType(  i_sLocalName,
     131        3699 :                                            io_rXNameRoom.TypeId(),
     132             :                                            i_nModuleOfOccurrence,
     133        3699 :                                            i_templateParameters );
     134        3699 :         lhf_Put2Storage_and_AssignId(rNewType);
     135        3699 :         ret = rNewType.TypeId();
     136        3699 :         io_rXNameRoom.Add_Name( sSearchLocalName, ret );
     137             :     }
     138       12729 :     return ret;
     139             : }
     140             : 
     141             : Type_id
     142        1125 : TypeAdmin::lhf_CheckIn_Sequence(Type_id i_nType)
     143             : {
     144             :     Type_id
     145        1125 :         ret = Storage().Search_SequenceOf(i_nType);
     146             : 
     147        1125 :     if (NOT ret.IsValid())
     148             :     {
     149             :         DYN Type &
     150         277 :             rNewSeq = *new Sequence(i_nType);
     151         277 :         lhf_Put2Storage_and_AssignId(rNewSeq);
     152         277 :         ret = rNewSeq.Id();
     153         277 :         Storage().Add_Sequence(i_nType, ret);
     154             :     }
     155        1125 :     return ret;
     156             : }
     157             : 
     158             : void
     159          15 : TypeAdmin::lhf_CheckIn_BuiltInType( const char *       i_sName,
     160             :                                     Rid                i_nId )
     161             : {
     162             :     DYN BuiltInType &
     163          15 :         rNewType = *new BuiltInType(i_sName);
     164          15 :     Storage().Set_Reserved(i_nId, rNewType);
     165             : 
     166             :     // Put them into both roots, to catch the syntactically correct
     167             :     //   (though unlikely) ::Any, ::long etc.
     168             :     Type_id
     169          15 :         nId(i_nId);
     170          15 :     find_ExplicitNameRoom(nXNameRoom_Root).Add_Name(i_sName, nId);
     171          15 :     find_ExplicitNameRoom(nXNameRoom_Global).Add_Name(i_sName, nId);
     172          15 : }
     173             : 
     174             : ExplicitNameRoom &
     175       10735 : TypeAdmin::lhf_Get_NameRoomRoot_forModuleofOccurrence( Ce_id i_nModuleOfOccurrence )
     176             : {
     177             :     const Type_id *
     178             :         pFound = csv::find_in_map( aMap_ModuleOfOccurrence2NameRoomRoot,
     179       10735 :                                    i_nModuleOfOccurrence );
     180       10735 :     if (pFound != 0)
     181       10624 :         return find_ExplicitNameRoom(*pFound);
     182             : 
     183             :     ExplicitNameRoom &
     184         111 :         ret = *new ExplicitNameRoom;
     185         111 :     lhf_Put2Storage_and_AssignId(ret);
     186         111 :     aMap_ModuleOfOccurrence2NameRoomRoot.insert(std::pair< const Ce_id, Type_id>(i_nModuleOfOccurrence,ret.TypeId()));
     187         111 :     return ret;
     188             : }
     189             : 
     190           1 : TypeAdmin::TypeAdmin()
     191           1 :     :   pStorage(new Type_Storage),
     192             :         pCes(0),    // Needs to be set directly after creation.
     193             :         nXNameRoom_Root( static_cast<ary::Rid>(predefined::type_Root_ofXNameRooms) ),
     194             :         nXNameRoom_Global( static_cast<ary::Rid>(predefined::type_GlobalXNameRoom) ),
     195           2 :         aMap_ModuleOfOccurrence2NameRoomRoot()
     196             : {
     197             :     DYN ExplicitNameRoom &
     198           1 :         drRoot = *new ExplicitNameRoom;
     199           1 :     Storage().Set_Reserved( nXNameRoom_Root.Value(), drRoot );
     200             : 
     201             :     DYN ExplicitNameRoom &
     202           1 :         drGlobal = *new ExplicitNameRoom(String::Null_(), drRoot);
     203           1 :     Storage().Set_Reserved( nXNameRoom_Global.Value(), drGlobal );
     204           1 :     drRoot.Add_Name( drGlobal.Name(), nXNameRoom_Global );
     205             : 
     206           1 :     lhf_Setup_BuildInTypes();
     207           1 : }
     208             : 
     209           2 : TypeAdmin::~TypeAdmin()
     210             : {
     211           2 : }
     212             : 
     213             : void
     214           1 : TypeAdmin::lhf_Setup_BuildInTypes()
     215             : {
     216           1 :     lhf_CheckIn_BuiltInType("any", predefined::type_any);
     217           1 :     lhf_CheckIn_BuiltInType("boolean", predefined::type_boolean);
     218           1 :     lhf_CheckIn_BuiltInType("byte", predefined::type_byte);
     219           1 :     lhf_CheckIn_BuiltInType("char", predefined::type_char);
     220           1 :     lhf_CheckIn_BuiltInType("double", predefined::type_double);
     221           1 :     lhf_CheckIn_BuiltInType("float", predefined::type_float);
     222           1 :     lhf_CheckIn_BuiltInType("hyper", predefined::type_hyper);
     223           1 :     lhf_CheckIn_BuiltInType("long", predefined::type_long);
     224           1 :     lhf_CheckIn_BuiltInType("short", predefined::type_short);
     225           1 :     lhf_CheckIn_BuiltInType("string", predefined::type_string);
     226           1 :     lhf_CheckIn_BuiltInType("type", predefined::type_type);
     227           1 :     lhf_CheckIn_BuiltInType("void", predefined::type_void);
     228           1 :     lhf_CheckIn_BuiltInType("unsigned hyper", predefined::type_u_hyper);
     229           1 :     lhf_CheckIn_BuiltInType("unsigned long", predefined::type_u_long);
     230           1 :     lhf_CheckIn_BuiltInType("unsigned short", predefined::type_u_short);
     231           1 : }
     232             : 
     233             : const Type &
     234       27487 : TypeAdmin::CheckIn_Type( QualifiedName &     i_rFullName,
     235             :                                  uintt               i_nSequenceCount,
     236             :                                  Ce_id               i_nModuleOfOccurrence,
     237             :                          const std::vector<Type_id> *   i_templateParameters )
     238             : {
     239             :     // Look in built-in types:
     240             :     Type_id
     241       27487 :         nType = lhf_findBuiltInType(i_rFullName.LocalName());
     242       27487 :     if (NOT nType.IsValid())
     243             :     {   // No built-in type:
     244             :         ExplicitNameRoom &
     245       12729 :             rNameRoom = lhf_CheckIn_XNameRoom(i_rFullName,i_nModuleOfOccurrence);
     246       12729 :         nType = lhf_CheckIn_TypeName( i_rFullName.LocalName(),
     247             :                                       rNameRoom,
     248             :                                       i_nModuleOfOccurrence,
     249       12729 :                                       i_templateParameters );
     250             :     }   // endif
     251             : 
     252       28612 :     for ( uintt s = 0; s < i_nSequenceCount; ++s )
     253             :     {
     254        1125 :         nType = lhf_CheckIn_Sequence(nType);
     255             :     }
     256             : 
     257       27487 :     return Storage()[nType];
     258             : }
     259             : 
     260             : TemplateParamType &
     261           3 : TypeAdmin::Store_TemplateParamType( String i_sName )
     262             : {
     263             :     DYN TemplateParamType &
     264           3 :         ret = *new TemplateParamType( i_sName );
     265           3 :     lhf_Put2Storage_and_AssignId(ret);
     266           3 :     return ret;
     267             : }
     268             : 
     269             : const Type &
     270       38616 : TypeAdmin::Find_Type( Type_id i_nType ) const
     271             : {
     272       38616 :     return Storage()[i_nType];
     273             : }
     274             : 
     275             : String
     276           0 : TypeAdmin::Search_LocalNameOf( Type_id i_nType ) const
     277             : {
     278             :     const Type *
     279           0 :         pType = Storage().Exists(i_nType)
     280             :                     ? 0
     281           0 :                     : & Storage()[i_nType];
     282           0 :     if (pType != 0)
     283             :     {
     284           0 :         switch (pType->AryClass())
     285             :         {
     286             :             case Ce_Type::class_id:
     287             :             case ExplicitType::class_id:
     288             :             case BuiltInType::class_id:
     289           0 :                     return static_cast< const Named_Type& >(*pType).Name();
     290             :         }
     291             :     }
     292           0 :     return String::Null_();
     293             : }
     294             : 
     295             : Ce_id
     296        6582 : TypeAdmin::Search_CeRelatedTo( Type_id i_nType ) const
     297             : {
     298             :     const Ce_Type *
     299        6582 :         ret = ary_cast<Ce_Type>( & Storage()[i_nType] );
     300             :     return ret != 0
     301             :             ?   ret->RelatedCe()
     302        6582 :             :   Ce_id_Null();
     303             : }
     304             : 
     305             : const ExplicitNameRoom &
     306           7 : TypeAdmin::Find_XNameRoom( Type_id i_nType ) const
     307             : {
     308           7 :     return find_ExplicitNameRoom(i_nType);
     309             : }
     310             : 
     311             : bool
     312       33226 : TypeAdmin::IsBuiltInOrRelated( const Type & i_rType ) const
     313             : {
     314       33226 :     if ( is_type<BuiltInType>(i_rType) )
     315       16774 :         return true;
     316             :     else
     317             :     {
     318             :         const Type *
     319       16452 :             pType = &i_rType;
     320       34098 :         while (is_type<Sequence>(*pType))
     321             :         {
     322             :             Type_id
     323        1194 :                 nt = ary_cast<Sequence>(pType)->RelatedType();
     324        1194 :             if (NOT nt.IsValid())
     325           0 :                 return false;
     326        1194 :             pType = & Storage()[nt];
     327             :         }
     328       16452 :         return is_type<BuiltInType>(*pType);
     329             :     }
     330             : }
     331             : 
     332             : 
     333             : String
     334          18 : MakeTemplateName( const String &                i_localName )
     335             : {
     336             :     StreamLock
     337          18 :         sl(200);
     338             : 
     339             :     // This is the simple solution, assuming that there is only
     340             :     // one version of templatisation allowed with a given name.
     341             :     return
     342          18 :         sl()
     343          18 :             << i_localName
     344          18 :             << C_cTemplateDelimiter
     345          18 :             << c_str;
     346             : }
     347             : 
     348             : 
     349             : 
     350             : }   // namespace idl
     351           3 : }   // namespace ary
     352             : 
     353             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10