[Libreoffice-commits] core.git: 3 commits - idl/inc idl/source

Noel Grandin noelgrandin at gmail.com
Wed Jun 22 07:27:40 UTC 2016


 idl/inc/parser.hxx             |    9 +
 idl/inc/slot.hxx               |    2 
 idl/source/objects/bastype.cxx |   19 +--
 idl/source/prj/parser.cxx      |  207 +++++++++++++++++++++++++++++++++--------
 4 files changed, 182 insertions(+), 55 deletions(-)

New commits:
commit 3e53c6ba9313dae334c0b4db78c911fa960a9fe2
Author: Noel Grandin <noelgrandin at gmail.com>
Date:   Fri Mar 11 14:05:30 2016 +0200

    move the attribute parsing code to SvParser
    
    and simplify considerably
    
    Change-Id: I2a4af15e77904b62abc81dad78a2990e2eab05f0

diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx
index d4d6abb..cc2696b 100644
--- a/idl/inc/parser.hxx
+++ b/idl/inc/parser.hxx
@@ -30,6 +30,7 @@ class SvMetaTypeEnum;
 class SvStringHashEntry;
 class SvMetaType;
 class SvMetaClass;
+class SvBOOL;
 
 class SvIdlParser
 {
@@ -44,16 +45,19 @@ public:
     void         ReadInclude( SvMetaModule& rModule );
     void         ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMetaTypeType );
     void         ReadInterfaceOrShellEntry( SvMetaClass& rClass );
-    bool         ReadInterfaceOrShellSlot( SvMetaSlot& rSlot );
+    bool         ReadSlot( SvMetaSlot& rSlot );
     void         ReadInterfaceOrShellMethod( SvMetaAttribute& rAttr );
     void         ReadItem();
     void         ReadStruct();
     void         ReadEnum();
     void         ReadEnumValue( SvMetaTypeEnum& rEnum );
     void         ReadSlotId(SvIdentifier& rSlotId);
+    void         ReadSlotAttribute( SvMetaSlot& rSlot );
     SvMetaClass* ReadKnownClass();
     SvMetaType*  ReadKnownType();
     void         Read(char cChar);
+    bool         ReadIfBoolAttribute( SvBOOL&, SvStringHashEntry* pName);
+    bool         ReadIfIdAttribute( SvIdentifier& rIdentifier, SvStringHashEntry* pName );
     bool         ReadIf(char cChar);
     void         ReadDelimiter();
     bool         ReadIfDelimiter();
