Kaydet (Commit) ac432839 authored tarafından Noel Grandin's avatar Noel Grandin

move item and struct parsing into SvIdlParser

Change-Id: I1ba88bca82b5b251ed34330ab5e0cb8bd88a5815
üst d4a10f00
......@@ -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
......
......@@ -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
......
......@@ -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()
{
}
......
......@@ -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 );
......
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment