idl/inc/lex.hxx | 6 idl/inc/module.hxx | 15 -- idl/inc/parser.hxx | 11 + idl/inc/types.hxx | 6 idl/source/objects/basobj.cxx | 12 - idl/source/objects/bastype.cxx | 18 +- idl/source/objects/module.cxx | 140 --------------------- idl/source/objects/object.cxx | 2 idl/source/objects/slot.cxx | 2 idl/source/objects/types.cxx | 58 --------- idl/source/prj/command.cxx | 2 idl/source/prj/parser.cxx | 264 +++++++++++++++++++++++++++++++++++++---- 12 files changed, 278 insertions(+), 258 deletions(-)
New commits: commit b27dcabad349b68d2068dfe68924a5b0867f5ee9 Author: Noel Grandin <[email protected]> Date: Fri Feb 12 08:58:26 2016 +0200 move parsing of enum into SvIdlParser Change-Id: I89eef20d62f92f7345750c48c34c9f3b7bca287e diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx index a9869de..7780a36 100644 --- a/idl/inc/lex.hxx +++ b/idl/inc/lex.hxx @@ -198,14 +198,16 @@ public: return false; } - void ReadIfDelimiter() + bool ReadIfDelimiter() { if( (*pCurToken)->IsChar() && (';' == (*pCurToken)->GetChar() || ',' == (*pCurToken)->GetChar()) ) { GetToken_Next(); + return true; } + return false; } sal_uInt32 Tell() const { return pCurToken-aTokList.begin(); } diff --git a/idl/inc/module.hxx b/idl/inc/module.hxx index 6ac8fcd..93f335a 100644 --- a/idl/inc/module.hxx +++ b/idl/inc/module.hxx @@ -23,7 +23,7 @@ #include <slot.hxx> #include <object.hxx> -class SvMetaModule : public SvMetaReference +class SvMetaModule : public SvMetaObject { bool bImported; public: diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index b1f9a67..67f63e3 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -25,6 +25,7 @@ class SvTokenStream; class SvIdlDataBase; class SvMetaModule; +class SvMetaTypeEnum; class SvIdlParser { @@ -36,6 +37,11 @@ public: bool ReadModuleHeader(SvMetaModule& rModule); bool ReadModuleBody(SvMetaModule& rModule); void ReadModuleElement( SvMetaModule& rModule ); + void ReadEnum(SvMetaTypeEnum& rEnum); + void ReadEnumValue( SvMetaTypeEnum& rEnum ); + void ReadChar(char cChar); + void ReadDelimiter(); + OString ReadIdentifier(); }; #endif // INCLUDED_IDL_INC_PARSER_HXX diff --git a/idl/inc/types.hxx b/idl/inc/types.hxx index 748dc6e..47c5672 100644 --- a/idl/inc/types.hxx +++ b/idl/inc/types.hxx @@ -107,19 +107,15 @@ public: class SvMetaTypeEnum : public SvMetaType { +public: SvRefMemberList<SvMetaEnumValue *> aEnumValueList; OString aPrefix; -protected: - virtual void ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; -public: SvMetaTypeEnum(); sal_uLong Count() const { return aEnumValueList.size(); } const OString& GetPrefix() const { return aPrefix; } SvMetaEnumValue * GetObject( sal_uLong n ) const { return aEnumValueList[n]; } - - virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; }; class SvMetaTypevoid : public SvMetaType diff --git a/idl/source/objects/types.cxx b/idl/source/objects/types.cxx index d63e8c7..c5c799d 100644 --- a/idl/source/objects/types.cxx +++ b/idl/source/objects/types.cxx @@ -354,60 +354,6 @@ SvMetaTypeEnum::SvMetaTypeEnum() { } -namespace -{ - OString getCommonSubPrefix(const OString &rA, const OString &rB) - { - 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); - } -} - -void SvMetaTypeEnum::ReadContextSvIdl( SvIdlDataBase & rBase, - SvTokenStream & rInStm ) -{ - sal_uInt32 nTokPos = rInStm.Tell(); - - tools::SvRef<SvMetaEnumValue> aEnumVal = new SvMetaEnumValue(); - bool bOk = aEnumVal->ReadSvIdl( rBase, rInStm ); - if( bOk ) - { - if( aEnumValueList.empty() ) - { - // the first - aPrefix = aEnumVal->GetName(); - } - else - { - aPrefix = getCommonSubPrefix(aPrefix, aEnumVal->GetName()); - } - aEnumValueList.push_back( aEnumVal ); - } - if( !bOk ) - rInStm.Seek( nTokPos ); -} - -bool SvMetaTypeEnum::ReadSvIdl( SvIdlDataBase & rBase, - SvTokenStream & rInStm ) -{ - sal_uInt32 nTokPos = rInStm.Tell(); - if( SvMetaType::ReadHeaderSvIdl( rBase, rInStm ) - && GetMetaTypeType() == MetaTypeType::Enum ) - { - if( SvMetaObject::ReadSvIdl( rBase, rInStm ) ) - return true; - } - rInStm.Seek( nTokPos ); - return false; -} - SvMetaTypevoid::SvMetaTypevoid() : SvMetaType( "void" ) { diff --git a/idl/source/prj/command.cxx b/idl/source/prj/command.cxx index 2095ad2..3b44679 100644 --- a/idl/source/prj/command.cxx +++ b/idl/source/prj/command.cxx @@ -131,7 +131,7 @@ bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand ) } catch (const SvParseException& ex) { pDataBase->SetError(ex.aError); pDataBase->WriteError(aTokStm); - return false; + return false; } } return true; diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index 99a14bc..33096e5 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -83,40 +83,31 @@ bool SvIdlParser::ReadModuleBody(SvMetaModule& rModule) bool bOk = true; if( rInStm.ReadIf( '[' ) ) { - sal_uInt32 nBeginPos = 0; // can not happen with Tell - while( nBeginPos != rInStm.Tell() ) + while( true ) { - nBeginPos = rInStm.Tell(); OString aSlotIdFile; - if( ReadStringSvIdl( SvHash_SlotIdFile(), rInStm, aSlotIdFile ) ) + if( !ReadStringSvIdl( SvHash_SlotIdFile(), rInStm, aSlotIdFile ) ) + break; + if( !rBase.ReadIdFile( OStringToOUString(aSlotIdFile, RTL_TEXTENCODING_ASCII_US)) ) { - if( !rBase.ReadIdFile( OStringToOUString(aSlotIdFile, RTL_TEXTENCODING_ASCII_US)) ) - { - throw SvParseException( rInStm, "cannot read file: " + aSlotIdFile ); - } + throw SvParseException( rInStm, "cannot read file: " + aSlotIdFile ); } rInStm.ReadIfDelimiter(); } - bOk = rInStm.ReadIf( ']' ); - } - - if( !bOk ) - { - rInStm.Seek( nTokPos ); - return bOk; + ReadChar( ']' ); } if( !rInStm.ReadIf( '{' ) ) return bOk; - sal_uInt32 nBeginPos = 0; // can not happen with Tell + sal_uInt32 nBeginPos = 0; while( nBeginPos != rInStm.Tell() ) { nBeginPos = rInStm.Tell(); ReadModuleElement( rModule ); rInStm.ReadIfDelimiter(); } - bOk = rInStm.ReadIf( '}' ); + ReadChar( '}' ); if( !bOk ) rInStm.Seek( nTokPos ); @@ -141,11 +132,9 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) { tools::SvRef<SvMetaTypeEnum> aEnum( new SvMetaTypeEnum() ); - if( aEnum->ReadSvIdl( rBase, rInStm ) ) - { - // announce globally - rBase.GetTypeList().push_back( aEnum ); - } + ReadEnum(*aEnum); + // announce globally + rBase.GetTypeList().push_back( aEnum ); } else if( rInStm.GetToken().Is( SvHash_item() ) || rInStm.GetToken().Is( SvHash_struct() ) ) @@ -189,13 +178,18 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) // reset error rBase.SetError( SvIdlError() ); - 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(); + 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 ) @@ -223,6 +217,81 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) } } +void SvIdlParser::ReadEnum(SvMetaTypeEnum& rEnum) +{ + rInStm.GetToken_Next(); + rEnum.SetType( MetaTypeType::Enum ); + rEnum.SetName( ReadIdentifier() ); + + ReadChar('{'); + while( true ) + { + ReadEnumValue( rEnum ); + if( !rInStm.ReadIfDelimiter() ) + break; + } + ReadChar( '}' ); +} + +namespace +{ + OString getCommonSubPrefix(const OString &rA, const OString &rB) + { + 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); + } +} +void SvIdlParser::ReadEnumValue( SvMetaTypeEnum& rEnum ) +{ + sal_uInt32 nTokPos = rInStm.Tell(); + + tools::SvRef<SvMetaEnumValue> aEnumVal = new SvMetaEnumValue(); + bool bOk = aEnumVal->ReadSvIdl( rBase, rInStm ); + if( bOk ) + { + if( rEnum.aEnumValueList.empty() ) + { + // the first + rEnum.aPrefix = aEnumVal->GetName(); + } + else + { + rEnum.aPrefix = getCommonSubPrefix(rEnum.aPrefix, aEnumVal->GetName()); + } + rEnum.aEnumValueList.push_back( aEnumVal ); + } + if( !bOk ) + rInStm.Seek( nTokPos ); +} + + + +void SvIdlParser::ReadChar(char cChar) +{ + if( !rInStm.ReadIf( cChar ) ) + throw SvParseException(rInStm, "expected char '" + OString(cChar) + "'"); +} + +void SvIdlParser::ReadDelimiter() +{ + if( !rInStm.ReadIfDelimiter() ) + throw SvParseException(rInStm, "expected delimiter"); +} + +OString SvIdlParser::ReadIdentifier() +{ + SvToken& rTok = rInStm.GetToken_Next(); + if( !rTok.IsIdentifier() ) + throw SvParseException("expected identifier", rTok); + return rTok.GetString(); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit f3f533f0c60d90fb723ecf417ce3a20bc38fa6c7 Author: Noel Grandin <[email protected]> Date: Thu Feb 11 15:41:48 2016 +0200 move module parsing into SvIdlParser class Change-Id: I99937935a1d41fa5b0ff6c2f5e92bde3b4847e9f diff --git a/idl/inc/module.hxx b/idl/inc/module.hxx index ce5f8db..6ac8fcd 100644 --- a/idl/inc/module.hxx +++ b/idl/inc/module.hxx @@ -25,22 +25,14 @@ class SvMetaModule : public SvMetaReference { - SvRefMemberList<SvMetaClass *> aClassList; -// browser - OString aSlotIdFile; - - bool bImported : 1; -protected: - virtual void ReadAttributesSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; - virtual void ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; + bool bImported; public: + SvRefMemberList<SvMetaClass *> aClassList; SvMetaModule( bool bImported ); bool IsImported() const { return bImported; } - virtual bool ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; - void WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm ); }; diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index 97cb3d5..b1f9a67 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -24,6 +24,7 @@ class SvTokenStream; class SvIdlDataBase; +class SvMetaModule; class SvIdlParser { @@ -32,8 +33,9 @@ class SvIdlParser public: SvIdlParser( SvIdlDataBase& rBase_, SvTokenStream & rInStrm_) : rBase(rBase_), rInStm(rInStrm_) {} bool ReadSvIdl( bool bImported, const OUString & rPath ); - bool ReadModuleImport(const OUString & rPath); - + bool ReadModuleHeader(SvMetaModule& rModule); + bool ReadModuleBody(SvMetaModule& rModule); + void ReadModuleElement( SvMetaModule& rModule ); }; #endif // INCLUDED_IDL_INC_PARSER_HXX diff --git a/idl/source/objects/module.cxx b/idl/source/objects/module.cxx index b364ddf..11b31cb 100644 --- a/idl/source/objects/module.cxx +++ b/idl/source/objects/module.cxx @@ -33,142 +33,6 @@ SvMetaModule::SvMetaModule( bool bImp ) { } -void SvMetaModule::ReadAttributesSvIdl( SvIdlDataBase & rBase, - SvTokenStream & rInStm ) -{ - SvMetaReference::ReadAttributesSvIdl( rBase, rInStm ); - - if( ReadStringSvIdl( SvHash_SlotIdFile(), rInStm, aSlotIdFile ) ) - { - if( !rBase.ReadIdFile( OStringToOUString(aSlotIdFile, RTL_TEXTENCODING_ASCII_US)) ) - { - throw SvParseException( rInStm, "cannot read file: " + aSlotIdFile ); - } - } -} - -void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase, - SvTokenStream & rInStm ) -{ - sal_uInt32 nTokPos = rInStm.Tell(); - if( rInStm.GetToken().Is( SvHash_interface() ) - || rInStm.GetToken().Is( SvHash_shell() ) ) - { - tools::SvRef<SvMetaClass> aClass( new SvMetaClass() ); - if( aClass->ReadSvIdl( rBase, rInStm ) ) - { - aClassList.push_back( aClass ); - // announce globally - rBase.GetClassList().push_back( aClass ); - } - } - else if( rInStm.GetToken().Is( SvHash_enum() ) ) - { - tools::SvRef<SvMetaTypeEnum> aEnum( new SvMetaTypeEnum() ); - - if( aEnum->ReadSvIdl( rBase, rInStm ) ) - { - // announce globally - rBase.GetTypeList().push_back( aEnum ); - } - } - else if( rInStm.GetToken().Is( SvHash_item() ) - || rInStm.GetToken().Is( SvHash_struct() ) ) - { - tools::SvRef<SvMetaType> xItem(new SvMetaType() ); - - if( xItem->ReadSvIdl( rBase, rInStm ) ) - { - // announce globally - rBase.GetTypeList().push_back( xItem ); - } - } - 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() ); - - sal_uInt32 nBeginPos = 0xFFFFFFFF; // can not happen with Tell - while( nBeginPos != aTokStm.Tell() ) - { - nBeginPos = aTokStm.Tell(); - ReadContextSvIdl( rBase, aTokStm ); - aTokStm.ReadIfDelimiter(); - } - bOk = aTokStm.GetToken().IsEof(); - if( !bOk ) - { - rBase.WriteError( aTokStm ); - } - // recover error from old file - rBase.SetError( aOldErr ); - } - if( !bOk ) - rInStm.Seek( nTokPos ); - } - else - { - tools::SvRef<SvMetaSlot> xSlot( new SvMetaSlot() ); - - if( xSlot->ReadSvIdl( rBase, rInStm ) ) - { - if( xSlot->Test( rInStm ) ) - { - // announce globally - rBase.AppendSlot( xSlot ); - } - } - } -} - -bool SvMetaModule::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) -{ - sal_uInt32 nTokPos = rInStm.Tell(); - SvToken& rTok = rInStm.GetToken_Next(); - bool bOk = rTok.Is( SvHash_module() ); - rInStm.ReadIfDelimiter(); - if( bOk ) - { - rBase.Push( this ); // onto the context stack - - if( ReadNameSvIdl( rInStm ) ) - { - // set pointer to itself - bOk = SvMetaObject::ReadSvIdl( rBase, rInStm ); - } - rBase.GetStack().pop_back(); // remove from stack - } - if( !bOk ) - rInStm.Seek( nTokPos ); - return bOk; -} - void SvMetaModule::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm ) { for( sal_uLong n = 0; n < aClassList.size(); n++ ) diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index 065c3e2..99a14bc 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -29,11 +29,6 @@ bool SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath ) rBase.SetPath(rPath); // only valid for this iteration bool bOk = true; SvToken& rTok = rInStm.GetToken(); - // only one import at the very beginning - if( rTok.Is( SvHash_import() ) ) - { - bOk = ReadModuleImport(rPath); - } while( bOk ) { @@ -44,7 +39,7 @@ bool SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath ) if( rTok.Is( SvHash_module() ) ) { tools::SvRef<SvMetaModule> aModule = new SvMetaModule( bImported ); - if( aModule->ReadSvIdl( rBase, rInStm ) ) + if( ReadModuleHeader(*aModule) ) rBase.GetModuleList().push_back( aModule ); else bOk = false; @@ -61,29 +56,173 @@ bool SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath ) return true; } -bool SvIdlParser::ReadModuleImport(const OUString & rPath) +bool SvIdlParser::ReadModuleHeader(SvMetaModule& rModule) { - SvToken& rTok = rInStm.GetToken_Next(); + 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; + } + rBase.Push( &rModule ); // onto the context stack + rModule.SetName( rTok.GetString() ); + bOk = ReadModuleBody(rModule); + rBase.GetStack().pop_back(); // remove from stack + if( !bOk ) + rInStm.Seek( nTokPos ); + return bOk; +} + +bool SvIdlParser::ReadModuleBody(SvMetaModule& rModule) +{ + sal_uInt32 nTokPos = rInStm.Tell(); bool bOk = true; - if( rTok.IsString() ) + if( rInStm.ReadIf( '[' ) ) { - OUString aFullName; - if( osl::FileBase::E_None == osl::File::searchFileURL( - OStringToOUString(rTok.GetString(), RTL_TEXTENCODING_ASCII_US), - rPath, - aFullName) ) + sal_uInt32 nBeginPos = 0; // can not happen with Tell + while( nBeginPos != rInStm.Tell() ) { - osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName ); - rBase.AddDepFile(aFullName); - SvTokenStream aTokStm( aFullName ); - SvIdlParser aInputParser(rBase, aTokStm); - bOk = aInputParser.ReadSvIdl( true, rPath ); + nBeginPos = rInStm.Tell(); + OString aSlotIdFile; + if( ReadStringSvIdl( SvHash_SlotIdFile(), rInStm, aSlotIdFile ) ) + { + if( !rBase.ReadIdFile( OStringToOUString(aSlotIdFile, RTL_TEXTENCODING_ASCII_US)) ) + { + throw SvParseException( rInStm, "cannot read file: " + aSlotIdFile ); + } } - else - bOk = false; + rInStm.ReadIfDelimiter(); } - else - bOk = false; + bOk = rInStm.ReadIf( ']' ); + } + + if( !bOk ) + { + rInStm.Seek( nTokPos ); + return bOk; + } + + if( !rInStm.ReadIf( '{' ) ) + return bOk; + + sal_uInt32 nBeginPos = 0; // can not happen with Tell + while( nBeginPos != rInStm.Tell() ) + { + nBeginPos = rInStm.Tell(); + ReadModuleElement( rModule ); + rInStm.ReadIfDelimiter(); + } + bOk = rInStm.ReadIf( '}' ); + + if( !bOk ) + rInStm.Seek( nTokPos ); return bOk; } + +void SvIdlParser::ReadModuleElement( SvMetaModule& rModule ) +{ + sal_uInt32 nTokPos = rInStm.Tell(); + if( rInStm.GetToken().Is( SvHash_interface() ) + || rInStm.GetToken().Is( SvHash_shell() ) ) + { + tools::SvRef<SvMetaClass> aClass( new SvMetaClass() ); + if( aClass->ReadSvIdl( rBase, rInStm ) ) + { + rModule.aClassList.push_back( aClass ); + // announce globally + rBase.GetClassList().push_back( aClass ); + } + } + else if( rInStm.GetToken().Is( SvHash_enum() ) ) + { + tools::SvRef<SvMetaTypeEnum> aEnum( new SvMetaTypeEnum() ); + + if( aEnum->ReadSvIdl( rBase, rInStm ) ) + { + // announce globally + rBase.GetTypeList().push_back( aEnum ); + } + } + else if( rInStm.GetToken().Is( SvHash_item() ) + || rInStm.GetToken().Is( SvHash_struct() ) ) + { + tools::SvRef<SvMetaType> xItem(new SvMetaType() ); + + if( xItem->ReadSvIdl( rBase, rInStm ) ) + { + // announce globally + rBase.GetTypeList().push_back( xItem ); + } + } + 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() ); + + 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(); + } + bOk = aTokStm.GetToken().IsEof(); + if( !bOk ) + { + rBase.WriteError( aTokStm ); + } + // recover error from old file + rBase.SetError( aOldErr ); + } + if( !bOk ) + rInStm.Seek( nTokPos ); + } + else + { + tools::SvRef<SvMetaSlot> xSlot( new SvMetaSlot() ); + + if( xSlot->ReadSvIdl( rBase, rInStm ) ) + { + if( xSlot->Test( rInStm ) ) + { + // announce globally + rBase.AppendSlot( xSlot ); + } + } + } +} + + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit e60296840bf9da3f61a3cce02e1369e4315354b3 Author: Noel Grandin <[email protected]> Date: Thu Feb 11 15:19:50 2016 +0200 move parsing of "import" into own method Change-Id: Ib3b3fb6fea52b846ada6fb92478ae8f9f769a665 diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index 8a15bb4..97cb3d5 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -32,6 +32,7 @@ class SvIdlParser public: SvIdlParser( SvIdlDataBase& rBase_, SvTokenStream & rInStrm_) : rBase(rBase_), rInStm(rInStrm_) {} bool ReadSvIdl( bool bImported, const OUString & rPath ); + bool ReadModuleImport(const OUString & rPath); }; diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index 34820f2..065c3e2 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -32,26 +32,7 @@ bool SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath ) // only one import at the very beginning if( rTok.Is( SvHash_import() ) ) { - rTok = rInStm.GetToken_Next(); - if( rTok.IsString() ) - { - OUString aFullName; - if( osl::FileBase::E_None == osl::File::searchFileURL( - OStringToOUString(rTok.GetString(), RTL_TEXTENCODING_ASCII_US), - rPath, - aFullName) ) - { - osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName ); - rBase.AddDepFile(aFullName); - SvTokenStream aTokStm( aFullName ); - SvIdlParser aInputParser(rBase, aTokStm); - bOk = aInputParser.ReadSvIdl( true, rPath ); - } - else - bOk = false; - } - else - bOk = false; + bOk = ReadModuleImport(rPath); } while( bOk ) @@ -80,4 +61,29 @@ bool SvIdlParser::ReadSvIdl( bool bImported, const OUString & rPath ) return true; } +bool SvIdlParser::ReadModuleImport(const OUString & rPath) +{ + SvToken& rTok = rInStm.GetToken_Next(); + bool bOk = true; + if( rTok.IsString() ) + { + OUString aFullName; + if( osl::FileBase::E_None == osl::File::searchFileURL( + OStringToOUString(rTok.GetString(), RTL_TEXTENCODING_ASCII_US), + rPath, + aFullName) ) + { + osl::FileBase::getSystemPathFromFileURL( aFullName, aFullName ); + rBase.AddDepFile(aFullName); + SvTokenStream aTokStm( aFullName ); + SvIdlParser aInputParser(rBase, aTokStm); + bOk = aInputParser.ReadSvIdl( true, rPath ); + } + else + bOk = false; + } + else + bOk = false; + return bOk; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 62225eeb9832b982023dca6c5ce2bc64ac92728f Author: Noel Grandin <[email protected]> Date: Thu Feb 11 14:50:15 2016 +0200 bIsModified in SvMetaModule is unused Change-Id: Idc6effddce9923f0d48a111b2a04458efc11ebf9 diff --git a/idl/inc/module.hxx b/idl/inc/module.hxx index 8973565..ce5f8db 100644 --- a/idl/inc/module.hxx +++ b/idl/inc/module.hxx @@ -29,8 +29,7 @@ class SvMetaModule : public SvMetaReference // browser OString aSlotIdFile; - bool bImported : 1, - bIsModified : 1; + bool bImported : 1; protected: virtual void ReadAttributesSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; virtual void ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & rInStm ) override; diff --git a/idl/source/objects/module.cxx b/idl/source/objects/module.cxx index 06614ed..b364ddf 100644 --- a/idl/source/objects/module.cxx +++ b/idl/source/objects/module.cxx @@ -29,7 +29,7 @@ SvMetaModule::SvMetaModule( bool bImp ) - : bImported( bImp ), bIsModified( false ) + : bImported( bImp ) { } @@ -149,8 +149,6 @@ void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase, bool SvMetaModule::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) { - bIsModified = true; // up to now always when compiler running - sal_uInt32 nTokPos = rInStm.Tell(); SvToken& rTok = rInStm.GetToken_Next(); bool bOk = rTok.Is( SvHash_module() ); commit 0c6d6aa47ea0a7260b4bc01519e51ef78e97f459 Author: Noel Grandin <[email protected]> Date: Thu Feb 11 14:49:27 2016 +0200 rename Read()->ReadIf() and ReadDelimiter()->ReadIfDelimiter() Change-Id: I589dc0280c5bb587aa024b0f1dcf0b623d719aa4 diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx index bc0feea..a9869de 100644 --- a/idl/inc/lex.hxx +++ b/idl/inc/lex.hxx @@ -186,7 +186,7 @@ public: SvToken& GetToken() const { return *(*pCurToken).get(); } - bool Read( char cChar ) + bool ReadIf( char cChar ) { if( (*pCurToken)->IsChar() && cChar == (*pCurToken)->GetChar() ) @@ -198,7 +198,7 @@ public: return false; } - void ReadDelimiter() + void ReadIfDelimiter() { if( (*pCurToken)->IsChar() && (';' == (*pCurToken)->GetChar() diff --git a/idl/source/objects/basobj.cxx b/idl/source/objects/basobj.cxx index 62632a7..835ae2d 100644 --- a/idl/source/objects/basobj.cxx +++ b/idl/source/objects/basobj.cxx @@ -100,7 +100,7 @@ void SvMetaObject::DoReadContextSvIdl( SvIdlDataBase & rBase, { nBeginPos = rInStm.Tell(); ReadContextSvIdl( rBase, rInStm ); - rInStm.ReadDelimiter(); + rInStm.ReadIfDelimiter(); } } @@ -117,24 +117,24 @@ bool SvMetaObject::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) { sal_uInt32 nTokPos = rInStm.Tell(); bool bOk = true; - if( rInStm.Read( '[' ) ) + if( rInStm.ReadIf( '[' ) ) { sal_uInt32 nBeginPos = 0; // can not happen with Tell while( nBeginPos != rInStm.Tell() ) { nBeginPos = rInStm.Tell(); ReadAttributesSvIdl( rBase, rInStm ); - rInStm.ReadDelimiter(); + rInStm.ReadIfDelimiter(); } - bOk = rInStm.Read( ']' ); + bOk = rInStm.ReadIf( ']' ); } if( bOk ) { - if( rInStm.Read( '{' ) ) + if( rInStm.ReadIf( '{' ) ) { DoReadContextSvIdl( rBase, rInStm ); - bOk = rInStm.Read( '}' ); + bOk = rInStm.ReadIf( '}' ); } } diff --git a/idl/source/objects/bastype.cxx b/idl/source/objects/bastype.cxx index d200f68..08c59f9 100644 --- a/idl/source/objects/bastype.cxx +++ b/idl/source/objects/bastype.cxx @@ -36,8 +36,8 @@ bool SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm ) if( rTok.Is( pName ) ) { bool bOk = true; - bool bBracket = rInStm.Read( '(' ); - if( bBracket || rInStm.Read( '=' ) ) + bool bBracket = rInStm.ReadIf( '(' ); + if( bBracket || rInStm.ReadIf( '=' ) ) { rTok = rInStm.GetToken(); if( rTok.IsBool() ) @@ -47,7 +47,7 @@ bool SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm ) rInStm.GetToken_Next(); } if( bOk && bBracket ) - bOk = rInStm.Read( ')' ); + bOk = rInStm.ReadIf( ')' ); } else *this = true; //default action set to TRUE @@ -66,8 +66,8 @@ bool SvIdentifier::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm if( rTok.Is( pName ) ) { bool bOk = true; - bool bBracket = rInStm.Read( '(' ); - if( bBracket || rInStm.Read( '=' ) ) + bool bBracket = rInStm.ReadIf( '(' ); + if( bBracket || rInStm.ReadIf( '=' ) ) { rTok = rInStm.GetToken(); if( rTok.IsIdentifier() ) @@ -76,7 +76,7 @@ bool SvIdentifier::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm rInStm.GetToken_Next(); } if( bOk && bBracket ) - bOk = rInStm.Read( ')' ); + bOk = rInStm.ReadIf( ')' ); } if( bOk ) return true; @@ -111,8 +111,8 @@ bool ReadStringSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm, OString if( rTok.Is( pName ) ) { bool bOk = true; - bool bBracket = rInStm.Read( '(' ); - if( bBracket || rInStm.Read( '=' ) ) + bool bBracket = rInStm.ReadIf( '(' ); + if( bBracket || rInStm.ReadIf( '=' ) ) { rTok = rInStm.GetToken(); if( rTok.IsString() ) @@ -121,7 +121,7 @@ bool ReadStringSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm, OString rInStm.GetToken_Next(); } if( bOk && bBracket ) - bOk = rInStm.Read( ')' ); + bOk = rInStm.ReadIf( ')' ); } if( bOk ) return true; diff --git a/idl/source/objects/module.cxx b/idl/source/objects/module.cxx index 2062f05..06614ed 100644 --- a/idl/source/objects/module.cxx +++ b/idl/source/objects/module.cxx @@ -119,7 +119,7 @@ void SvMetaModule::ReadContextSvIdl( SvIdlDataBase & rBase, { nBeginPos = aTokStm.Tell(); ReadContextSvIdl( rBase, aTokStm ); - aTokStm.ReadDelimiter(); + aTokStm.ReadIfDelimiter(); } bOk = aTokStm.GetToken().IsEof(); if( !bOk ) @@ -154,7 +154,7 @@ bool SvMetaModule::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) sal_uInt32 nTokPos = rInStm.Tell(); SvToken& rTok = rInStm.GetToken_Next(); bool bOk = rTok.Is( SvHash_module() ); - rInStm.ReadDelimiter(); + rInStm.ReadIfDelimiter(); if( bOk ) { rBase.Push( this ); // onto the context stack diff --git a/idl/source/objects/object.cxx b/idl/source/objects/object.cxx index 396eeda..c5c3589 100644 --- a/idl/source/objects/object.cxx +++ b/idl/source/objects/object.cxx @@ -106,7 +106,7 @@ bool SvMetaClass::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) (GetMetaTypeType() == MetaTypeType::Interface || GetMetaTypeType() == MetaTypeType::Shell) ) { bool bOk = true; - if( rInStm.Read( ':' ) ) + if( rInStm.ReadIf( ':' ) ) { aSuperClass = rBase.ReadKnownClass( rInStm ); bOk = aSuperClass.Is(); diff --git a/idl/source/objects/slot.cxx b/idl/source/objects/slot.cxx index 60960d2..894d316 100644 --- a/idl/source/objects/slot.cxx +++ b/idl/source/objects/slot.cxx @@ -283,7 +283,7 @@ void SvMetaSlot::ReadAttributesSvIdl( SvIdlDataBase & rBase, SvToken& rTok = rInStm.GetToken_Next(); if( rTok.Is( SvHash_SlotType() ) ) { - if( rInStm.Read( '=' ) ) + if( rInStm.ReadIf( '=' ) ) { aSlotType = rBase.ReadKnownType( rInStm ); if( !aSlotType.Is() ) diff --git a/idl/source/objects/types.cxx b/idl/source/objects/types.cxx index eb48cf6..d63e8c7 100644 --- a/idl/source/objects/types.cxx +++ b/idl/source/objects/types.cxx @@ -322,10 +322,10 @@ bool SvMetaType::ReadMethodArgs( SvIdlDataBase & rBase, SvTokenStream & rInStm ) { sal_uInt32 nTokPos = rInStm.Tell(); - if( rInStm.Read( '(' ) ) + if( rInStm.ReadIf( '(' ) ) { DoReadContextSvIdl( rBase, rInStm ); - if( rInStm.Read( ')' ) ) + if( rInStm.ReadIf( ')' ) ) { SetType( MetaTypeType::Method ); return true; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
