summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-02-12 13:09:24 +0200
committerNoel Grandin <noel@peralex.com>2016-02-15 15:47:30 +0200
commitac432839329866659e339b582d31a1980c035c2e (patch)
treef1fcf2470e4182cdbb2ac005229016372238666d
parentd4a10f00c96c2fc4be2755873f6b26e72a996ca6 (diff)
move item and struct parsing into SvIdlParser
Change-Id: I1ba88bca82b5b251ed34330ab5e0cb8bd88a5815
-rw-r--r--idl/inc/parser.hxx6
-rw-r--r--idl/inc/types.hxx8
-rw-r--r--idl/source/objects/types.cxx30
-rw-r--r--idl/source/prj/database.cxx25
-rw-r--r--idl/source/prj/parser.cxx104
5 files changed, 92 insertions, 81 deletions
diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx
index 9284096d2b7e..8418d0be77da 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 47c56722bab1..3be88e1b2eb8 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 c5c799d83dc2..13174100b1ff 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 96c4e3a0f802..00f2ab18b9c1 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 3f8f09d8acc1..f2bc458e4b24 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: */