diff --git a/idl/inc/slot.hxx b/idl/inc/slot.hxx
index 93f127d..bb80784 100644
--- a/idl/inc/slot.hxx
+++ b/idl/inc/slot.hxx
@@ -25,6 +25,7 @@
 
 class SvMetaSlot : public SvMetaAttribute
 {
+public:
     tools::SvRef<SvMetaType>      aSlotType;
     tools::SvRef<SvMetaSlot>      aMethod;
     SvIdentifier     aGroupId;
@@ -69,7 +70,6 @@ class SvMetaSlot : public SvMetaAttribute
     bool            IsVariable() const;
     bool            IsMethod() const;
 
-protected:
     void    SetToggle( bool bSet ) { aToggle = bSet; }
     void    SetAutoUpdate( bool bSet ) { aAutoUpdate = bSet; }
     void    SetAsynchron( bool bSet ) { aAsynchron = bSet; }
diff --git a/idl/source/objects/bastype.cxx b/idl/source/objects/bastype.cxx
index 08c59f9..adff4d5 100644
--- a/idl/source/objects/bastype.cxx
+++ b/idl/source/objects/bastype.cxx
@@ -35,24 +35,17 @@ bool SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
 
     if( rTok.Is( pName ) )
     {
-        bool bOk = true;
-        bool bBracket = rInStm.ReadIf( '(' );
-        if( bBracket || rInStm.ReadIf( '=' ) )
+        if( rInStm.ReadIf( '=' ) )
         {
             rTok = rInStm.GetToken();
-            if( rTok.IsBool() )
-            {
-                *this = rTok.GetBool();
-
-                rInStm.GetToken_Next();
-            }
-            if( bOk && bBracket )
-                bOk = rInStm.ReadIf( ')' );
+            if( !rTok.IsBool() )
+                throw SvParseException(rInStm, "xxx");
+            *this = rTok.GetBool();
+            rInStm.GetToken_Next();
         }
         else
             *this = true; //default action set to TRUE
-        if( bOk )
-            return true;
+        return true;
     }
     rInStm.Seek( nTokPos );
     return false;
diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx
index 1438bec..849bf4c 100644
--- a/idl/source/prj/parser.cxx
+++ b/idl/source/prj/parser.cxx
@@ -114,7 +114,7 @@ void SvIdlParser::ReadModuleElement( SvMetaModule& rModule )
     {
         tools::SvRef<SvMetaSlot> xSlot( new SvMetaSlot() );
 
-        if( xSlot->ReadSvIdl( rBase, rInStm ) )
+        if (ReadSlot(*xSlot))
         {
             if( xSlot->Test( rInStm ) )
             {
@@ -311,7 +311,7 @@ void SvIdlParser::ReadInterfaceOrShellEntry(SvMetaClass& rClass)
         if( !pType || pType->IsItem() )
         {
             xAttr = new SvMetaSlot( pType );
-            bOk = ReadInterfaceOrShellSlot(static_cast<SvMetaSlot&>(*xAttr));
+            bOk = ReadSlot(static_cast<SvMetaSlot&>(*xAttr));
         }
         else
         {
@@ -332,7 +332,7 @@ void SvIdlParser::ReadInterfaceOrShellEntry(SvMetaClass& rClass)
     }
 }
 
-bool SvIdlParser::ReadInterfaceOrShellSlot(SvMetaSlot& rSlot)
+bool SvIdlParser::ReadSlot(SvMetaSlot& rSlot)
 {
     sal_uInt32  nTokPos = rInStm.Tell();
     bool        bOk     = true;
@@ -351,7 +351,7 @@ bool SvIdlParser::ReadInterfaceOrShellSlot(SvMetaSlot& rSlot)
             while( nBeginPos != rInStm.Tell() )
             {
                 nBeginPos = rInStm.Tell();
-                rSlot.ReadAttributesSvIdl( rBase, rInStm );
+                ReadSlotAttribute(rSlot);
                 ReadIfDelimiter();
             }
             Read( ']' );
@@ -379,6 +379,98 @@ bool SvIdlParser::ReadInterfaceOrShellSlot(SvMetaSlot& rSlot)
     return bOk;
 }
 
+void SvIdlParser::ReadSlotAttribute( SvMetaSlot& rSlot )
+{
+    bool bOk = false;
+    bOk |= ReadIfBoolAttribute(rSlot.aPseudoSlots, SvHash_PseudoSlots() );
+    bOk |= ReadIfIdAttribute(rSlot.aGroupId, SvHash_GroupId() );
+    bOk |= ReadIfIdAttribute(rSlot.aExecMethod, SvHash_ExecMethod() );
+    bOk |= ReadIfIdAttribute(rSlot.aStateMethod, SvHash_StateMethod() );
+    bOk |= ReadStringSvIdl( SvHash_DisableFlags(), rInStm, rSlot.aDisableFlags );
+    bOk |= ReadIfBoolAttribute(rSlot.aReadOnlyDoc, SvHash_ReadOnlyDoc() );
+    bOk |= ReadIfBoolAttribute(rSlot.aExport, SvHash_Export() );
+
+    bOk |= ReadIfBoolAttribute(rSlot.aToggle, SvHash_Toggle() );
+    bOk |= ReadIfBoolAttribute(rSlot.aAutoUpdate, SvHash_AutoUpdate() );
+    bOk |= ReadIfBoolAttribute(rSlot.aAsynchron, SvHash_Asynchron() );
+    bOk |= ReadIfBoolAttribute(rSlot.aRecordAbsolute, SvHash_RecordAbsolute() );
+
+    if( ReadIfBoolAttribute(rSlot.aRecordPerItem, SvHash_RecordPerItem()) )
+    {
+        if (rSlot.aRecordPerSet.IsSet() || rSlot.aNoRecord.IsSet())
+            throw SvParseException(rInStm, "conflicting attributes");
+        rSlot.SetRecordPerItem( rSlot.aRecordPerItem );
+        bOk = true;
+    }
+    if( ReadIfBoolAttribute(rSlot.aRecordPerSet, SvHash_RecordPerSet() ) )
+    {
+        if (rSlot.aRecordPerItem.IsSet() || rSlot.aNoRecord.IsSet())
+            throw SvParseException(rInStm, "conflicting attributes");
+        rSlot.SetRecordPerSet( rSlot.aRecordPerSet );
+        bOk = true;
+    }
+    if( ReadIfBoolAttribute(rSlot.aNoRecord, SvHash_NoRecord() ) )
+    {
+        if (rSlot.aRecordPerItem.IsSet() || rSlot.aRecordPerSet.IsSet())
+            throw SvParseException(rInStm, "conflicting attributes");
+        rSlot.SetNoRecord( rSlot.aNoRecord );
+        bOk = true;
+    }
+
+    bOk |= ReadIfIdAttribute(rSlot.aPseudoPrefix, SvHash_PseudoPrefix() );
+    bOk |= ReadIfBoolAttribute(rSlot.aMenuConfig, SvHash_MenuConfig() );
+    bOk |= ReadIfBoolAttribute(rSlot.aToolBoxConfig, SvHash_ToolBoxConfig() );
+    bOk |= ReadIfBoolAttribute(rSlot.aAccelConfig, SvHash_AccelConfig() );
+
+    bOk |= ReadIfBoolAttribute(rSlot.aFastCall, SvHash_FastCall() );
+    bOk |= ReadIfBoolAttribute(rSlot.aContainer, SvHash_Container() );
+    bOk |= ReadIfBoolAttribute(rSlot.aImageRotation, SvHash_ImageRotation() );
+    bOk |= ReadIfBoolAttribute(rSlot.aImageReflection, SvHash_ImageReflection() );
+
+    if( bOk )
+        return;
+
+    if( !rSlot.aSlotType.Is() )
+    {
+        sal_uInt32 nTokPos = rInStm.Tell();
+        SvToken& rTok = rInStm.GetToken_Next();
+        if( rTok.Is( SvHash_SlotType() ) )
+        {
+            if( rInStm.ReadIf( '=' ) )
+            {
+                rSlot.aSlotType = rBase.ReadKnownType( rInStm );
+                if( !rSlot.aSlotType.Is() )
+                    throw SvParseException( rInStm, "SlotType with unknown item type" );
+                if( !rSlot.aSlotType->IsItem() )
+                    throw SvParseException( rInStm, "the SlotType is not a item" );
+                return;
+            }
+        }
+        rInStm.Seek( nTokPos );
+
+    }
+    if( !rSlot.aMethod.Is() )
+    {
+        SvToken& rTok = rInStm.GetToken();
+        if( rTok.IsIdentifier() )
+        {
+            rSlot.aMethod = new SvMetaSlot();
+            sal_uInt32 nTokPos = rInStm.Tell();
+            if( rSlot.aMethod->ReadSvIdl( rBase, rInStm ) )
+            {
+                if( rSlot.aMethod->IsMethod() )
+                {
+                    rSlot.aMethod->SetSlotId( rSlot.GetSlotId() );
+                    if( rSlot.aMethod->Test( rInStm ) )
+                        return;
+                }
+                rInStm.Seek( nTokPos );
+            }
+            rSlot.aMethod.Clear();
+        }
+    }
+}
+
 void SvIdlParser::ReadInterfaceOrShellMethod( SvMetaAttribute& rAttr )
 {
     rAttr.SetName( ReadIdentifier() );
@@ -435,6 +527,49 @@ SvMetaType * SvIdlParser::ReadKnownType()
     throw SvParseException( rInStm, "wrong typedef: ");
 }
 
+bool SvIdlParser::ReadIfBoolAttribute( SvBOOL& rBool, SvStringHashEntry * pName )
+{
+    sal_uInt32 nTokPos = rInStm.Tell();
+    SvToken& rTok = rInStm.GetToken_Next();
+
+    if( rTok.Is( pName ) )
+    {
+        if( rInStm.ReadIf( '=' ) )
+        {
+            rTok = rInStm.GetToken();
+            if( !rTok.IsBool() )
+                throw SvParseException(rInStm, "xxx");
+            rBool = rTok.GetBool();
+            rInStm.GetToken_Next();
+        }
+        else
+            rBool = true; //default action set to TRUE
+        return true;
+    }
+    rInStm.Seek( nTokPos );
+    return false;
+}
+
+bool SvIdlParser::ReadIfIdAttribute( SvIdentifier& rIdentifier, SvStringHashEntry * pName )
+{
+    sal_uInt32 nTokPos = rInStm.Tell();
+    SvToken& rTok = rInStm.GetToken_Next();
+
+    if( rTok.Is( pName ) )
+    {
+        if( rInStm.ReadIf( '=' ) )
+        {
+            rTok = rInStm.GetToken();
+            if( !rTok.IsIdentifier() )
+                throw SvParseException(rInStm, "expected identifier");
+            rIdentifier.setString(rTok.GetString());
+            rInStm.GetToken_Next();
+        }
+        return true;
+    }
+    rInStm.Seek( nTokPos );
+    return false;
+}
 
 void SvIdlParser::ReadDelimiter()
 {
commit 5a39ad3b259a20fa1c78e34ca9146dcec7fe90b0
Author: Noel Grandin <noelgrandin at gmail.com>
Date:   Fri Mar 11 10:38:44 2016 +0200

    move the method param parsing code into SvParser
    
    Change-Id: I5718c309acd213f94e96efc2e9a98ab0344fe341

diff --git a/idl/inc/parser.hxx b/idl/inc/parser.hxx
index 7f6186c..d4d6abb 100644
--- a/idl/inc/parser.hxx
+++ b/idl/inc/parser.hxx
@@ -45,11 +45,12 @@ public:
     void         ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMetaTypeType );
     void         ReadInterfaceOrShellEntry( SvMetaClass& rClass );
     bool         ReadInterfaceOrShellSlot( SvMetaSlot& rSlot );
-    void         ReadInterfaceOrShellMethodOrAttribute( SvMetaAttribute& rAttr );
+    void         ReadInterfaceOrShellMethod( SvMetaAttribute& rAttr );
     void         ReadItem();
     void         ReadStruct();
     void         ReadEnum();
     void         ReadEnumValue( SvMetaTypeEnum& rEnum );
+    void         ReadSlotId(SvIdentifier& rSlotId);
     SvMetaClass* ReadKnownClass();
     SvMetaType*  ReadKnownType();
     void         Read(char cChar);
diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx
index a71e367..1438bec 100644
--- a/idl/source/prj/parser.cxx
+++ b/idl/source/prj/parser.cxx
@@ -316,7 +316,7 @@ void SvIdlParser::ReadInterfaceOrShellEntry(SvMetaClass& rClass)
         else
         {
             xAttr = new SvMetaAttribute( pType );
-            ReadInterfaceOrShellMethodOrAttribute(*xAttr);
+            ReadInterfaceOrShellMethod(*xAttr);
             bOk = true;
         }
         if( bOk )
@@ -354,7 +354,7 @@ bool SvIdlParser::ReadInterfaceOrShellSlot(SvMetaSlot& rSlot)
                 rSlot.ReadAttributesSvIdl( rBase, rInStm );
                 ReadIfDelimiter();
             }
-            bOk = ReadIf( ']' );
+            Read( ']' );
         }
     }
     else
