summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-02-11 15:41:48 +0200
committerNoel Grandin <noel@peralex.com>2016-02-12 09:13:43 +0200
commitf3f533f0c60d90fb723ecf417ce3a20bc38fa6c7 (patch)
tree739ba2608f0c53c2b121384a9c55a2584a466638
parente60296840bf9da3f61a3cce02e1369e4315354b3 (diff)
move module parsing into SvIdlParser class
Change-Id: I99937935a1d41fa5b0ff6c2f5e92bde3b4847e9f
-rw-r--r--idl/inc/module.hxx12
-rw-r--r--idl/inc/parser.hxx6
-rw-r--r--idl/source/objects/module.cxx136
-rw-r--r--idl/source/prj/parser.cxx185
4 files changed, 168 insertions, 171 deletions
diff --git a/idl/inc/module.hxx b/idl/inc/module.hxx
index ce5f8db0f236..6ac8fcd07acf 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 97cb3d50d29d..b1f9a67b4956 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 b364ddf7bedc..11b31cbe84f8 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 065c3e200949..99a14bce8fa8 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: */