LCOV - code coverage report
Current view: top level - idl/source/objects - module.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 108 124 87.1 %
Date: 2014-11-03 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       13452 : 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        1473 : bool SvMetaModule::FillNextName( SvGlobalName * pName )
      49             : {
      50        1473 :     *pName = aNextName;
      51             : 
      52        1473 :     if( aNextName < aEndName )
      53             :     {
      54        1473 :         ++aNextName;
      55        1473 :         bIsModified = true;
      56        1473 :         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       10238 : void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase,
      85             :                                      SvTokenStream & rInStm )
      86             : {
      87       10238 :     sal_uInt32  nTokPos = rInStm.Tell();
      88       20476 :     if( rInStm.GetToken()->Is( SvHash_interface() )
      89       10238 :       || 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       10048 :     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       19658 :     else if( rInStm.GetToken()->Is( SvHash_item() )
     112        8663 :       || rInStm.GetToken()->Is( SvHash_struct() )
     113       18185 :       || rInStm.GetToken()->Is( SvHash_typedef() ) )
     114             :     {
     115        1473 :         SvMetaTypeRef xItem = new SvMetaType();
     116             : 
     117        1473 :         if( xItem->ReadSvIdl( rBase, rInStm ) )
     118             :         {
     119             :             // declared in module
     120        1473 :             aTypeList.push_back( xItem );
     121             :             // announce globally
     122        1473 :             rBase.GetTypeList().push_back( xItem );
     123        1473 :         }
     124             :     }
     125        8356 :     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       10336 :                     while( nBeginPos != aTokStm.Tell() )
     151             :                     {
     152       10070 :                         nBeginPos = aTokStm.Tell();
     153       10070 :                         ReadContextSvIdl( rBase, aTokStm );
     154       10070 :                         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        8223 :         SvMetaSlotRef xSlot = new SvMetaSlot();
     184             : 
     185        8223 :         if( xSlot->ReadSvIdl( rBase, rInStm ) )
     186             :         {
     187        8082 :             if( xSlot->Test( rBase, rInStm ) )
     188             :             {
     189             :                 // declared in module
     190        8082 :                 aAttrList.push_back( xSlot );
     191             :                 // announce globally
     192        8082 :                 rBase.AppendAttr( xSlot );
     193             :             }
     194        8223 :         }
     195             :     }
     196       10238 : }
     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.10