idl/inc/object.hxx | 10 - idl/inc/parser.hxx | 18 +- idl/inc/types.hxx | 8 idl/source/objects/object.cxx | 28 --- idl/source/objects/types.cxx | 30 --- idl/source/prj/command.cxx | 3 idl/source/prj/database.cxx | 25 -- idl/source/prj/parser.cxx | 358 ++++++++++++++++++++++++------------------ 8 files changed, 234 insertions(+), 246 deletions(-)
New commits: commit 645394f02334548d6158187308cffd65b0b4ec77 Author: Noel Grandin <[email protected]> Date: Mon Feb 15 15:36:14 2016 +0200 cid#1352218 and cid#1352216 in .SDI parser Change-Id: I273d80b4e9fb45955c5496cf5559df5dd4b057b0 diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index ccd2f64..2258369 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -36,9 +36,9 @@ class SvIdlParser SvTokenStream & rInStm; public: SvIdlParser( SvIdlDataBase& rBase_, SvTokenStream & rInStrm_) : rBase(rBase_), rInStm(rInStrm_) {} - bool ReadSvIdl( bool bImported, const OUString & rPath ); - bool ReadModuleHeader(SvMetaModule& rModule); - bool ReadModuleBody(SvMetaModule& rModule); + void ReadSvIdl( bool bImported, const OUString & rPath ); + void ReadModuleHeader(SvMetaModule& rModule); + void ReadModuleBody(SvMetaModule& rModule); void ReadModuleElement( SvMetaModule& rModule ); void ReadInclude( SvMetaModule& rModule ); void ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMetaTypeType ); diff --git a/idl/source/prj/command.cxx b/idl/source/prj/command.cxx index 3b44679..c12c1e7 100644 --- a/idl/source/prj/command.cxx +++ b/idl/source/prj/command.cxx @@ -126,8 +126,7 @@ bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand ) SvTokenStream aTokStm( aFileName ); try { SvIdlParser aParser(*pDataBase, aTokStm); - if( !aParser.ReadSvIdl( false, rCommand.aPath ) ) - return false; + aParser.ReadSvIdl( false, rCommand.aPath ); } catch (const SvParseException& ex) { pDataBase->SetError(ex.aError); pDataBase->WriteError(aTokStm); diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index cdd80df..8f368b4 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -26,63 +26,38 @@ #include <globals.hxx> #include <osl/file.hxx> -bool SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath ) +void SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath ) { rBase.SetPath(rPath); // only valid for this iteration - bool bOk = true; SvToken& rTok = rInStm.GetToken(); - while( bOk ) + while( true ) { rTok = rInStm.GetToken(); if( rTok.IsEof() ) - return true; + return; if( rTok.Is( SvHash_module() ) ) { tools::SvRef<SvMetaModule> aModule = new SvMetaModule( bImported ); - if( ReadModuleHeader(*aModule) ) - rBase.GetModuleList().push_back( aModule ); - else - bOk = false; + ReadModuleHeader(*aModule); + rBase.GetModuleList().push_back( aModule ); } - else - bOk = false; - } - if( !bOk || !rTok.IsEof() ) - { - // error treatment - rBase.WriteError( rInStm ); - return false; } - return true; } -bool SvIdlParser::ReadModuleHeader(SvMetaModule& rModule) +void SvIdlParser::ReadModuleHeader(SvMetaModule& rModule) { - sal_uInt32 nTokPos = rInStm.Tell(); - SvToken& rTok = rInStm.GetToken_Next(); - bool bOk = true; - - rTok = rInStm.GetToken_Next(); - if( !rTok.IsIdentifier() ) - { - rInStm.Seek( nTokPos ); - return false; - } + rInStm.GetToken_Next(); + OString aName = ReadIdentifier(); rBase.Push( &rModule ); // onto the context stack - rModule.SetName( rTok.GetString() ); - bOk = ReadModuleBody(rModule); + rModule.SetName( aName ); + ReadModuleBody(rModule); rBase.GetStack().pop_back(); // remove from stack - if( !bOk ) - rInStm.Seek( nTokPos ); - return bOk; } -bool SvIdlParser::ReadModuleBody(SvMetaModule& rModule) +void SvIdlParser::ReadModuleBody(SvMetaModule& rModule) { - sal_uInt32 nTokPos = rInStm.Tell(); - bool bOk = true; if( rInStm.ReadIf( '[' ) ) { while( true ) @@ -100,7 +75,7 @@ bool SvIdlParser::ReadModuleBody(SvMetaModule& rModule) } if( !rInStm.ReadIf( '{' ) ) - return bOk; + return; sal_uInt32 nBeginPos = 0; while( nBeginPos != rInStm.Tell() ) @@ -110,10 +85,6 @@ bool SvIdlParser::ReadModuleBody(SvMetaModule& rModule) rInStm.ReadIfDelimiter(); } ReadChar( '}' ); - - if( !bOk ) - rInStm.Seek( nTokPos ); - return bOk; } void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) commit f7520bbc80b571a15adca5279cc7fc5e8965e53c Author: Noel Grandin <[email protected]> Date: Mon Feb 15 14:22:36 2016 +0200 move interface/shell parsing to SvIdlParser Change-Id: I95cce21c6c9beb5637dd4f4a769f455eaacbec2b diff --git a/idl/inc/object.hxx b/idl/inc/object.hxx index 3967fa9..12f5af2 100644 --- a/idl/inc/object.hxx +++ b/idl/inc/object.hxx @@ -48,9 +48,11 @@ public: class SvMetaClass : public SvMetaType { +public: + tools::SvRef<SvMetaClass> aSuperClass; +private: SvRefMemberList<SvMetaAttribute *> aAttrList; std::vector<SvClassElement> aClassElementList; - tools::SvRef<SvMetaClass> aSuperClass; bool TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm, SvMetaAttribute & rAttr ) const; @@ -70,15 +72,13 @@ class SvMetaClass : public SvMetaType SvMetaClassList & rClassList, const OString& rPrefix, SvIdlDataBase& rBase ); -protected: - virtual void ReadContextSvIdl( SvIdlDataBase &, - SvTokenStream & rInStm ) override; public: SvMetaClass(); + virtual void ReadContextSvIdl( SvIdlDataBase &, + SvTokenStream & rInStm ) override; void FillClasses( SvMetaClassList & rList ); - virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; virtual void WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm ) override; }; diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index 8418d0b..ccd2f64 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -21,6 +21,7 @@ #define INCLUDED_IDL_INC_PARSER_HXX #include <rtl/ustring.hxx> +#include <types.hxx> class SvTokenStream; class SvIdlDataBase; @@ -40,6 +41,7 @@ public: bool ReadModuleBody(SvMetaModule& rModule); void ReadModuleElement( SvMetaModule& rModule ); void ReadInclude( SvMetaModule& rModule ); + void ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMetaTypeType ); void ReadItem(); void ReadStruct(); void ReadEnum(); diff --git a/idl/source/objects/object.cxx b/idl/source/objects/object.cxx index c5c3589..711ca195 100644 --- a/idl/source/objects/object.cxx +++ b/idl/source/objects/object.cxx @@ -99,34 +99,6 @@ void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase, rInStm.Seek( nTokPos ); } -bool SvMetaClass::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) -{ - sal_uLong nTokPos = rInStm.Tell(); - if( SvMetaType::ReadHeaderSvIdl( rBase, rInStm ) && - (GetMetaTypeType() == MetaTypeType::Interface || GetMetaTypeType() == MetaTypeType::Shell) ) - { - bool bOk = true; - if( rInStm.ReadIf( ':' ) ) - { - aSuperClass = rBase.ReadKnownClass( rInStm ); - bOk = aSuperClass.Is(); - if( !bOk ) - { - throw SvParseException( rInStm, "unknown super class" ); - } - } - if( bOk ) - { - rBase.Write(OString('.')); - bOk = SvMetaObject::ReadSvIdl( rBase, rInStm ); - } - if( bOk ) - return bOk; - } - rInStm.Seek( nTokPos ); - return false; -} - bool SvMetaClass::TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm, SvMetaAttribute & rAttr ) const { diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index f2bc458..cdd80df 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -118,16 +118,13 @@ bool SvIdlParser::ReadModuleBody(SvMetaModule& rModule) void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) { - if( rInStm.GetToken().Is( SvHash_interface() ) - || rInStm.GetToken().Is( SvHash_shell() ) ) + if( rInStm.GetToken().Is( SvHash_interface() ) ) { - tools::SvRef<SvMetaClass> aClass( new SvMetaClass() ); - if( aClass->ReadSvIdl( rBase, rInStm ) ) - { - rModule.aClassList.push_back( aClass ); - // announce globally - rBase.GetClassList().push_back( aClass ); - } + ReadInterfaceOrShell(rModule, MetaTypeType::Interface); + } + else if( rInStm.GetToken().Is( SvHash_shell() ) ) + { + ReadInterfaceOrShell(rModule, MetaTypeType::Shell); } else if( rInStm.GetToken().Is( SvHash_enum() ) ) { @@ -254,20 +251,6 @@ void SvIdlParser::ReadItem() rBase.GetTypeList().push_back( xItem ); } -SvMetaType * SvIdlParser::ReadKnownType() -{ - OString aName = ReadIdentifier(); - for( const auto& aType : rBase.GetTypeList() ) - { - if( aType->GetName().equals(aName) ) - { - return aType; - } - } - throw SvParseException( rInStm, "wrong typedef: "); -} - - void SvIdlParser::ReadEnum() { rInStm.GetToken_Next(); @@ -316,14 +299,52 @@ void SvIdlParser::ReadEnumValue( SvMetaTypeEnum& rEnum ) rEnum.aEnumValueList.push_back( aEnumVal ); } +void SvIdlParser::ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMetaTypeType ) +{ + tools::SvRef<SvMetaClass> aClass( new SvMetaClass() ); + rInStm.GetToken_Next(); -void SvIdlParser::ReadChar(char cChar) + aClass->SetType( aMetaTypeType ); + + aClass->SetName( ReadIdentifier() ); + + if( rInStm.ReadIf( ':' ) ) + { + aClass->aSuperClass = rBase.ReadKnownClass( rInStm ); + if( !aClass->aSuperClass.Is() ) + throw SvParseException( rInStm, "unknown super class" ); + } + if( rInStm.ReadIf( '{' ) ) + { + sal_uInt32 nBeginPos = 0; // can not happen with Tell + while( nBeginPos != rInStm.Tell() ) + { + nBeginPos = rInStm.Tell(); + aClass->ReadContextSvIdl( rBase, rInStm ); + rInStm.ReadIfDelimiter(); + } + ReadChar( '}' ); + } + rModule.aClassList.push_back( aClass ); + // announce globally + rBase.GetClassList().push_back( aClass ); +} + +SvMetaType * SvIdlParser::ReadKnownType() { - if( !rInStm.ReadIf( cChar ) ) - throw SvParseException(rInStm, "expected char '" + OString(cChar) + "'"); + OString aName = ReadIdentifier(); + for( const auto& aType : rBase.GetTypeList() ) + { + if( aType->GetName().equals(aName) ) + { + return aType; + } + } + throw SvParseException( rInStm, "wrong typedef: "); } + void SvIdlParser::ReadDelimiter() { if( !rInStm.ReadIfDelimiter() ) @@ -346,6 +367,12 @@ OString SvIdlParser::ReadString() return rTok.GetString(); } +void SvIdlParser::ReadChar(char cChar) +{ + if( !rInStm.ReadIf( cChar ) ) + throw SvParseException(rInStm, "expected char '" + OString(cChar) + "'"); +} + void SvIdlParser::ReadToken(SvStringHashEntry* entry) { if( !rInStm.GetToken().Is(entry) ) commit ac432839329866659e339b582d31a1980c035c2e Author: Noel Grandin <[email protected]> Date: Fri Feb 12 13:09:24 2016 +0200 move item and struct parsing into SvIdlParser Change-Id: I1ba88bca82b5b251ed34330ab5e0cb8bd88a5815 diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index 9284096..8418d0b 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -26,6 +26,8 @@ class SvTokenStream; class SvIdlDataBase; class SvMetaModule; class SvMetaTypeEnum; +class SvStringHashEntry; +class SvMetaType; class SvIdlParser { @@ -38,12 +40,16 @@ public: bool ReadModuleBody(SvMetaModule& rModule); void ReadModuleElement( SvMetaModule& rModule ); void ReadInclude( SvMetaModule& rModule ); + void ReadItem(); + void ReadStruct(); void ReadEnum(); void ReadEnumValue( SvMetaTypeEnum& rEnum ); + SvMetaType* ReadKnownType(); void ReadChar(char cChar); void ReadDelimiter(); OString ReadIdentifier(); OString ReadString(); + void ReadToken(SvStringHashEntry*); }; #endif // INCLUDED_IDL_INC_PARSER_HXX diff --git a/idl/inc/types.hxx b/idl/inc/types.hxx index 47c5672..3be88e1b 100644 --- a/idl/inc/types.hxx +++ b/idl/inc/types.hxx @@ -30,13 +30,12 @@ typedef SvRefMemberList< SvMetaSlot* > SvSlotElementList; class SvMetaAttribute : public SvMetaReference { - tools::SvRef<SvMetaType> aType; - SvIdentifier aSlotId; - protected: virtual void ReadAttributesSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) override; public: + tools::SvRef<SvMetaType> aType; + SvIdentifier aSlotId; SvMetaAttribute(); SvMetaAttribute( SvMetaType * ); @@ -81,6 +80,7 @@ public: MetaTypeType GetMetaTypeType() const { return nType; } SvMetaType * GetBaseType() const; SvMetaType * GetReturnType() const; + void SetItem(bool b) { bIsItem = b; } bool IsItem() const { return bIsItem; } virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; @@ -101,8 +101,6 @@ class SvMetaEnumValue : public SvMetaObject { public: SvMetaEnumValue(); - - virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; }; class SvMetaTypeEnum : public SvMetaType diff --git a/idl/source/objects/types.cxx b/idl/source/objects/types.cxx index c5c799d..1317410 100644 --- a/idl/source/objects/types.cxx +++ b/idl/source/objects/types.cxx @@ -74,7 +74,7 @@ bool SvMetaAttribute::ReadSvIdl( SvIdlDataBase & rBase, bOk = true; SvToken& rTok = rInStm.GetToken(); - if( bOk && rTok.IsChar() && rTok.GetChar() == '(' ) + if( rTok.IsChar() && rTok.GetChar() == '(' ) { tools::SvRef<SvMetaType> xT(new SvMetaType() ); xT->SetRef( GetType() ); @@ -164,7 +164,7 @@ SvMetaType * SvMetaType::GetReturnType() const return static_cast<SvMetaType *>(GetRef()); } -bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase, +bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & , SvTokenStream & rInStm ) { bool bOk = false; @@ -181,26 +181,6 @@ bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase, SetType( MetaTypeType::Shell ); bOk = ReadNamesSvIdl( rInStm ); } - else if( rTok.Is( SvHash_struct() ) ) - { - SetType( MetaTypeType::Struct ); - bOk = ReadNamesSvIdl( rInStm ); - } - else if( rTok.Is( SvHash_enum() ) ) - { - SetType( MetaTypeType::Enum ); - bOk = ReadNameSvIdl( rInStm ); - } - else if( rTok.Is( SvHash_item() ) ) - { - bIsItem = true; - - SvMetaType * pType = rBase.ReadKnownType( rInStm ); - if( !pType ) - throw SvParseException( rInStm, "wrong typedef: "); - SetRef( pType ); - bOk = ReadNameSvIdl( rInStm ); - } if( !bOk ) rInStm.Seek( nTokPos ); return bOk; @@ -344,12 +324,6 @@ SvMetaEnumValue::SvMetaEnumValue() { } -bool SvMetaEnumValue::ReadSvIdl( SvIdlDataBase & , - SvTokenStream & rInStm ) -{ - return ReadNameSvIdl( rInStm ); -} - SvMetaTypeEnum::SvMetaTypeEnum() { } diff --git a/idl/source/prj/database.cxx b/idl/source/prj/database.cxx index 96c4e3a..00f2ab1 100644 --- a/idl/source/prj/database.cxx +++ b/idl/source/prj/database.cxx @@ -274,34 +274,15 @@ SvMetaType * SvIdlDataBase::ReadKnownType( SvTokenStream & rInStm ) sal_uInt32 nTokPos = rInStm.Tell(); SvToken& rTok = rInStm.GetToken_Next(); - if( rTok.HasHash() ) - { - sal_uInt32 nBeginPos = 0; // can not happen with Tell - while( nBeginPos != rInStm.Tell() ) - { - nBeginPos = rInStm.Tell(); - } - } - if( rTok.IsIdentifier() ) { OString aName = rTok.GetString(); - SvRefMemberList<SvMetaType *> & rList = GetTypeList(); - SvRefMemberList<SvMetaType *>::const_iterator it = rList.begin(); - SvMetaType * pType = nullptr; - while( it != rList.end() ) + for( const auto& aType : GetTypeList() ) { - if( (*it)->GetName().equals(aName) ) + if( aType->GetName().equals(aName) ) { - pType = *it; - break; + return aType; } - ++it; - } - if( pType ) - { - // is exactly this type - return pType; } } rInStm.Seek( nTokPos ); diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index 3f8f09d..f2bc458 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -133,16 +133,13 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) { ReadEnum(); } - else if( rInStm.GetToken().Is( SvHash_item() ) - || rInStm.GetToken().Is( SvHash_struct() ) ) + else if( rInStm.GetToken().Is( SvHash_item() ) ) { - tools::SvRef<SvMetaType> xItem(new SvMetaType() ); - - if( xItem->ReadSvIdl( rBase, rInStm ) ) - { - // announce globally - rBase.GetTypeList().push_back( xItem ); - } + ReadItem(); + } + else if( rInStm.GetToken().Is( SvHash_struct() ) ) + { + ReadStruct(); } else if( rInStm.GetToken().Is( SvHash_include() ) ) { @@ -215,10 +212,66 @@ void SvIdlParser::ReadInclude( SvMetaModule& rModule ) rInStm.Seek( nTokPos ); } +void SvIdlParser::ReadStruct() +{ + ReadToken( SvHash_struct() ); + rInStm.GetToken_Next(); + tools::SvRef<SvMetaType> xStruct(new SvMetaType() ); + xStruct->SetType( MetaTypeType::Struct ); + xStruct->SetName( ReadIdentifier() ); + ReadChar( '{' ); + sal_uInt32 nBeginPos = 0; // can not happen with Tell + while( nBeginPos != rInStm.Tell() ) + { + nBeginPos = rInStm.Tell(); + tools::SvRef<SvMetaAttribute> xAttr( new SvMetaAttribute() ); + xAttr->aType = ReadKnownType(); + xAttr->SetName(ReadIdentifier()); + xAttr->aSlotId.setString(ReadIdentifier()); + sal_uLong n; + if( !rBase.FindId( xAttr->aSlotId.getString(), &n ) ) + throw SvParseException( rInStm, "no value for identifier <" + xAttr->aSlotId.getString() + "> " ); + xAttr->aSlotId.SetValue(n); + xStruct->GetAttrList().push_back( xAttr ); + rInStm.ReadIfDelimiter(); + if ( rInStm.GetToken().IsChar() && rInStm.GetToken().GetChar() == '}') + break; + } + ReadChar( '}' ); + // announce globally + rBase.GetTypeList().push_back( xStruct ); +} + +void SvIdlParser::ReadItem() +{ + ReadToken( SvHash_item() ); + rInStm.GetToken_Next(); + tools::SvRef<SvMetaType> xItem(new SvMetaType() ); + xItem->SetItem(true); + xItem->SetRef( ReadKnownType() ); + xItem->SetName( ReadIdentifier() ); + // announce globally + rBase.GetTypeList().push_back( xItem ); +} + +SvMetaType * SvIdlParser::ReadKnownType() +{ + OString aName = ReadIdentifier(); + for( const auto& aType : rBase.GetTypeList() ) + { + if( aType->GetName().equals(aName) ) + { + return aType; + } + } + throw SvParseException( rInStm, "wrong typedef: "); +} + + void SvIdlParser::ReadEnum() { - tools::SvRef<SvMetaTypeEnum> xEnum( new SvMetaTypeEnum() ); rInStm.GetToken_Next(); + tools::SvRef<SvMetaTypeEnum> xEnum( new SvMetaTypeEnum() ); xEnum->SetType( MetaTypeType::Enum ); xEnum->SetName( ReadIdentifier() ); @@ -249,25 +302,18 @@ static OString getCommonSubPrefix(const OString &rA, const OString &rB) void SvIdlParser::ReadEnumValue( SvMetaTypeEnum& rEnum ) { - sal_uInt32 nTokPos = rInStm.Tell(); - tools::SvRef<SvMetaEnumValue> aEnumVal = new SvMetaEnumValue(); - bool bOk = aEnumVal->ReadSvIdl( rBase, rInStm ); - if( bOk ) + aEnumVal->SetName( ReadIdentifier() ); + if( rEnum.aEnumValueList.empty() ) { - if( rEnum.aEnumValueList.empty() ) - { - // the first - rEnum.aPrefix = aEnumVal->GetName(); - } - else - { - rEnum.aPrefix = getCommonSubPrefix(rEnum.aPrefix, aEnumVal->GetName()); - } - rEnum.aEnumValueList.push_back( aEnumVal ); + // the first + rEnum.aPrefix = aEnumVal->GetName(); } - if( !bOk ) - rInStm.Seek( nTokPos ); + else + { + rEnum.aPrefix = getCommonSubPrefix(rEnum.aPrefix, aEnumVal->GetName()); + } + rEnum.aEnumValueList.push_back( aEnumVal ); } @@ -300,4 +346,10 @@ OString SvIdlParser::ReadString() return rTok.GetString(); } +void SvIdlParser::ReadToken(SvStringHashEntry* entry) +{ + if( !rInStm.GetToken().Is(entry) ) + throw SvParseException("expected " + entry->GetName(), rInStm.GetToken()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit d4a10f00c96c2fc4be2755873f6b26e72a996ca6 Author: Noel Grandin <[email protected]> Date: Fri Feb 12 10:41:48 2016 +0200 move include parsing into own method Change-Id: Id3ce7ce651f541106cf60116f717e6ffd805db24 diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index 67f63e3..9284096 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -37,11 +37,13 @@ public: bool ReadModuleHeader(SvMetaModule& rModule); bool ReadModuleBody(SvMetaModule& rModule); void ReadModuleElement( SvMetaModule& rModule ); - void ReadEnum(SvMetaTypeEnum& rEnum); + void ReadInclude( SvMetaModule& rModule ); + void ReadEnum(); void ReadEnumValue( SvMetaTypeEnum& rEnum ); void ReadChar(char cChar); void ReadDelimiter(); OString ReadIdentifier(); + OString ReadString(); }; #endif // INCLUDED_IDL_INC_PARSER_HXX diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index 2593c290..3f8f09d 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -118,7 +118,6 @@ bool SvIdlParser::ReadModuleBody(SvMetaModule& rModule) void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) { - sal_uInt32 nTokPos = rInStm.Tell(); if( rInStm.GetToken().Is( SvHash_interface() ) || rInStm.GetToken().Is( SvHash_shell() ) ) { @@ -132,11 +131,7 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) } else if( rInStm.GetToken().Is( SvHash_enum() ) ) { - tools::SvRef<SvMetaTypeEnum> aEnum( new SvMetaTypeEnum() ); - - ReadEnum(*aEnum); - // announce globally - rBase.GetTypeList().push_back( aEnum ); + ReadEnum(); } else if( rInStm.GetToken().Is( SvHash_item() ) || rInStm.GetToken().Is( SvHash_struct() ) ) @@ -151,58 +146,7 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) } else if( rInStm.GetToken().Is( SvHash_include() ) ) { - bool bOk = false; - rInStm.GetToken_Next(); - SvToken& rTok = rInStm.GetToken_Next(); - if( rTok.IsString() ) - { - 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( SVSTREAM_OK != aTokStm.GetStream().GetError() ) - { - OStringBuffer aStr("cannot open file: "); - aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8)); - throw SvParseException(aStr.makeStringAndClear(), rTok); - } - // rescue error from old file - SvIdlError aOldErr = rBase.GetError(); - // reset error - rBase.SetError( SvIdlError() ); - - try { - SvIdlParser aIncludeParser( rBase, aTokStm ); - sal_uInt32 nBeginPos = 0xFFFFFFFF; // can not happen with Tell - while( nBeginPos != aTokStm.Tell() ) - { - nBeginPos = aTokStm.Tell(); - aIncludeParser.ReadModuleElement(rModule); - aTokStm.ReadIfDelimiter(); - } - } catch (const SvParseException& ex) { - rBase.SetError(ex.aError); - rBase.WriteError(aTokStm); - } - bOk = aTokStm.GetToken().IsEof(); - if( !bOk ) - { - rBase.WriteError( aTokStm ); - } - // recover error from old file - rBase.SetError( aOldErr ); - } - if( !bOk ) - rInStm.Seek( nTokPos ); + ReadInclude(rModule); } else { @@ -219,39 +163,90 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) } } -void SvIdlParser::ReadEnum(SvMetaTypeEnum& rEnum) +void SvIdlParser::ReadInclude( SvMetaModule& rModule ) +{ + sal_uInt32 nTokPos = rInStm.Tell(); + bool bOk = false; + rInStm.GetToken_Next(); + OUString aFullName(OStringToOUString(ReadString(), 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(), rInStm.GetToken()); + } + osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName ); + rBase.AddDepFile( aFullName ); + SvTokenStream aTokStm( aFullName ); + if( SVSTREAM_OK != aTokStm.GetStream().GetError() ) + { + OStringBuffer aStr("cannot open file: "); + aStr.append(OUStringToOString(aFullName, RTL_TEXTENCODING_UTF8)); + throw SvParseException(aStr.makeStringAndClear(), rInStm.GetToken()); + } + // rescue error from old file + SvIdlError aOldErr = rBase.GetError(); + // reset error + rBase.SetError( SvIdlError() ); + + try { + SvIdlParser aIncludeParser( rBase, aTokStm ); + sal_uInt32 nBeginPos = 0xFFFFFFFF; // can not happen with Tell + while( nBeginPos != aTokStm.Tell() ) + { + nBeginPos = aTokStm.Tell(); + aIncludeParser.ReadModuleElement(rModule); + aTokStm.ReadIfDelimiter(); + } + } catch (const SvParseException& ex) { + rBase.SetError(ex.aError); + rBase.WriteError(aTokStm); + } + bOk = aTokStm.GetToken().IsEof(); + if( !bOk ) + { + rBase.WriteError( aTokStm ); + } + // recover error from old file + rBase.SetError( aOldErr ); + if( !bOk ) + rInStm.Seek( nTokPos ); +} + +void SvIdlParser::ReadEnum() { + tools::SvRef<SvMetaTypeEnum> xEnum( new SvMetaTypeEnum() ); rInStm.GetToken_Next(); - rEnum.SetType( MetaTypeType::Enum ); - rEnum.SetName( ReadIdentifier() ); + xEnum->SetType( MetaTypeType::Enum ); + xEnum->SetName( ReadIdentifier() ); ReadChar('{'); while( true ) { - ReadEnumValue( rEnum ); + ReadEnumValue( *xEnum ); if( !rInStm.ReadIfDelimiter() ) break; } ReadChar( '}' ); + // announce globally + rBase.GetTypeList().push_back( xEnum ); } -namespace +static OString getCommonSubPrefix(const OString &rA, const OString &rB) { - OString getCommonSubPrefix(const OString &rA, const OString &rB) + sal_Int32 nMax = std::min(rA.getLength(), rB.getLength()); + sal_Int32 nI = 0; + while (nI < nMax) { - sal_Int32 nMax = std::min(rA.getLength(), rB.getLength()); - sal_Int32 nI = 0; - while (nI < nMax) - { - if (rA[nI] != rB[nI]) - break; - ++nI; - } - return rA.copy(0, nI); + if (rA[nI] != rB[nI]) + break; + ++nI; } + return rA.copy(0, nI); } - void SvIdlParser::ReadEnumValue( SvMetaTypeEnum& rEnum ) { sal_uInt32 nTokPos = rInStm.Tell(); @@ -296,4 +291,13 @@ OString SvIdlParser::ReadIdentifier() throw SvParseException("expected identifier", rTok); return rTok.GetString(); } + +OString SvIdlParser::ReadString() +{ + SvToken& rTok = rInStm.GetToken_Next(); + if( !rTok.IsString() ) + throw SvParseException("expected string", rTok); + return rTok.GetString(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
