diff options
author | Noel Grandin <noel@peralex.com> | 2016-02-11 14:33:36 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2016-02-11 14:47:01 +0200 |
commit | 4e13a6911259d3d7d23b61cb76614263608bbd95 (patch) | |
tree | 7dcd289f650a0a179b6ab3fd2934dea2252c42d5 /idl/source/prj | |
parent | 489dd9027f53e6328f281bf087bb5a59246f9500 (diff) |
use exceptions for error handling in .SDI parsing
to simplify the normal control flow
Change-Id: If325ec0507a51d8e2d3340fc5b628bb75a078a44
Diffstat (limited to 'idl/source/prj')
-rw-r--r-- | idl/source/prj/command.cxx | 12 | ||||
-rw-r--r-- | idl/source/prj/database.cxx | 75 |
2 files changed, 40 insertions, 47 deletions
diff --git a/idl/source/prj/command.cxx b/idl/source/prj/command.cxx index 4ad62f971d3f..2095ad267c3b 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 ee5a072871af..96c4e3a0f802 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() ) |