[Libreoffice-commits] core.git: 4 commits - idl/inc idl/source
Noel Grandin
noel at peralex.com
Thu Feb 11 12:47:26 UTC 2016
idl/inc/basobj.hxx | 2
idl/inc/database.hxx | 15 ++-
idl/inc/lex.hxx | 13 +-
idl/inc/parser.hxx | 5 -
idl/inc/slot.hxx | 2
idl/inc/types.hxx | 2
idl/source/cmptools/lex.cxx | 8 -
idl/source/objects/basobj.cxx | 8 -
idl/source/objects/bastype.cxx | 47 ++++-----
idl/source/objects/module.cxx | 82 +++++++----------
idl/source/objects/object.cxx | 55 +++--------
idl/source/objects/slot.cxx | 69 +++++---------
idl/source/objects/types.cxx | 35 ++-----
idl/source/prj/command.cxx | 21 +---
idl/source/prj/database.cxx | 197 ++++++++++++++++++-----------------------
idl/source/prj/parser.cxx | 27 ++---
16 files changed, 254 insertions(+), 334 deletions(-)
New commits:
commit 4e13a6911259d3d7d23b61cb76614263608bbd95
Author: Noel Grandin <noel at peralex.com>
Date: Thu Feb 11 14:33:36 2016 +0200
use exceptions for error handling in .SDI parsing
to simplify the normal control flow
Change-Id: If325ec0507a51d8e2d3340fc5b628bb75a078a44
diff --git a/idl/inc/basobj.hxx b/idl/inc/basobj.hxx
index 8b30126..12a1dc7 100644
--- a/idl/inc/basobj.hxx
+++ b/idl/inc/basobj.hxx
@@ -103,7 +103,7 @@ public:
void SetName( const OString& rName );
virtual const OString & GetName() const { return aName; }
- virtual bool Test( SvIdlDataBase &, SvTokenStream & rInStm );
+ virtual bool Test( SvTokenStream & rInStm );
virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm );
};
diff --git a/idl/inc/database.hxx b/idl/inc/database.hxx
index 3b7f15f..22d6b78 100644
--- a/idl/inc/database.hxx
+++ b/idl/inc/database.hxx
@@ -28,6 +28,7 @@
#include <rtl/ustring.hxx>
#include <set>
+#include <exception>
class SvCommand;
@@ -53,6 +54,16 @@ public:
}
};
+class SvParseException : public std::exception
+{
+public:
+ SvIdlError aError;
+ SvParseException( SvTokenStream & rInStm, const OString& rError );
+ SvParseException( const OString& rError, SvToken& rTok );
+};
+
+
+
class SvIdlDataBase
{
bool bExport;
@@ -106,10 +117,6 @@ public:
SvRefMemberList<SvMetaObject *>& GetStack() { return aContextStack; }
void Write(const OString& rText);
- static void WriteError(const OString& rErrWrn,
- const OString& rFileName,
- const OString& rErrorText,
- sal_uLong nRow = 0, sal_uLong nColumn = 0 );
void WriteError( SvTokenStream & rInStm );
void SetError( const OString& rError, SvToken& rTok );
void SetAndWriteError( SvTokenStream & rInStm, const OString& rError );
diff --git a/idl/inc/slot.hxx b/idl/inc/slot.hxx
index 8c838ad..93f127d 100644
--- a/idl/inc/slot.hxx
+++ b/idl/inc/slot.hxx
@@ -136,7 +136,7 @@ public:
void ResetSlotPointer()
{ pNextSlot = pLinkedSlot = nullptr; }
- virtual bool Test( SvIdlDataBase &, SvTokenStream & rInStm ) override;
+ virtual bool Test( SvTokenStream & rInStm ) override;
virtual void ReadAttributesSvIdl( SvIdlDataBase & rBase,
SvTokenStream & rInStm ) override;
virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override;
diff --git a/idl/inc/types.hxx b/idl/inc/types.hxx
index 34f12d7..748dc6e 100644
--- a/idl/inc/types.hxx
+++ b/idl/inc/types.hxx
@@ -45,7 +45,7 @@ public:
const SvIdentifier& GetSlotId() const;
SvMetaType * GetType() const;
- virtual bool Test( SvIdlDataBase &, SvTokenStream & rInStm ) override;
+ virtual bool Test( SvTokenStream & rInStm ) override;
virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override;
sal_uLong MakeSfx( OStringBuffer& rAtrrArray );
virtual void Insert( SvSlotElementList&, const OString& rPrefix,
diff --git a/idl/source/objects/basobj.cxx b/idl/source/objects/basobj.cxx
index 797b849..62632a7 100644
--- a/idl/source/objects/basobj.cxx
+++ b/idl/source/objects/basobj.cxx
@@ -108,7 +108,7 @@ void SvMetaObject::ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & )
{
}
-bool SvMetaObject::Test( SvIdlDataBase &, SvTokenStream & )
+bool SvMetaObject::Test( SvTokenStream & )
{
return true;
}
diff --git a/idl/source/objects/bastype.cxx b/idl/source/objects/bastype.cxx
index ce1d8f3..d200f68 100644
--- a/idl/source/objects/bastype.cxx
+++ b/idl/source/objects/bastype.cxx
@@ -94,16 +94,11 @@ void SvIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
if( rTok.IsIdentifier() )
{
sal_uLong n;
- if( rBase.FindId( rTok.GetString(), &n ) )
- {
- setString(rTok.GetString());
- nValue = n;
- return;
- }
- else
- {
+ if( !rBase.FindId( rTok.GetString(), &n ) )
rBase.SetAndWriteError( rInStm, "no value for identifier <" + getString() + "> " );
- }
+ setString(rTok.GetString());
+ nValue = n;
+ return;
}
rInStm.Seek( nTokPos );
}
diff --git a/idl/source/objects/module.cxx b/idl/source/objects/module.cxx
index 29ce9721..2062f05 100644
--- a/idl/source/objects/module.cxx
+++ b/idl/source/objects/module.cxx
@@ -40,12 +40,9 @@ void SvMetaModule::ReadAttributesSvIdl( SvIdlDataBase & rBase,
if( ReadStringSvIdl( SvHash_SlotIdFile(), rInStm, aSlotIdFile ) )
{
- sal_uInt32 nTokPos = rInStm.Tell();
if( !rBase.ReadIdFile( OStringToOUString(aSlotIdFile, RTL_TEXTENCODING_ASCII_US)) )
{
- rBase.SetAndWriteError( rInStm, "cannot read file: " + aSlotIdFile );
-
- rInStm.Seek( nTokPos );
+ throw SvParseException( rInStm, "cannot read file: " + aSlotIdFile );
}
}
}
@@ -96,48 +93,41 @@ void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase,
OUString aFullName(OStringToOUString(rTok.GetString(), RTL_TEXTENCODING_ASCII_US));
rBase.StartNewFile( aFullName );
osl::FileBase::RC searchError = osl::File::searchFileURL(aFullName, rBase.GetPath(), aFullName);
+ if( osl::FileBase::E_None != searchError )
+ {
+ OStringBuffer aStr("cannot find file:");
+ aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
+ throw SvParseException(aStr.makeStringAndClear(), rTok);
+ }
osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName );
+ rBase.AddDepFile( aFullName );
+ SvTokenStream aTokStm( aFullName );
- if( osl::FileBase::E_None == searchError )
+ if( SVSTREAM_OK != aTokStm.GetStream().GetError() )
{
- rBase.AddDepFile( aFullName );
- SvTokenStream aTokStm( aFullName );
-
- if( SVSTREAM_OK == aTokStm.GetStream().GetError() )
- {
- // rescue error from old file
- SvIdlError aOldErr = rBase.GetError();
- // reset error
- rBase.SetError( SvIdlError() );
-
- sal_uInt32 nBeginPos = 0xFFFFFFFF; // can not happen with Tell
- while( nBeginPos != aTokStm.Tell() )
- {
- nBeginPos = aTokStm.Tell();
- ReadContextSvIdl( rBase, aTokStm );
- aTokStm.ReadDelimiter();
- }
- bOk = aTokStm.GetToken().IsEof();
- if( !bOk )
- {
- rBase.WriteError( aTokStm );
- }
- // recover error from old file
- rBase.SetError( aOldErr );
- }
- else
- {
- OStringBuffer aStr("cannot open file: ");
- aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
- rBase.SetError(aStr.makeStringAndClear(), rTok);
- }
+ OStringBuffer aStr("cannot open file: ");
+ aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
+ throw SvParseException(aStr.makeStringAndClear(), rTok);
}
- else
+ // rescue error from old file
+ SvIdlError aOldErr = rBase.GetError();
+ // reset error
+ rBase.SetError( SvIdlError() );
+
+ sal_uInt32 nBeginPos = 0xFFFFFFFF; // can not happen with Tell
+ while( nBeginPos != aTokStm.Tell() )
{
- OStringBuffer aStr("cannot find file:");
- aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
- rBase.SetError(aStr.makeStringAndClear(), rTok);
+ nBeginPos = aTokStm.Tell();
+ ReadContextSvIdl( rBase, aTokStm );
+ aTokStm.ReadDelimiter();
+ }
+ bOk = aTokStm.GetToken().IsEof();
+ if( !bOk )
+ {
+ rBase.WriteError( aTokStm );
}
+ // recover error from old file
+ rBase.SetError( aOldErr );
}
if( !bOk )
rInStm.Seek( nTokPos );
@@ -148,7 +138,7 @@ void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase,
if( xSlot->ReadSvIdl( rBase, rInStm ) )
{
- if( xSlot->Test( rBase, rInStm ) )
+ if( xSlot->Test( rInStm ) )
{
// announce globally
rBase.AppendSlot( xSlot );
diff --git a/idl/source/objects/object.cxx b/idl/source/objects/object.cxx
index 697fe9f..396eeda 100644
--- a/idl/source/objects/object.cxx
+++ b/idl/source/objects/object.cxx
@@ -48,25 +48,19 @@ void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase,
if( rTok.Is( SvHash_import() ) )
{
SvMetaClass * pClass = rBase.ReadKnownClass( rInStm );
- if( pClass )
+ if( !pClass )
+ throw SvParseException( rInStm, "unknown imported interface" );
+ SvClassElement xEle;
+ xEle.SetClass( pClass );
+ aClassElementList.push_back( xEle );
+
+ rTok = rInStm.GetToken();
+ if( rTok.IsString() )
{
- SvClassElement xEle;
- xEle.SetClass( pClass );
- aClassElementList.push_back( xEle );
-
- rTok = rInStm.GetToken();
- if( rTok.IsString() )
- {
- xEle.SetPrefix( rTok.GetString() );
- rInStm.GetToken_Next();
- }
- return;
- }
- else
- {
- // set error
- rBase.SetAndWriteError( rInStm, "unknown imported interface" );
+ xEle.SetPrefix( rTok.GetString() );
+ rInStm.GetToken_Next();
}
+ return;
}
else
{
@@ -79,13 +73,13 @@ void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase,
{
xAttr = new SvMetaSlot( pType );
if( xAttr->ReadSvIdl( rBase, rInStm ) )
- bOk = xAttr->Test( rBase, rInStm );
+ bOk = xAttr->Test( rInStm );
}
else
{
xAttr = new SvMetaAttribute( pType );
if( xAttr->ReadSvIdl( rBase, rInStm ) )
- bOk = xAttr->Test( rBase, rInStm );
+ bOk = xAttr->Test( rInStm );
}
if( bOk )
@@ -118,8 +112,7 @@ bool SvMetaClass::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
bOk = aSuperClass.Is();
if( !bOk )
{
- // set error
- rBase.SetAndWriteError( rInStm, "unknown super class" );
+ throw SvParseException( rInStm, "unknown super class" );
}
}
if( bOk )
@@ -151,13 +144,7 @@ bool SvMetaClass::TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm,
// values have to match
if( pS->GetSlotId().GetValue() != rAttr.GetSlotId().GetValue() )
{
- OSL_FAIL( "Same Name in MetaClass : " );
- OSL_FAIL( pS->GetName().getStr() );
- OSL_FAIL( pS->GetSlotId().getString().getStr() );
- OSL_FAIL( rAttr.GetSlotId().getString().getStr() );
-
- rBase.SetAndWriteError(rInStm, "Attribute's " + pS->GetName() + " with different id's");
- return false;
+ throw SvParseException( rInStm, "Attribute's " + pS->GetName() + " with different id's");
}
}
else
@@ -166,14 +153,8 @@ bool SvMetaClass::TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm,
sal_uInt32 nId2 = rAttr.GetSlotId().GetValue();
if( nId1 == nId2 && nId1 != 0 )
{
- OSL_FAIL( "Gleiche Id in MetaClass : " );
- OSL_FAIL(OString::number(pS->GetSlotId().GetValue()).getStr());
- OSL_FAIL( pS->GetSlotId().getString().getStr() );
- OSL_FAIL( rAttr.GetSlotId().getString().getStr() );
-
OString aStr = "Attribute " + pS->GetName() + " and Attribute " + rAttr.GetName() + " with equal id's";
- rBase.SetAndWriteError(rInStm, aStr);
- return false;
+ throw SvParseException(rInStm, aStr);
}
}
}
diff --git a/idl/source/objects/slot.cxx b/idl/source/objects/slot.cxx
index 7246369..60960d2 100644
--- a/idl/source/objects/slot.cxx
+++ b/idl/source/objects/slot.cxx
@@ -286,15 +286,11 @@ void SvMetaSlot::ReadAttributesSvIdl( SvIdlDataBase & rBase,
if( rInStm.Read( '=' ) )
{
aSlotType = rBase.ReadKnownType( rInStm );
- if( aSlotType.Is() )
- {
- if( aSlotType->IsItem() )
- {
- return;
- }
- rBase.SetAndWriteError( rInStm, "the SlotType is not a item" );
- }
- rBase.SetAndWriteError( rInStm, "SlotType with unknown item type" );
+ if( !aSlotType.Is() )
+ throw SvParseException( rInStm, "SlotType with unknown item type" );
+ if( !aSlotType->IsItem() )
+ throw SvParseException( rInStm, "the SlotType is not a item" );
+ return;
}
}
rInStm.Seek( nTokPos );
@@ -312,7 +308,7 @@ void SvMetaSlot::ReadAttributesSvIdl( SvIdlDataBase & rBase,
if( aMethod->IsMethod() )
{
aMethod->SetSlotId( GetSlotId() );
- if( aMethod->Test( rBase, rInStm ) )
+ if( aMethod->Test( rInStm ) )
return;
}
rInStm.Seek( nTokPos );
@@ -323,9 +319,9 @@ void SvMetaSlot::ReadAttributesSvIdl( SvIdlDataBase & rBase,
}
}
-bool SvMetaSlot::Test( SvIdlDataBase & rBase, SvTokenStream & rInStm )
+bool SvMetaSlot::Test( SvTokenStream & rInStm )
{
- bool bOk = SvMetaAttribute::Test( rBase, rInStm );
+ bool bOk = SvMetaAttribute::Test( rInStm );
if( bOk )
{
SvMetaType * pType = GetType();
@@ -333,8 +329,7 @@ bool SvMetaSlot::Test( SvIdlDataBase & rBase, SvTokenStream & rInStm )
pType = pType->GetReturnType();
if( !pType->IsItem() )
{
- rBase.SetAndWriteError( rInStm, "this attribute is not a slot" );
- bOk = false;
+ throw SvParseException( rInStm, "this attribute is not a slot" );
}
}
@@ -351,17 +346,11 @@ bool SvMetaSlot::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
{
// c
SvMetaSlot * pKnownSlot = dynamic_cast<SvMetaSlot*>( pAttr );
- if( pKnownSlot )
- {
- SetRef( pKnownSlot );
- SetName( pKnownSlot->GetName() );
- bOk = SvMetaObject::ReadSvIdl( rBase, rInStm );
- }
- else
- {
- rBase.SetAndWriteError( rInStm, "attribute " + pAttr->GetName() + " is method or variable but not a slot" );
- bOk = false;
- }
+ if( !pKnownSlot )
+ throw SvParseException( rInStm, "attribute " + pAttr->GetName() + " is method or variable but not a slot" );
+ SetRef( pKnownSlot );
+ SetName( pKnownSlot->GetName() );
+ bOk = SvMetaObject::ReadSvIdl( rBase, rInStm );
}
else
{
@@ -372,25 +361,19 @@ bool SvMetaSlot::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
{
// for testing purposes: reference in case of complete definition
SvMetaSlot * pKnownSlot = dynamic_cast<SvMetaSlot*>( pAttr2 );
- if( pKnownSlot )
- {
- SetRef( pKnownSlot );
-
- // names may differ, because explicitly given
- if ( pKnownSlot->GetName() != GetName() )
- {
- OSL_FAIL("Illegal definition!");
- rInStm.Seek( nTokPos );
- return false;
- }
+ if( !pKnownSlot )
+ throw SvParseException( rInStm, "attribute " + pAttr2->GetName() + " is method or variable but not a slot" );
+ SetRef( pKnownSlot );
- SetName( pKnownSlot->GetName() );
- }
- else
+ // names may differ, because explicitly given
+ if ( pKnownSlot->GetName() != GetName() )
{
- rBase.SetAndWriteError( rInStm, "attribute " + pAttr2->GetName() + " is method or variable but not a slot" );
- bOk = false;
+ OSL_FAIL("Illegal definition!");
+ rInStm.Seek( nTokPos );
+ return false;
}
+
+ SetName( pKnownSlot->GetName() );
}
}
diff --git a/idl/source/objects/types.cxx b/idl/source/objects/types.cxx
index 393eb42..f0bf9d6 100644
--- a/idl/source/objects/types.cxx
+++ b/idl/source/objects/types.cxx
@@ -50,13 +50,12 @@ const SvIdentifier & SvMetaAttribute::GetSlotId() const
return static_cast<SvMetaAttribute *>(GetRef())->GetSlotId();
}
-bool SvMetaAttribute::Test( SvIdlDataBase & rBase,
- SvTokenStream & rInStm )
+bool SvMetaAttribute::Test( SvTokenStream & rInStm )
{
bool bOk = true;
if( GetType()->IsItem() && !GetSlotId().IsSet() )
{
- rBase.SetAndWriteError( rInStm, "slot without id declared" );
+ throw SvParseException( rInStm, "slot without id declared" );
bOk = false;
}
return bOk;
@@ -199,15 +198,10 @@ bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase,
bIsItem = true;
SvMetaType * pType = rBase.ReadKnownType( rInStm );
- if( pType )
- {
- SetRef( pType );
- bOk = ReadNameSvIdl( rInStm );
- }
- else
- {
- rBase.SetAndWriteError( rInStm, "wrong typedef: ");
- }
+ if( !pType )
+ throw SvParseException( rInStm, "wrong typedef: ");
+ SetRef( pType );
+ bOk = ReadNameSvIdl( rInStm );
}
if( !bOk )
rInStm.Seek( nTokPos );
@@ -236,7 +230,7 @@ void SvMetaType::ReadContextSvIdl( SvIdlDataBase & rBase,
tools::SvRef<SvMetaAttribute> xAttr( new SvMetaAttribute() );
if( xAttr->ReadSvIdl( rBase, rInStm ) )
{
- if( xAttr->Test( rBase, rInStm ) )
+ if( xAttr->Test( rInStm ) )
GetAttrList().push_back( xAttr );
}
}
diff --git a/idl/source/prj/command.cxx b/idl/source/prj/command.cxx
index 4ad62f9..2095ad2 100644
--- a/idl/source/prj/command.cxx
+++ b/idl/source/prj/command.cxx
@@ -124,9 +124,15 @@ bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
OUString aFileName ( rCommand.aInFileList[ n ] );
pDataBase->AddDepFile(aFileName);
SvTokenStream aTokStm( aFileName );
- SvIdlParser aParser(*pDataBase, aTokStm);
- if( !aParser.ReadSvIdl( false, rCommand.aPath ) )
- return false;
+ try {
+ SvIdlParser aParser(*pDataBase, aTokStm);
+ if( !aParser.ReadSvIdl( false, rCommand.aPath ) )
+ return false;
+ } catch (const SvParseException& ex) {
+ pDataBase->SetError(ex.aError);
+ pDataBase->WriteError(aTokStm);
+ return false;
+ }
}
return true;
}
diff --git a/idl/source/prj/database.cxx b/idl/source/prj/database.cxx
index ee5a072..96c4e3a 100644
--- a/idl/source/prj/database.cxx
+++ b/idl/source/prj/database.cxx
@@ -29,6 +29,21 @@
#include <rtl/strbuf.hxx>
#include <osl/file.hxx>
+
+SvParseException::SvParseException( SvTokenStream & rInStm, const OString& rError )
+{
+ SvToken& rTok = rInStm.GetToken();
+ aError = SvIdlError( rTok.GetLine(), rTok.GetColumn() );
+ aError.SetText( rError );
+};
+
+SvParseException::SvParseException( const OString& rError, SvToken& rTok )
+{
+ aError = SvIdlError( rTok.GetLine(), rTok.GetColumn() );
+ aError.SetText( rError );
+};
+
+
SvIdlDataBase::SvIdlDataBase( const SvCommand& rCmd )
: bExport( false )
, nUniqueId( 0 )
@@ -150,16 +165,9 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
{
rTok = aTokStm.GetToken_Next();
OString aDefName;
- if( rTok.IsIdentifier() )
- aDefName = rTok.GetString();
- else
- {
- OString aStr("unexpected token after define");
- // set error
- SetError( aStr, rTok );
- WriteError( aTokStm );
- return false;
- }
+ if( !rTok.IsIdentifier() )
+ throw SvParseException( "unexpected token after define", rTok );
+ aDefName = rTok.GetString();
sal_uLong nVal = 0;
bool bOk = true;
@@ -184,11 +192,7 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
|| rTok.GetChar() == '^'
|| rTok.GetChar() == '~' )
{
- OString aStr = "unknown operator '" + OString(rTok.GetChar()) + "'in define";
- // set error
- SetError( aStr, rTok );
- WriteError( aTokStm );
- return false;
+ throw SvParseException( "unknown operator '" + OString(rTok.GetChar()) + "'in define", rTok );
}
if( rTok.GetChar() != '+'
&& rTok.GetChar() != '('
@@ -208,10 +212,7 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
{
if( !InsertId( aDefName, nVal ) )
{
- OString aStr("hash table overflow: ");
- SetError( aStr, rTok );
- WriteError( aTokStm );
- return false;
+ throw SvParseException( "hash table overflow: ", rTok );
}
}
}
@@ -232,19 +233,13 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
}
if( rTok.IsEof() )
{
- OString aStr("unexpected eof in #include");
- // set error
- SetError(aStr, rTok);
- WriteError( aTokStm );
- return false;
+ throw SvParseException("unexpected eof in #include", rTok);
}
}
if (!ReadIdFile(OStringToOUString(aName.toString(),
RTL_TEXTENCODING_ASCII_US)))
{
- SetError("cannot read file: " + aName, rTok);
- WriteError( aTokStm );
- return false;
+ throw SvParseException("cannot read file: " + aName, rTok);
}
}
}
@@ -394,21 +389,6 @@ void SvIdlDataBase::Write(const OString& rText)
fprintf( stdout, "%s", rText.getStr() );
}
-void SvIdlDataBase::WriteError( const OString& rErrWrn,
- const OString& rFileName,
- const OString& rErrorText,
- sal_uLong nRow, sal_uLong nColumn )
-{
- // error treatment
- fprintf( stderr, "\n%s --- %s: ( %" SAL_PRIuUINTPTR ", %" SAL_PRIuUINTPTR " )\n",
- rFileName.getStr(), rErrWrn.getStr(), nRow, nColumn );
-
- if( !rErrorText.isEmpty() )
- { // error set
- fprintf( stderr, "\t%s\n", rErrorText.getStr() );
- }
-}
-
void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
{
// error treatment
@@ -453,8 +433,15 @@ void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
aError = SvIdlError();
}
- WriteError("error", OUStringToOString(aFileName,
- RTL_TEXTENCODING_UTF8), aErrorText.makeStringAndClear(), nRow, nColumn);
+ // error treatment
+ fprintf( stderr, "\n%s --- %s: ( %" SAL_PRIuUINTPTR ", %" SAL_PRIuUINTPTR " )\n",
+ OUStringToOString(aFileName, RTL_TEXTENCODING_UTF8).getStr(),
+ "error", nRow, nColumn );
+
+ if( !aErrorText.isEmpty() )
+ { // error set
+ fprintf( stderr, "\t%s\n", aErrorText.getStr() );
+ }
// look for identifier close by
if( !rTok.IsIdentifier() )
commit 489dd9027f53e6328f281bf087bb5a59246f9500
Author: Noel Grandin <noel at peralex.com>
Date: Thu Feb 11 12:31:03 2016 +0200
rename SeekEnd()->SeekToMax()
Change-Id: I3274106d4459532145aaa9222df0e9d715cf59fc
diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx
index 0bfe491..bc0feea 100644
--- a/idl/inc/lex.hxx
+++ b/idl/inc/lex.hxx
@@ -216,7 +216,7 @@ public:
SetMax();
}
- void SeekEnd()
+ void SeekToMax()
{
pCurToken = aTokList.begin()+nMaxPos;
}
diff --git a/idl/source/prj/database.cxx b/idl/source/prj/database.cxx
index bb6318f..ee5a072 100644
--- a/idl/source/prj/database.cxx
+++ b/idl/source/prj/database.cxx
@@ -416,7 +416,7 @@ void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
OStringBuffer aErrorText;
sal_uLong nRow = 0, nColumn = 0;
- rInStm.SeekEnd();
+ rInStm.SeekToMax();
SvToken& rTok = rInStm.GetToken();
// error position
commit 33e128b816300d552ae9ad3c611c8464fff08e68
Author: Noel Grandin <noel at peralex.com>
Date: Thu Feb 11 11:41:21 2016 +0200
simplify SvTokenStream handling
Change-Id: Ic8d8c7df54bd9debea3b9601d9c8d67b0412b5ab
diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx
index e2e5bc3..0bfe491 100644
--- a/idl/inc/lex.hxx
+++ b/idl/inc/lex.hxx
@@ -150,7 +150,6 @@ class SvTokenStream
}
public:
SvTokenStream( const OUString & rFileName );
- SvTokenStream( SvStream & rInStream, const OUString & rFileName );
~SvTokenStream();
const OUString & GetFileName() const { return aFileName; }
diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx
index c06287b..8a15bb4 100644
--- a/idl/inc/parser.hxx
+++ b/idl/inc/parser.hxx
@@ -27,8 +27,11 @@ class SvIdlDataBase;
class SvIdlParser
{
+ SvIdlDataBase& rBase;
+ SvTokenStream & rInStm;
public:
- bool ReadSvIdl( SvIdlDataBase& rBase, SvTokenStream &, bool bImported, const OUString & rPath );
+ SvIdlParser( SvIdlDataBase& rBase_, SvTokenStream & rInStrm_) : rBase(rBase_), rInStm(rInStrm_) {}
+ bool ReadSvIdl( bool bImported, const OUString & rPath );
};
diff --git a/idl/source/cmptools/lex.cxx b/idl/source/cmptools/lex.cxx
index 67c2cf1..e243302 100644
--- a/idl/source/cmptools/lex.cxx
+++ b/idl/source/cmptools/lex.cxx
@@ -91,14 +91,6 @@ SvTokenStream::SvTokenStream( const OUString & rFileName )
InitCtor();
}
-SvTokenStream::SvTokenStream( SvStream & rStream, const OUString & rFileName )
- : pInStream( nullptr )
- , rInStream( rStream )
- , aFileName( rFileName )
-{
- InitCtor();
-}
-
SvTokenStream::~SvTokenStream()
{
delete pInStream;
diff --git a/idl/source/prj/command.cxx b/idl/source/prj/command.cxx
index 2967e05..4ad62f9 100644
--- a/idl/source/prj/command.cxx
+++ b/idl/source/prj/command.cxx
@@ -123,21 +123,10 @@ bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
{
OUString aFileName ( rCommand.aInFileList[ n ] );
pDataBase->AddDepFile(aFileName);
- SvFileStream aStm( aFileName, STREAM_STD_READ | StreamMode::NOCREATE );
- if( aStm.GetError() == SVSTREAM_OK )
- {
- SvTokenStream aTokStm( aStm, aFileName );
- SvIdlParser aParser;
- if( !aParser.ReadSvIdl( *pDataBase, aTokStm, false, rCommand.aPath ) )
- return false;
- }
- else
- {
- const OString aStr(OUStringToOString(aFileName,
- RTL_TEXTENCODING_UTF8));
- fprintf( stderr, "unable to read input file: %s\n", aStr.getStr() );
+ SvTokenStream aTokStm( aFileName );
+ SvIdlParser aParser(*pDataBase, aTokStm);
+ if( !aParser.ReadSvIdl( false, rCommand.aPath ) )
return false;
- }
}
return true;
}
diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx
index 7a48c6f..34820f2 100644
--- a/idl/source/prj/parser.cxx
+++ b/idl/source/prj/parser.cxx
@@ -24,7 +24,7 @@
#include <globals.hxx>
#include <osl/file.hxx>
-bool SvIdlParser::ReadSvIdl( SvIdlDataBase& rBase, SvTokenStream & rInStm, bool bImported, const OUString & rPath )
+bool SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath )
{
rBase.SetPath(rPath); // only valid for this iteration
bool bOk = true;
@@ -32,7 +32,6 @@ bool SvIdlParser::ReadSvIdl( SvIdlDataBase& rBase, SvTokenStream & rInStm, bool
// only one import at the very beginning
if( rTok.Is( SvHash_import() ) )
{
- rInStm.GetToken_Next();
rTok = rInStm.GetToken_Next();
if( rTok.IsString() )
{
@@ -44,9 +43,9 @@ bool SvIdlParser::ReadSvIdl( SvIdlDataBase& rBase, SvTokenStream & rInStm, bool
{
osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName );
rBase.AddDepFile(aFullName);
- SvFileStream aStm( aFullName, STREAM_STD_READ | StreamMode::NOCREATE );
- SvTokenStream aTokStm( aStm, aFullName );
- bOk = ReadSvIdl( rBase, aTokStm, true, rPath );
+ SvTokenStream aTokStm( aFullName );
+ SvIdlParser aInputParser(rBase, aTokStm);
+ bOk = aInputParser.ReadSvIdl( true, rPath );
}
else
bOk = false;
commit 09d58f7be8802c7e3f60ced1b428195b4d6bb7fa
Author: Noel Grandin <noel at peralex.com>
Date: Thu Feb 11 10:37:29 2016 +0200
GetToken never returns null, so use a reference
Change-Id: I0164e546b0ee0b40acc7b9253d3c0ecded97280c
diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx
index 14b91cd..e2e5bc3 100644
--- a/idl/inc/lex.hxx
+++ b/idl/inc/lex.hxx
@@ -156,7 +156,7 @@ public:
const OUString & GetFileName() const { return aFileName; }
SvStream & GetStream() { return rInStream; }
- SvToken* GetToken_PrevAll()
+ SvToken& GetToken_PrevAll()
{
std::vector<std::unique_ptr<SvToken> >::iterator pRetToken = pCurToken;
@@ -164,10 +164,10 @@ public:
if(pCurToken != aTokList.begin())
--pCurToken;
- return (*pRetToken).get();
+ return *(*pRetToken).get();
}
- SvToken* GetToken_NextAll()
+ SvToken& GetToken_NextAll()
{
std::vector<std::unique_ptr<SvToken> >::iterator pRetToken = pCurToken++;
@@ -176,10 +176,10 @@ public:
SetMax();
- return (*pRetToken).get();
+ return *(*pRetToken).get();
}
- SvToken* GetToken_Next()
+ SvToken& GetToken_Next()
{
// comments get removed initially
return GetToken_NextAll();
diff --git a/idl/source/objects/basobj.cxx b/idl/source/objects/basobj.cxx
index 5812626..797b849 100644
--- a/idl/source/objects/basobj.cxx
+++ b/idl/source/objects/basobj.cxx
@@ -74,12 +74,12 @@ void SvMetaObject::SetName( const OString& rName )
bool SvMetaObject::ReadNameSvIdl( SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
// read module name
- if( pTok->IsIdentifier() )
+ if( rTok.IsIdentifier() )
{
- SetName( pTok->GetString() );
+ SetName( rTok.GetString() );
return true;
}
diff --git a/idl/source/objects/bastype.cxx b/idl/source/objects/bastype.cxx
index 26877f8..ce1d8f3 100644
--- a/idl/source/objects/bastype.cxx
+++ b/idl/source/objects/bastype.cxx
@@ -31,18 +31,18 @@
bool SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->Is( pName ) )
+ if( rTok.Is( pName ) )
{
bool bOk = true;
bool bBracket = rInStm.Read( '(' );
if( bBracket || rInStm.Read( '=' ) )
{
- pTok = &rInStm.GetToken();
- if( pTok->IsBool() )
+ rTok = rInStm.GetToken();
+ if( rTok.IsBool() )
{
- *this = pTok->GetBool();
+ *this = rTok.GetBool();
rInStm.GetToken_Next();
}
@@ -61,18 +61,18 @@ bool SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
bool SvIdentifier::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->Is( pName ) )
+ if( rTok.Is( pName ) )
{
bool bOk = true;
bool bBracket = rInStm.Read( '(' );
if( bBracket || rInStm.Read( '=' ) )
{
- pTok = &rInStm.GetToken();
- if( pTok->IsIdentifier() )
+ rTok = rInStm.GetToken();
+ if( rTok.IsIdentifier() )
{
- setString(pTok->GetString());
+ setString(rTok.GetString());
rInStm.GetToken_Next();
}
if( bOk && bBracket )
@@ -89,14 +89,14 @@ void SvIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->IsIdentifier() )
+ if( rTok.IsIdentifier() )
{
sal_uLong n;
- if( rBase.FindId( pTok->GetString(), &n ) )
+ if( rBase.FindId( rTok.GetString(), &n ) )
{
- setString(pTok->GetString());
+ setString(rTok.GetString());
nValue = n;
return;
}
@@ -111,18 +111,18 @@ void SvIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
bool ReadStringSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm, OString& aRetString )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->Is( pName ) )
+ if( rTok.Is( pName ) )
{
bool bOk = true;
bool bBracket = rInStm.Read( '(' );
if( bBracket || rInStm.Read( '=' ) )
{
- pTok = &rInStm.GetToken();
- if( pTok->IsString() )
+ rTok = rInStm.GetToken();
+ if( rTok.IsString() )
{
- aRetString = pTok->GetString();
+ aRetString = rTok.GetString();
rInStm.GetToken_Next();
}
if( bOk && bBracket )
diff --git a/idl/source/objects/module.cxx b/idl/source/objects/module.cxx
index ea040f5..29ce9721 100644
--- a/idl/source/objects/module.cxx
+++ b/idl/source/objects/module.cxx
@@ -90,10 +90,10 @@ void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase,
{
bool bOk = false;
rInStm.GetToken_Next();
- SvToken * pTok = rInStm.GetToken_Next();
- if( pTok->IsString() )
+ SvToken& rTok = rInStm.GetToken_Next();
+ if( rTok.IsString() )
{
- OUString aFullName(OStringToOUString(pTok->GetString(), RTL_TEXTENCODING_ASCII_US));
+ OUString aFullName(OStringToOUString(rTok.GetString(), RTL_TEXTENCODING_ASCII_US));
rBase.StartNewFile( aFullName );
osl::FileBase::RC searchError = osl::File::searchFileURL(aFullName, rBase.GetPath(), aFullName);
osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName );
@@ -129,14 +129,14 @@ void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase,
{
OStringBuffer aStr("cannot open file: ");
aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
- rBase.SetError(aStr.makeStringAndClear(), *pTok);
+ rBase.SetError(aStr.makeStringAndClear(), rTok);
}
}
else
{
OStringBuffer aStr("cannot find file:");
aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8));
- rBase.SetError(aStr.makeStringAndClear(), *pTok);
+ rBase.SetError(aStr.makeStringAndClear(), rTok);
}
}
if( !bOk )
@@ -162,8 +162,8 @@ bool SvMetaModule::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
bIsModified = true; // up to now always when compiler running
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
- bool bOk = pTok->Is( SvHash_module() );
+ SvToken& rTok = rInStm.GetToken_Next();
+ bool bOk = rTok.Is( SvHash_module() );
rInStm.ReadDelimiter();
if( bOk )
{
diff --git a/idl/source/objects/object.cxx b/idl/source/objects/object.cxx
index 38cfe6b..697fe9f 100644
--- a/idl/source/objects/object.cxx
+++ b/idl/source/objects/object.cxx
@@ -43,9 +43,9 @@ void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase,
SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->Is( SvHash_import() ) )
+ if( rTok.Is( SvHash_import() ) )
{
SvMetaClass * pClass = rBase.ReadKnownClass( rInStm );
if( pClass )
@@ -54,10 +54,10 @@ void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase,
xEle.SetClass( pClass );
aClassElementList.push_back( xEle );
- pTok = &rInStm.GetToken();
- if( pTok->IsString() )
+ rTok = rInStm.GetToken();
+ if( rTok.IsString() )
{
- xEle.SetPrefix( pTok->GetString() );
+ xEle.SetPrefix( rTok.GetString() );
rInStm.GetToken_Next();
}
return;
diff --git a/idl/source/objects/slot.cxx b/idl/source/objects/slot.cxx
index 6cdeea7..7246369 100644
--- a/idl/source/objects/slot.cxx
+++ b/idl/source/objects/slot.cxx
@@ -280,8 +280,8 @@ void SvMetaSlot::ReadAttributesSvIdl( SvIdlDataBase & rBase,
if( !aSlotType.Is() )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
- if( pTok->Is( SvHash_SlotType() ) )
+ SvToken& rTok = rInStm.GetToken_Next();
+ if( rTok.Is( SvHash_SlotType() ) )
{
if( rInStm.Read( '=' ) )
{
diff --git a/idl/source/objects/types.cxx b/idl/source/objects/types.cxx
index 50fe11b..393eb42 100644
--- a/idl/source/objects/types.cxx
+++ b/idl/source/objects/types.cxx
@@ -172,32 +172,31 @@ bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase,
{
bool bOk = false;
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->Is( SvHash_interface() ) )
+ if( rTok.Is( SvHash_interface() ) )
{
SetType( MetaTypeType::Interface );
bOk = ReadNamesSvIdl( rInStm );
}
- else if( pTok->Is( SvHash_shell() ) )
+ else if( rTok.Is( SvHash_shell() ) )
{
SetType( MetaTypeType::Shell );
bOk = ReadNamesSvIdl( rInStm );
}
- else if( pTok->Is( SvHash_struct() ) )
+ else if( rTok.Is( SvHash_struct() ) )
{
SetType( MetaTypeType::Struct );
bOk = ReadNamesSvIdl( rInStm );
}
- else if( pTok->Is( SvHash_enum() ) )
+ else if( rTok.Is( SvHash_enum() ) )
{
SetType( MetaTypeType::Enum );
bOk = ReadNameSvIdl( rInStm );
}
- else if( pTok->Is( SvHash_item() ) )
+ else if( rTok.Is( SvHash_item() ) )
{
- if( pTok->Is( SvHash_item() ) )
- bIsItem = true;
+ bIsItem = true;
SvMetaType * pType = rBase.ReadKnownType( rInStm );
if( pType )
diff --git a/idl/source/prj/database.cxx b/idl/source/prj/database.cxx
index 0a15351..bb6318f 100644
--- a/idl/source/prj/database.cxx
+++ b/idl/source/prj/database.cxx
@@ -139,24 +139,24 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
SvTokenStream aTokStm( aFullName );
if( aTokStm.GetStream().GetError() == SVSTREAM_OK )
{
- SvToken * pTok = aTokStm.GetToken_Next();
+ SvToken& rTok = aTokStm.GetToken_Next();
- while( !pTok->IsEof() )
+ while( !rTok.IsEof() )
{
- if( pTok->IsChar() && pTok->GetChar() == '#' )
+ if( rTok.IsChar() && rTok.GetChar() == '#' )
{
- pTok = aTokStm.GetToken_Next();
- if( pTok->Is( SvHash_define() ) )
+ rTok = aTokStm.GetToken_Next();
+ if( rTok.Is( SvHash_define() ) )
{
- pTok = aTokStm.GetToken_Next();
+ rTok = aTokStm.GetToken_Next();
OString aDefName;
- if( pTok->IsIdentifier() )
- aDefName = pTok->GetString();
+ if( rTok.IsIdentifier() )
+ aDefName = rTok.GetString();
else
{
OString aStr("unexpected token after define");
// set error
- SetError( aStr, *pTok );
+ SetError( aStr, rTok );
WriteError( aTokStm );
return false;
}
@@ -165,41 +165,41 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
bool bOk = true;
while( bOk )
{
- pTok = aTokStm.GetToken_Next();
- if( pTok->IsIdentifier() )
+ rTok = aTokStm.GetToken_Next();
+ if( rTok.IsIdentifier() )
{
sal_uLong n;
- if( FindId( pTok->GetString(), &n ) )
+ if( FindId( rTok.GetString(), &n ) )
nVal += n;
else
bOk = false;
}
- else if( pTok->IsChar() )
+ else if( rTok.IsChar() )
{
- if( pTok->GetChar() == '-'
- || pTok->GetChar() == '/'
- || pTok->GetChar() == '*'
- || pTok->GetChar() == '&'
- || pTok->GetChar() == '|'
- || pTok->GetChar() == '^'
- || pTok->GetChar() == '~' )
+ if( rTok.GetChar() == '-'
+ || rTok.GetChar() == '/'
+ || rTok.GetChar() == '*'
+ || rTok.GetChar() == '&'
+ || rTok.GetChar() == '|'
+ || rTok.GetChar() == '^'
+ || rTok.GetChar() == '~' )
{
- OString aStr = "unknown operator '" + OString(pTok->GetChar()) + "'in define";
+ OString aStr = "unknown operator '" + OString(rTok.GetChar()) + "'in define";
// set error
- SetError( aStr, *pTok );
+ SetError( aStr, rTok );
WriteError( aTokStm );
return false;
}
- if( pTok->GetChar() != '+'
- && pTok->GetChar() != '('
- && pTok->GetChar() != ')' )
+ if( rTok.GetChar() != '+'
+ && rTok.GetChar() != '('
+ && rTok.GetChar() != ')' )
// only + is allowed, parentheses are immaterial
// because + is commutative
break;
}
- else if( pTok->IsInteger() )
+ else if( rTok.IsInteger() )
{
- nVal += pTok->GetNumber();
+ nVal += rTok.GetNumber();
}
else
break;
@@ -209,32 +209,32 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
if( !InsertId( aDefName, nVal ) )
{
OString aStr("hash table overflow: ");
- SetError( aStr, *pTok );
+ SetError( aStr, rTok );
WriteError( aTokStm );
return false;
}
}
}
- else if( pTok->Is( SvHash_include() ) )
+ else if( rTok.Is( SvHash_include() ) )
{
- pTok = aTokStm.GetToken_Next();
+ rTok = aTokStm.GetToken_Next();
OStringBuffer aName;
- if( pTok->IsString() )
- aName.append(pTok->GetString());
- else if( pTok->IsChar() && pTok->GetChar() == '<' )
+ if( rTok.IsString() )
+ aName.append(rTok.GetString());
+ else if( rTok.IsChar() && rTok.GetChar() == '<' )
{
- pTok = aTokStm.GetToken_Next();
- while( !pTok->IsEof()
- && !(pTok->IsChar() && pTok->GetChar() == '>') )
+ rTok = aTokStm.GetToken_Next();
+ while( !rTok.IsEof()
+ && !(rTok.IsChar() && rTok.GetChar() == '>') )
{
- aName.append(pTok->GetTokenAsString());
- pTok = aTokStm.GetToken_Next();
+ aName.append(rTok.GetTokenAsString());
+ rTok = aTokStm.GetToken_Next();
}
- if( pTok->IsEof() )
+ if( rTok.IsEof() )
{
OString aStr("unexpected eof in #include");
// set error
- SetError(aStr, *pTok);
+ SetError(aStr, rTok);
WriteError( aTokStm );
return false;
}
@@ -242,14 +242,14 @@ bool SvIdlDataBase::ReadIdFile( const OUString & rFileName )
if (!ReadIdFile(OStringToOUString(aName.toString(),
RTL_TEXTENCODING_ASCII_US)))
{
- SetError("cannot read file: " + aName, *pTok);
+ SetError("cannot read file: " + aName, rTok);
WriteError( aTokStm );
return false;
}
}
}
else
- pTok = aTokStm.GetToken_Next();
+ rTok = aTokStm.GetToken_Next();
}
}
else
@@ -277,9 +277,9 @@ SvMetaType * SvIdlDataBase::FindType( const OString& rName )
SvMetaType * SvIdlDataBase::ReadKnownType( SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->HasHash() )
+ if( rTok.HasHash() )
{
sal_uInt32 nBeginPos = 0; // can not happen with Tell
while( nBeginPos != rInStm.Tell() )
@@ -288,9 +288,9 @@ SvMetaType * SvIdlDataBase::ReadKnownType( SvTokenStream & rInStm )
}
}
- if( pTok->IsIdentifier() )
+ if( rTok.IsIdentifier() )
{
- OString aName = pTok->GetString();
+ OString aName = rTok.GetString();
SvRefMemberList<SvMetaType *> & rList = GetTypeList();
SvRefMemberList<SvMetaType *>::const_iterator it = rList.begin();
SvMetaType * pType = nullptr;
@@ -328,22 +328,22 @@ SvMetaAttribute * SvIdlDataBase::ReadKnownAttr
if( !pType )
{
// otherwise SlotId?
- SvToken * pTok = rInStm.GetToken_Next();
- if( pTok->IsIdentifier() )
+ SvToken& rTok = rInStm.GetToken_Next();
+ if( rTok.IsIdentifier() )
{
sal_uLong n;
- if( FindId( pTok->GetString(), &n ) )
+ if( FindId( rTok.GetString(), &n ) )
{
for( sal_uLong i = 0; i < aSlotList.size(); i++ )
{
SvMetaSlot * pSlot = aSlotList[i];
- if( pSlot->GetSlotId().getString().equals(pTok->GetString()) )
+ if( pSlot->GetSlotId().getString().equals(rTok.GetString()) )
return pSlot;
}
}
OStringBuffer aStr("Not found : ");
- aStr.append(pTok->GetString());
+ aStr.append(rTok.GetString());
OSL_FAIL(aStr.getStr());
}
}
@@ -374,13 +374,13 @@ SvMetaAttribute* SvIdlDataBase::SearchKnownAttr
SvMetaClass * SvIdlDataBase::ReadKnownClass( SvTokenStream & rInStm )
{
sal_uInt32 nTokPos = rInStm.Tell();
- SvToken * pTok = rInStm.GetToken_Next();
+ SvToken& rTok = rInStm.GetToken_Next();
- if( pTok->IsIdentifier() )
+ if( rTok.IsIdentifier() )
for( sal_uLong n = 0; n < aClassList.size(); n++ )
{
SvMetaClass * pClass = aClassList[n];
- if( pClass->GetName().equals(pTok->GetString()) )
+ if( pClass->GetName().equals(rTok.GetString()) )
return pClass;
}
@@ -417,11 +417,11 @@ void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
sal_uLong nRow = 0, nColumn = 0;
rInStm.SeekEnd();
- SvToken *pTok = &rInStm.GetToken();
+ SvToken& rTok = rInStm.GetToken();
// error position
- nRow = pTok->GetLine();
- nColumn = pTok->GetColumn();
+ nRow = rTok.GetLine();
+ nColumn = rTok.GetColumn();
if( aError.IsError() )
{ // error set
@@ -433,13 +433,13 @@ void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
aErrorText.append(aError.GetText());
}
SvToken * pPrevTok = nullptr;
- while( pTok != pPrevTok )
+ while( &rTok != pPrevTok )
{
- pPrevTok = pTok;
- if( pTok->GetLine() == aError.nLine
- && pTok->GetColumn() == aError.nColumn )
+ pPrevTok = &rTok;
+ if( rTok.GetLine() == aError.nLine
+ && rTok.GetColumn() == aError.nColumn )
break;
- pTok = rInStm.GetToken_PrevAll();
+ rTok = rInStm.GetToken_PrevAll();
}
// error position
@@ -456,21 +456,17 @@ void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
WriteError("error", OUStringToOString(aFileName,
RTL_TEXTENCODING_UTF8), aErrorText.makeStringAndClear(), nRow, nColumn);
- DBG_ASSERT( pTok, "token must be found" );
- if( !pTok )
- return;
-
// look for identifier close by
- if( !pTok->IsIdentifier() )
+ if( !rTok.IsIdentifier() )
{
rInStm.GetToken_PrevAll();
- pTok = &rInStm.GetToken();
+ rTok = rInStm.GetToken();
}
- if( pTok && pTok->IsIdentifier() )
+ if( rTok.IsIdentifier() )
{
- OString aN = GetIdlApp().pHashTable->GetNearString( pTok->GetString() );
+ OString aN = GetIdlApp().pHashTable->GetNearString( rTok.GetString() );
if( !aN.isEmpty() )
- fprintf( stderr, "%s versus %s\n", pTok->GetString().getStr(), aN.getStr() );
+ fprintf( stderr, "%s versus %s\n", rTok.GetString().getStr(), aN.getStr() );
}
}
diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx
index db594ab..7a48c6f 100644
--- a/idl/source/prj/parser.cxx
+++ b/idl/source/prj/parser.cxx
@@ -28,17 +28,17 @@ bool SvIdlParser::ReadSvIdl( SvIdlDataBase& rBase, SvTokenStream & rInStm, bool
{
rBase.SetPath(rPath); // only valid for this iteration
bool bOk = true;
- SvToken * pTok = &rInStm.GetToken();
+ SvToken& rTok = rInStm.GetToken();
// only one import at the very beginning
- if( pTok->Is( SvHash_import() ) )
+ if( rTok.Is( SvHash_import() ) )
{
rInStm.GetToken_Next();
- pTok = rInStm.GetToken_Next();
- if( pTok && pTok->IsString() )
+ rTok = rInStm.GetToken_Next();
+ if( rTok.IsString() )
{
OUString aFullName;
if( osl::FileBase::E_None == osl::File::searchFileURL(
- OStringToOUString(pTok->GetString(), RTL_TEXTENCODING_ASCII_US),
+ OStringToOUString(rTok.GetString(), RTL_TEXTENCODING_ASCII_US),
rPath,
aFullName) )
{
@@ -57,11 +57,11 @@ bool SvIdlParser::ReadSvIdl( SvIdlDataBase& rBase, SvTokenStream & rInStm, bool
while( bOk )
{
- pTok = &rInStm.GetToken();
- if( pTok->IsEof() )
+ rTok = rInStm.GetToken();
+ if( rTok.IsEof() )
return true;
- if( pTok->Is( SvHash_module() ) )
+ if( rTok.Is( SvHash_module() ) )
{
tools::SvRef<SvMetaModule> aModule = new SvMetaModule( bImported );
if( aModule->ReadSvIdl( rBase, rInStm ) )
@@ -72,7 +72,7 @@ bool SvIdlParser::ReadSvIdl( SvIdlDataBase& rBase, SvTokenStream & rInStm, bool
else
bOk = false;
}
- if( !bOk || !pTok->IsEof() )
+ if( !bOk || !rTok.IsEof() )
{
// error treatment
rBase.WriteError( rInStm );
More information about the Libreoffice-commits
mailing list