diff options
author | Noel Grandin <noel@peralex.com> | 2016-02-12 08:58:26 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2016-02-12 09:13:43 +0200 |
commit | b27dcabad349b68d2068dfe68924a5b0867f5ee9 (patch) | |
tree | 1f8810d1d321445b112ed76ba727dba1b3710450 /idl | |
parent | f3f533f0c60d90fb723ecf417ce3a20bc38fa6c7 (diff) |
move parsing of enum into SvIdlParser
Change-Id: I89eef20d62f92f7345750c48c34c9f3b7bca287e
Diffstat (limited to 'idl')
-rw-r--r-- | idl/inc/lex.hxx | 4 | ||||
-rw-r--r-- | idl/inc/module.hxx | 2 | ||||
-rw-r--r-- | idl/inc/parser.hxx | 6 | ||||
-rw-r--r-- | idl/inc/types.hxx | 6 | ||||
-rw-r--r-- | idl/source/objects/types.cxx | 54 | ||||
-rw-r--r-- | idl/source/prj/command.cxx | 2 | ||||
-rw-r--r-- | idl/source/prj/parser.cxx | 127 |
7 files changed, 110 insertions, 91 deletions
diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx index a9869de4c2ed..7780a36a49ec 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 6ac8fcd07acf..93f335a23449 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 b1f9a67b4956..67f63e3fe0fc 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 748dc6ef637d..47c56722bab1 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 d63e8c7801d2..c5c799d83dc2 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 2095ad267c3b..3b4467948526 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 99a14bce8fa8..33096e540210 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: */ |