From 314cb543fe69d2a08fa40084512f40062437bed1 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 16 Feb 2016 08:55:36 +0200 Subject: parse shell/interface entries in SvIdlParser Change-Id: Ief68b26be0a0890ffdfa02a5904ba9d2cb364c65 --- idl/inc/bastype.hxx | 1 + idl/inc/object.hxx | 6 +-- idl/inc/parser.hxx | 4 ++ idl/inc/types.hxx | 3 +- idl/source/objects/object.cxx | 2 +- idl/source/prj/parser.cxx | 118 +++++++++++++++++++++++++++++++++++++++++- 6 files changed, 127 insertions(+), 7 deletions(-) (limited to 'idl') diff --git a/idl/inc/bastype.hxx b/idl/inc/bastype.hxx index ef7a88c2e144..afe3642d10e0 100644 --- a/idl/inc/bastype.hxx +++ b/idl/inc/bastype.hxx @@ -52,6 +52,7 @@ class SvIdentifier sal_uInt32 nValue; public: SvIdentifier() : nValue( 0 ) {}; + SvIdentifier(sal_uInt32 n) : nValue( n ) {}; void setString(const OString& rStr) { m_aStr = rStr; } const OString& getString() const { return m_aStr; } diff --git a/idl/inc/object.hxx b/idl/inc/object.hxx index 12f5af2b06ac..6d56eebeceac 100644 --- a/idl/inc/object.hxx +++ b/idl/inc/object.hxx @@ -50,12 +50,12 @@ class SvMetaClass : public SvMetaType { public: tools::SvRef aSuperClass; -private: - SvRefMemberList aAttrList; std::vector aClassElementList; - + SvRefMemberList aAttrList; bool TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm, SvMetaAttribute & rAttr ) const; +private: + static void WriteSlotStubs( const OString& rShellName, SvSlotElementList & rSlotList, ByteStringList & rList, diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx index 225836967c00..78a62af53ca1 100644 --- a/idl/inc/parser.hxx +++ b/idl/inc/parser.hxx @@ -29,6 +29,7 @@ class SvMetaModule; class SvMetaTypeEnum; class SvStringHashEntry; class SvMetaType; +class SvMetaClass; class SvIdlParser { @@ -42,6 +43,9 @@ public: void ReadModuleElement( SvMetaModule& rModule ); void ReadInclude( SvMetaModule& rModule ); void ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMetaTypeType ); + void ReadInterfaceOrShellEntry( SvMetaClass& rClass ); + bool ReadInterfaceOrShellSlot( SvMetaSlot& rSlot ); + bool ReadInterfaceOrShellAttribute( SvMetaAttribute& rAttr ); void ReadItem(); void ReadStruct(); void ReadEnum(); diff --git a/idl/inc/types.hxx b/idl/inc/types.hxx index 3be88e1b2eb8..ec7a0de281ee 100644 --- a/idl/inc/types.hxx +++ b/idl/inc/types.hxx @@ -30,10 +30,9 @@ typedef SvRefMemberList< SvMetaSlot* > SvSlotElementList; class SvMetaAttribute : public SvMetaReference { -protected: +public: virtual void ReadAttributesSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm ) override; -public: tools::SvRef aType; SvIdentifier aSlotId; SvMetaAttribute(); diff --git a/idl/source/objects/object.cxx b/idl/source/objects/object.cxx index 711ca195f915..31b6515a30ee 100644 --- a/idl/source/objects/object.cxx +++ b/idl/source/objects/object.cxx @@ -102,7 +102,7 @@ void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase, bool SvMetaClass::TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm, SvMetaAttribute & rAttr ) const { - if ( !rAttr.GetRef() && dynamic_cast(&rAttr) != nullptr ) + if ( !rAttr.GetRef() && dynamic_cast(&rAttr) ) { OSL_FAIL( "Neuer Slot : " ); OSL_FAIL( rAttr.GetSlotId().getString().getStr() ); diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx index 8f368b4d2c32..777359859b50 100644 --- a/idl/source/prj/parser.cxx +++ b/idl/source/prj/parser.cxx @@ -292,7 +292,7 @@ void SvIdlParser::ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMet while( nBeginPos != rInStm.Tell() ) { nBeginPos = rInStm.Tell(); - aClass->ReadContextSvIdl( rBase, rInStm ); + ReadInterfaceOrShellEntry(*aClass); rInStm.ReadIfDelimiter(); } ReadChar( '}' ); @@ -302,6 +302,122 @@ void SvIdlParser::ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMet rBase.GetClassList().push_back( aClass ); } +void SvIdlParser::ReadInterfaceOrShellEntry(SvMetaClass& rClass) +{ + sal_uInt32 nTokPos = rInStm.Tell(); + SvToken& rTok = rInStm.GetToken_Next(); + + if( rTok.Is( SvHash_import() ) ) + { + SvMetaClass * pClass = rBase.ReadKnownClass( rInStm ); + if( !pClass ) + throw SvParseException( rInStm, "unknown imported interface" ); + SvClassElement xEle; + xEle.SetClass( pClass ); + rClass.aClassElementList.push_back( xEle ); + + rTok = rInStm.GetToken(); + if( rTok.IsString() ) + { + xEle.SetPrefix( rTok.GetString() ); + rInStm.GetToken_Next(); + } + return; + } + else + { + rInStm.Seek( nTokPos ); + SvMetaType * pType = rBase.ReadKnownType( rInStm ); + tools::SvRef xAttr; + bool bOk = false; + if( !pType || pType->IsItem() ) + { + xAttr = new SvMetaSlot( pType ); + bOk = ReadInterfaceOrShellSlot(static_cast(*xAttr)); + } + else + { + xAttr = new SvMetaAttribute( pType ); + bOk = ReadInterfaceOrShellAttribute(*xAttr); + } + if( bOk ) + bOk = xAttr->Test( rInStm ); + if( bOk ) + bOk = rClass.TestAttribute( rBase, rInStm, *xAttr ); + if( bOk ) + { + if( !xAttr->GetSlotId().IsSet() ) + xAttr->SetSlotId( SvIdentifier(rBase.GetUniqueId()) ); + rClass.aAttrList.push_back( xAttr ); + return; + } + } + rInStm.Seek( nTokPos ); +} + +bool SvIdlParser::ReadInterfaceOrShellSlot(SvMetaSlot& rSlot) +{ + sal_uInt32 nTokPos = rInStm.Tell(); + bool bOk = true; + + SvMetaAttribute * pAttr = rBase.ReadKnownAttr( rInStm, rSlot.GetType() ); + if( pAttr ) + { + SvMetaSlot * pKnownSlot = dynamic_cast( pAttr ); + if( !pKnownSlot ) + throw SvParseException( rInStm, "attribute " + pAttr->GetName() + " is method or variable but not a slot" ); + rSlot.SetRef( pKnownSlot ); + rSlot.SetName( pKnownSlot->GetName() ); + bOk = rSlot.SvMetaObject::ReadSvIdl( rBase, rInStm ); + } + else + { + bOk = rSlot.SvMetaAttribute::ReadSvIdl( rBase, rInStm ); + SvMetaAttribute *pAttr2 = rBase.SearchKnownAttr( rSlot.GetSlotId() ); + if( pAttr2 ) + { + SvMetaSlot * pKnownSlot = dynamic_cast( pAttr2 ); + if( !pKnownSlot ) + throw SvParseException( rInStm, "attribute " + pAttr2->GetName() + " is method or variable but not a slot" ); + rSlot.SetRef( pKnownSlot ); + // names may differ, because explicitly given + if ( pKnownSlot->GetName() != rSlot.GetName() ) + throw SvParseException( rInStm, "Illegal definition!" ); + } + } + + if( !bOk ) + rInStm.Seek( nTokPos ); + + return bOk; +} + +bool SvIdlParser::ReadInterfaceOrShellAttribute( SvMetaAttribute& rAttr ) +{ + sal_uInt32 nTokPos = rInStm.Tell(); + bool bOk = false; + rAttr.SetName( ReadIdentifier() ); + rAttr.aSlotId.ReadSvIdl( rBase, rInStm ); + + bOk = true; + SvToken& rTok = rInStm.GetToken(); + if( rTok.IsChar() && rTok.GetChar() == '(' ) + { + tools::SvRef xT(new SvMetaType() ); + xT->SetRef(rAttr.GetType() ); + rAttr.aType = xT; + bOk = rAttr.aType->ReadMethodArgs( rBase, rInStm ); + } + if( bOk && rInStm.ReadIf( '[' ) ) + { + ReadChar( ']' ); + } + + if( !bOk ) + rInStm.Seek( nTokPos ); + return bOk; +} + SvMetaType * SvIdlParser::ReadKnownType() { OString aName = ReadIdentifier(); -- cgit