LCOV - code coverage report
Current view: top level - idl/source/objects - module.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 108 124 87.1 %
Date: 2015-06-13 12:38:46 Functions: 10 12 83.3 %
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             : 
      21             : #include <ctype.h>
      22             : #include <stdio.h>
      23             : 
      24             : #include <module.hxx>
      25             : #include <globals.hxx>
      26             : #include <database.hxx>
      27             : #include <tools/debug.hxx>
      28             : #include <osl/file.hxx>
      29             : 
      30       13508 : TYPEINIT1( SvMetaModule, SvMetaExtern );
      31             : 
      32           8 : SvMetaModule::SvMetaModule( const OUString & rIdlFileName, bool bImp )
      33             :     : aIdlFileName( rIdlFileName )
      34           8 :     , bImported( bImp ), bIsModified( false )
      35             : {
      36           8 : }
      37             : 
      38           8 : bool SvMetaModule::SetName( const OString& rName, SvIdlDataBase * pBase )
      39             : {
      40           8 :     if( pBase )
      41             :     {
      42           8 :         if( pBase->GetModule( rName ) )
      43           0 :             return false;
      44             :     }
      45           8 :     return SvMetaExtern::SetName( rName );
      46             : }
      47             : 
      48        1480 : bool SvMetaModule::FillNextName( SvGlobalName * pName )
      49             : {
      50        1480 :     *pName = aNextName;
      51             : 
      52        1480 :     if( aNextName < aEndName )
      53             :     {
      54        1480 :         ++aNextName;
      55        1480 :         bIsModified = true;
      56        1480 :         return true;
      57             :     }
      58           0 :     return false;
      59             : }
      60             : 
      61          21 : void SvMetaModule::ReadAttributesSvIdl( SvIdlDataBase & rBase,
      62             :                                         SvTokenStream & rInStm )
      63             : {
      64          21 :     SvMetaExtern::ReadAttributesSvIdl( rBase, rInStm );
      65             : 
      66          21 :     aHelpFileName.ReadSvIdl( SvHash_HelpFile(), rInStm );
      67          21 :     if( aSlotIdFile.ReadSvIdl( SvHash_SlotIdFile(), rInStm ) )
      68             :     {
      69          11 :         sal_uInt32 nTokPos = rInStm.Tell();
      70          11 :         if( !rBase.ReadIdFile( OStringToOUString(aSlotIdFile.getString(), RTL_TEXTENCODING_ASCII_US)) )
      71             :         {
      72           0 :             OStringBuffer aStr("cannot read file: ");
      73           0 :             aStr.append(aSlotIdFile.getString());
      74           0 :             rBase.SetError( aStr.makeStringAndClear(), rInStm.GetToken() );
      75           0 :             rBase.WriteError( rInStm );
      76             : 
      77           0 :             rInStm.Seek( nTokPos );
      78             :         }
      79             :     }
      80          21 :     aTypeLibFile.ReadSvIdl( SvHash_TypeLibFile(), rInStm );
      81          21 :     aModulePrefix.ReadSvIdl( SvHash_ModulePrefix(), rInStm );
      82          21 : }
      83             : 
      84       10292 : void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase,
      85             :                                      SvTokenStream & rInStm )
      86             : {
      87       10292 :     sal_uInt32  nTokPos = rInStm.Tell();
      88       20584 :     if( rInStm.GetToken()->Is( SvHash_interface() )
      89       10292 :       || rInStm.GetToken()->Is( SvHash_shell() ) )
      90             :     {
      91         190 :         SvMetaClassRef aClass = new SvMetaClass();
      92         190 :         if( aClass->ReadSvIdl( rBase, rInStm ) )
      93             :         {
      94         190 :             aClassList.push_back( aClass );
      95             :             // announce globally
      96         190 :             rBase.GetClassList().push_back( aClass );
      97         190 :         }
      98             :     }
      99       10102 :     else if( rInStm.GetToken()->Is( SvHash_enum() ) )
     100             :     {
     101         219 :         SvMetaTypeEnumRef aEnum = new SvMetaTypeEnum();
     102             : 
     103         219 :         if( aEnum->ReadSvIdl( rBase, rInStm ) )
     104             :         {
     105             :             // declared in module
     106         219 :             aTypeList.push_back( aEnum );
     107             :             // announce globally
     108         219 :             rBase.GetTypeList().push_back( aEnum );
     109         219 :         }
     110             :     }
     111       19766 :     else if( rInStm.GetToken()->Is( SvHash_item() )
     112        8710 :       || rInStm.GetToken()->Is( SvHash_struct() )
     113       18286 :       || rInStm.GetToken()->Is( SvHash_typedef() ) )
     114             :     {
     115        1480 :         SvMetaTypeRef xItem = new SvMetaType();
     116             : 
     117        1480 :         if( xItem->ReadSvIdl( rBase, rInStm ) )
     118             :         {
     119             :             // declared in module
     120        1480 :             aTypeList.push_back( xItem );
     121             :             // announce globally
     122        1480 :             rBase.GetTypeList().push_back( xItem );
     123        1480 :         }
     124             :     }
     125        8403 :     else if( rInStm.GetToken()->Is( SvHash_include() ) )
     126             :     {
     127         133 :         bool bOk = false;
     128         133 :         rInStm.GetToken_Next();
     129         133 :         SvToken * pTok = rInStm.GetToken_Next();
     130         133 :         if( pTok->IsString() )
     131             :         {
     132         133 :             OUString aFullName(OStringToOUString(pTok->GetString(), RTL_TEXTENCODING_ASCII_US));
     133         133 :             rBase.StartNewFile( aFullName );
     134         133 :             osl::FileBase::RC searchError = osl::File::searchFileURL(aFullName, rBase.GetPath(), aFullName);
     135         133 :             osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName );
     136             : 
     137         133 :             if( osl::FileBase::E_None == searchError )
     138             :             {
     139         133 :                 rBase.AddDepFile( aFullName );
     140         133 :                 SvTokenStream aTokStm( aFullName );
     141             : 
     142         133 :                 if( SVSTREAM_OK == aTokStm.GetStream().GetError() )
     143             :                 {
     144             :                     // rescue error from old file
     145         133 :                     SvIdlError aOldErr = rBase.GetError();
     146             :                     // reset error
     147         133 :                     rBase.SetError( SvIdlError() );
     148             : 
     149         133 :                     sal_uInt32 nBeginPos = 0xFFFFFFFF; // can not happen with Tell
     150       10390 :                     while( nBeginPos != aTokStm.Tell() )
     151             :                     {
     152       10124 :                         nBeginPos = aTokStm.Tell();
     153       10124 :                         ReadContextSvIdl( rBase, aTokStm );
     154       10124 :                         aTokStm.ReadDelemiter();
     155             :                     }
     156         133 :                     bOk = aTokStm.GetToken()->IsEof();
     157         133 :                     if( !bOk )
     158             :                     {
     159           0 :                         rBase.WriteError( aTokStm );
     160             :                     }
     161             :                     // recover error from old file
     162         133 :                     rBase.SetError( aOldErr );
     163             :                 }
     164             :                 else
     165             :                 {
     166           0 :                     OStringBuffer aStr("cannot open file: ");
     167           0 :                     aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
     168           0 :                     rBase.SetError(aStr.makeStringAndClear(), pTok);
     169         133 :                 }
     170             :             }
     171             :             else
     172             :             {
     173           0 :                 OStringBuffer aStr("cannot find file:");
     174           0 :                 aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
     175           0 :                 rBase.SetError(aStr.makeStringAndClear(), pTok);
     176         133 :             }
     177             :         }
     178         133 :         if( !bOk )
     179           0 :             rInStm.Seek( nTokPos );
     180             :     }
     181             :     else
     182             :     {
     183        8270 :         SvMetaSlotRef xSlot = new SvMetaSlot();
     184             : 
     185        8270 :         if( xSlot->ReadSvIdl( rBase, rInStm ) )
     186             :         {
     187        8129 :             if( xSlot->Test( rBase, rInStm ) )
     188             :             {
     189             :                 // declared in module
     190        8129 :                 aAttrList.push_back( xSlot );
     191             :                 // announce globally
     192        8129 :                 rBase.AppendAttr( xSlot );
     193             :             }
     194        8270 :         }
     195             :     }
     196       10292 : }
     197             : 
     198           8 : bool SvMetaModule::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
     199             : {
     200           8 :     bIsModified = true; // up to now always when compiler running
     201             : 
     202           8 :     sal_uInt32  nTokPos = rInStm.Tell();
     203           8 :     SvToken * pTok  = rInStm.GetToken_Next();
     204           8 :     bool bOk = pTok->Is( SvHash_module() );
     205           8 :     if( bOk )
     206             :     {
     207           8 :         pTok = rInStm.GetToken_Next();
     208           8 :         if( pTok->IsString() )
     209           8 :              bOk = aBeginName.MakeId(OStringToOUString(pTok->GetString(), RTL_TEXTENCODING_ASCII_US));
     210             :     }
     211           8 :     rInStm.ReadDelemiter();
     212           8 :     if( bOk )
     213             :     {
     214           8 :         pTok = rInStm.GetToken_Next();
     215           8 :         if( pTok->IsString() )
     216           8 :              bOk = aEndName.MakeId(OStringToOUString(pTok->GetString(), RTL_TEXTENCODING_ASCII_US));
     217             :     }
     218           8 :     rInStm.ReadDelemiter();
     219           8 :     if( bOk )
     220             :     {
     221           8 :         aNextName = aBeginName;
     222             : 
     223           8 :         rBase.Push( this ); // onto the context stack
     224             : 
     225           8 :         if( ReadNameSvIdl( rBase, rInStm ) )
     226             :         {
     227             :             // set pointer to itself
     228           8 :             SetModule( rBase );
     229           8 :             bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
     230             :         }
     231           8 :         rBase.GetStack().Pop(); // remove from stack
     232             :     }
     233           8 :     if( !bOk )
     234           0 :         rInStm.Seek( nTokPos );
     235           8 :     return bOk;
     236             : }
     237             : 
     238           8 : void SvMetaModule::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
     239             : {
     240         198 :     for( sal_uLong n = 0; n < aClassList.size(); n++ )
     241             :     {
     242         190 :         SvMetaClass * pClass = aClassList[n];
     243         190 :         pClass->WriteSfx( rBase, rOutStm );
     244             :     }
     245           8 : }
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11