@@ -379,17 +379,13 @@ bool SvIdlParser::ReadInterfaceOrShellSlot(SvMetaSlot& rSlot)
     return bOk;
 }
 
-void SvIdlParser::ReadInterfaceOrShellMethodOrAttribute( SvMetaAttribute& rAttr )
+void SvIdlParser::ReadInterfaceOrShellMethod( SvMetaAttribute& rAttr )
 {
     rAttr.SetName( ReadIdentifier() );
-    rAttr.aSlotId.setString( ReadIdentifier() );
-    sal_uLong n;
-    if( !rBase.FindId( rAttr.aSlotId.getString(), &n ) )
-        throw SvParseException( rInStm, "no value for identifier <" + rAttr.aSlotId.getString() + "> " );
-    rAttr.aSlotId.SetValue(n);
+    ReadSlotId( rAttr.aSlotId );
 
-    Read( '(' );
     // read method arguments
+    Read( '(' );
     tools::SvRef<SvMetaType> xT(new SvMetaType() );
     xT->SetRef(rAttr.GetType() );
     rAttr.aType = xT;
@@ -398,12 +394,11 @@ void SvIdlParser::ReadInterfaceOrShellMethodOrAttribute( SvMetaAttribute& rAttr
     {
         while (true)
         {
-            tools::SvRef<SvMetaAttribute> xAttr( new SvMetaAttribute() );
-            if( !xAttr->ReadSvIdl( rBase, rInStm ) )
-                throw SvParseException(rInStm, "ReadSvIdl in method argument parsing failed");
-            if( !xAttr->Test( rInStm ) )
-                throw SvParseException(rInStm, "test in method argument parsing failed");
-            rAttr.aType->GetAttrList().push_back( xAttr );
+            tools::SvRef<SvMetaAttribute> xParamAttr( new SvMetaAttribute() );
+            xParamAttr->aType = ReadKnownType();
+            xParamAttr->SetName( ReadIdentifier() );
+            ReadSlotId(xParamAttr->aSlotId);
+            rAttr.aType->GetAttrList().push_back( xParamAttr );
             if (!ReadIfDelimiter())
                 break;
         }
@@ -411,6 +406,15 @@ void SvIdlParser::ReadInterfaceOrShellMethodOrAttribute( SvMetaAttribute& rAttr
     }
 }
 
+void SvIdlParser::ReadSlotId(SvIdentifier& rSlotId)
+{
+    rSlotId.setString( ReadIdentifier() );
+    sal_uLong n;
+    if( !rBase.FindId( rSlotId.getString(), &n ) )
+        throw SvParseException( rInStm, "no value for identifier <" + rSlotId.getString() + "> " );
+    rSlotId.SetValue(n);
+}
+
 SvMetaClass * SvIdlParser::ReadKnownClass()
 {
     OString aName(ReadIdentifier());
@@ -470,9 +474,8 @@ OString SvIdlParser::ReadString()
 
 void SvIdlParser::Read(char cChar)
 {
-    if( !(rInStm.GetToken().IsChar() && rInStm.GetToken().GetChar() == cChar ) )
+    if( !ReadIf(cChar) )
         throw SvParseException(rInStm, "expected char '" + OString(cChar) + "'");
-    rInStm.GetToken_Next();
 }
 
 bool SvIdlParser::ReadIf(char cChar)
commit dc1df1b8f92b873b0776bff4ca3da79af05392ba
Author: Noel Grandin <noel at peralex.com>
Date:   Tue Jun 21 14:13:53 2016 +0200

    simplify parser
    
    Change-Id: If6b9ed2a0cb373c8bec5d3ff20488f5ee00231ff

diff --git a/idl/source/prj/parser.cxx b/idl/source/prj/parser.cxx
index cb2cd8b..a71e367 100644
--- a/idl/source/prj/parser.cxx
+++ b/idl/source/prj/parser.cxx
@@ -182,10 +182,8 @@ void SvIdlParser::ReadStruct()
     xStruct->SetType( MetaTypeType::Struct );
     xStruct->SetName( ReadIdentifier() );
     Read( '{' );
-    sal_uInt32 nBeginPos = 0; // can not happen with Tell
-    while( nBeginPos != rInStm.Tell() )
+    while( true )
     {
-        nBeginPos = rInStm.Tell();
         tools::SvRef<SvMetaAttribute> xAttr( new SvMetaAttribute() );
         xAttr->aType = ReadKnownType();
         xAttr->SetName(ReadIdentifier());
@@ -293,25 +291,20 @@ void SvIdlParser::ReadInterfaceOrShell( SvMetaModule& rModule, MetaTypeType aMet
 
 void SvIdlParser::ReadInterfaceOrShellEntry(SvMetaClass& rClass)
 {
-    sal_uInt32  nTokPos = rInStm.Tell();
-    SvToken&    rTok = rInStm.GetToken_Next();
-
-    if( rTok.Is( SvHash_import() ) )
+    if( ReadIf( SvHash_import() ) )
     {
         SvMetaClass * pClass = ReadKnownClass();
         SvClassElement aEle(pClass);
-        rTok = rInStm.GetToken();
+        SvToken& rTok = rInStm.GetToken();
         if( rTok.IsString() )
         {
             aEle.SetPrefix( rTok.GetString() );
             rInStm.GetToken_Next();
         }
         rClass.aClassElementList.push_back( aEle );
-        return;
     }
     else
     {
-        rInStm.Seek( nTokPos );
         SvMetaType * pType = rBase.ReadKnownType( rInStm );
         tools::SvRef<SvMetaAttribute> xAttr;
         bool bOk = false;
@@ -335,10 +328,8 @@ void SvIdlParser::ReadInterfaceOrShellEntry(SvMetaClass& rClass)
             if( !xAttr->GetSlotId().IsSet() )
                 xAttr->SetSlotId( SvIdentifier(rBase.GetUniqueId()) );
             rClass.aAttrList.push_back( xAttr );
-            return;
         }
     }
-    rInStm.Seek( nTokPos );
 }
 
 bool SvIdlParser::ReadInterfaceOrShellSlot(SvMetaSlot& rSlot)
@@ -402,20 +393,22 @@ void SvIdlParser::ReadInterfaceOrShellMethodOrAttribute( SvMetaAttribute& rAttr
     tools::SvRef<SvMetaType> xT(new SvMetaType() );
     xT->SetRef(rAttr.GetType() );
     rAttr.aType = xT;
-    sal_uInt32 nBeginPos = 0; // can not happen with Tell
-    while( nBeginPos != rInStm.Tell() )
+    rAttr.aType->SetType( MetaTypeType::Method );
+    if (!ReadIf(')'))
     {
-        nBeginPos = rInStm.Tell();
-        tools::SvRef<SvMetaAttribute> xAttr( new SvMetaAttribute() );
-        if( xAttr->ReadSvIdl( rBase, rInStm ) )
+        while (true)
         {
-            if( xAttr->Test( rInStm ) )
-                rAttr.aType->GetAttrList().push_back( xAttr );
+            tools::SvRef<SvMetaAttribute> xAttr( new SvMetaAttribute() );
+            if( !xAttr->ReadSvIdl( rBase, rInStm ) )
+                throw SvParseException(rInStm, "ReadSvIdl in method argument parsing failed");
+            if( !xAttr->Test( rInStm ) )
+                throw SvParseException(rInStm, "test in method argument parsing failed");
+            rAttr.aType->GetAttrList().push_back( xAttr );
+            if (!ReadIfDelimiter())
+                break;
         }
-        ReadIfDelimiter();
+        Read(')');
     }
-    Read( ')' );
-    rAttr.aType->SetType( MetaTypeType::Method );
 }
 
 SvMetaClass * SvIdlParser::ReadKnownClass()
@@ -433,9 +426,7 @@ SvMetaType * SvIdlParser::ReadKnownType()
     for( const auto& aType : rBase.GetTypeList() )
     {
         if( aType->GetName() == aName )
-        {
             return aType;
-        }
     }
     throw SvParseException( rInStm, "wrong typedef: ");
 }


More information about the Libreoffice-commits mailing list